Blame SOURCES/kvm-nbd-client-Refactor-nbd_opt_go-to-support-NBD_OPT_IN.patch

383d26
From 265ca77d8f1c82a680789bdb26fc7992077de567 Mon Sep 17 00:00:00 2001
383d26
From: John Snow <jsnow@redhat.com>
383d26
Date: Wed, 27 Mar 2019 17:22:50 +0100
383d26
Subject: [PATCH 112/163] nbd/client: Refactor nbd_opt_go() to support
383d26
 NBD_OPT_INFO
383d26
383d26
RH-Author: John Snow <jsnow@redhat.com>
383d26
Message-id: <20190327172308.31077-38-jsnow@redhat.com>
383d26
Patchwork-id: 85198
383d26
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 37/55] nbd/client: Refactor nbd_opt_go() to support NBD_OPT_INFO
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
Rename the function to nbd_opt_info_or_go() with an added parameter
383d26
and slight changes to comments and trace messages, in order to
383d26
reuse the function for NBD_OPT_INFO.
383d26
383d26
Signed-off-by: Eric Blake <eblake@redhat.com>
383d26
Message-Id: <20190117193658.16413-17-eblake@redhat.com>
383d26
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
383d26
(cherry picked from commit 138796d0f545ad4b6c74ad2cbe5f6e08c454a0b9)
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 nbd/client.c     | 36 ++++++++++++++++++++++--------------
383d26
 nbd/trace-events |  8 ++++----
383d26
 2 files changed, 26 insertions(+), 18 deletions(-)
383d26
383d26
diff --git a/nbd/client.c b/nbd/client.c
383d26
index 6829c68..fa1657a 100644
383d26
--- a/nbd/client.c
383d26
+++ b/nbd/client.c
383d26
@@ -330,11 +330,16 @@ static int nbd_receive_list(QIOChannel *ioc, char **name, char **description,
383d26
 }
383d26
 
383d26
 
383d26
-/* Returns -1 if NBD_OPT_GO proves the export @info->name cannot be
383d26
- * used, 0 if NBD_OPT_GO is unsupported (fall back to NBD_OPT_LIST and
383d26
+/*
383d26
+ * nbd_opt_info_or_go:
383d26
+ * Send option for NBD_OPT_INFO or NBD_OPT_GO and parse the reply.
383d26
+ * Returns -1 if the option proves the export @info->name cannot be
383d26
+ * used, 0 if the option is unsupported (fall back to NBD_OPT_LIST and
383d26
  * NBD_OPT_EXPORT_NAME in that case), and > 0 if the export is good to
383d26
- * go (with the rest of @info populated). */
383d26
-static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *info, Error **errp)
383d26
+ * go (with the rest of @info populated).
383d26
+ */
383d26
+static int nbd_opt_info_or_go(QIOChannel *ioc, uint32_t opt,
383d26
+                              NBDExportInfo *info, Error **errp)
383d26
 {
383d26
     NBDOptionReply reply;
383d26
     uint32_t len = strlen(info->name);
383d26
@@ -347,7 +352,8 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *info, Error **errp)
383d26
      * flags still 0 is a witness of a broken server. */
383d26
     info->flags = 0;
383d26
 
383d26
-    trace_nbd_opt_go_start(info->name);
383d26
+    assert(opt == NBD_OPT_GO || opt == NBD_OPT_INFO);
383d26
+    trace_nbd_opt_info_go_start(nbd_opt_lookup(opt), info->name);
383d26
     buf = g_malloc(4 + len + 2 + 2 * info->request_sizes + 1);
383d26
     stl_be_p(buf, len);
383d26
     memcpy(buf + 4, info->name, len);
383d26
@@ -356,7 +362,7 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *info, Error **errp)
383d26
     if (info->request_sizes) {
383d26
         stw_be_p(buf + 4 + len + 2, NBD_INFO_BLOCK_SIZE);
383d26
     }
383d26
-    error = nbd_send_option_request(ioc, NBD_OPT_GO,
383d26
+    error = nbd_send_option_request(ioc, opt,
383d26
                                     4 + len + 2 + 2 * info->request_sizes,
383d26
                                     buf, errp);
383d26
     g_free(buf);
383d26
@@ -365,7 +371,7 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *info, Error **errp)
383d26
     }
383d26
 
383d26
     while (1) {
383d26
-        if (nbd_receive_option_reply(ioc, NBD_OPT_GO, &reply, errp) < 0) {
383d26
+        if (nbd_receive_option_reply(ioc, opt, &reply, errp) < 0) {
383d26
             return -1;
383d26
         }
383d26
         error = nbd_handle_reply_err(ioc, &reply, errp);
383d26
@@ -375,8 +381,10 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *info, Error **errp)
383d26
         len = reply.length;
383d26
 
383d26
         if (reply.type == NBD_REP_ACK) {
383d26
-            /* Server is done sending info and moved into transmission
383d26
-               phase, but make sure it sent flags */
383d26
+            /*
383d26
+             * Server is done sending info, and moved into transmission
383d26
+             * phase for NBD_OPT_GO, but make sure it sent flags
383d26
+             */
383d26
             if (len) {
383d26
                 error_setg(errp, "server sent invalid NBD_REP_ACK");
383d26
                 return -1;
383d26
@@ -385,7 +393,7 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *info, Error **errp)
383d26
                 error_setg(errp, "broken server omitted NBD_INFO_EXPORT");
383d26
                 return -1;
383d26
             }
383d26
-            trace_nbd_opt_go_success();
383d26
+            trace_nbd_opt_info_go_success(nbd_opt_lookup(opt));
383d26
             return 1;
383d26
         }
383d26
         if (reply.type != NBD_REP_INFO) {
383d26
@@ -479,12 +487,12 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *info, Error **errp)
383d26
                 nbd_send_opt_abort(ioc);
383d26
                 return -1;
383d26
             }
383d26
-            trace_nbd_opt_go_info_block_size(info->min_block, info->opt_block,
383d26
-                                             info->max_block);
383d26
+            trace_nbd_opt_info_block_size(info->min_block, info->opt_block,
383d26
+                                          info->max_block);
383d26
             break;
383d26
 
383d26
         default:
383d26
-            trace_nbd_opt_go_info_unknown(type, nbd_info_lookup(type));
383d26
+            trace_nbd_opt_info_unknown(type, nbd_info_lookup(type));
383d26
             if (nbd_drop(ioc, len, errp) < 0) {
383d26
                 error_prepend(errp, "Failed to read info payload: ");
383d26
                 nbd_send_opt_abort(ioc);
383d26
@@ -993,7 +1001,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
383d26
          * TLS).  If it is not available, fall back to
383d26
          * NBD_OPT_LIST for nicer error messages about a missing
383d26
          * export, then use NBD_OPT_EXPORT_NAME.  */
383d26
-        result = nbd_opt_go(ioc, info, errp);
383d26
+        result = nbd_opt_info_or_go(ioc, NBD_OPT_GO, info, errp);
383d26
         if (result < 0) {
383d26
             return -EINVAL;
383d26
         }
383d26
diff --git a/nbd/trace-events b/nbd/trace-events
383d26
index 663d116..7f10ebd 100644
383d26
--- a/nbd/trace-events
383d26
+++ b/nbd/trace-events
383d26
@@ -4,10 +4,10 @@ nbd_receive_option_reply(uint32_t option, const char *optname, uint32_t type, co
383d26
 nbd_server_error_msg(uint32_t err, const char *type, const char *msg) "server reported error 0x%" PRIx32 " (%s) with additional message: %s"
383d26
 nbd_reply_err_unsup(uint32_t option, const char *name) "server doesn't understand request %" PRIu32 " (%s), attempting fallback"
383d26
 nbd_receive_list(const char *name, const char *desc) "export list includes '%s', description '%s'"
383d26
-nbd_opt_go_start(const char *name) "Attempting NBD_OPT_GO for export '%s'"
383d26
-nbd_opt_go_success(void) "Export is good to go"
383d26
-nbd_opt_go_info_unknown(int info, const char *name) "Ignoring unknown info %d (%s)"
383d26
-nbd_opt_go_info_block_size(uint32_t minimum, uint32_t preferred, uint32_t maximum) "Block sizes are 0x%" PRIx32 ", 0x%" PRIx32 ", 0x%" PRIx32
383d26
+nbd_opt_info_go_start(const char *opt, const char *name) "Attempting %s for export '%s'"
383d26
+nbd_opt_info_go_success(const char *opt) "Export is ready after %s request"
383d26
+nbd_opt_info_unknown(int info, const char *name) "Ignoring unknown info %d (%s)"
383d26
+nbd_opt_info_block_size(uint32_t minimum, uint32_t preferred, uint32_t maximum) "Block sizes are 0x%" PRIx32 ", 0x%" PRIx32 ", 0x%" PRIx32
383d26
 nbd_receive_query_exports_start(const char *wantname) "Querying export list for '%s'"
383d26
 nbd_receive_query_exports_success(const char *wantname) "Found desired export name '%s'"
383d26
 nbd_receive_starttls_new_client(void) "Setting up TLS"
383d26
-- 
383d26
1.8.3.1
383d26