Blame SOURCES/kvm-nbd-Merge-nbd_export_bitmap-into-nbd_export_new.patch

7711c0
From 13ac133e5fbde2559899dc3717b2a2c20ce9aeb1 Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Wed, 27 Mar 2019 17:22:32 +0100
7711c0
Subject: [PATCH 093/163] nbd: Merge nbd_export_bitmap into nbd_export_new
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190327172308.31077-20-jsnow@redhat.com>
7711c0
Patchwork-id: 85190
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 19/55] nbd: Merge nbd_export_bitmap into nbd_export_new
7711c0
Bugzilla: 1691009
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Max Reitz <mreitz@redhat.com>
7711c0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
7711c0
From: Eric Blake <eblake@redhat.com>
7711c0
7711c0
We only have one caller that wants to export a bitmap name,
7711c0
which it does right after creation of the export. But there is
7711c0
still a brief window of time where an NBD client could see the
7711c0
export but not the dirty bitmap, which a robust client would
7711c0
have to interpret as meaning the entire image should be treated
7711c0
as dirty.  Better is to eliminate the window entirely, by
7711c0
inlining nbd_export_bitmap() into nbd_export_new(), and refusing
7711c0
to create the bitmap in the first place if the requested bitmap
7711c0
can't be located.
7711c0
7711c0
We also no longer need logic for setting a different bitmap
7711c0
name compared to the bitmap being exported.
7711c0
7711c0
Signed-off-by: Eric Blake <eblake@redhat.com>
7711c0
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7711c0
Message-Id: <20190111194720.15671-8-eblake@redhat.com>
7711c0
(cherry picked from commit 678ba275c77b5b12f3bc9bb369a1b824fc9f679f)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 blockdev-nbd.c      | 11 +------
7711c0
 include/block/nbd.h |  9 ++----
7711c0
 nbd/server.c        | 87 ++++++++++++++++++++++++-----------------------------
7711c0
 qemu-nbd.c          |  5 +--
7711c0
 4 files changed, 47 insertions(+), 65 deletions(-)
7711c0
7711c0
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
7711c0
index cd86b38..c76d541 100644
7711c0
--- a/blockdev-nbd.c
7711c0
+++ b/blockdev-nbd.c
7711c0
@@ -175,7 +175,7 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
7711c0
         writable = false;
7711c0
     }
7711c0
 
7711c0
-    exp = nbd_export_new(bs, 0, -1, name, NULL,
7711c0
+    exp = nbd_export_new(bs, 0, -1, name, NULL, bitmap,
7711c0
                          writable ? 0 : NBD_FLAG_READ_ONLY,
7711c0
                          NULL, false, on_eject_blk, errp);
7711c0
     if (!exp) {
7711c0
@@ -186,15 +186,6 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
7711c0
      * our only way of accessing it is through nbd_export_find(), so we can drop
7711c0
      * the strong reference that is @exp. */
7711c0
     nbd_export_put(exp);
7711c0
-
7711c0
-    if (has_bitmap) {
7711c0
-        Error *err = NULL;
7711c0
-        nbd_export_bitmap(exp, bitmap, bitmap, &err;;
7711c0
-        if (err) {
7711c0
-            error_propagate(errp, err);
7711c0
-            nbd_export_remove(exp, NBD_SERVER_REMOVE_MODE_HARD, NULL);
7711c0
-        }
7711c0
-    }
7711c0
 }
7711c0
 
7711c0
 void qmp_nbd_server_remove(const char *name,
7711c0
diff --git a/include/block/nbd.h b/include/block/nbd.h
7711c0
index 2f9a2ae..1971b55 100644
7711c0
--- a/include/block/nbd.h
7711c0
+++ b/include/block/nbd.h
7711c0
@@ -296,9 +296,9 @@ typedef struct NBDClient NBDClient;
7711c0
 
7711c0
 NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size,
7711c0
                           const char *name, const char *description,
7711c0
-                          uint16_t nbdflags, void (*close)(NBDExport *),
7711c0
-                          bool writethrough, BlockBackend *on_eject_blk,
7711c0
-                          Error **errp);
7711c0
+                          const char *bitmap, uint16_t nbdflags,
7711c0
+                          void (*close)(NBDExport *), bool writethrough,
7711c0
+                          BlockBackend *on_eject_blk, Error **errp);
7711c0
 void nbd_export_close(NBDExport *exp);
7711c0
 void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp);
7711c0
 void nbd_export_get(NBDExport *exp);
7711c0
@@ -319,9 +319,6 @@ void nbd_client_put(NBDClient *client);
7711c0
 void nbd_server_start(SocketAddress *addr, const char *tls_creds,
7711c0
                       Error **errp);
7711c0
 
7711c0
-void nbd_export_bitmap(NBDExport *exp, const char *bitmap,
7711c0
-                       const char *bitmap_export_name, Error **errp);
7711c0
-
7711c0
 /* nbd_read
7711c0
  * Reads @size bytes from @ioc. Returns 0 on success.
7711c0
  */
7711c0
diff --git a/nbd/server.c b/nbd/server.c
7711c0
index 6c02b57..6b13601 100644
7711c0
--- a/nbd/server.c
7711c0
+++ b/nbd/server.c
7711c0
@@ -1457,9 +1457,9 @@ static void nbd_eject_notifier(Notifier *n, void *data)
7711c0
 
7711c0
 NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size,
7711c0
                           const char *name, const char *description,
7711c0
-                          uint16_t nbdflags, void (*close)(NBDExport *),
7711c0
-                          bool writethrough, BlockBackend *on_eject_blk,
7711c0
-                          Error **errp)
7711c0
+                          const char *bitmap, uint16_t nbdflags,
7711c0
+                          void (*close)(NBDExport *), bool writethrough,
7711c0
+                          BlockBackend *on_eject_blk, Error **errp)
7711c0
 {
7711c0
     AioContext *ctx;
7711c0
     BlockBackend *blk;
7711c0
@@ -1507,6 +1507,43 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size,
7711c0
     }
7711c0
     exp->size -= exp->size % BDRV_SECTOR_SIZE;
7711c0
 
7711c0
+    if (bitmap) {
7711c0
+        BdrvDirtyBitmap *bm = NULL;
7711c0
+        BlockDriverState *bs = blk_bs(blk);
7711c0
+
7711c0
+        while (true) {
7711c0
+            bm = bdrv_find_dirty_bitmap(bs, bitmap);
7711c0
+            if (bm != NULL || bs->backing == NULL) {
7711c0
+                break;
7711c0
+            }
7711c0
+
7711c0
+            bs = bs->backing->bs;
7711c0
+        }
7711c0
+
7711c0
+        if (bm == NULL) {
7711c0
+            error_setg(errp, "Bitmap '%s' is not found", bitmap);
7711c0
+            goto fail;
7711c0
+        }
7711c0
+
7711c0
+        if ((nbdflags & NBD_FLAG_READ_ONLY) && bdrv_is_writable(bs) &&
7711c0
+            bdrv_dirty_bitmap_enabled(bm)) {
7711c0
+            error_setg(errp,
7711c0
+                       "Enabled bitmap '%s' incompatible with readonly export",
7711c0
+                       bitmap);
7711c0
+            goto fail;
7711c0
+        }
7711c0
+
7711c0
+        if (bdrv_dirty_bitmap_user_locked(bm)) {
7711c0
+            error_setg(errp, "Bitmap '%s' is in use", bitmap);
7711c0
+            goto fail;
7711c0
+        }
7711c0
+
7711c0
+        bdrv_dirty_bitmap_set_qmp_locked(bm, true);
7711c0
+        exp->export_bitmap = bm;
7711c0
+        exp->export_bitmap_context = g_strdup_printf("qemu:dirty-bitmap:%s",
7711c0
+                                                     bitmap);
7711c0
+    }
7711c0
+
7711c0
     exp->close = close;
7711c0
     exp->ctx = blk_get_aio_context(blk);
7711c0
     blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, exp);
7711c0
@@ -2424,47 +2461,3 @@ void nbd_client_new(QIOChannelSocket *sioc,
7711c0
     co = qemu_coroutine_create(nbd_co_client_start, client);
7711c0
     qemu_coroutine_enter(co);
7711c0
 }
7711c0
-
7711c0
-void nbd_export_bitmap(NBDExport *exp, const char *bitmap,
7711c0
-                       const char *bitmap_export_name, Error **errp)
7711c0
-{
7711c0
-    BdrvDirtyBitmap *bm = NULL;
7711c0
-    BlockDriverState *bs = blk_bs(exp->blk);
7711c0
-
7711c0
-    if (exp->export_bitmap) {
7711c0
-        error_setg(errp, "Export bitmap is already set");
7711c0
-        return;
7711c0
-    }
7711c0
-
7711c0
-    while (true) {
7711c0
-        bm = bdrv_find_dirty_bitmap(bs, bitmap);
7711c0
-        if (bm != NULL || bs->backing == NULL) {
7711c0
-            break;
7711c0
-        }
7711c0
-
7711c0
-        bs = bs->backing->bs;
7711c0
-    }
7711c0
-
7711c0
-    if (bm == NULL) {
7711c0
-        error_setg(errp, "Bitmap '%s' is not found", bitmap);
7711c0
-        return;
7711c0
-    }
7711c0
-
7711c0
-    if ((exp->nbdflags & NBD_FLAG_READ_ONLY) && bdrv_is_writable(bs) &&
7711c0
-        bdrv_dirty_bitmap_enabled(bm)) {
7711c0
-        error_setg(errp,
7711c0
-                   "Enabled bitmap '%s' incompatible with readonly export",
7711c0
-                   bitmap);
7711c0
-        return;
7711c0
-    }
7711c0
-
7711c0
-    if (bdrv_dirty_bitmap_user_locked(bm)) {
7711c0
-        error_setg(errp, "Bitmap '%s' is in use", bitmap);
7711c0
-        return;
7711c0
-    }
7711c0
-
7711c0
-    bdrv_dirty_bitmap_set_qmp_locked(bm, true);
7711c0
-    exp->export_bitmap = bm;
7711c0
-    exp->export_bitmap_context =
7711c0
-            g_strdup_printf("qemu:dirty-bitmap:%s", bitmap_export_name);
7711c0
-}
7711c0
diff --git a/qemu-nbd.c b/qemu-nbd.c
7711c0
index c85aee4..ac4c958 100644
7711c0
--- a/qemu-nbd.c
7711c0
+++ b/qemu-nbd.c
7711c0
@@ -1018,8 +1018,9 @@ int main(int argc, char **argv)
7711c0
     }
7711c0
 
7711c0
     export = nbd_export_new(bs, dev_offset, fd_size, export_name,
7711c0
-                            export_description, nbdflags, nbd_export_closed,
7711c0
-                            writethrough, NULL, &error_fatal);
7711c0
+                            export_description, NULL, nbdflags,
7711c0
+                            nbd_export_closed, writethrough, NULL,
7711c0
+                            &error_fatal);
7711c0
 
7711c0
     if (device) {
7711c0
 #if HAVE_NBD_DEVICE
7711c0
-- 
7711c0
1.8.3.1
7711c0