From nobody Sat May 18 12:47:48 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=1587504196; cv=none; d=zohomail.com; s=zohoarc; b=VVrgdvPrgafjR1+jPMtcWOGpL5wguEzuC8f94fdSgBImlBjRoHRVbRGnMoTZdn4i4BBWmWn2utt80KQXeIfAHoWgYRvD7hIxLxRC3RIb13SMouNVihT7yVsM9bDxs+Qy3kc+uFRiz+2nN73pgqtb8jx7ZsofAbVb/FDY1re0sx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587504196; 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=66FBuX3kMTK7TLcLsZBvJg+BKOaPWvGWonKu5G7q3lU=; b=Na+D4SdyJPBcsMyGs9hbskQyPkcy0vLJXI3ZRIA8Cl1dZMd5P0pXgTJ/+synJ1Mhk95ZbO6d6jOAoKLZTzOyVEvrZSWBWpiOkXtBy+tqa3JXikDTvIDcaXzWsriGmzg7F3yHzbZSiOxMqBkw9V+7pi9fJ/yJIxyR/Pbed1puLDw= 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 1587504196970859.2054526220164; Tue, 21 Apr 2020 14:23:16 -0700 (PDT) Received: from localhost ([::1]:36290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0MM-0006dC-Bm for importer@patchew.org; Tue, 21 Apr 2020 17:23:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57986) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0Jn-0005Bg-OV for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jR0Ji-0004Rs-KL for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20:34 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:55654 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 1jR0Jh-0004Mi-EW for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20: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-391-HuHRNCToMgys0kllwYljug-1; Tue, 21 Apr 2020 17:20:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CED3D18C35A2; Tue, 21 Apr 2020 21:20:23 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-80.rdu2.redhat.com [10.10.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDA34A18BC; Tue, 21 Apr 2020 21:20:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587504026; 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=66FBuX3kMTK7TLcLsZBvJg+BKOaPWvGWonKu5G7q3lU=; b=ba5XTxsnqtn/SIUtr/JdyuO27gVbEsFA8JfvT6ibwnPHAy7OK78rmfJrWhz625nl5hTcOG J70gCTANfLe/qXr3m1rloDaeDlbpM5oxX5+EJAOT89mlLzkwiNTXu+kM3a4mPjIwes024j OaBxegaN8cv1qVGiQVfxevWLmLnrZoE= X-MC-Unique: HuHRNCToMgys0kllwYljug-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v2 1/6] docs: Sort sections on qemu-img subcommand parameters Date: Tue, 21 Apr 2020 16:20:14 -0500 Message-Id: <20200421212019.170707-2-eblake@redhat.com> In-Reply-To: <20200421212019.170707-1-eblake@redhat.com> References: <20200421212019.170707-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.120; envelope-from=eblake@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/21 17:20:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: nsoffer@redhat.com, kwolf@redhat.com, jsnow@redhat.com, qemu-block@nongnu.org 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" We already list the subcommand summaries alphabetically, we should do the same for the documentation related to subcommand-specific parameters. Signed-off-by: Eric Blake Reviewed-by: Max Reitz --- docs/tools/qemu-img.rst | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 0080f83a76c9..7d08c48d308f 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -142,30 +142,6 @@ by the used format or see the format descriptions belo= w for details. the documentation of the emulator's ``-drive cache=3D...`` option for al= lowed values. -Parameters to snapshot subcommand: - -.. program:: qemu-img-snapshot - -.. option:: snapshot - - Is the name of the snapshot to create, apply or delete - -.. option:: -a - - Applies a snapshot (revert disk to saved state) - -.. option:: -c - - Creates a snapshot - -.. option:: -d - - Deletes a snapshot - -.. option:: -l - - Lists all snapshots in the given image - Parameters to compare subcommand: .. program:: qemu-img-compare @@ -245,6 +221,30 @@ Parameters to dd subcommand: Sets the number of input blocks to skip +Parameters to snapshot subcommand: + +.. program:: qemu-img-snapshot + +.. option:: snapshot + + Is the name of the snapshot to create, apply or delete + +.. option:: -a + + Applies a snapshot (revert disk to saved state) + +.. option:: -c + + Creates a snapshot + +.. option:: -d + + Deletes a snapshot + +.. option:: -l + + Lists all snapshots in the given image + Command description: .. program:: qemu-img-commands --=20 2.26.2 From nobody Sat May 18 12:47:48 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=1587504350; cv=none; d=zohomail.com; s=zohoarc; b=WB8ka0X6f0tLHfIxmgDl9wJQrGBV8XPK0KdJ8bij06paiL7GW4JplSgH9Cc/qQl/zU7UFV2EGGK4W0H08827ZbIMqgDrPnZV4cixDee8AAqgd+zqg6Ok6GDt2EX4iBwKNkq900rL1+oaS1I9AlmCcRg8lMt9DE18CjJtPyXEFMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587504350; 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=/7LZQGGXbYbbgrrm+GbyBvkNWg62W/PwJiHjUr7hMBQ=; b=GH7nxC2tjbIKZv+RtrVxrytDzHd3nlKznu32cvxtvJmfMp4G84SmHO1bmliZWWLMI5iT4YKS3JdjfhB7RVR3ur4IFA2fV83qNy8uUDRTRGC53jyHZZ2kYy77rxWFso6ck9OBL86yT6Qhjp3mhHzJdlyw/ObDMtJAB32DSaSJDps= 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 1587504350654806.4137493586095; Tue, 21 Apr 2020 14:25:50 -0700 (PDT) Received: from localhost ([::1]:36324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0Or-0001cW-9H for importer@patchew.org; Tue, 21 Apr 2020 17:25:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58534) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0K4-0005K6-A2 for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:21:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jR0Jm-0004YP-PK for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20:49 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:49653 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 1jR0Jj-0004SA-Vf for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20: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-386-xak5nRvNNum5izF914m4Jw-1; Tue, 21 Apr 2020 17:20:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6429D8017FC; Tue, 21 Apr 2020 21:20:25 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-80.rdu2.redhat.com [10.10.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B65DA18B6; Tue, 21 Apr 2020 21:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587504030; 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=/7LZQGGXbYbbgrrm+GbyBvkNWg62W/PwJiHjUr7hMBQ=; b=WKl2nkI9RWNt0p3M34bQlRRjjWPu7BTrBC8BX6kVNZf3ON9ZNzvrTCE3md5I575/KAttUt O/rGJ3YuzTm7v/eR232JkJFE4Sc0z0LoNQ2lxvr01W5ZYGd209j/x+LOtyFkefSfPfLxbO GYc4dKhH2TjgFKVa2Q6UsFfyUDrrQJE= X-MC-Unique: xak5nRvNNum5izF914m4Jw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v2 2/6] blockdev: Split off basic bitmap operations for qemu-img Date: Tue, 21 Apr 2020 16:20:15 -0500 Message-Id: <20200421212019.170707-3-eblake@redhat.com> In-Reply-To: <20200421212019.170707-1-eblake@redhat.com> References: <20200421212019.170707-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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/04/21 15:21:16 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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, qemu-block@nongnu.org, Markus Armbruster , Max Reitz , nsoffer@redhat.com, jsnow@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" Upcoming patches want to add some basic bitmap manipulation abilities to qemu-img. But blockdev.o is too heavyweight to link into qemu-img (among other things, it would drag in block jobs and transaction support - qemu-img does offline manipulation, where atomicity is less important because there are no concurrent modifications to compete with), so it's time to split off the bare bones of what we will need into a new file blockbitmaps.o. In addition to exposing 6 QMP commands for use by qemu-img (add, remove, clear, enable, disable, merge), this also has to export three previously-static functions for use by blockdev.c transactions. Signed-off-by: Eric Blake --- Makefile.objs | 2 +- include/sysemu/blockdev.h | 14 ++ blockbitmaps.c | 324 ++++++++++++++++++++++++++++++++++++++ blockdev.c | 293 ---------------------------------- MAINTAINERS | 1 + 5 files changed, 340 insertions(+), 294 deletions(-) create mode 100644 blockbitmaps.c diff --git a/Makefile.objs b/Makefile.objs index a7c967633acf..44e30fa9a6e3 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -14,7 +14,7 @@ chardev-obj-y =3D chardev/ authz-obj-y =3D authz/ block-obj-y =3D nbd/ -block-obj-y +=3D block.o blockjob.o job.o +block-obj-y +=3D block.o blockbitmaps.o blockjob.o job.o block-obj-y +=3D block/ scsi/ block-obj-y +=3D qemu-io-cmds.o block-obj-$(CONFIG_REPLICATION) +=3D replication.o diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index a86d99b3d875..523b7493b1cd 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -57,4 +57,18 @@ QemuOpts *drive_add(BlockInterfaceType type, int index, = const char *file, DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type, Error **errp); +BdrvDirtyBitmap *block_dirty_bitmap_lookup(const char *node, + const char *name, + BlockDriverState **pbs, + Error **errp); +BdrvDirtyBitmap *do_block_dirty_bitmap_remove(const char *node, + const char *name, bool relea= se, + BlockDriverState **bitmap_bs, + Error **errp); +BdrvDirtyBitmap *do_block_dirty_bitmap_merge(const char *node, + const char *target, + BlockDirtyBitmapMergeSourceLi= st *bitmaps, + HBitmap **backup, Error **err= p); + + #endif diff --git a/blockbitmaps.c b/blockbitmaps.c new file mode 100644 index 000000000000..fea80efcd03a --- /dev/null +++ b/blockbitmaps.c @@ -0,0 +1,324 @@ +/* + * QEMU host block device bitmaps + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" + +#include "sysemu/blockdev.h" +#include "block/block.h" +#include "block/block_int.h" +#include "qapi/qapi-commands-block.h" +#include "qapi/error.h" + +/** + * block_dirty_bitmap_lookup: + * Return a dirty bitmap (if present), after validating + * the node reference and bitmap names. + * + * @node: The name of the BDS node to search for bitmaps + * @name: The name of the bitmap to search for + * @pbs: Output pointer for BDS lookup, if desired. Can be NULL. + * @errp: Output pointer for error information. Can be NULL. + * + * @return: A bitmap object on success, or NULL on failure. + */ +BdrvDirtyBitmap *block_dirty_bitmap_lookup(const char *node, + const char *name, + BlockDriverState **pbs, + Error **errp) +{ + BlockDriverState *bs; + BdrvDirtyBitmap *bitmap; + + if (!node) { + error_setg(errp, "Node cannot be NULL"); + return NULL; + } + if (!name) { + error_setg(errp, "Bitmap name cannot be NULL"); + return NULL; + } + bs =3D bdrv_lookup_bs(node, node, NULL); + if (!bs) { + error_setg(errp, "Node '%s' not found", node); + return NULL; + } + + bitmap =3D bdrv_find_dirty_bitmap(bs, name); + if (!bitmap) { + error_setg(errp, "Dirty bitmap '%s' not found", name); + return NULL; + } + + if (pbs) { + *pbs =3D bs; + } + + return bitmap; +} + +void qmp_block_dirty_bitmap_add(const char *node, const char *name, + bool has_granularity, uint32_t granularity, + bool has_persistent, bool persistent, + bool has_disabled, bool disabled, + Error **errp) +{ + BlockDriverState *bs; + BdrvDirtyBitmap *bitmap; + AioContext *aio_context; + + if (!name || name[0] =3D=3D '\0') { + error_setg(errp, "Bitmap name cannot be empty"); + return; + } + + bs =3D bdrv_lookup_bs(node, node, errp); + if (!bs) { + return; + } + + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + + if (has_granularity) { + if (granularity < 512 || !is_power_of_2(granularity)) { + error_setg(errp, "Granularity must be power of 2 " + "and at least 512"); + goto out; + } + } else { + /* Default to cluster size, if available: */ + granularity =3D bdrv_get_default_bitmap_granularity(bs); + } + + if (!has_persistent) { + persistent =3D false; + } + + if (!has_disabled) { + disabled =3D false; + } + + if (persistent && + !bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp)) + { + goto out; + } + + bitmap =3D bdrv_create_dirty_bitmap(bs, granularity, name, errp); + if (bitmap =3D=3D NULL) { + goto out; + } + + if (disabled) { + bdrv_disable_dirty_bitmap(bitmap); + } + + bdrv_dirty_bitmap_set_persistence(bitmap, persistent); + +out: + aio_context_release(aio_context); +} + +BdrvDirtyBitmap *do_block_dirty_bitmap_remove(const char *node, + const char *name, bool relea= se, + BlockDriverState **bitmap_bs, + Error **errp) +{ + BlockDriverState *bs; + BdrvDirtyBitmap *bitmap; + AioContext *aio_context; + + bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); + if (!bitmap || !bs) { + return NULL; + } + + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + + if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_BUSY | BDRV_BITMAP_RO, + errp)) { + aio_context_release(aio_context); + return NULL; + } + + if (bdrv_dirty_bitmap_get_persistence(bitmap) && + bdrv_remove_persistent_dirty_bitmap(bs, name, errp) < 0) + { + aio_context_release(aio_context); + return NULL; + } + + if (release) { + bdrv_release_dirty_bitmap(bitmap); + } + + if (bitmap_bs) { + *bitmap_bs =3D bs; + } + + aio_context_release(aio_context); + return release ? NULL : bitmap; +} + +void qmp_block_dirty_bitmap_remove(const char *node, const char *name, + Error **errp) +{ + do_block_dirty_bitmap_remove(node, name, true, NULL, errp); +} + +/** + * Completely clear a bitmap, for the purposes of synchronizing a bitmap + * immediately after a full backup operation. + */ +void qmp_block_dirty_bitmap_clear(const char *node, const char *name, + Error **errp) +{ + BdrvDirtyBitmap *bitmap; + BlockDriverState *bs; + + bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); + if (!bitmap || !bs) { + return; + } + + if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, errp)) { + return; + } + + bdrv_clear_dirty_bitmap(bitmap, NULL); +} + +void qmp_block_dirty_bitmap_enable(const char *node, const char *name, + Error **errp) +{ + BlockDriverState *bs; + BdrvDirtyBitmap *bitmap; + + bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); + if (!bitmap) { + return; + } + + if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) { + return; + } + + bdrv_enable_dirty_bitmap(bitmap); +} + +void qmp_block_dirty_bitmap_disable(const char *node, const char *name, + Error **errp) +{ + BlockDriverState *bs; + BdrvDirtyBitmap *bitmap; + + bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); + if (!bitmap) { + return; + } + + if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) { + return; + } + + bdrv_disable_dirty_bitmap(bitmap); +} + +BdrvDirtyBitmap *do_block_dirty_bitmap_merge( + const char *node, const char *target, + BlockDirtyBitmapMergeSourceList *bitmaps, + HBitmap **backup, Error **errp) +{ + BlockDriverState *bs; + BdrvDirtyBitmap *dst, *src, *anon; + BlockDirtyBitmapMergeSourceList *lst; + Error *local_err =3D NULL; + + dst =3D block_dirty_bitmap_lookup(node, target, &bs, errp); + if (!dst) { + return NULL; + } + + anon =3D bdrv_create_dirty_bitmap(bs, bdrv_dirty_bitmap_granularity(ds= t), + NULL, errp); + if (!anon) { + return NULL; + } + + for (lst =3D bitmaps; lst; lst =3D lst->next) { + switch (lst->value->type) { + const char *name, *node; + case QTYPE_QSTRING: + name =3D lst->value->u.local; + src =3D bdrv_find_dirty_bitmap(bs, name); + if (!src) { + error_setg(errp, "Dirty bitmap '%s' not found", name); + dst =3D NULL; + goto out; + } + break; + case QTYPE_QDICT: + node =3D lst->value->u.external.node; + name =3D lst->value->u.external.name; + src =3D block_dirty_bitmap_lookup(node, name, NULL, errp); + if (!src) { + dst =3D NULL; + goto out; + } + break; + default: + abort(); + } + + bdrv_merge_dirty_bitmap(anon, src, NULL, &local_err); + if (local_err) { + error_propagate(errp, local_err); + dst =3D NULL; + goto out; + } + } + + /* Merge into dst; dst is unchanged on failure. */ + bdrv_merge_dirty_bitmap(dst, anon, backup, errp); + + out: + bdrv_release_dirty_bitmap(anon); + return dst; +} + +void qmp_block_dirty_bitmap_merge(const char *node, const char *target, + BlockDirtyBitmapMergeSourceList *bitmaps, + Error **errp) +{ + do_block_dirty_bitmap_merge(node, target, bitmaps, NULL, errp); +} diff --git a/blockdev.c b/blockdev.c index 5faddaa7052f..d4efd4cbf2cb 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1185,53 +1185,6 @@ out_aio_context: return NULL; } -/** - * block_dirty_bitmap_lookup: - * Return a dirty bitmap (if present), after validating - * the node reference and bitmap names. - * - * @node: The name of the BDS node to search for bitmaps - * @name: The name of the bitmap to search for - * @pbs: Output pointer for BDS lookup, if desired. Can be NULL. - * @errp: Output pointer for error information. Can be NULL. - * - * @return: A bitmap object on success, or NULL on failure. - */ -static BdrvDirtyBitmap *block_dirty_bitmap_lookup(const char *node, - const char *name, - BlockDriverState **pbs, - Error **errp) -{ - BlockDriverState *bs; - BdrvDirtyBitmap *bitmap; - - if (!node) { - error_setg(errp, "Node cannot be NULL"); - return NULL; - } - if (!name) { - error_setg(errp, "Bitmap name cannot be NULL"); - return NULL; - } - bs =3D bdrv_lookup_bs(node, node, NULL); - if (!bs) { - error_setg(errp, "Node '%s' not found", node); - return NULL; - } - - bitmap =3D bdrv_find_dirty_bitmap(bs, name); - if (!bitmap) { - error_setg(errp, "Dirty bitmap '%s' not found", name); - return NULL; - } - - if (pbs) { - *pbs =3D bs; - } - - return bitmap; -} - /* New and old BlockDriverState structs for atomic group operations */ typedef struct BlkActionState BlkActionState; @@ -2171,11 +2124,6 @@ static void block_dirty_bitmap_disable_abort(BlkActi= onState *common) } } -static BdrvDirtyBitmap *do_block_dirty_bitmap_merge( - const char *node, const char *target, - BlockDirtyBitmapMergeSourceList *bitmaps, - HBitmap **backup, Error **errp); - static void block_dirty_bitmap_merge_prepare(BlkActionState *common, Error **errp) { @@ -2194,10 +2142,6 @@ static void block_dirty_bitmap_merge_prepare(BlkActi= onState *common, errp); } -static BdrvDirtyBitmap *do_block_dirty_bitmap_remove( - const char *node, const char *name, bool release, - BlockDriverState **bitmap_bs, Error **errp); - static void block_dirty_bitmap_remove_prepare(BlkActionState *common, Error **errp) { @@ -2441,243 +2385,6 @@ void qmp_block_passwd(bool has_device, const char *= device, "Setting block passwords directly is no longer supported"); } -void qmp_block_dirty_bitmap_add(const char *node, const char *name, - bool has_granularity, uint32_t granularity, - bool has_persistent, bool persistent, - bool has_disabled, bool disabled, - Error **errp) -{ - BlockDriverState *bs; - BdrvDirtyBitmap *bitmap; - AioContext *aio_context; - - if (!name || name[0] =3D=3D '\0') { - error_setg(errp, "Bitmap name cannot be empty"); - return; - } - - bs =3D bdrv_lookup_bs(node, node, errp); - if (!bs) { - return; - } - - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - - if (has_granularity) { - if (granularity < 512 || !is_power_of_2(granularity)) { - error_setg(errp, "Granularity must be power of 2 " - "and at least 512"); - goto out; - } - } else { - /* Default to cluster size, if available: */ - granularity =3D bdrv_get_default_bitmap_granularity(bs); - } - - if (!has_persistent) { - persistent =3D false; - } - - if (!has_disabled) { - disabled =3D false; - } - - if (persistent && - !bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp)) - { - goto out; - } - - bitmap =3D bdrv_create_dirty_bitmap(bs, granularity, name, errp); - if (bitmap =3D=3D NULL) { - goto out; - } - - if (disabled) { - bdrv_disable_dirty_bitmap(bitmap); - } - - bdrv_dirty_bitmap_set_persistence(bitmap, persistent); - -out: - aio_context_release(aio_context); -} - -static BdrvDirtyBitmap *do_block_dirty_bitmap_remove( - const char *node, const char *name, bool release, - BlockDriverState **bitmap_bs, Error **errp) -{ - BlockDriverState *bs; - BdrvDirtyBitmap *bitmap; - AioContext *aio_context; - - bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); - if (!bitmap || !bs) { - return NULL; - } - - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - - if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_BUSY | BDRV_BITMAP_RO, - errp)) { - aio_context_release(aio_context); - return NULL; - } - - if (bdrv_dirty_bitmap_get_persistence(bitmap) && - bdrv_remove_persistent_dirty_bitmap(bs, name, errp) < 0) - { - aio_context_release(aio_context); - return NULL; - } - - if (release) { - bdrv_release_dirty_bitmap(bitmap); - } - - if (bitmap_bs) { - *bitmap_bs =3D bs; - } - - aio_context_release(aio_context); - return release ? NULL : bitmap; -} - -void qmp_block_dirty_bitmap_remove(const char *node, const char *name, - Error **errp) -{ - do_block_dirty_bitmap_remove(node, name, true, NULL, errp); -} - -/** - * Completely clear a bitmap, for the purposes of synchronizing a bitmap - * immediately after a full backup operation. - */ -void qmp_block_dirty_bitmap_clear(const char *node, const char *name, - Error **errp) -{ - BdrvDirtyBitmap *bitmap; - BlockDriverState *bs; - - bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); - if (!bitmap || !bs) { - return; - } - - if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, errp)) { - return; - } - - bdrv_clear_dirty_bitmap(bitmap, NULL); -} - -void qmp_block_dirty_bitmap_enable(const char *node, const char *name, - Error **errp) -{ - BlockDriverState *bs; - BdrvDirtyBitmap *bitmap; - - bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); - if (!bitmap) { - return; - } - - if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) { - return; - } - - bdrv_enable_dirty_bitmap(bitmap); -} - -void qmp_block_dirty_bitmap_disable(const char *node, const char *name, - Error **errp) -{ - BlockDriverState *bs; - BdrvDirtyBitmap *bitmap; - - bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); - if (!bitmap) { - return; - } - - if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) { - return; - } - - bdrv_disable_dirty_bitmap(bitmap); -} - -static BdrvDirtyBitmap *do_block_dirty_bitmap_merge( - const char *node, const char *target, - BlockDirtyBitmapMergeSourceList *bitmaps, - HBitmap **backup, Error **errp) -{ - BlockDriverState *bs; - BdrvDirtyBitmap *dst, *src, *anon; - BlockDirtyBitmapMergeSourceList *lst; - Error *local_err =3D NULL; - - dst =3D block_dirty_bitmap_lookup(node, target, &bs, errp); - if (!dst) { - return NULL; - } - - anon =3D bdrv_create_dirty_bitmap(bs, bdrv_dirty_bitmap_granularity(ds= t), - NULL, errp); - if (!anon) { - return NULL; - } - - for (lst =3D bitmaps; lst; lst =3D lst->next) { - switch (lst->value->type) { - const char *name, *node; - case QTYPE_QSTRING: - name =3D lst->value->u.local; - src =3D bdrv_find_dirty_bitmap(bs, name); - if (!src) { - error_setg(errp, "Dirty bitmap '%s' not found", name); - dst =3D NULL; - goto out; - } - break; - case QTYPE_QDICT: - node =3D lst->value->u.external.node; - name =3D lst->value->u.external.name; - src =3D block_dirty_bitmap_lookup(node, name, NULL, errp); - if (!src) { - dst =3D NULL; - goto out; - } - break; - default: - abort(); - } - - bdrv_merge_dirty_bitmap(anon, src, NULL, &local_err); - if (local_err) { - error_propagate(errp, local_err); - dst =3D NULL; - goto out; - } - } - - /* Merge into dst; dst is unchanged on failure. */ - bdrv_merge_dirty_bitmap(dst, anon, backup, errp); - - out: - bdrv_release_dirty_bitmap(anon); - return dst; -} - -void qmp_block_dirty_bitmap_merge(const char *node, const char *target, - BlockDirtyBitmapMergeSourceList *bitmaps, - Error **errp) -{ - do_block_dirty_bitmap_merge(node, target, bitmaps, NULL, errp); -} - BlockDirtyBitmapSha256 *qmp_x_debug_block_dirty_bitmap_sha256(const char *= node, const char *= name, Error **errp) diff --git a/MAINTAINERS b/MAINTAINERS index 8cbc1fac2bfc..769cd357d281 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1989,6 +1989,7 @@ T: git https://github.com/jnsnow/qemu.git jobs Block QAPI, monitor, command line M: Markus Armbruster S: Supported +F: blockbitmaps.c F: blockdev.c F: blockdev-hmp-cmds.c F: block/qapi.c --=20 2.26.2 From nobody Sat May 18 12:47:48 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=1587504339; cv=none; d=zohomail.com; s=zohoarc; b=d9l3FVYwd9HWITStH07MSwGStUcjfurVijXyOd4p9mcryYkKo5ofo6kjJ+ZgS4zf2nUvoUxryd7496PSMom3ja0L2lg7NuychvSfNNUZVSI/uR4et+mOmqddlEhmMEK2wUZWvCQVAOCkW4LZLyZV6gcYsks9nwfqa4tx6RGAS3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587504339; 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=N1p+XEQXqhHd/4LsBuiMrXV5IvjDV2boahY1DBkB22o=; b=bZJkOJClSSzv6nLcjW66x3j0oYAug9RK776Sp3N01uxjUGoYRet2S3s8Lev1w9YVAaPbg2GdAIe4l28oc2Qhf+wRF2kcR5JWn+9iRmEV82JQwABHi5dtNVAYfJbaSuBlGFr5kyA1nq1YcszugqA41JEY/e2YDzzO8lMpH9H5OoI= 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 1587504339486895.9028791593805; Tue, 21 Apr 2020 14:25:39 -0700 (PDT) Received: from localhost ([::1]:36320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0Og-0001Jk-3X for importer@patchew.org; Tue, 21 Apr 2020 17:25:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58640) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0K8-0005Mk-7P for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:21:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jR0Jr-0004g2-5C for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20:54 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:25437 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 1jR0Jo-0004XI-GI for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20:36 -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-174-hiDAlmN0Ng-7kxGmVX7MQA-1; Tue, 21 Apr 2020 17:20:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B131818C35A0; Tue, 21 Apr 2020 21:20:26 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-80.rdu2.redhat.com [10.10.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE392A18B6; Tue, 21 Apr 2020 21:20:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587504032; 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=N1p+XEQXqhHd/4LsBuiMrXV5IvjDV2boahY1DBkB22o=; b=ic/vQXwvlXMSE7dxchKdmyQyZ783Vc6Ehr2z9CGCA2QiLF7QllqXe3hyEd7U4x0ovpusw+ YH+EXz0Sxjx1mNLQXNA5OBUvW+e2CnAZHkN5/UlbndBwrEuxSsjki0DQU7Zu74E0riKxrB cwt28NBXzMd5PP222+rkZS0RVkOeI1w= X-MC-Unique: hiDAlmN0Ng-7kxGmVX7MQA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v2 3/6] qemu-img: Add bitmap sub-command Date: Tue, 21 Apr 2020 16:20:16 -0500 Message-Id: <20200421212019.170707-4-eblake@redhat.com> In-Reply-To: <20200421212019.170707-1-eblake@redhat.com> References: <20200421212019.170707-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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/04/21 15:21:16 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: nsoffer@redhat.com, kwolf@redhat.com, jsnow@redhat.com, qemu-block@nongnu.org, Max Reitz 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" Include actions for --add, --remove, --clear, --enable, --disable, and --merge (note that --clear is a bit of fluff, because the same can be accomplished by removing a bitmap and then adding a new one in its place, but it matches what QMP commands exist). Listing is omitted, because it does not require a bitmap name and because it was already possible with 'qemu-img info'. Merge can work either from another bitmap in the same image, or from a bitmap in a distinct image. While this supports --image-opts for the file being modified, I did not think it worth the extra complexity to support that for the source file in a cross-file bitmap merge. Likewise, I chose to have --merge only take a single source rather than following the QMP support for multiple merges in one go; in part to simplify the command line, and in part because an offline image can achieve the same effect by multiple qemu-img bitmap --merge calls. We can enhance that if needed in the future (the same way that 'qemu-img convert' has a mode that concatenates multiple sources into one destination). Upcoming patches will add iotest coverage of these commands while also testing other features. Signed-off-by: Eric Blake --- docs/tools/qemu-img.rst | 24 +++++ qemu-img.c | 198 ++++++++++++++++++++++++++++++++++++++++ qemu-img-cmds.hx | 7 ++ 3 files changed, 229 insertions(+) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 7d08c48d308f..4f3b0e2c9ace 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -281,6 +281,30 @@ Command description: For write tests, by default a buffer filled with zeros is written. This = can be overridden with a pattern byte specified by *PATTERN*. +.. option:: bitmap {--add [-g GRANULARITY] [--disabled] | --remove | --cle= ar | --enable | --disable | --merge SOURCE_BITMAP [-b SOURCE_FILE [-F SOURC= E_FMT]]} [--object OBJECTDEF] [--image-opts] [-f FMT] FILENAME BITMAP + + Perform a modification of the persistent bitmap *BITMAP* in the disk + image *FILENAME*. The various modifications are: + + ``--add`` to create *BITMAP*, with additional options ``-g`` to + specify a non-default *GRANULARITY*, or whether the bitmap should be + ``--disabled`` instead of enabled. + + ``--remove`` to remove *BITMAP*. + + ``--clear`` to clear *BITMAP*. + + ``--enable`` to change *BITMAP* to start recording future edits. + + ``--disable`` to change *BITMAP* to stop recording future edits. + + ``--merge`` to merge the contents of *SOURCE_BITMAP* into *BITMAP*. + This defaults to requiring a source bitmap from the same *FILENAME*, + but can also be used for cross-image merge by supplying ``-b`` to + specify a different *SOURCE_FILE*. + + To see what bitmaps are present in an image, use ``qemu-img info``. + .. option:: check [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [--out= put=3DOFMT] [-r [leaks | all]] [-T SRC_CACHE] [-U] FILENAME Perform a consistency check on the disk image *FILENAME*. The command can diff --git a/qemu-img.c b/qemu-img.c index 821cbf610e5f..02ebd870faa1 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -28,6 +28,7 @@ #include "qemu-common.h" #include "qemu-version.h" #include "qapi/error.h" +#include "qapi/qapi-commands-block-core.h" #include "qapi/qapi-visit-block-core.h" #include "qapi/qobject-output-visitor.h" #include "qapi/qmp/qjson.h" @@ -71,6 +72,12 @@ enum { OPTION_SHRINK =3D 266, OPTION_SALVAGE =3D 267, OPTION_TARGET_IS_ZERO =3D 268, + OPTION_ADD =3D 269, + OPTION_REMOVE =3D 270, + OPTION_CLEAR =3D 271, + OPTION_ENABLE =3D 272, + OPTION_DISABLE =3D 273, + OPTION_MERGE =3D 274, }; typedef enum OutputFormat { @@ -4438,6 +4445,197 @@ out: return 0; } +static int img_bitmap(int argc, char **argv) +{ + Error *err =3D NULL; + int c, ret =3D -1; + QemuOpts *opts =3D NULL; + const char *fmt =3D NULL, *src_fmt =3D NULL, *src_filename =3D NULL; + const char *filename, *bitmap; + BlockBackend *blk =3D NULL, *src =3D NULL; + BlockDriverState *bs =3D NULL, *src_bs =3D NULL; + bool image_opts =3D false; + unsigned long granularity =3D 0; + bool add =3D false, remove =3D false, clear =3D false; + bool enable =3D false, disable =3D false, add_disabled =3D false; + const char *merge =3D NULL; + + for (;;) { + static const struct option long_options[] =3D { + {"help", no_argument, 0, 'h'}, + {"object", required_argument, 0, OPTION_OBJECT}, + {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"add", no_argument, 0, OPTION_ADD}, + {"remove", no_argument, 0, OPTION_REMOVE}, + {"clear", no_argument, 0, OPTION_CLEAR}, + {"enable", no_argument, 0, OPTION_ENABLE}, + {"disable", no_argument, 0, OPTION_DISABLE}, + {"disabled", no_argument, 0, OPTION_DISABLE}, + {"merge", required_argument, 0, OPTION_MERGE}, + {"granularity", required_argument, 0, 'g'}, + {"source-file", required_argument, 0, 'b'}, + {"source-format", required_argument, 0, 'F'}, + {0, 0, 0, 0} + }; + c =3D getopt_long(argc, argv, ":b:f:F:g:h", long_options, NULL); + if (c =3D=3D -1) { + break; + } + + switch (c) { + case ':': + missing_argument(argv[optind - 1]); + break; + case '?': + unrecognized_option(argv[optind - 1]); + break; + case 'h': + help(); + break; + case 'b': + src_filename =3D optarg; + break; + case 'f': + fmt =3D optarg; + break; + case 'F': + src_fmt =3D optarg; + break; + case 'g': + if (qemu_strtosz(optarg, NULL, &granularity)) { + error_report("Invalid granularity specified"); + return 1; + } + break; + case OPTION_ADD: + add =3D true; + break; + case OPTION_REMOVE: + remove =3D true; + break; + case OPTION_CLEAR: + clear =3D true; + break; + case OPTION_ENABLE: + enable =3D true; + break; + case OPTION_DISABLE: + disable =3D true; + break; + case OPTION_MERGE: + merge =3D optarg; + break; + case OPTION_OBJECT: + opts =3D qemu_opts_parse_noisily(&qemu_object_opts, + optarg, true); + if (!opts) { + goto out; + } + break; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; + } + } + + if (qemu_opts_foreach(&qemu_object_opts, + user_creatable_add_opts_foreach, + qemu_img_object_print_help, &error_fatal)) { + goto out; + } + + if (add && disable) { + disable =3D false; + add_disabled =3D true; + } + if (add + remove + clear + enable + disable + !!merge !=3D 1) { + error_report("Need exactly one mode of --add, --remove, --clear, " + "--enable, --disable, or --merge"); + goto out; + } + if (granularity && !add) { + error_report("granularity only supported with --add"); + goto out; + } + if (src_fmt && !src_filename) { + error_report("-F only supported with -b"); + goto out; + } + if (src_filename && !merge) { + error_report("alternate source file only supported with --merge"); + goto out; + } + + if (optind !=3D argc - 2) { + error_report("Expecting filename and bitmap name"); + goto out; + } + + filename =3D argv[optind]; + bitmap =3D argv[optind + 1]; + + blk =3D img_open(image_opts, filename, fmt, BDRV_O_RDWR, false, false, + false); + if (!blk) { + goto out; + } + bs =3D blk_bs(blk); + + if (add) { + qmp_block_dirty_bitmap_add(bs->node_name, bitmap, + !!granularity, granularity, true, true, + true, add_disabled, &err); + } else if (remove) { + qmp_block_dirty_bitmap_remove(bs->node_name, bitmap, &err); + } else if (clear) { + qmp_block_dirty_bitmap_clear(bs->node_name, bitmap, &err); + } else if (enable) { + qmp_block_dirty_bitmap_enable(bs->node_name, bitmap, &err); + } else if (disable) { + qmp_block_dirty_bitmap_disable(bs->node_name, bitmap, &err); + } else if (merge) { + BlockDirtyBitmapMergeSource *merge_src; + BlockDirtyBitmapMergeSourceList *list; + + if (src_filename) { + src =3D img_open(NULL, src_filename, src_fmt, 0, false, false, + false); + if (!src) { + goto out; + } + src_bs =3D blk_bs(src); + } else { + src_bs =3D bs; + } + + 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(merge); + 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); + } + + if (err) { + error_reportf_err(err, "Bitmap %s operation failed", bitmap); + ret =3D -1; + goto out; + } + + ret =3D 0; + + out: + blk_unref(src); + blk_unref(blk); + qemu_opts_del(opts); + if (ret) { + return 1; + } + return 0; +} + #define C_BS 01 #define C_COUNT 02 #define C_IF 04 diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index c9c54de1df40..bf0035e226c8 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -20,6 +20,13 @@ DEF("bench", img_bench, SRST .. option:: bench [-c COUNT] [-d DEPTH] [-f FMT] [--flush-interval=3DFLUSH= _INTERVAL] [-i AIO] [-n] [--no-drain] [-o OFFSET] [--pattern=3DPATTERN] [-q= ] [-s BUFFER_SIZE] [-S STEP_SIZE] [-t CACHE] [-w] [-U] FILENAME ERST + +DEF("bitmap", img_bitmap, + "bitmap {--add [-g granularity] [--disabled] | --remove | --clear | --= enable | --disable | --merge source_bitmap [-b source_file [-F source_fmt]]= } [--object objectdef] [--image-opts] [-f fmt] filename bitmap") +SRST +.. option:: bitmap {--add [-g GRANULARITY] [--disabled] | --remove | --cle= ar | --enable | --disable | --merge SOURCE_BITMAP [-b SOURCE_FILE [-F SOURC= E_FMT]]} [--object OBJECTDEF] [--image-opts] [-f FMT] FILENAME BITMAP +ERST + DEF("check", img_check, "check [--object objectdef] [--image-opts] [-q] [-f fmt] [--output=3Do= fmt] [-r [leaks | all]] [-T src_cache] [-U] filename") SRST --=20 2.26.2 From nobody Sat May 18 12:47:48 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=1587504337; cv=none; d=zohomail.com; s=zohoarc; b=VVYrjcLD3u3dcWVMpdcK8/iQZPx9/DDs/3qlgYDjERzhYKMyVhv067jsrHWVzLBBKa3ytLVMi6vM+ArN/d56yehZEjrgpTyiXPguqk7NeHnnKzxE2HyezTkN03mIfecCPA6WlCHFTP6t2I8WjhESclJEhP8mekh+quKhdW5rZes= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587504337; 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=FfAA0Jb7QuNan7uKzWGnFWZynmSGfPXfc7CqpnCzqgQ=; b=B2X6XODZN2VTHi6IXu5XRu93JvVNA63UP6a47Aux/UQfP24Ldu+/8aKMh8af29qcPVSfQC7sGof8jHcHv09jbiHPWr1ucXyI2DCkBo1jlTohXu4K2C86PJ0fCdaij5sPorQ+pX0WaTdVPvd+JWQAblCXPFGAG1K8rMnHIRYiNfg= 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 158750433733093.69369454238938; Tue, 21 Apr 2020 14:25:37 -0700 (PDT) Received: from localhost ([::1]:36318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0Od-0001It-Vl for importer@patchew.org; Tue, 21 Apr 2020 17:25:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58502) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0K1-0005JU-VZ for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:21:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jR0Jq-0004dP-JK for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20:48 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:31725 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 1jR0Jm-0004Ub-DU for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20: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-12-EPqmGf_eN0C4vvb_PMSBdw-1; Tue, 21 Apr 2020 17:20:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2879118C35A2; Tue, 21 Apr 2020 21:20:28 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-80.rdu2.redhat.com [10.10.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 122F2A18B6; Tue, 21 Apr 2020 21:20:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587504031; 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=FfAA0Jb7QuNan7uKzWGnFWZynmSGfPXfc7CqpnCzqgQ=; b=ObairFKoCD39qgQJHYGUneLLLXg+rmT+qxaLzXyNjGd15TSBmt9uGG+YkqGWhxV4qm6Jc7 KunlfUO73W0yajvdVz/70D/AcYrouyVDnTRSqpHfrur7ZSH/ND9FSi/2nsNVo847gZRG7U C4PQKxf/R6zhO0uIAFuyiAcu7k27ydU= X-MC-Unique: EPqmGf_eN0C4vvb_PMSBdw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v2 4/6] qcow2: Expose bitmaps' size during measure Date: Tue, 21 Apr 2020 16:20:17 -0500 Message-Id: <20200421212019.170707-5-eblake@redhat.com> In-Reply-To: <20200421212019.170707-1-eblake@redhat.com> References: <20200421212019.170707-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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/04/21 15:21:16 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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, qemu-block@nongnu.org, Markus Armbruster , Max Reitz , nsoffer@redhat.com, jsnow@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" 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 field. Update iotest 190 to cover it and a portion of the just-added qemu-img bitmap command. 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. See also: https://bugzilla.redhat.com/1779904 Reported-by: Nir Soffer Signed-off-by: Eric Blake --- qapi/block-core.json | 15 ++++++++++----- block/crypto.c | 2 +- block/qcow2.c | 29 ++++++++++++++++++++++++++++- block/raw-format.c | 2 +- qemu-img.c | 3 +++ tests/qemu-iotests/190 | 15 +++++++++++++-- tests/qemu-iotests/190.out | 13 ++++++++++++- 7 files changed, 68 insertions(+), 11 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 943df1926a91..b47c6d69ba27 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -633,18 +633,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 +# 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 for bitmap metadata not directly used +# for guest contents, when that metadata can be copied in additi= on +# to guest contents. (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/crypto.c b/block/crypto.c index d577f89659fa..4e0f3ec97f0e 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -535,7 +535,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.c b/block/qcow2.c index b524b0c53f84..9fd650928016 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4657,6 +4657,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, PreallocMode prealloc; bool has_backing_file; bool has_luks; + uint64_t bitmaps_size =3D 0; /* size occupied by bitmaps in in_bs */ /* Parse image creation options */ cluster_size =3D qcow2_opt_get_cluster_size_del(opts, &local_err); @@ -4732,6 +4733,8 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, /* Account for input image */ if (in_bs) { + BdrvDirtyBitmap *bm; + size_t bitmap_overhead =3D 0; int64_t ssize =3D bdrv_getlength(in_bs); if (ssize < 0) { error_setg_errno(&local_err, -ssize, @@ -4739,6 +4742,28 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opt= s, BlockDriverState *in_bs, goto err; } + FOR_EACH_DIRTY_BITMAP(in_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 bmbits =3D DIV_ROUND_UP(bdrv_dirty_bitmap_size(bm= ), + granularity); + uint64_t bmclusters =3D DIV_ROUND_UP(DIV_ROUND_UP(bmbits, + CHAR_BIT), + 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); + /* Guess at contribution to bitmap directory size */ + bitmap_overhead +=3D ROUND_UP(strlen(name) + 24, + sizeof(uint64_t)); + } + } + bitmaps_size +=3D ROUND_UP(bitmap_overhead, cluster_size); + virtual_size =3D ROUND_UP(ssize, cluster_size); if (has_backing_file) { @@ -4785,7 +4810,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , 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; @@ -4795,6 +4820,8 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, * still counted. */ info->required =3D info->fully_allocated - virtual_size + required; + info->has_bitmaps =3D !!bitmaps_size; + info->bitmaps =3D bitmaps_size; return info; err: diff --git a/block/raw-format.c b/block/raw-format.c index 93b25e1b6b0b..4bb54f4ac6c5 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -346,7 +346,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 02ebd870faa1..e1127273f21e 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5207,6 +5207,9 @@ static int img_measure(int argc, char **argv) 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/tests/qemu-iotests/190 b/tests/qemu-iotests/190 index 6d41650438e1..cae643149a01 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,17 @@ $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 + +$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" + # 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..11962f972429 100644 --- a/tests/qemu-iotests/190.out +++ b/tests/qemu-iotests/190.out @@ -1,5 +1,5 @@ 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 @@ -8,4 +8,15 @@ required size: 335806464 fully allocated size: 2199359062016 required size: 18874368 fully allocated size: 2199042129920 + +=3D=3D Huge file with bitmaps =3D=3D + +required size: 2199023255552 +fully allocated size: 2199023255552 +required size: 335806464 +fully allocated size: 2199359062016 +bitmaps size: 537198592 +required size: 18874368 +fully allocated size: 2199042129920 +bitmaps size: 545259520 *** done --=20 2.26.2 From nobody Sat May 18 12:47:48 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=1587504219; cv=none; d=zohomail.com; s=zohoarc; b=G0ztN7x1WkeEcXru5j2jufcDHKrHmlEL4L7aE1Y2G9x+1vG9eV/qpkpYHCOUQQjZkb3/yS58VA4BhvOwSB66qqkoBtHN5Kzh58+8mzI3xD+qM7NG7ttz6jM/rNn8vobAtr2T0h64J1NmjndrMArxYOjdsn/Z6OX5p+qEvGOig2U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587504219; 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=tyNwNlAI3/UdDqYJZEEjujm56+3KWTXeD6WEShYsXQA=; b=cBbj8XINh6vHb1W2nG+AFxX8SiOy8rLWWMy5HbcsZLxWOX4ndMTbiUKanuHZ7DJsvIJnTIT5WvnznFzOE2ddeVxAEMw1nZtJb9LP27k1Fb4CM4KyskB1MOBeQlwOo1gRRks0916+2k8VTpbxi8CrhhKXPCVEPufEtX4ypXIJ+hA= 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 1587504219690501.3416054895562; Tue, 21 Apr 2020 14:23:39 -0700 (PDT) Received: from localhost ([::1]:36296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0Mk-0007DG-Ai for importer@patchew.org; Tue, 21 Apr 2020 17:23:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58660) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0K8-0005NH-Rm for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:21:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jR0Jt-0004jC-Bc for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20:56 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:28186 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 1jR0Jo-0004ZS-Px for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20:37 -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-55-ScnwtlOKOW2q3x_BJBXpvA-1; Tue, 21 Apr 2020 17:20:30 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F601800D53; Tue, 21 Apr 2020 21:20:29 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-80.rdu2.redhat.com [10.10.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71D69A18BC; Tue, 21 Apr 2020 21:20:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587504034; 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=tyNwNlAI3/UdDqYJZEEjujm56+3KWTXeD6WEShYsXQA=; b=Mdd9vVhp8iE8ItFRe+Tio+lNjWeQ45x/HNOKYXbrLRVWhQV0QsVS/FR+vAaVjETW+a+48l F6SpUkrdStOseamKIujKJ6ICzkqZmf4O9oiXLEC4COl/3PcdDJ7wHjVVLKgdP2u/l/gPHP b1NJAXaHtvWYGh14d+4j5TIG//qI0AA= X-MC-Unique: ScnwtlOKOW2q3x_BJBXpvA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v2 5/6] qemu-img: Add convert --bitmaps option Date: Tue, 21 Apr 2020 16:20:18 -0500 Message-Id: <20200421212019.170707-6-eblake@redhat.com> In-Reply-To: <20200421212019.170707-1-eblake@redhat.com> References: <20200421212019.170707-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.81; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/21 17:20:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: nsoffer@redhat.com, kwolf@redhat.com, jsnow@redhat.com, qemu-block@nongnu.org, Max Reitz 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 a source image along with the 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. See also https://bugzilla.redhat.com/show_bug.cgi?id=3D1779893 Signed-off-by: Eric Blake Reviewed-by: Max Reitz --- docs/tools/qemu-img.rst | 6 +++- qemu-img.c | 80 +++++++++++++++++++++++++++++++++++++++-- qemu-img-cmds.hx | 4 +-- 3 files changed, 84 insertions(+), 6 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 4f3b0e2c9ace..430fb5b46e43 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 bitmaps + .. 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 e1127273f21e..6cfc1f52ef98 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 { @@ -183,6 +184,7 @@ static void QEMU_NORETURN help(void) " hiding corruption that has already occurred.\n" "\n" "Parameters to convert subcommand:\n" + " '--bitmaps' copies all persistent bitmaps to destination\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" @@ -2061,6 +2063,47 @@ 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; + BlockDirtyBitmapMergeSource *merge; + BlockDirtyBitmapMergeSourceList *list; + + 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; + } + + merge =3D g_new0(BlockDirtyBitmapMergeSource, 1); + merge->type =3D QTYPE_QDICT; + merge->u.external.node =3D g_strdup(src->node_name); + merge->u.external.name =3D g_strdup(name); + list =3D g_new0(BlockDirtyBitmapMergeSourceList, 1); + list->value =3D merge; + qmp_block_dirty_bitmap_merge(dst->node_name, name, list, &err); + qapi_free_BlockDirtyBitmapMergeSourceList(list); + 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) @@ -2082,6 +2125,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 */ @@ -2101,6 +2146,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", @@ -2232,6 +2278,9 @@ static int img_convert(int argc, char **argv) */ s.has_zero_init =3D true; break; + case OPTION_BITMAPS: + bitmaps =3D true; + break; } } @@ -2293,7 +2342,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) { @@ -2453,6 +2501,28 @@ 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; + } + FOR_EACH_DIRTY_BITMAP(blk_bs(s.src[0]), bm) { + if (bdrv_dirty_bitmap_get_persistence(bm)) { + nbitmaps++; + } + } + if (nbitmaps > 0 && drv && !drv->bdrv_co_can_store_new_dirty_bitma= p) { + error_report("Format driver '%s' does not support bitmaps", + out_fmt); + ret =3D -1; + goto out; + } + } + /* * The later open call will need any decryption secrets, and * bdrv_create() will purge "opts", so extract them now before @@ -2461,9 +2531,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) { @@ -2560,6 +2628,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 bf0035e226c8..cf574792bd99 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 Sat May 18 12:47:48 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=1587504497; cv=none; d=zohomail.com; s=zohoarc; b=acPKdDqPP3WfzykisMMx4UL5NJF2kw2i12XQLz2pfK3aJ+noZL4vRtPAW+7mvQ7/4FEc4YhRVADWRTrkak47eM/OLub2xS6bIMtCnLrubPPsafbpmY4TF/0ieEkeG0OWu13bPEQMhp6zrAAta3ieDFCJUvQZu++zFDN/yp+3W6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587504497; 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=K/BIvCiFKTAcqXvASzJDVgXFckpyHRztdhQwBe2MmiU=; b=Eql06yTQCkkyifjsa7pPJswn76QSy8K4qNK6RdJrcley/hFdQ0d8iJv0NXC7DfBoOL6Yq9eZXHK6hKui2HZGpZm96OND3udfmKa0VJh2GCFY8WDCi8u79wQ4+O0PA7Wqvx3HepEwrIOth8T8qA6BXoqy/qIfwsnqDUg0qSLsf7c= 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 1587504497442840.7100113617196; Tue, 21 Apr 2020 14:28:17 -0700 (PDT) Received: from localhost ([::1]:36358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0RD-0004HG-BO for importer@patchew.org; Tue, 21 Apr 2020 17:28:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58654) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR0K8-0005NF-Hw for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:21:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jR0Jt-0004kl-Uz for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20:56 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:37759 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 1jR0Jq-0004bn-A8 for qemu-devel@nongnu.org; Tue, 21 Apr 2020 17:20:38 -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-418-imiDTirvOk2n8KzGYN-fag-1; Tue, 21 Apr 2020 17:20:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BCE778017F3; Tue, 21 Apr 2020 21:20:30 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-80.rdu2.redhat.com [10.10.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF922A18B6; Tue, 21 Apr 2020 21:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587504035; 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=K/BIvCiFKTAcqXvASzJDVgXFckpyHRztdhQwBe2MmiU=; b=cr3CfuU+xW0IIEarQqX7Uf2agA/jHeo18F3uav1Oft7WjJ7NulNEsFn0SdWVnukw3UY0Os F0yrZ9D2GZn+5xr9Kh7G+ve4M5/kCVNPt3CI1tnLC8xmPGjmIMBCQDqJBdouT+OZrInkvn pH66JMolnoPPL3XV1eI1HUwkYE9lC7M= X-MC-Unique: imiDTirvOk2n8KzGYN-fag-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v2 6/6] iotests: Add test 291 to for qemu-img bitmap coverage Date: Tue, 21 Apr 2020 16:20:19 -0500 Message-Id: <20200421212019.170707-7-eblake@redhat.com> In-Reply-To: <20200421212019.170707-1-eblake@redhat.com> References: <20200421212019.170707-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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/04/21 17:20:31 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: nsoffer@redhat.com, kwolf@redhat.com, jsnow@redhat.com, qemu-block@nongnu.org, Max Reitz 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 --- tests/qemu-iotests/291 | 103 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/291.out | 78 ++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 182 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..77713c0cfea7 --- /dev/null +++ b/tests/qemu-iotests/291 @@ -0,0 +1,103 @@ +#!/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. +_make_test_img -b "$TEST_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 --disabled -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 + +mv "$TEST_IMG" "$TEST_IMG.orig" +$QEMU_IMG convert --bitmaps -O raw "$TEST_IMG.orig" "$TEST_IMG" + +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 +$QEMU_IMG bitmap --add --disabled -f $IMGFMT "$TEST_IMG" b0 +$QEMU_IMG bitmap --add -f $IMGFMT "$TEST_IMG" tmp +$QEMU_IMG bitmap --merge b0 -b "$TEST_IMG.base" -F $IMGFMT "$TEST_IMG" tmp +$QEMU_IMG bitmap --merge tmp "$TEST_IMG" b0 +$QEMU_IMG bitmap --remove -f $IMGFMT "$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 + +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..d716c0c7cc0b --- /dev/null +++ b/tests/qemu-iotests/291.out @@ -0,0 +1,78 @@ +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', 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 + 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.49 MiB +Format specific information: + compat: 1.1 + 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 435dccd5af90..8e9b9513a091 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -297,3 +297,4 @@ 288 quick 289 rw quick 290 rw auto quick +291 rw quick --=20 2.26.2