Blame SOURCES/kvm-nbd-client-Change-signature-of-nbd_negotiate_simple_.patch

383d26
From 6b1be3a2c8f8eb10c46a4d98ada0347569284141 Mon Sep 17 00:00:00 2001
383d26
From: John Snow <jsnow@redhat.com>
383d26
Date: Wed, 27 Mar 2019 17:22:44 +0100
383d26
Subject: [PATCH 106/163] nbd/client: Change signature of
383d26
 nbd_negotiate_simple_meta_context()
383d26
383d26
RH-Author: John Snow <jsnow@redhat.com>
383d26
Message-id: <20190327172308.31077-32-jsnow@redhat.com>
383d26
Patchwork-id: 85194
383d26
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 31/55] nbd/client: Change signature of nbd_negotiate_simple_meta_context()
383d26
Bugzilla: 1691009
383d26
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
383d26
RH-Acked-by: Max Reitz <mreitz@redhat.com>
383d26
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
383d26
From: Eric Blake <eblake@redhat.com>
383d26
383d26
Pass 'info' instead of three separate parameters related to info,
383d26
when requesting the server to set the meta context.  Update the
383d26
NBDExportInfo struct to rename the received id field to match the
383d26
fact that we are currently overloading the field to match whatever
383d26
context the user supplied through the x-dirty-bitmap hack, as well
383d26
as adding a TODO comment to remind future patches about a desire
383d26
to request two contexts at once.
383d26
383d26
Signed-off-by: Eric Blake <eblake@redhat.com>
383d26
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
383d26
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
383d26
Message-Id: <20190117193658.16413-11-eblake@redhat.com>
383d26
(cherry picked from commit 2df94eb52b68d16f8a050bc28dd94a8c7d3366ec)
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 block/nbd-client.c  |  4 ++--
383d26
 include/block/nbd.h |  2 +-
383d26
 nbd/client.c        | 53 +++++++++++++++++++++++++----------------------------
383d26
 3 files changed, 28 insertions(+), 31 deletions(-)
383d26
383d26
diff --git a/block/nbd-client.c b/block/nbd-client.c
383d26
index 3309376..8135396 100644
383d26
--- a/block/nbd-client.c
383d26
+++ b/block/nbd-client.c
383d26
@@ -249,11 +249,11 @@ static int nbd_parse_blockstatus_payload(NBDClientSession *client,
383d26
     }
383d26
 
383d26
     context_id = payload_advance32(&payload);
383d26
-    if (client->info.meta_base_allocation_id != context_id) {
383d26
+    if (client->info.context_id != context_id) {
383d26
         error_setg(errp, "Protocol error: unexpected context id %d for "
383d26
                          "NBD_REPLY_TYPE_BLOCK_STATUS, when negotiated context "
383d26
                          "id is %d", context_id,
383d26
-                         client->info.meta_base_allocation_id);
383d26
+                         client->info.context_id);
383d26
         return -EINVAL;
383d26
     }
383d26
 
383d26
diff --git a/include/block/nbd.h b/include/block/nbd.h
383d26
index 00d3eb5..be19aac 100644
383d26
--- a/include/block/nbd.h
383d26
+++ b/include/block/nbd.h
383d26
@@ -276,7 +276,7 @@ struct NBDExportInfo {
383d26
     uint32_t opt_block;
383d26
     uint32_t max_block;
383d26
 
383d26
-    uint32_t meta_base_allocation_id;
383d26
+    uint32_t context_id;
383d26
 };
383d26
 typedef struct NBDExportInfo NBDExportInfo;
383d26
 
383d26
diff --git a/nbd/client.c b/nbd/client.c
383d26
index 8227e69..7799389 100644
383d26
--- a/nbd/client.c
383d26
+++ b/nbd/client.c
383d26
@@ -630,26 +630,30 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
383d26
 }
383d26
 
383d26
 /* nbd_negotiate_simple_meta_context:
383d26
- * Set one meta context. Simple means that reply must contain zero (not
383d26
- * negotiated) or one (negotiated) contexts. More contexts would be considered
383d26
- * as a protocol error. It's also implied that meta-data query equals queried
383d26
- * context name, so, if server replies with something different than @context,
383d26
- * it is considered an error too.
383d26
- * return 1 for successful negotiation, context_id is set
383d26
+ * Request the server to set the meta context for export @info->name
383d26
+ * using @info->x_dirty_bitmap with a fallback to "base:allocation",
383d26
+ * setting @info->context_id to the resulting id. Fail if the server
383d26
+ * responds with more than one context or with a context different
383d26
+ * than the query.
383d26
+ * return 1 for successful negotiation,
383d26
  *        0 if operation is unsupported,
383d26
  *        -1 with errp set for any other error
383d26
  */
383d26
 static int nbd_negotiate_simple_meta_context(QIOChannel *ioc,
383d26
-                                             const char *export,
383d26
-                                             const char *context,
383d26
-                                             uint32_t *context_id,
383d26
+                                             NBDExportInfo *info,
383d26
                                              Error **errp)
383d26
 {
383d26
+    /*
383d26
+     * TODO: Removing the x_dirty_bitmap hack will mean refactoring
383d26
+     * this function to request and store ids for multiple contexts
383d26
+     * (both base:allocation and a dirty bitmap), at which point this
383d26
+     * function should lose the term _simple.
383d26
+     */
383d26
     int ret;
383d26
     NBDOptionReply reply;
383d26
-    uint32_t received_id = 0;
383d26
+    const char *context = info->x_dirty_bitmap ?: "base:allocation";
383d26
     bool received = false;
383d26
-    uint32_t export_len = strlen(export);
383d26
+    uint32_t export_len = strlen(info->name);
383d26
     uint32_t context_len = strlen(context);
383d26
     uint32_t data_len = sizeof(export_len) + export_len +
383d26
                         sizeof(uint32_t) + /* number of queries */
383d26
@@ -657,9 +661,9 @@ static int nbd_negotiate_simple_meta_context(QIOChannel *ioc,
383d26
     char *data = g_malloc(data_len);
383d26
     char *p = data;
383d26
 
383d26
-    trace_nbd_opt_meta_request(context, export);
383d26
+    trace_nbd_opt_meta_request(context, info->name);
383d26
     stl_be_p(p, export_len);
383d26
-    memcpy(p += sizeof(export_len), export, export_len);
383d26
+    memcpy(p += sizeof(export_len), info->name, export_len);
383d26
     stl_be_p(p += export_len, 1);
383d26
     stl_be_p(p += sizeof(uint32_t), context_len);
383d26
     memcpy(p += sizeof(context_len), context, context_len);
383d26
@@ -685,7 +689,7 @@ static int nbd_negotiate_simple_meta_context(QIOChannel *ioc,
383d26
     if (reply.type == NBD_REP_META_CONTEXT) {
383d26
         char *name;
383d26
 
383d26
-        if (reply.length != sizeof(received_id) + context_len) {
383d26
+        if (reply.length != sizeof(info->context_id) + context_len) {
383d26
             error_setg(errp, "Failed to negotiate meta context '%s', server "
383d26
                        "answered with unexpected length %" PRIu32, context,
383d26
                        reply.length);
383d26
@@ -693,12 +697,13 @@ static int nbd_negotiate_simple_meta_context(QIOChannel *ioc,
383d26
             return -1;
383d26
         }
383d26
 
383d26
-        if (nbd_read(ioc, &received_id, sizeof(received_id), errp) < 0) {
383d26
+        if (nbd_read(ioc, &info->context_id, sizeof(info->context_id),
383d26
+                     errp) < 0) {
383d26
             return -1;
383d26
         }
383d26
-        received_id = be32_to_cpu(received_id);
383d26
+        info->context_id = be32_to_cpu(info->context_id);
383d26
 
383d26
-        reply.length -= sizeof(received_id);
383d26
+        reply.length -= sizeof(info->context_id);
383d26
         name = g_malloc(reply.length + 1);
383d26
         if (nbd_read(ioc, name, reply.length, errp) < 0) {
383d26
             g_free(name);
383d26
@@ -715,7 +720,7 @@ static int nbd_negotiate_simple_meta_context(QIOChannel *ioc,
383d26
         }
383d26
         g_free(name);
383d26
 
383d26
-        trace_nbd_opt_meta_reply(context, received_id);
383d26
+        trace_nbd_opt_meta_reply(context, info->context_id);
383d26
         received = true;
383d26
 
383d26
         /* receive NBD_REP_ACK */
383d26
@@ -744,12 +749,7 @@ static int nbd_negotiate_simple_meta_context(QIOChannel *ioc,
383d26
         return -1;
383d26
     }
383d26
 
383d26
-    if (received) {
383d26
-        *context_id = received_id;
383d26
-        return 1;
383d26
-    }
383d26
-
383d26
-    return 0;
383d26
+    return received;
383d26
 }
383d26
 
383d26
 int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
383d26
@@ -848,10 +848,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
383d26
             }
383d26
 
383d26
             if (info->structured_reply && base_allocation) {
383d26
-                result = nbd_negotiate_simple_meta_context(
383d26
-                        ioc, info->name,
383d26
-                        info->x_dirty_bitmap ?: "base:allocation",
383d26
-                        &info->meta_base_allocation_id, errp);
383d26
+                result = nbd_negotiate_simple_meta_context(ioc, info, errp);
383d26
                 if (result < 0) {
383d26
                     goto fail;
383d26
                 }
383d26
-- 
383d26
1.8.3.1
383d26