Blame SOURCES/kvm-nbd-client-Pull-out-oldstyle-size-determination.patch

7711c0
From 4b3d650918d54c4034e0162421410c1a076a057b Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Wed, 27 Mar 2019 17:22:49 +0100
7711c0
Subject: [PATCH 111/163] nbd/client: Pull out oldstyle size determination
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190327172308.31077-37-jsnow@redhat.com>
7711c0
Patchwork-id: 85197
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 36/55] nbd/client: Pull out oldstyle size determination
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
Another refactoring creating nbd_negotiate_finish_oldstyle()
7711c0
for further reuse during 'qemu-nbd --list'.
7711c0
7711c0
Signed-off-by: Eric Blake <eblake@redhat.com>
7711c0
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
7711c0
Message-Id: <20190117193658.16413-16-eblake@redhat.com>
7711c0
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7711c0
(cherry picked from commit b3c9d33bc4e7c2ab2828b16ebc96f0414b0f1acf)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 nbd/client.c | 49 ++++++++++++++++++++++++++++++++-----------------
7711c0
 1 file changed, 32 insertions(+), 17 deletions(-)
7711c0
7711c0
diff --git a/nbd/client.c b/nbd/client.c
7711c0
index 77cc123..6829c68 100644
7711c0
--- a/nbd/client.c
7711c0
+++ b/nbd/client.c
7711c0
@@ -814,7 +814,7 @@ static int nbd_negotiate_simple_meta_context(QIOChannel *ioc,
7711c0
  * Start the handshake to the server.  After a positive return, the server
7711c0
  * is ready to accept additional NBD_OPT requests.
7711c0
  * Returns: negative errno: failure talking to server
7711c0
- *          0: server is oldstyle, client must still parse export size
7711c0
+ *          0: server is oldstyle, must call nbd_negotiate_finish_oldstyle
7711c0
  *          1: server is newstyle, but can only accept EXPORT_NAME
7711c0
  *          2: server is newstyle, but lacks structured replies
7711c0
  *          3: server is newstyle and set up for structured replies
7711c0
@@ -921,6 +921,36 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
7711c0
 }
7711c0
 
7711c0
 /*
7711c0
+ * nbd_negotiate_finish_oldstyle:
7711c0
+ * Populate @info with the size and export flags from an oldstyle server,
7711c0
+ * but does not consume 124 bytes of reserved zero padding.
7711c0
+ * Returns 0 on success, -1 with @errp set on failure
7711c0
+ */
7711c0
+static int nbd_negotiate_finish_oldstyle(QIOChannel *ioc, NBDExportInfo *info,
7711c0
+                                         Error **errp)
7711c0
+{
7711c0
+    uint32_t oldflags;
7711c0
+
7711c0
+    if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) {
7711c0
+        error_prepend(errp, "Failed to read export length: ");
7711c0
+        return -EINVAL;
7711c0
+    }
7711c0
+    info->size = be64_to_cpu(info->size);
7711c0
+
7711c0
+    if (nbd_read(ioc, &oldflags, sizeof(oldflags), errp) < 0) {
7711c0
+        error_prepend(errp, "Failed to read export flags: ");
7711c0
+        return -EINVAL;
7711c0
+    }
7711c0
+    oldflags = be32_to_cpu(oldflags);
7711c0
+    if (oldflags & ~0xffff) {
7711c0
+        error_setg(errp, "Unexpected export flags %0x" PRIx32, oldflags);
7711c0
+        return -EINVAL;
7711c0
+    }
7711c0
+    info->flags = oldflags;
7711c0
+    return 0;
7711c0
+}
7711c0
+
7711c0
+/*
7711c0
  * nbd_receive_negotiate:
7711c0
  * Connect to server, complete negotiation, and move into transmission phase.
7711c0
  * Returns: negative errno: failure talking to server
7711c0
@@ -933,7 +963,6 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
7711c0
     int result;
7711c0
     bool zeroes;
7711c0
     bool base_allocation = info->base_allocation;
7711c0
-    uint32_t oldflags;
7711c0
 
7711c0
     assert(info->name);
7711c0
     trace_nbd_receive_negotiate_name(info->name);
7711c0
@@ -1006,23 +1035,9 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
7711c0
             error_setg(errp, "Server does not support non-empty export names");
7711c0
             return -EINVAL;
7711c0
         }
7711c0
-
7711c0
-        if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) {
7711c0
-            error_prepend(errp, "Failed to read export length: ");
7711c0
-            return -EINVAL;
7711c0
-        }
7711c0
-        info->size = be64_to_cpu(info->size);
7711c0
-
7711c0
-        if (nbd_read(ioc, &oldflags, sizeof(oldflags), errp) < 0) {
7711c0
-            error_prepend(errp, "Failed to read export flags: ");
7711c0
-            return -EINVAL;
7711c0
-        }
7711c0
-        oldflags = be32_to_cpu(oldflags);
7711c0
-        if (oldflags & ~0xffff) {
7711c0
-            error_setg(errp, "Unexpected export flags %0x" PRIx32, oldflags);
7711c0
+        if (nbd_negotiate_finish_oldstyle(ioc, info, errp) < 0) {
7711c0
             return -EINVAL;
7711c0
         }
7711c0
-        info->flags = oldflags;
7711c0
         break;
7711c0
     default:
7711c0
         return result;
7711c0
-- 
7711c0
1.8.3.1
7711c0