From nobody Thu Oct 30 08:11:36 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526088655872476.13220377337325; Fri, 11 May 2018 18:30:55 -0700 (PDT) Received: from localhost ([::1]:33837 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHJN9-0002E3-0j for importer@patchew.org; Fri, 11 May 2018 21:30:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHJIE-0006SR-Af for qemu-devel@nongnu.org; Fri, 11 May 2018 21:25:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fHJIB-0006Yr-Pt for qemu-devel@nongnu.org; Fri, 11 May 2018 21:25:50 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33936 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fHJI8-0006Ue-PQ; Fri, 11 May 2018 21:25:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 448B3F640A; Sat, 12 May 2018 01:25:44 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-231.bos.redhat.com [10.18.17.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id E01BB215CDB7; Sat, 12 May 2018 01:25:43 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 11 May 2018 21:25:37 -0400 Message-Id: <20180512012537.22478-13-jsnow@redhat.com> In-Reply-To: <20180512012537.22478-1-jsnow@redhat.com> References: <20180512012537.22478-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sat, 12 May 2018 01:25:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sat, 12 May 2018 01:25:44 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [RFC PATCH 12/12] qemu-img: add bitmap clear 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 , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Max Reitz , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: 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: John Snow --- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index d25f359f5a..7b6ec73488 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -23,9 +23,9 @@ STEXI ETEXI =20 DEF("bitmap", img_bitmap, - "bitmap dump [--object objectdef] [--image-opts] [-f fmt] [--output=3D= ofmt] [-U] filename [bitmap]") + "bitmap [--object objectdef] [--image-opts] [-f fmt] [--o= utput=3Dofmt] [-U] filename [bitmap]") STEXI -@item bitmap dump [--object @var{objectdef}] [--image-opts] [-f @var{fmt}]= [--output=3D@var{ofmt}] [-U] @var{filename} [@var{bitmap}] +@item bitmap [--object @var{objectdef}] [--image-opts] [-f @v= ar{fmt}] [--output=3D@var{ofmt}] [-U] @var{filename} [@var{bitmap}] ETEXI =20 DEF("check", img_check, diff --git a/qemu-img.c b/qemu-img.c index 1141216617..b5ab8a3837 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2967,7 +2967,22 @@ static void dump_bitmap_mapping(BitmapMapping *bm, O= utputFormat output_format, } } =20 -/* img_bitmap subcommands: dump */ +static int do_bitmap_clear(BlockDriverState *bs, BdrvDirtyBitmap *bitmap) +{ + bool enabled =3D bdrv_dirty_bitmap_enabled(bitmap); + + if (!enabled) { + bdrv_enable_dirty_bitmap(bitmap); + } + bdrv_clear_dirty_bitmap(bitmap, NULL); + if (!enabled) { + bdrv_disable_dirty_bitmap(bitmap); + } + + return 0; +} + +/* img_bitmap subcommands: dump, clear */ =20 typedef struct BitmapOpts { CommonOpts base; @@ -3017,6 +3032,30 @@ static int bitmap_cmd_dump(BlockDriverState *bs, Bit= mapOpts *opts) return 0; } =20 +static int bitmap_cmd_clear(BlockDriverState *bs, BitmapOpts *opts) +{ + BdrvDirtyBitmap *bitmap =3D NULL; + + if (opts->name) { + bitmap =3D bdrv_find_dirty_bitmap(bs, opts->name); + if (!bitmap) { + error_report("No bitmap named '%s' found", opts->name); + return -1; + } + if (do_bitmap_clear(bs, bitmap)) { + return -1; + } + } else { + while ((bitmap =3D bdrv_dirty_bitmap_next(bs, bitmap))) { + if (do_bitmap_clear(bs, bitmap)) { + return -1; + } + } + } + + return 0; +} + static int img_bitmap(int argc, char **argv) { const char *cmd; @@ -3029,12 +3068,15 @@ static int img_bitmap(int argc, char **argv) int (* handler)(BlockDriverState *b, BitmapOpts *opts); =20 if (argc < 2) { - error_report("Expected a bitmap subcommand: "); + error_report("Expected a bitmap subcommand: "); return EXIT_FAILURE; } cmd =3D argv[1]; if (strcmp(cmd, "dump") =3D=3D 0) { handler =3D bitmap_cmd_dump; + } else if (strcmp(cmd, "clear") =3D=3D 0) { + flags |=3D BDRV_O_RDWR; + handler =3D bitmap_cmd_clear; } else { error_report("Unrecognized bitmap subcommand '%s'", cmd); return EXIT_FAILURE; --=20 2.14.3