From nobody Thu Apr 25 15:24:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1590012192; cv=none; d=zohomail.com; s=zohoarc; b=nBcbuPTsyK7sBwTksQoy9EhVif1SgiKJazpqoIeFQj41sIxICNd+c50GnmWd2/7FBIac9Kh/I+ZiAZ4oP4D1RGFX/ALFsumTyIFc53L2IcDeuyGLadj5wxc2PCCD3AdjNHUD2oMh3P855xhyF9nhF0PJ4mPxHJbUPohHl03pcq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590012192; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f1TIUNaxqUfftacYSKNFTNyWmHUN2ovlEP7oiPq5BTw=; b=Wo27jY4JiUAX1t8gHgEzqGVuMcnVm1yL7vzTzLCvLV9eQ2U4BaFBAM/8nVtQftrp63/naNbz9tO+ooWwWM2oNWuxYWn1bAYZwzVrbd5xsNNCQ81JjMUfj97ycwEQMnR0QKYMyKJxhftPX8GZHlw2/lab1gqeHJg/MrDf6W/LD4o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590012192000576.835508332484; Wed, 20 May 2020 15:03:12 -0700 (PDT) Received: from localhost ([::1]:59042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbWnu-0007Gr-9F for importer@patchew.org; Wed, 20 May 2020 18:03:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbWmI-00052L-2L for qemu-devel@nongnu.org; Wed, 20 May 2020 18:01:30 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:53293 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jbWmF-0005in-AB for qemu-devel@nongnu.org; Wed, 20 May 2020 18:01:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-150-AzyJcU7oPcqnXqs5xHrlyQ-1; Wed, 20 May 2020 18:01:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 081A91005510; Wed, 20 May 2020 22:01:22 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-88.phx2.redhat.com [10.3.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 382196AD00; Wed, 20 May 2020 22:01:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590012085; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f1TIUNaxqUfftacYSKNFTNyWmHUN2ovlEP7oiPq5BTw=; b=ED5PvccbrEIFVj+ZKvNbs02coO/4F1v02M/hNCzhPGyq3VV3C5n3ktuOGMHFX1sJUdkbR+ gDgIwzbAMk6ejJ3pnruzFRnS2l0Wp4qfn1oumecdVP05zNwoP+mJlKkRjq1okNnXEsCLJ/ oRqHOvmPref+AvHiWdRBAhHCMlaBG58= X-MC-Unique: AzyJcU7oPcqnXqs5xHrlyQ-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v5 1/5] iotests: Fix test 178 Date: Wed, 20 May 2020 17:01:14 -0500 Message-Id: <20200520220118.1037094-2-eblake@redhat.com> In-Reply-To: <20200520220118.1037094-1-eblake@redhat.com> References: <20200520220118.1037094-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 18:01:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, nsoffer@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" A recent change to qemu-img changed expected error message output, but 178 takes long enough to execute that it does not get run by 'make check' or './check -g quick'. Fixes: 43d589b074 Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/178.out.qcow2 | 2 +- tests/qemu-iotests/178.out.raw | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.= qcow2 index f59bf4b2fbc4..4b69524c80ee 100644 --- a/tests/qemu-iotests/178.out.qcow2 +++ b/tests/qemu-iotests/178.out.qcow2 @@ -13,7 +13,7 @@ qemu-img: Invalid option list: , qemu-img: Invalid parameter 'snapshot.foo' qemu-img: Failed in parsing snapshot param 'snapshot.foo' qemu-img: --output must be used with human or json as argument. -qemu-img: Image size must be less than 8 EiB! +qemu-img: Invalid image size specified. Must be between 0 and 922337203685= 4775807. qemu-img: Unknown file format 'foo' =3D=3D Size calculation for a new file (human) =3D=3D diff --git a/tests/qemu-iotests/178.out.raw b/tests/qemu-iotests/178.out.raw index 404ca908d8c2..20e17da115cb 100644 --- a/tests/qemu-iotests/178.out.raw +++ b/tests/qemu-iotests/178.out.raw @@ -13,7 +13,7 @@ qemu-img: Invalid option list: , qemu-img: Invalid parameter 'snapshot.foo' qemu-img: Failed in parsing snapshot param 'snapshot.foo' qemu-img: --output must be used with human or json as argument. -qemu-img: Image size must be less than 8 EiB! +qemu-img: Invalid image size specified. Must be between 0 and 922337203685= 4775807. qemu-img: Unknown file format 'foo' =3D=3D Size calculation for a new file (human) =3D=3D --=20 2.26.2 From nobody Thu Apr 25 15:24:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1590012227; cv=none; d=zohomail.com; s=zohoarc; b=dj5guqaUEn5NspTQFimds1V5t5INqFMsefkRUpKI+/hMG2cL22HJIRIWPGe5iSciLyDEBxcY4woYmP/xSdLGs/F5Bt5KlLFTxWseIp5JdaSLoI1tYInE9puqG1nCEeohv5rnfxSXSC+l/sO+Oml37GelHDLo/BtJS/aGR1myY9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590012227; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Xmdy/NNhStwXr8t2VRCx7vWf2DxDdTACLP6hjJPMxfI=; b=kDH7WmC39YDEvW0/yeVaOSqKLeDbjONrPoVFM/vvXUqq5CVqMBIm1zS9vPa8Mysd4s0Fw7pSEorslGwJQnx3qhN2v7tdRSHXL7OSi7j2sHVz4IXNCT+SV+rMkX4hq+N6Ab3N7VuJMCtWSJBNUihHuquTM7HYjIHan1q5KOCLTwI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590012227041705.290366402862; Wed, 20 May 2020 15:03:47 -0700 (PDT) Received: from localhost ([::1]:33210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbWoT-0000aP-Nm for importer@patchew.org; Wed, 20 May 2020 18:03:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbWmH-000521-W8 for qemu-devel@nongnu.org; Wed, 20 May 2020 18:01:30 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:24481 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jbWmF-0005iw-9X for qemu-devel@nongnu.org; Wed, 20 May 2020 18:01:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-118-pGVeIsqwP2iDEeq-lXGdfg-1; Wed, 20 May 2020 18:01:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03D6B107ACCA; Wed, 20 May 2020 22:01:23 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-88.phx2.redhat.com [10.3.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 502126AD00; Wed, 20 May 2020 22:01:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590012086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xmdy/NNhStwXr8t2VRCx7vWf2DxDdTACLP6hjJPMxfI=; b=WXtNfggPtWU1HqcJYTNlR9OPbXuEq0jXdZ2BunzLgT7pbTWlzidVr3iungRrl8tcmMin6m KOWFIPSUJRCxIf8lnC7Bo5PgW2/C5wHn+g1QeX4ILakR3u6U9pfuEzLM/GVdQKloZUPvUn wUelG1OV61Qi9/hZh0H5dCanCC64IOE= X-MC-Unique: pGVeIsqwP2iDEeq-lXGdfg-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v5 2/5] qcow2: Expose bitmaps' size during measure Date: Wed, 20 May 2020 17:01:15 -0500 Message-Id: <20200520220118.1037094-3-eblake@redhat.com> In-Reply-To: <20200520220118.1037094-1-eblake@redhat.com> References: <20200520220118.1037094-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 18:01:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org, Markus Armbruster , mreitz@redhat.com, nsoffer@redhat.com, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It's useful to know how much space can be occupied by qcow2 persistent bitmaps, even though such metadata is unrelated to the guest-visible data. Report this value as an additional QMP field, present when measuring an existing image and output format that both support bitmaps. Update iotest 178 and 190 to updated output, as well as new coverage in 190 demonstrating non-zero values made possible with the recently-added qemu-img bitmap command. On the command-line side, 'qemu-img measure' gains a new --bitmaps flag. When present, the bitmap size is rolled into the two existing measures (or errors if either the source image or destination format lacks bitmaps); when absent, there is never an error (for back-compat), but the output will instead include a new line item for bitmaps (which you would have to manually add), with that line being omitted in the same cases where passing --bitmaps would error. The behavior chosen here is symmetrical with the upcoming 'qemu-img convert --bitmaps' being added in the next patch: that is, either both commands will succeed (your qemu-img was new enough to do bitmap manipulations, AND you correctly measured and copied the bitmaps, even if that measurement was 0 because there was nothing to copy) or both fail (either your qemu-img is too old to understand --bitmaps, or it understands it but your choice of images do not support seamless transition of bitmaps because either source, destination, or both lack bitmap support). The addition of a new field demonstrates why we should always zero-initialize qapi C structs; while the qcow2 driver still fully populates all fields, the raw and crypto drivers had to be tweaked to avoid uninitialized data. See also: https://bugzilla.redhat.com/1779904 Reported-by: Nir Soffer Signed-off-by: Eric Blake --- docs/tools/qemu-img.rst | 12 ++++++- qapi/block-core.json | 15 ++++++--- block/qcow2.h | 2 ++ block/crypto.c | 2 +- block/qcow2-bitmap.c | 36 ++++++++++++++++++++ block/qcow2.c | 14 ++++++-- block/raw-format.c | 2 +- qemu-img.c | 25 ++++++++++++++ qemu-img-cmds.hx | 4 +-- tests/qemu-iotests/178.out.qcow2 | 16 +++++++++ tests/qemu-iotests/190 | 58 ++++++++++++++++++++++++++++++-- tests/qemu-iotests/190.out | 35 ++++++++++++++++++- 12 files changed, 205 insertions(+), 16 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 38d464ea3f23..9a8112fc9f58 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -593,7 +593,7 @@ Command description: For more information, consult ``include/block/block.h`` in QEMU's source code. -.. option:: measure [--output=3DOFMT] [-O OUTPUT_FMT] [-o OPTIONS] [--size= N | [--object OBJECTDEF] [--image-opts] [-f FMT] [-l SNAPSHOT_PARAM] FILEN= AME] +.. option:: measure [--output=3DOFMT] [-O OUTPUT_FMT] [-o OPTIONS] [--size= N | [--object OBJECTDEF] [--image-opts] [-f FMT] [--bitmaps] [-l SNAPSHOT_= PARAM] FILENAME] Calculate the file size required for a new image. This information can be used to size logical volumes or SAN LUNs appropriately for @@ -616,6 +616,7 @@ Command description: required size: 524288 fully allocated size: 1074069504 + bitmaps size: 0 The ``required size`` is the file size of the new image. It may be smal= ler than the virtual disk size if the image format supports compact represen= tation. @@ -625,6 +626,15 @@ Command description: occupy with the exception of internal snapshots, dirty bitmaps, vmstate = data, and other advanced image format features. + The ``bitmaps size`` is the additional size required in order to + copy bitmaps from a source image in addition to the guest-visible + data; the line is omitted if either source or destination lacks + bitmap support, or 0 if bitmaps are supported but there is nothing + to copy. If the ``--bitmaps`` option is in use, the bitmap size is + instead folded into the required and fully-allocated size for + convenience, rather than being a separate line item; using the + option will raise an error if bitmaps are not supported. + .. option:: snapshot [--object OBJECTDEF] [--image-opts] [-U] [-q] [-l | -= a SNAPSHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME List, apply, create or delete snapshots in image *FILENAME*. diff --git a/qapi/block-core.json b/qapi/block-core.json index 6fbacddab2cc..d5049c309380 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -636,18 +636,23 @@ # efficiently so file size may be smaller than virtual disk size. # # The values are upper bounds that are guaranteed to fit the new image fil= e. -# Subsequent modification, such as internal snapshot or bitmap creation, m= ay -# require additional space and is not covered here. +# Subsequent modification, such as internal snapshot or further bitmap +# creation, may require additional space and is not covered here. # -# @required: Size required for a new image file, in bytes. +# @required: Size required for a new image file, in bytes, when copying ju= st +# allocated guest-visible contents. # # @fully-allocated: Image file size, in bytes, once data has been written -# to all sectors. +# to all sectors, when copying just guest-visible conten= ts. +# +# @bitmaps: Additional size required if all the top-level bitmap metadata = in +# the source image were to be copied to the destination, present +# when the destination supports persistent bitmaps. (since 5.1) # # Since: 2.10 ## { 'struct': 'BlockMeasureInfo', - 'data': {'required': 'int', 'fully-allocated': 'int'} } + 'data': {'required': 'int', 'fully-allocated': 'int', '*bitmaps': 'int'}= } ## # @query-block: diff --git a/block/qcow2.h b/block/qcow2.h index 402e8acb1cb7..7ce2c23bdb7a 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -783,6 +783,8 @@ int qcow2_co_remove_persistent_dirty_bitmap(BlockDriver= State *bs, const char *name, Error **errp); bool qcow2_supports_persistent_dirty_bitmap(BlockDriverState *bs); +uint64_t qcow2_get_persistent_dirty_bitmap_size(BlockDriverState *bs, + uint32_t cluster_size); ssize_t coroutine_fn qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size, diff --git a/block/crypto.c b/block/crypto.c index b216e12c3154..973b57b3eb74 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -552,7 +552,7 @@ static BlockMeasureInfo *block_crypto_measure(QemuOpts = *opts, * Unallocated blocks are still encrypted so allocation status makes no * difference to the file size. */ - info =3D g_new(BlockMeasureInfo, 1); + info =3D g_new0(BlockMeasureInfo, 1); info->fully_allocated =3D luks_payload_size + size; info->required =3D luks_payload_size + size; return info; diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 1cf6d2ab77a3..7bf12502da8c 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1755,3 +1755,39 @@ bool qcow2_supports_persistent_dirty_bitmap(BlockDri= verState *bs) return s->qcow_version >=3D 3; } + +/* + * Compute the space required for bitmaps in @bs. + * + * The computation is based as if copying to a new image with the + * given @cluster_size, which may differ from the cluster size in @bs. + */ +uint64_t qcow2_get_persistent_dirty_bitmap_size(BlockDriverState *bs, + uint32_t cluster_size) +{ + uint64_t bitmaps_size =3D 0; + BdrvDirtyBitmap *bm; + size_t bitmap_dir_size =3D 0; + + FOR_EACH_DIRTY_BITMAP(bs, bm) { + if (bdrv_dirty_bitmap_get_persistence(bm)) { + const char *name =3D bdrv_dirty_bitmap_name(bm); + uint32_t granularity =3D bdrv_dirty_bitmap_granularity(bm); + uint64_t bmbytes =3D + get_bitmap_bytes_needed(bdrv_dirty_bitmap_size(bm), + granularity); + uint64_t bmclusters =3D DIV_ROUND_UP(bmbytes, cluster_size); + + /* Assume the entire bitmap is allocated */ + bitmaps_size +=3D bmclusters * cluster_size; + /* Also reserve space for the bitmap table entries */ + bitmaps_size +=3D ROUND_UP(bmclusters * sizeof(uint64_t), + cluster_size); + /* And space for contribution to bitmap directory size */ + bitmap_dir_size +=3D calc_dir_entry_size(strlen(name), 0); + } + } + bitmaps_size +=3D ROUND_UP(bitmap_dir_size, cluster_size); + + return bitmaps_size; +} diff --git a/block/qcow2.c b/block/qcow2.c index dfab8d2f6cd8..0cd2e6757e8c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4953,16 +4953,24 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *op= ts, BlockDriverState *in_bs, required =3D virtual_size; } - info =3D g_new(BlockMeasureInfo, 1); + info =3D g_new0(BlockMeasureInfo, 1); info->fully_allocated =3D qcow2_calc_prealloc_size(virtual_size, cluster_size, ctz32(refcount_bits)) + luks_payload_size; - /* Remove data clusters that are not required. This overestimates the + /* + * Remove data clusters that are not required. This overestimates the * required size because metadata needed for the fully allocated file = is - * still counted. + * still counted. Show bitmaps only if both source and destination + * would support them. */ info->required =3D info->fully_allocated - virtual_size + required; + info->has_bitmaps =3D version >=3D 3 && in_bs && + bdrv_supports_persistent_dirty_bitmap(in_bs); + if (info->has_bitmaps) { + info->bitmaps =3D qcow2_get_persistent_dirty_bitmap_size(in_bs, + cluster_siz= e); + } return info; err: diff --git a/block/raw-format.c b/block/raw-format.c index 018441bddf27..233d019ca338 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -359,7 +359,7 @@ static BlockMeasureInfo *raw_measure(QemuOpts *opts, Bl= ockDriverState *in_bs, BDRV_SECTOR_SIZE); } - info =3D g_new(BlockMeasureInfo, 1); + info =3D g_new0(BlockMeasureInfo, 1); info->required =3D required; /* Unallocated sectors count towards the file size in raw images */ diff --git a/qemu-img.c b/qemu-img.c index 2d30682f129f..d719b9d35468 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -78,6 +78,7 @@ enum { OPTION_ENABLE =3D 272, OPTION_DISABLE =3D 273, OPTION_MERGE =3D 274, + OPTION_BITMAPS =3D 275, }; typedef enum OutputFormat { @@ -5128,6 +5129,7 @@ static int img_measure(int argc, char **argv) {"output", required_argument, 0, OPTION_OUTPUT}, {"size", required_argument, 0, OPTION_SIZE}, {"force-share", no_argument, 0, 'U'}, + {"bitmaps", no_argument, 0, OPTION_BITMAPS}, {0, 0, 0, 0} }; OutputFormat output_format =3D OFORMAT_HUMAN; @@ -5144,6 +5146,7 @@ static int img_measure(int argc, char **argv) QemuOpts *sn_opts =3D NULL; QemuOptsList *create_opts =3D NULL; bool image_opts =3D false; + bool bitmaps =3D false; uint64_t img_size =3D UINT64_MAX; BlockMeasureInfo *info =3D NULL; Error *local_err =3D NULL; @@ -5216,6 +5219,9 @@ static int img_measure(int argc, char **argv) img_size =3D (uint64_t)sval; } break; + case OPTION_BITMAPS: + bitmaps =3D true; + break; } } @@ -5244,6 +5250,10 @@ static int img_measure(int argc, char **argv) error_report("Either --size N or one filename must be specified."); goto out; } + if (!filename && bitmaps) { + error_report("--bitmaps is only supported with a filename."); + goto out; + } if (filename) { in_blk =3D img_open(image_opts, filename, fmt, 0, @@ -5299,9 +5309,24 @@ static int img_measure(int argc, char **argv) goto out; } + if (bitmaps) { + if (!info->has_bitmaps) { + error_report("no bitmaps measured, either source or destinatio= n " + "format lacks bitmap support"); + goto out; + } else { + info->required +=3D info->bitmaps; + info->fully_allocated +=3D info->bitmaps; + info->has_bitmaps =3D false; + } + } + if (output_format =3D=3D OFORMAT_HUMAN) { printf("required size: %" PRIu64 "\n", info->required); printf("fully allocated size: %" PRIu64 "\n", info->fully_allocate= d); + if (info->has_bitmaps) { + printf("bitmaps size: %" PRIu64 "\n", info->bitmaps); + } } else { dump_json_block_measure_info(info); } diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index a87d3cb264ce..235cc5fffadc 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -76,9 +76,9 @@ SRST ERST DEF("measure", img_measure, -"measure [--output=3Dofmt] [-O output_fmt] [-o options] [--size N | [--obj= ect objectdef] [--image-opts] [-f fmt] [-l snapshot_param] filename]") +"measure [--output=3Dofmt] [-O output_fmt] [-o options] [--size N | [--obj= ect objectdef] [--image-opts] [-f fmt] [--bitmaps] [-l snapshot_param] file= name]") SRST -.. option:: measure [--output=3DOFMT] [-O OUTPUT_FMT] [-o OPTIONS] [--size= N | [--object OBJECTDEF] [--image-opts] [-f FMT] [-l SNAPSHOT_PARAM] FILEN= AME] +.. option:: measure [--output=3DOFMT] [-O OUTPUT_FMT] [-o OPTIONS] [--size= N | [--object OBJECTDEF] [--image-opts] [-f FMT] [--bitmaps] [-l SNAPSHOT_= PARAM] FILENAME] ERST DEF("snapshot", img_snapshot, diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.= qcow2 index 4b69524c80ee..c7997760fd6f 100644 --- a/tests/qemu-iotests/178.out.qcow2 +++ b/tests/qemu-iotests/178.out.qcow2 @@ -37,6 +37,7 @@ qemu-img: The image size is too large (try using a larger= cluster size) Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D0 required size: 196608 fully allocated size: 196608 +bitmaps size: 0 converted image file size in bytes: 196608 @@ -45,6 +46,7 @@ converted image file size in bytes: 196608 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 required size: 393216 fully allocated size: 1074135040 +bitmaps size: 0 wrote 512/512 bytes at offset 512 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) wrote 65536/65536 bytes at offset 65536 @@ -53,6 +55,7 @@ wrote 64512/64512 bytes at offset 134217728 63 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) required size: 589824 fully allocated size: 1074135040 +bitmaps size: 0 converted image file size in bytes: 524288 @@ -60,6 +63,7 @@ converted image file size in bytes: 524288 required size: 524288 fully allocated size: 1074135040 +bitmaps size: 0 converted image file size in bytes: 458752 @@ -67,16 +71,19 @@ converted image file size in bytes: 458752 required size: 1074135040 fully allocated size: 1074135040 +bitmaps size: 0 =3D=3D qcow2 input image and LUKS encryption =3D=3D required size: 2686976 fully allocated size: 1076232192 +bitmaps size: 0 =3D=3D qcow2 input image and preallocation (human) =3D=3D required size: 1074135040 fully allocated size: 1074135040 +bitmaps size: 0 converted image file size in bytes: 1074135040 @@ -87,6 +94,7 @@ wrote 8388608/8388608 bytes at offset 0 8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) required size: 8716288 fully allocated size: 8716288 +bitmaps size: 0 converted image file size in bytes: 8716288 @@ -173,6 +181,7 @@ qemu-img: The image size is too large (try using a larg= er cluster size) Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D0 { + "bitmaps": 0, "required": 196608, "fully-allocated": 196608 } @@ -183,6 +192,7 @@ converted image file size in bytes: 196608 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 { + "bitmaps": 0, "required": 393216, "fully-allocated": 1074135040 } @@ -193,6 +203,7 @@ wrote 65536/65536 bytes at offset 65536 wrote 64512/64512 bytes at offset 134217728 63 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) { + "bitmaps": 0, "required": 589824, "fully-allocated": 1074135040 } @@ -202,6 +213,7 @@ converted image file size in bytes: 524288 =3D=3D qcow2 input image with internal snapshot (json) =3D=3D { + "bitmaps": 0, "required": 524288, "fully-allocated": 1074135040 } @@ -211,6 +223,7 @@ converted image file size in bytes: 458752 =3D=3D qcow2 input image and a backing file (json) =3D=3D { + "bitmaps": 0, "required": 1074135040, "fully-allocated": 1074135040 } @@ -218,6 +231,7 @@ converted image file size in bytes: 458752 =3D=3D qcow2 input image and LUKS encryption =3D=3D { + "bitmaps": 0, "required": 2686976, "fully-allocated": 1076232192 } @@ -225,6 +239,7 @@ converted image file size in bytes: 458752 =3D=3D qcow2 input image and preallocation (json) =3D=3D { + "bitmaps": 0, "required": 1074135040, "fully-allocated": 1074135040 } @@ -237,6 +252,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D838= 8608 wrote 8388608/8388608 bytes at offset 0 8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) { + "bitmaps": 0, "required": 8716288, "fully-allocated": 8716288 } diff --git a/tests/qemu-iotests/190 b/tests/qemu-iotests/190 index 6d41650438e1..acb23ebae44b 100755 --- a/tests/qemu-iotests/190 +++ b/tests/qemu-iotests/190 @@ -2,7 +2,7 @@ # # qemu-img measure sub-command tests on huge qcow2 files # -# Copyright (C) 2017 Red Hat, Inc. +# Copyright (C) 2017-2020 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -42,7 +42,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 _supported_fmt qcow2 _supported_proto file -echo "=3D=3D Huge file =3D=3D" +echo "=3D=3D Huge file without bitmaps =3D=3D" echo _make_test_img -o 'cluster_size=3D2M' 2T @@ -51,6 +51,60 @@ $QEMU_IMG measure -O raw -f qcow2 "$TEST_IMG" $QEMU_IMG measure -O qcow2 -o cluster_size=3D64k -f qcow2 "$TEST_IMG" $QEMU_IMG measure -O qcow2 -o cluster_size=3D2M -f qcow2 "$TEST_IMG" +echo +echo "=3D=3D Huge file with bitmaps =3D=3D" +echo + +$QEMU_IMG bitmap --add --granularity 512 -f qcow2 "$TEST_IMG" b1 +$QEMU_IMG bitmap --add -g 2M -f qcow2 "$TEST_IMG" b2 + +# No bitmap without a source +$QEMU_IMG measure --bitmaps -O qcow2 --size 10M && + echo "unexpected success" +# No bitmap output, since raw does not support it +$QEMU_IMG measure -O raw -f qcow2 "$TEST_IMG" || + echo "unexpected failure" +$QEMU_IMG measure --bitmaps -O raw -f qcow2 "$TEST_IMG" && + echo "unexpected success" +# No bitmap output, since no bitmaps on raw source +$QEMU_IMG measure -O qcow2 -f raw "$TEST_IMG" || + echo "unexpected failure" +$QEMU_IMG measure --bitmaps -O qcow2 -f raw "$TEST_IMG" && + echo "unexpected success" +# No bitmap output, since v2 does not support it +$QEMU_IMG measure -O qcow2 -o compat=3D0.10 -f qcow2 "$TEST_IMG" || + echo "unexpected failure" +$QEMU_IMG measure --bitmaps -O qcow2 -o compat=3D0.10 -f qcow2 "$TEST_IMG"= && + echo "unexpected success" + +# Compute expected output: bitmap clusters + bitmap tables + bitmaps direc= tory +echo +val2T=3D$((2*1024*1024*1024*1024)) +cluster=3D$((64*1024)) +b1clusters=3D$(( (val2T/512/8 + cluster - 1) / cluster )) +b2clusters=3D$(( (val2T/2/1024/1024/8 + cluster - 1) / cluster )) +echo expected bitmap $((b1clusters * cluster + + (b1clusters * 8 + cluster - 1) / cluster * cluster= + + b2clusters * cluster + + (b2clusters * 8 + cluster - 1) / cluster * cluster= + + cluster)) +$QEMU_IMG measure -O qcow2 -o cluster_size=3D64k -f qcow2 "$TEST_IMG" +$QEMU_IMG measure --bitmaps -O qcow2 -o cluster_size=3D64k -f qcow2 "$TEST= _IMG" + +# Compute expected output: bitmap clusters + bitmap tables + bitmaps direc= tory +echo +cluster=3D$((2*1024*1024)) +b1clusters=3D$(( (val2T/512/8 + cluster - 1) / cluster )) +b2clusters=3D$(( (val2T/2/1024/1024/8 + cluster - 1) / cluster )) +echo expected bitmap $((b1clusters * cluster + + (b1clusters * 8 + cluster - 1) / cluster * cluster= + + b2clusters * cluster + + (b2clusters * 8 + cluster - 1) / cluster * cluster= + + cluster)) +$QEMU_IMG measure --output=3Djson -O qcow2 -o cluster_size=3D2M -f qcow2 "= $TEST_IMG" +$QEMU_IMG measure --output=3Djson --bitmaps -O qcow2 -o cluster_size=3D2M \ + -f qcow2 "$TEST_IMG" + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/190.out b/tests/qemu-iotests/190.out index d001942002db..5c35f9268068 100644 --- a/tests/qemu-iotests/190.out +++ b/tests/qemu-iotests/190.out @@ -1,11 +1,44 @@ QA output created by 190 -=3D=3D Huge file =3D=3D +=3D=3D Huge file without bitmaps =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2199023255552 required size: 2199023255552 fully allocated size: 2199023255552 required size: 335806464 fully allocated size: 2199359062016 +bitmaps size: 0 required size: 18874368 fully allocated size: 2199042129920 +bitmaps size: 0 + +=3D=3D Huge file with bitmaps =3D=3D + +qemu-img: --bitmaps is only supported with a filename. +required size: 2199023255552 +fully allocated size: 2199023255552 +qemu-img: no bitmaps measured, either source or destination format lacks b= itmap support +required size: 7012352 +fully allocated size: 17170432 +qemu-img: no bitmaps measured, either source or destination format lacks b= itmap support +required size: 335806464 +fully allocated size: 2199359062016 +qemu-img: no bitmaps measured, either source or destination format lacks b= itmap support + +expected bitmap 537198592 +required size: 335806464 +fully allocated size: 2199359062016 +bitmaps size: 537198592 +required size: 873005056 +fully allocated size: 2199896260608 + +expected bitmap 545259520 +{ + "bitmaps": 545259520, + "required": 18874368, + "fully-allocated": 2199042129920 +} +{ + "required": 564133888, + "fully-allocated": 2199587389440 +} *** done --=20 2.26.2 From nobody Thu Apr 25 15:24:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1590012359; cv=none; d=zohomail.com; s=zohoarc; b=Bvc8GEQ2+Ef6j263r4flVZnFpYJUSyuuqfixAxK2PEOgx3grMDpBz1Dw1Ndg22lkzPc26VhnPUF1FavpDx068M7MOj5OGwOrAjN6jzyxKmiuSzI0vVRnHAK+hlehEsTM4PSLzDATMCOldV9alaosjRYoXZDBE3ZXRcIcfmOjymw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590012359; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mvD6/wijePKV88hyif56AI3+LaqSYZzBJIwiz8yHtYo=; b=hWQ78ADwsrQ0YPWMIxCVgp8sSvPTwl8tso+HbxAzbp9L5wRdEQbGeatXjt4JXaBs7BS2RAyDxZoASEpjD0tMN0ylOXT6MlCnQQteuIt/5m50IA5eFveGgRfH003VnUgQd7x0ZIvvfTG5siwIbJYmuOnNTzUL/+SdCnn1So1iLqA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590012359077508.1587923216989; Wed, 20 May 2020 15:05:59 -0700 (PDT) Received: from localhost ([::1]:42250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbWqb-0005Lw-Sy for importer@patchew.org; Wed, 20 May 2020 18:05:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbWmW-0005be-SO for qemu-devel@nongnu.org; Wed, 20 May 2020 18:01:44 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:57200 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jbWmV-0005lF-VR for qemu-devel@nongnu.org; Wed, 20 May 2020 18:01:44 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-324-umk9C6WbPA609qQ9DWkEHg-1; Wed, 20 May 2020 18:01:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB047107ACF2; Wed, 20 May 2020 22:01:23 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-88.phx2.redhat.com [10.3.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 305556AD00; Wed, 20 May 2020 22:01:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590012103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mvD6/wijePKV88hyif56AI3+LaqSYZzBJIwiz8yHtYo=; b=bgsoRYcCO6a6wElTufHvMqX7wTFx+XrVPKMGuuUMSl1BuY3y7mqAheCV3d3rMCsCdT0TXK p6qfKeGoW5kdAmOzcDFF96MflgaHBo8Sbj1zItIwQZTz8IQTaV41aaSamX2/z74+1Nm0hT UCpEnjwPN1HlBTG62sjBzUCbW0nS+Fs= X-MC-Unique: umk9C6WbPA609qQ9DWkEHg-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v5 3/5] qemu-img: Factor out code for merging bitmaps Date: Wed, 20 May 2020 17:01:16 -0500 Message-Id: <20200520220118.1037094-4-eblake@redhat.com> In-Reply-To: <20200520220118.1037094-1-eblake@redhat.com> References: <20200520220118.1037094-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 18:01:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, nsoffer@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The next patch will add another client that wants to merge dirty bitmaps; it will be easier to refactor the code to construct the QAPI struct correctly into a helper function. Signed-off-by: Eric Blake --- qemu-img.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index d719b9d35468..c1bafb57023a 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1639,6 +1639,23 @@ out4: return ret; } +static void do_dirty_bitmap_merge(const char *dst_node, const char *dst_na= me, + const char *src_node, const char *src_na= me, + Error **errp) +{ + BlockDirtyBitmapMergeSource *merge_src; + BlockDirtyBitmapMergeSourceList *list; + + merge_src =3D g_new0(BlockDirtyBitmapMergeSource, 1); + merge_src->type =3D QTYPE_QDICT; + merge_src->u.external.node =3D g_strdup(src_node); + merge_src->u.external.name =3D g_strdup(src_name); + list =3D g_new0(BlockDirtyBitmapMergeSourceList, 1); + list->value =3D merge_src; + qmp_block_dirty_bitmap_merge(dst_node, dst_name, list, errp); + qapi_free_BlockDirtyBitmapMergeSourceList(list); +} + enum ImgConvertBlockStatus { BLK_DATA, BLK_ZERO, @@ -4715,21 +4732,11 @@ static int img_bitmap(int argc, char **argv) qmp_block_dirty_bitmap_disable(bs->node_name, bitmap, &err); op =3D "disable"; break; - case BITMAP_MERGE: { - BlockDirtyBitmapMergeSource *merge_src; - BlockDirtyBitmapMergeSourceList *list; - - merge_src =3D g_new0(BlockDirtyBitmapMergeSource, 1); - merge_src->type =3D QTYPE_QDICT; - merge_src->u.external.node =3D g_strdup(src_bs->node_name); - merge_src->u.external.name =3D g_strdup(act->src); - list =3D g_new0(BlockDirtyBitmapMergeSourceList, 1); - list->value =3D merge_src; - qmp_block_dirty_bitmap_merge(bs->node_name, bitmap, list, &err= ); - qapi_free_BlockDirtyBitmapMergeSourceList(list); + case BITMAP_MERGE: + do_dirty_bitmap_merge(bs->node_name, bitmap, src_bs->node_name, + act->src, &err); op =3D "merge"; break; - } default: g_assert_not_reached(); } --=20 2.26.2 From nobody Thu Apr 25 15:24:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1590012282; cv=none; d=zohomail.com; s=zohoarc; b=NJKsmSW+vxTnajz0akC80sqlIXL6iQ9F8IP5P1+BAxPGybmVJ3GPJW8/UXRhqQ/HVZd4DnWhqzv3nl+zBx87TjwPD7vgz2oBXoV0G7wJ8rhiM4uItiM/wG7k0L0Jaxtu3HPRlmeudTO+I5dJE7ONWB3jtJu1oZmUbl0+zW1EIko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590012282; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IrKQgds3eX8I9cRTZDXZqk4YQTzwfFUE4ypxtX5Xnk8=; b=Lr6jR5ondRrdg958C1uPSmurZ/epIj10JxfnO6SAM90Rm1PLDb9fzYE32GvUMh2WP2jtDfIXYBqSkzIMXenKnpkl1NLdyJ+Sz0vsr+u0cPp1Ha6w7NXyQZzh0SF6x/eKJFakNUqKl+DbJ7VfydKI31mf3Fu61dApjKB0A6b0VpA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590012282295341.25591973213204; Wed, 20 May 2020 15:04:42 -0700 (PDT) Received: from localhost ([::1]:37672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbWpM-0002Qd-1K for importer@patchew.org; Wed, 20 May 2020 18:04:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbWmM-0005Cv-Fh for qemu-devel@nongnu.org; Wed, 20 May 2020 18:01:34 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:50498 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jbWmL-0005k3-5D for qemu-devel@nongnu.org; Wed, 20 May 2020 18:01:34 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-256-HTbuTbnKMbS1USsIA3gEUg-1; Wed, 20 May 2020 18:01:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 65F90800053; Wed, 20 May 2020 22:01:24 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-88.phx2.redhat.com [10.3.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id DED356EA28; Wed, 20 May 2020 22:01:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590012092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IrKQgds3eX8I9cRTZDXZqk4YQTzwfFUE4ypxtX5Xnk8=; b=UD5CdLcbX7DUon67HG//gZWup8Zcip4etmKJDor/2L4c4pM7XgWmDZej8p/G11zpvilgP4 5SPHHzUvUQ10z+eSnDL2273JZ45tcVLn3ogH7vvGr7OG2442PRbDpFqsmbJj6aE5d7Ywut 0RLIeo/PGh2kDkh6/hmd3e+EpGi1YwI= X-MC-Unique: HTbuTbnKMbS1USsIA3gEUg-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v5 4/5] qemu-img: Add convert --bitmaps option Date: Wed, 20 May 2020 17:01:17 -0500 Message-Id: <20200520220118.1037094-5-eblake@redhat.com> In-Reply-To: <20200520220118.1037094-1-eblake@redhat.com> References: <20200520220118.1037094-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 18:01:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, nsoffer@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Make it easier to copy all the persistent bitmaps of (the top layer of) a source image along with its guest-visible contents, by adding a boolean flag for use with qemu-img convert. This is basically shorthand, as the same effect could be accomplished with a series of 'qemu-img bitmap --add' and 'qemu-img bitmap --merge -b source' commands, or by QMP commands. Note that this command will fail in the same scenarios where 'qemu-img measure --bitmaps' fails, when either the source or the destanation lacks persistent bitmap support altogether. See also https://bugzilla.redhat.com/show_bug.cgi?id=3D1779893 While touching this, clean up a couple coding issues spotted in the same function: an extra blank line, and merging back-to-back 'if (!skip_create)' blocks. Signed-off-by: Eric Blake Message-Id: <20200513011648.166876-9-eblake@redhat.com> --- docs/tools/qemu-img.rst | 6 +++- qemu-img.c | 77 +++++++++++++++++++++++++++++++++++++++-- qemu-img-cmds.hx | 4 +-- 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 9a8112fc9f58..35050fc51070 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -162,6 +162,10 @@ Parameters to convert subcommand: .. program:: qemu-img-convert +.. option:: --bitmaps + + Additionally copy all persistent bitmaps from the top layer of the source + .. option:: -n Skip the creation of the target volume @@ -397,7 +401,7 @@ Command description: 4 Error on reading data -.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-op= ts] [--target-is-zero] [-U] [-C] [-c] [-p] [-q] [-n] [-f FMT] [-t CACHE] [-= T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKING_FILE] [-o OPTIONS] [-l SNAPSHOT_PA= RAM] [-S SPARSE_SIZE] [-m NUM_COROUTINES] [-W] FILENAME [FILENAME2 [...]] O= UTPUT_FILENAME +.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-op= ts] [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f FMT] [= -t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKING_FILE] [-o OPTIONS] [-l= SNAPSHOT_PARAM] [-S SPARSE_SIZE] [-m NUM_COROUTINES] [-W] FILENAME [FILENA= ME2 [...]] OUTPUT_FILENAME Convert the disk image *FILENAME* or a snapshot *SNAPSHOT_PARAM* to disk image *OUTPUT_FILENAME* using format *OUTPUT_FMT*. It can diff --git a/qemu-img.c b/qemu-img.c index c1bafb57023a..1494d8f5c409 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -192,6 +192,7 @@ static void QEMU_NORETURN help(void) " hiding corruption that has already occurred.\n" "\n" "Parameters to convert subcommand:\n" + " '--bitmaps' copies all top-level persistent bitmaps to desti= nation\n" " '-m' specifies how many coroutines work in parallel during t= he convert\n" " process (defaults to 8)\n" " '-W' allow to write to the target out of order rather than s= equential\n" @@ -2139,6 +2140,39 @@ static int convert_do_copy(ImgConvertState *s) return s->ret; } +static int convert_copy_bitmaps(BlockDriverState *src, BlockDriverState *d= st) +{ + BdrvDirtyBitmap *bm; + Error *err =3D NULL; + + FOR_EACH_DIRTY_BITMAP(src, bm) { + const char *name; + + if (!bdrv_dirty_bitmap_get_persistence(bm)) { + continue; + } + name =3D bdrv_dirty_bitmap_name(bm); + qmp_block_dirty_bitmap_add(dst->node_name, name, + true, bdrv_dirty_bitmap_granularity(bm), + true, true, + true, !bdrv_dirty_bitmap_enabled(bm), + &err); + if (err) { + error_reportf_err(err, "Failed to create bitmap %s: ", name); + return -1; + } + + do_dirty_bitmap_merge(dst->node_name, name, src->node_name, name, + &err); + if (err) { + error_reportf_err(err, "Failed to populate bitmap %s: ", name); + return -1; + } + } + + return 0; +} + #define MAX_BUF_SECTORS 32768 static int img_convert(int argc, char **argv) @@ -2160,6 +2194,8 @@ static int img_convert(int argc, char **argv) int64_t ret =3D -EINVAL; bool force_share =3D false; bool explict_min_sparse =3D false; + bool bitmaps =3D false; + size_t nbitmaps =3D 0; ImgConvertState s =3D (ImgConvertState) { /* Need at least 4k of zeros for sparse detection */ @@ -2179,6 +2215,7 @@ static int img_convert(int argc, char **argv) {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS= }, {"salvage", no_argument, 0, OPTION_SALVAGE}, {"target-is-zero", no_argument, 0, OPTION_TARGET_IS_ZERO}, + {"bitmaps", no_argument, 0, OPTION_BITMAPS}, {0, 0, 0, 0} }; c =3D getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WU", @@ -2304,6 +2341,9 @@ static int img_convert(int argc, char **argv) */ s.has_zero_init =3D true; break; + case OPTION_BITMAPS: + bitmaps =3D true; + break; } } @@ -2365,7 +2405,6 @@ static int img_convert(int argc, char **argv) goto fail_getopt; } - /* ret is still -EINVAL until here */ ret =3D bdrv_parse_cache_mode(src_cache, &src_flags, &src_writethrough= ); if (ret < 0) { @@ -2525,6 +2564,27 @@ static int img_convert(int argc, char **argv) } } + /* Determine how many bitmaps need copying */ + if (bitmaps) { + BdrvDirtyBitmap *bm; + + if (s.src_num > 1) { + error_report("Copying bitmaps only possible with single source= "); + ret =3D -1; + goto out; + } + if (!bdrv_supports_persistent_dirty_bitmap(blk_bs(s.src[0]))) { + error_report("Source lacks bitmap support"); + ret =3D -1; + goto out; + } + FOR_EACH_DIRTY_BITMAP(blk_bs(s.src[0]), bm) { + if (bdrv_dirty_bitmap_get_persistence(bm)) { + nbitmaps++; + } + } + } + /* * The later open call will need any decryption secrets, and * bdrv_create() will purge "opts", so extract them now before @@ -2533,9 +2593,7 @@ static int img_convert(int argc, char **argv) if (!skip_create) { open_opts =3D qdict_new(); qemu_opt_foreach(opts, img_add_key_secrets, open_opts, &error_abor= t); - } - if (!skip_create) { /* Create the new image */ ret =3D bdrv_create(drv, out_filename, opts, &local_err); if (ret < 0) { @@ -2573,6 +2631,13 @@ static int img_convert(int argc, char **argv) } out_bs =3D blk_bs(s.target); + if (nbitmaps > 0 && !bdrv_supports_persistent_dirty_bitmap(out_bs)) { + error_report("Format driver '%s' does not support bitmaps", + out_fmt); + ret =3D -1; + goto out; + } + if (s.compressed && !block_driver_can_compress(out_bs->drv)) { error_report("Compression not supported for this file format"); ret =3D -1; @@ -2632,6 +2697,12 @@ static int img_convert(int argc, char **argv) } ret =3D convert_do_copy(&s); + + /* Now copy the bitmaps */ + if (nbitmaps > 0 && ret =3D=3D 0) { + ret =3D convert_copy_bitmaps(blk_bs(s.src[0]), out_bs); + } + out: if (!ret) { qemu_progress_print(100, 0); diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 235cc5fffadc..e9beb15e614e 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -46,9 +46,9 @@ SRST ERST DEF("convert", img_convert, - "convert [--object objectdef] [--image-opts] [--target-image-opts] [--= target-is-zero] [-U] [-C] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_c= ache] [-O output_fmt] [-B backing_file] [-o options] [-l snapshot_param] [-= S sparse_size] [-m num_coroutines] [-W] [--salvage] filename [filename2 [..= .]] output_filename") + "convert [--object objectdef] [--image-opts] [--target-image-opts] [--= target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f fmt] [-t cach= e] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-l snapsh= ot_param] [-S sparse_size] [-m num_coroutines] [-W] [--salvage] filename [f= ilename2 [...]] output_filename") SRST -.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-op= ts] [--target-is-zero] [-U] [-C] [-c] [-p] [-q] [-n] [-f FMT] [-t CACHE] [-= T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKING_FILE] [-o OPTIONS] [-l SNAPSHOT_PA= RAM] [-S SPARSE_SIZE] [-m NUM_COROUTINES] [-W] [--salvage] FILENAME [FILENA= ME2 [...]] OUTPUT_FILENAME +.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-op= ts] [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f FMT] [= -t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKING_FILE] [-o OPTIONS] [-l= SNAPSHOT_PARAM] [-S SPARSE_SIZE] [-m NUM_COROUTINES] [-W] [--salvage] FILE= NAME [FILENAME2 [...]] OUTPUT_FILENAME ERST DEF("create", img_create, --=20 2.26.2 From nobody Thu Apr 25 15:24:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1590012195; cv=none; d=zohomail.com; s=zohoarc; b=T3jqdVm7R/rxXCJoj+DoSDkCWxt8R8jqG/V5VY9rVoBhvr7axPOYUHUxPOftw9YYH+CdPyYmH1Kjzaxi4IEbkT2gljgqHbhkVyA59kZYXu/HGRSS6m5UKS4Th1YIBtStzTf7KNn64qwCStIZwL8cDtnQnq+Mtu7q66m4kqUyRAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590012195; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6OVr8ibEOE5mMIhIy7+qnvD4Z98j/0E/PW+Pi7JthXk=; b=SxNZyNsrsu2k9s92mD2mIu080lwtcF5rcQY7cxs+gMvuyXXYM2e1EJl5Xt8nQMkWiLGxNDbLn3wBDFIAIQcGm9NOpNnssxMnWBvFYWpzSp05Qft9kIPb40BoVsIQbozKclqyTZWvdfPN5noH0Xd+HTZWNdZrTSYzf9t9gU0+1AQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590012195601151.32951951515201; Wed, 20 May 2020 15:03:15 -0700 (PDT) Received: from localhost ([::1]:59350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbWny-0007RB-4q for importer@patchew.org; Wed, 20 May 2020 18:03:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbWmK-000576-HP for qemu-devel@nongnu.org; Wed, 20 May 2020 18:01:32 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:22017 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jbWmI-0005jb-Rs for qemu-devel@nongnu.org; Wed, 20 May 2020 18:01:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-292-dG10YvwsPM-8SybwFY1BPw-1; Wed, 20 May 2020 18:01:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 227098014D7; Wed, 20 May 2020 22:01:25 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-88.phx2.redhat.com [10.3.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 992536AD00; Wed, 20 May 2020 22:01:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590012089; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6OVr8ibEOE5mMIhIy7+qnvD4Z98j/0E/PW+Pi7JthXk=; b=depjCtYOXeDox1DE+KDYF3snBaEu2dJHfm3h/tPKLYLdQFPgNXCHOtEZVWIlEzrGUV1ch1 iySF7YJjUVQIUILxsBAMVKmns4YW58t9T7jtCyI5RTmxOoXw4SVBrZR9vvHHrIAXgZYl6H WQS4A8iqc23YmrQg3sibTA1pcFo9eXY= X-MC-Unique: dG10YvwsPM-8SybwFY1BPw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v5 5/5] iotests: Add test 291 to for qemu-img bitmap coverage Date: Wed, 20 May 2020 17:01:18 -0500 Message-Id: <20200520220118.1037094-6-eblake@redhat.com> In-Reply-To: <20200520220118.1037094-1-eblake@redhat.com> References: <20200520220118.1037094-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=eblake@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 18:01:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, nsoffer@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add a new test covering the 'qemu-img bitmap' subcommand, as well as 'qemu-img convert --bitmaps', both added in recent patches. Signed-off-by: Eric Blake Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/291 | 112 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/291.out | 80 ++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 193 insertions(+) create mode 100755 tests/qemu-iotests/291 create mode 100644 tests/qemu-iotests/291.out diff --git a/tests/qemu-iotests/291 b/tests/qemu-iotests/291 new file mode 100755 index 000000000000..3ca83b9cd1f7 --- /dev/null +++ b/tests/qemu-iotests/291 @@ -0,0 +1,112 @@ +#!/usr/bin/env bash +# +# Test qemu-img bitmap handling +# +# Copyright (C) 2018-2020 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +seq=3D"$(basename $0)" +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + nbd_server_stop +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.nbd + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux +_require_command QEMU_NBD + +echo +echo "=3D=3D=3D Initial image setup =3D=3D=3D" +echo + +# Create backing image with one bitmap +TEST_IMG=3D"$TEST_IMG.base" _make_test_img 10M +$QEMU_IMG bitmap --add -f $IMGFMT "$TEST_IMG.base" b0 +$QEMU_IO -c 'w 3M 1M' -f $IMGFMT "$TEST_IMG.base" | _filter_qemu_io + +# Create initial image and populate two bitmaps: one active, one inactive. +ORIG_IMG=3D$TEST_IMG +TEST_IMG=3D$TEST_IMG.orig +_make_test_img -b "$ORIG_IMG.base" -F $IMGFMT 10M +$QEMU_IO -c 'w 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG bitmap --add -g 512k -f $IMGFMT "$TEST_IMG" b1 +$QEMU_IMG bitmap --add --disable -f $IMGFMT "$TEST_IMG" b2 +$QEMU_IO -c 'w 3M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG bitmap --clear -f $IMGFMT "$TEST_IMG" b1 +$QEMU_IO -c 'w 1M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG bitmap --disable -f $IMGFMT "$TEST_IMG" b1 +$QEMU_IMG bitmap --enable -f $IMGFMT "$TEST_IMG" b2 +$QEMU_IO -c 'w 2M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io + +echo +echo "=3D=3D=3D Bitmap preservation not possible to non-qcow2 =3D=3D=3D" +echo + +TEST_IMG=3D$ORIG_IMG +$QEMU_IMG convert --bitmaps -O raw "$TEST_IMG.orig" "$TEST_IMG" && + echo "unexpected success" + +echo +echo "=3D=3D=3D Convert with bitmap preservation =3D=3D=3D" +echo + +# Only bitmaps from the active layer are copied +$QEMU_IMG convert --bitmaps -O qcow2 "$TEST_IMG.orig" "$TEST_IMG" +$QEMU_IMG info "$TEST_IMG" | _filter_img_info --format-specific +# But we can also merge in bitmaps from other layers. This test is a bit +# contrived to cover more code paths, in reality, you could merge directly +# into b0 without going through tmp +$QEMU_IMG bitmap --add --disable -f $IMGFMT "$TEST_IMG" b0 +$QEMU_IMG bitmap --add --merge b0 -b "$TEST_IMG.base" -F $IMGFMT \ + -f $IMGFMT "$TEST_IMG" tmp +$QEMU_IMG bitmap --merge tmp -f $IMGFMT "$TEST_IMG" b0 +$QEMU_IMG bitmap --remove --image-opts \ + driver=3D$IMGFMT,file.driver=3Dfile,file.filename=3D"$TEST_IMG" tmp +$QEMU_IMG info "$TEST_IMG" | _filter_img_info --format-specific + +echo +echo "=3D=3D=3D Check bitmap contents =3D=3D=3D" +echo + +# x-dirty-bitmap is a hack for reading bitmaps; it abuses block status to +# report "data":false for portions of the bitmap which are set +IMG=3D"driver=3Dnbd,server.type=3Dunix,server.path=3D$nbd_unix_socket" +nbd_server_start_unix_socket -r -f qcow2 -B b0 "$TEST_IMG" +$QEMU_IMG map --output=3Djson --image-opts \ + "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b0" | _filter_qemu_img_map +nbd_server_start_unix_socket -r -f qcow2 -B b1 "$TEST_IMG" +$QEMU_IMG map --output=3Djson --image-opts \ + "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b1" | _filter_qemu_img_map +nbd_server_start_unix_socket -r -f qcow2 -B b2 "$TEST_IMG" +$QEMU_IMG map --output=3Djson --image-opts \ + "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b2" | _filter_qemu_img_map + +# success, all done +echo '*** done' +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/291.out b/tests/qemu-iotests/291.out new file mode 100644 index 000000000000..8c62017567e9 --- /dev/null +++ b/tests/qemu-iotests/291.out @@ -0,0 +1,80 @@ +QA output created by 291 + +=3D=3D=3D Initial image setup =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D10485760 +wrote 1048576/1048576 bytes at offset 3145728 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=3DIMGFMT size=3D10485760 backing_= file=3DTEST_DIR/t.IMGFMT.base backing_fmt=3DIMGFMT +wrote 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 1048576/1048576 bytes at offset 3145728 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 1048576/1048576 bytes at offset 2097152 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D=3D Bitmap preservation not possible to non-qcow2 =3D=3D=3D + +qemu-img: Format driver 'raw' does not support bitmaps + +=3D=3D=3D Convert with bitmap preservation =3D=3D=3D + +image: TEST_DIR/t.IMGFMT +file format: IMGFMT +virtual size: 10 MiB (10485760 bytes) +disk size: 4.39 MiB +Format specific information: + compat: 1.1 + compression type: zlib + lazy refcounts: false + bitmaps: + [0]: + flags: + name: b1 + granularity: 524288 + [1]: + flags: + [0]: auto + name: b2 + granularity: 65536 + refcount bits: 16 + corrupt: false +image: TEST_DIR/t.IMGFMT +file format: IMGFMT +virtual size: 10 MiB (10485760 bytes) +disk size: 4.48 MiB +Format specific information: + compat: 1.1 + compression type: zlib + lazy refcounts: false + bitmaps: + [0]: + flags: + name: b1 + granularity: 524288 + [1]: + flags: + [0]: auto + name: b2 + granularity: 65536 + [2]: + flags: + name: b0 + granularity: 65536 + refcount bits: 16 + corrupt: false + +=3D=3D=3D Check bitmap contents =3D=3D=3D + +[{ "start": 0, "length": 3145728, "depth": 0, "zero": false, "data": true,= "offset": OFFSET}, +{ "start": 3145728, "length": 1048576, "depth": 0, "zero": false, "data": = false}, +{ "start": 4194304, "length": 6291456, "depth": 0, "zero": false, "data": = true, "offset": OFFSET}] +[{ "start": 0, "length": 1048576, "depth": 0, "zero": false, "data": true,= "offset": OFFSET}, +{ "start": 1048576, "length": 1048576, "depth": 0, "zero": false, "data": = false}, +{ "start": 2097152, "length": 8388608, "depth": 0, "zero": false, "data": = true, "offset": OFFSET}] +[{ "start": 0, "length": 2097152, "depth": 0, "zero": false, "data": true,= "offset": OFFSET}, +{ "start": 2097152, "length": 1048576, "depth": 0, "zero": false, "data": = false}, +{ "start": 3145728, "length": 7340032, "depth": 0, "zero": false, "data": = true, "offset": OFFSET}] +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 445c26f8d2e2..d886fa0cb355 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -299,5 +299,6 @@ 288 quick 289 rw quick 290 rw auto quick +291 rw quick 292 rw auto quick 297 meta --=20 2.26.2