From nobody Fri Dec 19 17:37:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536668594949293.95303133957475; Tue, 11 Sep 2018 05:23:14 -0700 (PDT) Received: from localhost ([::1]:57431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzhhD-0000VM-2H for importer@patchew.org; Tue, 11 Sep 2018 08:23:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzeBG-0003YI-Iw for qemu-devel@nongnu.org; Tue, 11 Sep 2018 04:37:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fzeBD-000698-CE for qemu-devel@nongnu.org; Tue, 11 Sep 2018 04:37:54 -0400 Received: from m50-132.163.com ([123.125.50.132]:42706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzeBC-00066T-Ns; Tue, 11 Sep 2018 04:37:51 -0400 Received: from chishui0007.ys (unknown [111.202.144.35]) by smtp2 (Coremail) with SMTP id DNGowACnxgjUfpdbq4kPAA--.179S4; Tue, 11 Sep 2018 16:37:42 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=QPuzT4M1foRDbeP9kx vReOGNXNB2KPs3fnWA9Urv99U=; b=ZsH/ul1Hv6AHf0mwL0tko8nOjrEbcoExMm wjV/FxN3M1BiwJuhd8FgTdx7Qgb5utoFomB8oeqKuX+XRL1PInDf42pBuCR8TSRn 1/ZpRnzCERRGKxVwJHDloi8eOJfD6g1N7YN4Mp/6ZDVtj7vEWj9sv41b9AXTC6l9 EEQMsDdLQ= From: Ma Haocong To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 11 Sep 2018 16:37:06 +0800 Message-Id: <20180911083706.5378-2-mahaocong_work@163.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180911083706.5378-1-mahaocong_work@163.com> References: <20180911083706.5378-1-mahaocong_work@163.com> X-CM-TRANSID: DNGowACnxgjUfpdbq4kPAA--.179S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxZr18XryxtFW5Cw1DZFW5Jrb_yoW5KFy8pF n3JrySgrnYya13Zr4fAa4kJw1ruwn5Xr1DJryxZ343tF4aqrn8X340kF1avFZrJF4UJa13 ZF4YyryDGa1YvFJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jCc_-UUUUU= X-Originating-IP: [111.202.144.35] X-CM-SenderInfo: 5pdkt05frqwspzruyqqrwthudrp/1tbiJxa+ClXloCgI+AAAsN X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 123.125.50.132 X-Mailman-Approved-At: Tue, 11 Sep 2018 08:21:43 -0400 Subject: [Qemu-devel] [PATCH v1 1/1] qemu-img: add new function to remove bitmap in image X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Ma Haocong , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Ma Haocong --- qemu-img-cmds.hx | 6 +++ qemu-img.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 125 insertions(+) diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 1526f327a5..cc397b64e4 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -97,6 +97,12 @@ STEXI @item resize [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [--p= reallocation=3D@var{prealloc}] [-q] [--shrink] @var{filename} [+ | -]@var{s= ize} ETEXI =20 +DEF("removebmp", img_removebmp, + "removebmp [--object objectdef] [--image-opts] [-q] [-f fmt] filename = dirtybitmap") +STEXI +@item removebmp [--object @var{objectdef}] [--image-opts] [-q] [-f @var{fm= t}] @var{filename} @var{dirtybitmap} +ETEXI + STEXI @end table ETEXI diff --git a/qemu-img.c b/qemu-img.c index b12f4cd19b..fdafb4a131 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -835,6 +835,125 @@ fail: return ret; } =20 +/* + * Remove a named dirty bitmap in image. + * This command should be used with no other QEMU process + * open the image at the same time. Otherwise it may be + * croputed the bitmap even the image. + */ +static int img_removebmp(int argc, char **argv) +{ + int c, ret; + const char *filename, *fmt, *bitmapname; + bool quiet =3D false; + BlockBackend *blk; + BlockDriverState *bs; + BdrvDirtyBitmap *bitmap; + Error *local_err =3D NULL; + bool image_opts =3D false; + fmt =3D NULL; + + for (;;) { + int option_index =3D 0; + static const struct option long_options[] =3D { + {"help", no_argument, 0, 'h'}, + {"format", required_argument, 0, 'f'}, + {"object", required_argument, 0, OPTION_OBJECT}, + {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {0, 0, 0, 0} + }; + c =3D getopt_long(argc, argv, ":hf:q", + long_options, &option_index); + 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 'f': + fmt =3D optarg; + break; + case 'q': + quiet =3D true; + break; + case OPTION_OBJECT: { + QemuOpts *opts; + opts =3D qemu_opts_parse_noisily(&qemu_object_opts, + optarg, true); + if (!opts) { + return 1; + } + } break; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; + } + } + + if (optind !=3D argc - 2) { + error_exit("Expecting two parameters"); + } + filename =3D argv[optind++]; + bitmapname =3D argv[optind++]; + + if (qemu_opts_foreach(&qemu_object_opts, + user_creatable_add_opts_foreach, + NULL, NULL)) { + return 1; + } + + blk =3D img_open(image_opts, filename, fmt, + BDRV_O_RDWR, false, quiet, false); + if (!blk) { + ret =3D -1; + goto out; + } + bs =3D blk_bs(blk); + if (!bs) { + ret =3D -1; + goto out; + } + + bitmap =3D bdrv_find_dirty_bitmap(bs, bitmapname); + + /* + * Dirty bitmap may not be load if the 'IN_USE' flag is set (e.g. the + * qemu thread is corrupted and the 'IN_USE' flag is not be cleared), + * so the result of bdrv_find_dirty_bitmap is null. In this case, + * we delete bitmap in qcow2 file directly. + */ + if (!bitmap) { + bdrv_remove_persistent_dirty_bitmap(bs, bitmapname, &local_err); + if (local_err !=3D NULL) { + ret =3D -1; + goto out; + } + } else { + if (bdrv_dirty_bitmap_get_persistance(bitmap)) { + bdrv_remove_persistent_dirty_bitmap(bs, bitmapname, &local_err= ); + if (local_err !=3D NULL) { + ret =3D -1; + goto out; + } + } + bdrv_release_dirty_bitmap(bs, bitmap); + } + +out: + blk_unref(blk); + if (ret) { + return 1; + } + return 0; +} + typedef struct CommonBlockJobCBInfo { BlockDriverState *bs; Error **errp; --=20 2.14.1