thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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