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

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