From nobody Wed Apr 24 19:51:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1565736329; cv=none; d=zoho.com; s=zohoarc; b=gtJMEBzYL79bCzJoDzYIKL2iulCu/amaYg1M8MJ+ioGsTaJJL02GNPAumq/Zi9jLI8yuuek3soKGZO8aNOK97swH5pK850xp4vRGSkqPplr3tw1A1RCzAysO30WxV+4rZ/P4beEk0IZVqWZJ6LD/vzjVEJjd1kS5qB5pw1/Qt+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565736329; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=SJ7klDGCQAqGWFdpNmPzn/plefSacM0fpRuuCR0Tfic=; b=iajstdmNOzFv30eL9yBiIe7Vt3GgmU8UuPPUM1spKUWpLoFntKu4DUdnZ6+FnGowmPNfiDbp7TsUGWLdBU2JvBu95E71ayRULbuTkdHUYUUgPEOC+YtBmYWeUG5/0xwutXFIUenhrWe7ZubzPgTKvjTXpKYvaLylBciEEJNqQHw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1565736329434654.3956982271086; Tue, 13 Aug 2019 15:45:29 -0700 (PDT) Received: from localhost ([::1]:55972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hxfXk-0001sC-8V for importer@patchew.org; Tue, 13 Aug 2019 18:45:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55445) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hxfXD-0000wO-6s for qemu-devel@nongnu.org; Tue, 13 Aug 2019 18:44:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hxfXB-0003OS-UR for qemu-devel@nongnu.org; Tue, 13 Aug 2019 18:44:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44506) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hxfX9-0003Na-Bq; Tue, 13 Aug 2019 18:44:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9703883F3C; Tue, 13 Aug 2019 22:44:50 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-169.bos.redhat.com [10.18.17.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FAD94C5; Tue, 13 Aug 2019 22:44:47 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 13 Aug 2019 18:44:46 -0400 Message-Id: <20190813224446.14145-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 13 Aug 2019 22:44:50 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC] dirty-bitmaps: add block-dirty-bitmap-persist command 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: Kevin Wolf , John Snow , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This is for the purpose of toggling on/off persistence on a bitmap. This enables you to save a bitmap that was not persistent, but may have already accumulated valuable data. This is simply a QOL enhancement: - Allows user to "upgrade" an existing bitmap to persistent - Allows user to "downgrade" an existing bitmap to transient, removing it from storage without deleting the bitmap. Signed-off-by: John Snow --- This is just an RFC because I'm not sure if I really want to pursue adding this, but it was raised in a discussion I had recently that it was a little annoying as an API design that persistence couldn't be changed after addition, so I wanted to see how much code it would take to address that. (So this patch isn't really tested; just: "Hey, look!") I don't like this patch because it exacerbates my perceived problems with the "check if I can make it persistent, then toggle the flag" model, where I prefer the "Just try to set it persistent and let it fail if it cannot" model, but there were some issues with that patchset that I want to revisit. --- blockdev.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 34 ++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/blockdev.c b/blockdev.c index 2d7e7be538..230442e921 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3095,6 +3095,55 @@ void qmp_block_dirty_bitmap_merge(const char *node, = const char *target, do_block_dirty_bitmap_merge(node, target, bitmaps, NULL, errp); } =20 +void qmp_block_dirty_bitmap_persist(const char *node, const char *name, + bool persist, Error **errp) +{ + BdrvDirtyBitmap *bitmap; + BlockDriverState *bs; + AioContext *aio_context =3D NULL; + Error *local_err =3D NULL; + bool persistent; + + 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; + } + + persistent =3D bdrv_dirty_bitmap_get_persistence(bitmap); + + if (persist !=3D persistent) { + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + } + + if (!persist && persistent) { + bdrv_remove_persistent_dirty_bitmap(bs, name, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + goto out; + } + } + + if (persist && !persistent) { + uint32_t granularity =3D bdrv_dirty_bitmap_granularity(bitmap); + if (!bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp))= { + goto out; + } + } + + bdrv_dirty_bitmap_set_persistence(bitmap, persistent); + + out: + if (aio_context) { + aio_context_release(aio_context); + } + return; +} + BlockDirtyBitmapSha256 *qmp_x_debug_block_dirty_bitmap_sha256(const char *= node, const char *= name, Error **errp) diff --git a/qapi/block-core.json b/qapi/block-core.json index 3dbf23d874..9c0957f528 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2001,6 +2001,19 @@ 'data': { 'node': 'str', 'name': 'str', '*granularity': 'uint32', '*persistent': 'bool', '*autoload': 'bool', '*disabled': 'bool= ' } } =20 +## +# @BlockDirtyBitmapPersist: +# +# @persist: True sets the specified bitmap as persistent. +# False will remove it from storage and mark it transient. +# +# Since: 4.2 +## +{ 'struct': 'BlockDirtyBitmapPersist', + 'base': 'BlockDirtyBitmap', + 'data': { 'persist': 'bool' } +} + ## # @BlockDirtyBitmapMergeSource: # @@ -2173,6 +2186,27 @@ { 'command': 'block-dirty-bitmap-merge', 'data': 'BlockDirtyBitmapMerge' } =20 +## +# @block-dirty-bitmap-persist: +# +# Mark a dirty bitmap as either persistent or transient. +# +# Returns: nothing on success; including for no-op. +# GenericError with explanation if the operation did not succeed. +# +# Example: +# +# -> { "execute": "block-dirty-bitmap-persist", +# "arguments": { "node": "drive0", +# "bitmap": "bitmap0", +# "persist": true } } +# <- { "return": {} } +# +# Since: 4.2 +## +{ 'command': 'block-dirty-bitmap-persist', + 'data': 'BlockDirtyBitmapPersist' } + ## # @BlockDirtyBitmapSha256: # --=20 2.21.0