Blame SOURCES/kvm-nbd-client-Add-x-dirty-bitmap-to-query-bitmap-from-s.patch

383d26
From d52addb6a2ca32ce942f348ed47da26cd9524fbd Mon Sep 17 00:00:00 2001
383d26
From: John Snow <jsnow@redhat.com>
383d26
Date: Wed, 18 Jul 2018 22:55:10 +0200
383d26
Subject: [PATCH 85/89] nbd/client: Add x-dirty-bitmap to query bitmap from
383d26
 server
383d26
383d26
RH-Author: John Snow <jsnow@redhat.com>
383d26
Message-id: <20180718225511.14878-35-jsnow@redhat.com>
383d26
Patchwork-id: 81414
383d26
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 34/35] nbd/client: Add x-dirty-bitmap to query bitmap from server
383d26
Bugzilla: 1207657
383d26
RH-Acked-by: Eric Blake <eblake@redhat.com>
383d26
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
383d26
RH-Acked-by: Fam Zheng <famz@redhat.com>
383d26
383d26
From: Eric Blake <eblake@redhat.com>
383d26
383d26
In order to test that the NBD server is properly advertising
383d26
dirty bitmaps, we need a bare minimum client that can request
383d26
and read the context.  Since feature freeze for 3.0 is imminent,
383d26
this is the smallest workable patch, which replaces the qemu
383d26
block status report with the results of the NBD server's dirty
383d26
bitmap (making it very easy to use 'qemu-img map --output=json'
383d26
to learn where the dirty portions are).  Note that the NBD
383d26
protocol defines a dirty section with the same bit but opposite
383d26
sense that normal "base:allocation" uses to report an allocated
383d26
section; so in qemu-img map output, "data":true corresponds to
383d26
clean, "data":false corresponds to dirty.
383d26
383d26
A more complete solution that allows dirty bitmaps to be queried
383d26
at the same time as normal block status will be required before
383d26
this addition can lose the x- prefix.  Until then, the fact that
383d26
this replaces normal status with dirty status means actions
383d26
like 'qemu-img convert' will likely misbehave due to treating
383d26
dirty regions of the file as if they are unallocated.
383d26
383d26
The next patch adds an iotest to exercise this new code.
383d26
383d26
Signed-off-by: Eric Blake <eblake@redhat.com>
383d26
Message-Id: <20180702191458.28741-2-eblake@redhat.com>
383d26
(cherry picked from commit 216ee3657e14013505abe7853cecb632199fb13e)
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 block/nbd-client.c   |  3 +++
383d26
 block/nbd-client.h   |  1 +
383d26
 block/nbd.c          | 10 ++++++++--
383d26
 include/block/nbd.h  |  1 +
383d26
 nbd/client.c         |  4 ++--
383d26
 qapi/block-core.json |  7 ++++++-
383d26
 6 files changed, 21 insertions(+), 5 deletions(-)
383d26
383d26
diff --git a/block/nbd-client.c b/block/nbd-client.c
383d26
index e7caf49..98637c0 100644
383d26
--- a/block/nbd-client.c
383d26
+++ b/block/nbd-client.c
383d26
@@ -966,6 +966,7 @@ int nbd_client_init(BlockDriverState *bs,
383d26
                     const char *export,
383d26
                     QCryptoTLSCreds *tlscreds,
383d26
                     const char *hostname,
383d26
+                    const char *x_dirty_bitmap,
383d26
                     Error **errp)
383d26
 {
383d26
     NBDClientSession *client = nbd_get_client_session(bs);
383d26
@@ -978,9 +979,11 @@ int nbd_client_init(BlockDriverState *bs,
383d26
     client->info.request_sizes = true;
383d26
     client->info.structured_reply = true;
383d26
     client->info.base_allocation = true;
383d26
+    client->info.x_dirty_bitmap = g_strdup(x_dirty_bitmap);
383d26
     ret = nbd_receive_negotiate(QIO_CHANNEL(sioc), export,
383d26
                                 tlscreds, hostname,
383d26
                                 &client->ioc, &client->info, errp);
383d26
+    g_free(client->info.x_dirty_bitmap);
383d26
     if (ret < 0) {
383d26
         logout("Failed to negotiate with the NBD server\n");
383d26
         return ret;
383d26
diff --git a/block/nbd-client.h b/block/nbd-client.h
383d26
index 0ece76e..cfc9055 100644
383d26
--- a/block/nbd-client.h
383d26
+++ b/block/nbd-client.h
383d26
@@ -45,6 +45,7 @@ int nbd_client_init(BlockDriverState *bs,
383d26
                     const char *export_name,
383d26
                     QCryptoTLSCreds *tlscreds,
383d26
                     const char *hostname,
383d26
+                    const char *x_dirty_bitmap,
383d26
                     Error **errp);
383d26
 void nbd_client_close(BlockDriverState *bs);
383d26
 
383d26
diff --git a/block/nbd.c b/block/nbd.c
383d26
index 10912c3..f29c10f 100644
383d26
--- a/block/nbd.c
383d26
+++ b/block/nbd.c
383d26
@@ -378,6 +378,12 @@ static QemuOptsList nbd_runtime_opts = {
383d26
             .type = QEMU_OPT_STRING,
383d26
             .help = "ID of the TLS credentials to use",
383d26
         },
383d26
+        {
383d26
+            .name = "x-dirty-bitmap",
383d26
+            .type = QEMU_OPT_STRING,
383d26
+            .help = "experimental: expose named dirty bitmap in place of "
383d26
+                    "block status",
383d26
+        },
383d26
         { /* end of list */ }
383d26
     },
383d26
 };
383d26
@@ -438,8 +444,8 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
383d26
     }
383d26
 
383d26
     /* NBD handshake */
383d26
-    ret = nbd_client_init(bs, sioc, s->export,
383d26
-                          tlscreds, hostname, errp);
383d26
+    ret = nbd_client_init(bs, sioc, s->export, tlscreds, hostname,
383d26
+                          qemu_opt_get(opts, "x-dirty-bitmap"), errp);
383d26
  error:
383d26
     if (sioc) {
383d26
         object_unref(OBJECT(sioc));
383d26
diff --git a/include/block/nbd.h b/include/block/nbd.h
383d26
index daaeae6..4638c83 100644
383d26
--- a/include/block/nbd.h
383d26
+++ b/include/block/nbd.h
383d26
@@ -259,6 +259,7 @@ static inline bool nbd_reply_type_is_error(int type)
383d26
 struct NBDExportInfo {
383d26
     /* Set by client before nbd_receive_negotiate() */
383d26
     bool request_sizes;
383d26
+    char *x_dirty_bitmap;
383d26
 
383d26
     /* In-out fields, set by client before nbd_receive_negotiate() and
383d26
      * updated by server results during nbd_receive_negotiate() */
383d26
diff --git a/nbd/client.c b/nbd/client.c
383d26
index b9e175d..25603f2 100644
383d26
--- a/nbd/client.c
383d26
+++ b/nbd/client.c
383d26
@@ -1,5 +1,5 @@
383d26
 /*
383d26
- *  Copyright (C) 2016-2017 Red Hat, Inc.
383d26
+ *  Copyright (C) 2016-2018 Red Hat, Inc.
383d26
  *  Copyright (C) 2005  Anthony Liguori <anthony@codemonkey.ws>
383d26
  *
383d26
  *  Network Block Device Client Side
383d26
@@ -825,7 +825,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name,
383d26
 
383d26
             if (info->structured_reply && base_allocation) {
383d26
                 result = nbd_negotiate_simple_meta_context(
383d26
-                        ioc, name, "base:allocation",
383d26
+                        ioc, name, info->x_dirty_bitmap ?: "base:allocation",
383d26
                         &info->meta_base_allocation_id, errp);
383d26
                 if (result < 0) {
383d26
                     goto fail;
383d26
diff --git a/qapi/block-core.json b/qapi/block-core.json
383d26
index 69e0cf8..8a00bec 100644
383d26
--- a/qapi/block-core.json
383d26
+++ b/qapi/block-core.json
383d26
@@ -3457,12 +3457,17 @@
383d26
 #
383d26
 # @tls-creds:   TLS credentials ID
383d26
 #
383d26
+# @x-dirty-bitmap: A "qemu:dirty-bitmap:NAME" string to query in place of
383d26
+#                  traditional "base:allocation" block status (see
383d26
+#                  NBD_OPT_LIST_META_CONTEXT in the NBD protocol) (since 3.0)
383d26
+#
383d26
 # Since: 2.9
383d26
 ##
383d26
 { 'struct': 'BlockdevOptionsNbd',
383d26
   'data': { 'server': 'SocketAddress',
383d26
             '*export': 'str',
383d26
-            '*tls-creds': 'str' } }
383d26
+            '*tls-creds': 'str',
383d26
+            '*x-dirty-bitmap': 'str' } }
383d26
 
383d26
 ##
383d26
 # @BlockdevOptionsRaw:
383d26
-- 
383d26
1.8.3.1
383d26