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

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