yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Make-it-easier-to-learn-which-BDS-support-bitm.patch

77c23f
From 41d6c207c482093df8669f7cdcdb49bb25dba741 Mon Sep 17 00:00:00 2001
77c23f
From: Eric Blake <eblake@redhat.com>
77c23f
Date: Tue, 2 Jun 2020 02:34:12 +0100
77c23f
Subject: [PATCH 07/26] block: Make it easier to learn which BDS support
77c23f
 bitmaps
77c23f
MIME-Version: 1.0
77c23f
Content-Type: text/plain; charset=UTF-8
77c23f
Content-Transfer-Encoding: 8bit
77c23f
77c23f
RH-Author: Eric Blake <eblake@redhat.com>
77c23f
Message-id: <20200602023420.2133649-5-eblake@redhat.com>
77c23f
Patchwork-id: 97071
77c23f
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 04/12] block: Make it easier to learn which BDS support bitmaps
77c23f
Bugzilla: 1779893 1779904
77c23f
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
77c23f
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
77c23f
RH-Acked-by: Max Reitz <mreitz@redhat.com>
77c23f
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
77c23f
77c23f
Upcoming patches will enhance bitmap support in qemu-img, but in doing
77c23f
so, it turns out to be nice to suppress output when persistent bitmaps
77c23f
make no sense (such as on a qcow2 v2 image).  Add a hook to make this
77c23f
easier to query.
77c23f
77c23f
This patch adds a new callback .bdrv_supports_persistent_dirty_bitmap,
77c23f
rather than trying to shoehorn the answer in via existing callbacks.
77c23f
In particular, while it might have been possible to overload
77c23f
.bdrv_co_can_store_new_dirty_bitmap to special-case a NULL input to
77c23f
answer whether any persistent bitmaps are supported, that is at odds
77c23f
with whether a particular bitmap can be stored (for example, even on
77c23f
an image that supports persistent bitmaps but has currently filled up
77c23f
the maximum number of bitmaps, attempts to store another one should
77c23f
fail); and the new functionality doesn't require coroutine safety.
77c23f
Similarly, we could have added one more piece of information to
77c23f
.bdrv_get_info, but then again, most callers to that function tend to
77c23f
already discard extraneous information, and making it a catch-all
77c23f
rather than a series of dedicated scalar queries hasn't really
77c23f
simplified life.
77c23f
77c23f
In the future, when we improve the ability to look up bitmaps through
77c23f
a filter, we will probably also want to teach the block layer to
77c23f
automatically let filters pass this request on through.
77c23f
77c23f
Signed-off-by: Eric Blake <eblake@redhat.com>
77c23f
Message-Id: <20200513011648.166876-4-eblake@redhat.com>
77c23f
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
77c23f
(cherry picked from commit ef893b5c84f3199d777e33966dc28839f71b1a5c)
77c23f
Signed-off-by: Eric Blake <eblake@redhat.com>
77c23f
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
77c23f
---
77c23f
 block/dirty-bitmap.c         | 9 +++++++++
77c23f
 block/qcow2-bitmap.c         | 7 +++++++
77c23f
 block/qcow2.c                | 2 ++
77c23f
 block/qcow2.h                | 1 +
77c23f
 include/block/block_int.h    | 1 +
77c23f
 include/block/dirty-bitmap.h | 1 +
77c23f
 6 files changed, 21 insertions(+)
77c23f
77c23f
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
77c23f
index 7039e82..2f96acc 100644
77c23f
--- a/block/dirty-bitmap.c
77c23f
+++ b/block/dirty-bitmap.c
77c23f
@@ -478,6 +478,15 @@ int bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name,
77c23f
     }
77c23f
 }
77c23f
 
77c23f
+bool
77c23f
+bdrv_supports_persistent_dirty_bitmap(BlockDriverState *bs)
77c23f
+{
77c23f
+    if (bs->drv && bs->drv->bdrv_supports_persistent_dirty_bitmap) {
77c23f
+        return bs->drv->bdrv_supports_persistent_dirty_bitmap(bs);
77c23f
+    }
77c23f
+    return false;
77c23f
+}
77c23f
+
77c23f
 static bool coroutine_fn
77c23f
 bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name,
77c23f
                                    uint32_t granularity, Error **errp)
77c23f
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
77c23f
index c6c8ebb..cbac905 100644
77c23f
--- a/block/qcow2-bitmap.c
77c23f
+++ b/block/qcow2-bitmap.c
77c23f
@@ -1759,3 +1759,10 @@ fail:
77c23f
                   name, bdrv_get_device_or_node_name(bs));
77c23f
     return false;
77c23f
 }
77c23f
+
77c23f
+bool qcow2_supports_persistent_dirty_bitmap(BlockDriverState *bs)
77c23f
+{
77c23f
+    BDRVQcow2State *s = bs->opaque;
77c23f
+
77c23f
+    return s->qcow_version >= 3;
77c23f
+}
77c23f
diff --git a/block/qcow2.c b/block/qcow2.c
77c23f
index af0ad4a..36b0f7d 100644
77c23f
--- a/block/qcow2.c
77c23f
+++ b/block/qcow2.c
77c23f
@@ -5551,6 +5551,8 @@ BlockDriver bdrv_qcow2 = {
77c23f
     .bdrv_detach_aio_context  = qcow2_detach_aio_context,
77c23f
     .bdrv_attach_aio_context  = qcow2_attach_aio_context,
77c23f
 
77c23f
+    .bdrv_supports_persistent_dirty_bitmap =
77c23f
+            qcow2_supports_persistent_dirty_bitmap,
77c23f
     .bdrv_co_can_store_new_dirty_bitmap = qcow2_co_can_store_new_dirty_bitmap,
77c23f
     .bdrv_co_remove_persistent_dirty_bitmap =
77c23f
             qcow2_co_remove_persistent_dirty_bitmap,
77c23f
diff --git a/block/qcow2.h b/block/qcow2.h
77c23f
index 0942126..ceb1ceb 100644
77c23f
--- a/block/qcow2.h
77c23f
+++ b/block/qcow2.h
77c23f
@@ -767,6 +767,7 @@ bool qcow2_co_can_store_new_dirty_bitmap(BlockDriverState *bs,
77c23f
 int qcow2_co_remove_persistent_dirty_bitmap(BlockDriverState *bs,
77c23f
                                             const char *name,
77c23f
                                             Error **errp);
77c23f
+bool qcow2_supports_persistent_dirty_bitmap(BlockDriverState *bs);
77c23f
 
77c23f
 ssize_t coroutine_fn
77c23f
 qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size,
77c23f
diff --git a/include/block/block_int.h b/include/block/block_int.h
77c23f
index 562dca1..cc18e8d 100644
77c23f
--- a/include/block/block_int.h
77c23f
+++ b/include/block/block_int.h
77c23f
@@ -568,6 +568,7 @@ struct BlockDriver {
77c23f
                              uint64_t parent_perm, uint64_t parent_shared,
77c23f
                              uint64_t *nperm, uint64_t *nshared);
77c23f
 
77c23f
+    bool (*bdrv_supports_persistent_dirty_bitmap)(BlockDriverState *bs);
77c23f
     bool (*bdrv_co_can_store_new_dirty_bitmap)(BlockDriverState *bs,
77c23f
                                                const char *name,
77c23f
                                                uint32_t granularity,
77c23f
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
77c23f
index e2b20ec..f6e9a38 100644
77c23f
--- a/include/block/dirty-bitmap.h
77c23f
+++ b/include/block/dirty-bitmap.h
77c23f
@@ -16,6 +16,7 @@ typedef enum BitmapCheckFlags {
77c23f
 
77c23f
 #define BDRV_BITMAP_MAX_NAME_SIZE 1023
77c23f
 
77c23f
+bool bdrv_supports_persistent_dirty_bitmap(BlockDriverState *bs);
77c23f
 BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
77c23f
                                           uint32_t granularity,
77c23f
                                           const char *name,
77c23f
-- 
77c23f
1.8.3.1
77c23f