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

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