Blame SOURCES/kvm-nbd-generalize-usage-of-nbd_read.patch

383d26
From 3523bdc1d6abb74fdc0a572c9fecd7f2633ec4b9 Mon Sep 17 00:00:00 2001
383d26
From: John Snow <jsnow@redhat.com>
383d26
Date: Wed, 27 Mar 2019 17:22:57 +0100
383d26
Subject: [PATCH 119/163] nbd: generalize usage of nbd_read
383d26
383d26
RH-Author: John Snow <jsnow@redhat.com>
383d26
Message-id: <20190327172308.31077-45-jsnow@redhat.com>
383d26
Patchwork-id: 85205
383d26
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 44/55] nbd: generalize usage of nbd_read
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: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
383d26
383d26
We generally do very similar things around nbd_read: error_prepend
383d26
specifying what we have tried to read, and be_to_cpu conversion of
383d26
integers.
383d26
383d26
So, it seems reasonable to move common things to helper functions,
383d26
which:
383d26
1. simplify code a bit
383d26
2. generalize nbd_read error descriptions, all starting with
383d26
   "Failed to read"
383d26
3. make it more difficult to forget to convert things from BE
383d26
383d26
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
383d26
Reviewed-by: Eric Blake <eblake@redhat.com>
383d26
Message-Id: <20190128165830.165170-1-vsementsov@virtuozzo.com>
383d26
[eblake: rename macro to DEF_NBD_READ_N and formatting tweaks;
383d26
checkpatch has false positive complaint]
383d26
Signed-off-by: Eric Blake <eblake@redhat.com>
383d26
(cherry picked from commit e6798f06a67a25def45a6636259de38cc38f1414)
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 block/nbd-client.c  |  5 ++-
383d26
 include/block/nbd.h | 32 +++++++++++++++++--
383d26
 nbd/client.c        | 88 ++++++++++++++++++-----------------------------------
383d26
 nbd/common.c        |  2 +-
383d26
 nbd/server.c        | 27 ++++++----------
383d26
 5 files changed, 71 insertions(+), 83 deletions(-)
383d26
383d26
diff --git a/block/nbd-client.c b/block/nbd-client.c
383d26
index 8135396..5c97052 100644
383d26
--- a/block/nbd-client.c
383d26
+++ b/block/nbd-client.c
383d26
@@ -337,10 +337,9 @@ static int nbd_co_receive_offset_data_payload(NBDClientSession *s,
383d26
         return -EINVAL;
383d26
     }
383d26
 
383d26
-    if (nbd_read(s->ioc, &offset, sizeof(offset), errp) < 0) {
383d26
+    if (nbd_read64(s->ioc, &offset, "OFFSET_DATA offset", errp) < 0) {
383d26
         return -EIO;
383d26
     }
383d26
-    be64_to_cpus(&offset);
383d26
 
383d26
     data_size = chunk->length - sizeof(offset);
383d26
     assert(data_size);
383d26
@@ -387,7 +386,7 @@ static coroutine_fn int nbd_co_receive_structured_payload(
383d26
     }
383d26
 
383d26
     *payload = g_new(char, len);
383d26
-    ret = nbd_read(s->ioc, *payload, len, errp);
383d26
+    ret = nbd_read(s->ioc, *payload, len, "structured payload", errp);
383d26
     if (ret < 0) {
383d26
         g_free(*payload);
383d26
         *payload = NULL;
383d26
diff --git a/include/block/nbd.h b/include/block/nbd.h
383d26
index 4faf394..96cfb1d 100644
383d26
--- a/include/block/nbd.h
383d26
+++ b/include/block/nbd.h
383d26
@@ -23,6 +23,7 @@
383d26
 #include "qapi/qapi-types-block.h"
383d26
 #include "io/channel-socket.h"
383d26
 #include "crypto/tlscreds.h"
383d26
+#include "qapi/error.h"
383d26
 
383d26
 /* Handshake phase structs - this struct is passed on the wire */
383d26
 
383d26
@@ -336,11 +337,38 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds,
383d26
  * Reads @size bytes from @ioc. Returns 0 on success.
383d26
  */
383d26
 static inline int nbd_read(QIOChannel *ioc, void *buffer, size_t size,
383d26
-                           Error **errp)
383d26
+                           const char *desc, Error **errp)
383d26
 {
383d26
-    return qio_channel_read_all(ioc, buffer, size, errp) < 0 ? -EIO : 0;
383d26
+    int ret = qio_channel_read_all(ioc, buffer, size, errp) < 0 ? -EIO : 0;
383d26
+
383d26
+    if (ret < 0) {
383d26
+        if (desc) {
383d26
+            error_prepend(errp, "Failed to read %s: ", desc);
383d26
+        }
383d26
+        return -1;
383d26
+    }
383d26
+
383d26
+    return 0;
383d26
+}
383d26
+
383d26
+#define DEF_NBD_READ_N(bits)                                            \
383d26
+static inline int nbd_read##bits(QIOChannel *ioc,                       \
383d26
+                                 uint##bits##_t *val,                   \
383d26
+                                 const char *desc, Error **errp)        \
383d26
+{                                                                       \
383d26
+    if (nbd_read(ioc, val, sizeof(*val), desc, errp) < 0) {             \
383d26
+        return -1;                                                      \
383d26
+    }                                                                   \
383d26
+    *val = be##bits##_to_cpu(*val);                                     \
383d26
+    return 0;                                                           \
383d26
 }
383d26
 
383d26
+DEF_NBD_READ_N(16) /* Defines nbd_read16(). */
383d26
+DEF_NBD_READ_N(32) /* Defines nbd_read32(). */
383d26
+DEF_NBD_READ_N(64) /* Defines nbd_read64(). */
383d26
+
383d26
+#undef DEF_NBD_READ_N
383d26
+
383d26
 static inline bool nbd_reply_is_simple(NBDReply *reply)
383d26
 {
383d26
     return reply->magic == NBD_SIMPLE_REPLY_MAGIC;
383d26
diff --git a/nbd/client.c b/nbd/client.c
383d26
index 8a083c2..10a52ad 100644
383d26
--- a/nbd/client.c
383d26
+++ b/nbd/client.c
383d26
@@ -113,8 +113,7 @@ static int nbd_receive_option_reply(QIOChannel *ioc, uint32_t opt,
383d26
                                     NBDOptionReply *reply, Error **errp)
383d26
 {
383d26
     QEMU_BUILD_BUG_ON(sizeof(*reply) != 20);
383d26
-    if (nbd_read(ioc, reply, sizeof(*reply), errp) < 0) {
383d26
-        error_prepend(errp, "failed to read option reply: ");
383d26
+    if (nbd_read(ioc, reply, sizeof(*reply), "option reply", errp) < 0) {
383d26
         nbd_send_opt_abort(ioc);
383d26
         return -1;
383d26
     }
383d26
@@ -166,8 +165,8 @@ static int nbd_handle_reply_err(QIOChannel *ioc, NBDOptionReply *reply,
383d26
             goto cleanup;
383d26
         }
383d26
         msg = g_malloc(reply->length + 1);
383d26
-        if (nbd_read(ioc, msg, reply->length, errp) < 0) {
383d26
-            error_prepend(errp, "failed to read option error %" PRIu32
383d26
+        if (nbd_read(ioc, msg, reply->length, NULL, errp) < 0) {
383d26
+            error_prepend(errp, "Failed to read option error %" PRIu32
383d26
                           " (%s) message: ",
383d26
                           reply->type, nbd_rep_lookup(reply->type));
383d26
             goto cleanup;
383d26
@@ -284,12 +283,10 @@ static int nbd_receive_list(QIOChannel *ioc, char **name, char **description,
383d26
         nbd_send_opt_abort(ioc);
383d26
         return -1;
383d26
     }
383d26
-    if (nbd_read(ioc, &namelen, sizeof(namelen), errp) < 0) {
383d26
-        error_prepend(errp, "failed to read option name length: ");
383d26
+    if (nbd_read32(ioc, &namelen, "option name length", errp) < 0) {
383d26
         nbd_send_opt_abort(ioc);
383d26
         return -1;
383d26
     }
383d26
-    namelen = be32_to_cpu(namelen);
383d26
     len -= sizeof(namelen);
383d26
     if (len < namelen) {
383d26
         error_setg(errp, "incorrect option name length");
383d26
@@ -298,8 +295,7 @@ static int nbd_receive_list(QIOChannel *ioc, char **name, char **description,
383d26
     }
383d26
 
383d26
     local_name = g_malloc(namelen + 1);
383d26
-    if (nbd_read(ioc, local_name, namelen, errp) < 0) {
383d26
-        error_prepend(errp, "failed to read export name: ");
383d26
+    if (nbd_read(ioc, local_name, namelen, "export name", errp) < 0) {
383d26
         nbd_send_opt_abort(ioc);
383d26
         goto out;
383d26
     }
383d26
@@ -307,8 +303,7 @@ static int nbd_receive_list(QIOChannel *ioc, char **name, char **description,
383d26
     len -= namelen;
383d26
     if (len) {
383d26
         local_desc = g_malloc(len + 1);
383d26
-        if (nbd_read(ioc, local_desc, len, errp) < 0) {
383d26
-            error_prepend(errp, "failed to read export description: ");
383d26
+        if (nbd_read(ioc, local_desc, len, "export description", errp) < 0) {
383d26
             nbd_send_opt_abort(ioc);
383d26
             goto out;
383d26
         }
383d26
@@ -410,13 +405,11 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32_t opt,
383d26
             nbd_send_opt_abort(ioc);
383d26
             return -1;
383d26
         }
383d26
-        if (nbd_read(ioc, &type, sizeof(type), errp) < 0) {
383d26
-            error_prepend(errp, "failed to read info type: ");
383d26
+        if (nbd_read16(ioc, &type, "info type", errp) < 0) {
383d26
             nbd_send_opt_abort(ioc);
383d26
             return -1;
383d26
         }
383d26
         len -= sizeof(type);
383d26
-        type = be16_to_cpu(type);
383d26
         switch (type) {
383d26
         case NBD_INFO_EXPORT:
383d26
             if (len != sizeof(info->size) + sizeof(info->flags)) {
383d26
@@ -425,18 +418,14 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32_t opt,
383d26
                 nbd_send_opt_abort(ioc);
383d26
                 return -1;
383d26
             }
383d26
-            if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) {
383d26
-                error_prepend(errp, "failed to read info size: ");
383d26
+            if (nbd_read64(ioc, &info->size, "info size", errp) < 0) {
383d26
                 nbd_send_opt_abort(ioc);
383d26
                 return -1;
383d26
             }
383d26
-            info->size = be64_to_cpu(info->size);
383d26
-            if (nbd_read(ioc, &info->flags, sizeof(info->flags), errp) < 0) {
383d26
-                error_prepend(errp, "failed to read info flags: ");
383d26
+            if (nbd_read16(ioc, &info->flags, "info flags", errp) < 0) {
383d26
                 nbd_send_opt_abort(ioc);
383d26
                 return -1;
383d26
             }
383d26
-            info->flags = be16_to_cpu(info->flags);
383d26
             trace_nbd_receive_negotiate_size_flags(info->size, info->flags);
383d26
             break;
383d26
 
383d26
@@ -447,27 +436,23 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32_t opt,
383d26
                 nbd_send_opt_abort(ioc);
383d26
                 return -1;
383d26
             }
383d26
-            if (nbd_read(ioc, &info->min_block, sizeof(info->min_block),
383d26
-                         errp) < 0) {
383d26
-                error_prepend(errp, "failed to read info minimum block size: ");
383d26
+            if (nbd_read32(ioc, &info->min_block, "info minimum block size",
383d26
+                           errp) < 0) {
383d26
                 nbd_send_opt_abort(ioc);
383d26
                 return -1;
383d26
             }
383d26
-            info->min_block = be32_to_cpu(info->min_block);
383d26
             if (!is_power_of_2(info->min_block)) {
383d26
                 error_setg(errp, "server minimum block size %" PRIu32
383d26
                            " is not a power of two", info->min_block);
383d26
                 nbd_send_opt_abort(ioc);
383d26
                 return -1;
383d26
             }
383d26
-            if (nbd_read(ioc, &info->opt_block, sizeof(info->opt_block),
383d26
-                         errp) < 0) {
383d26
-                error_prepend(errp,
383d26
-                              "failed to read info preferred block size: ");
383d26
+            if (nbd_read32(ioc, &info->opt_block, "info preferred block size",
383d26
+                           errp) < 0)
383d26
+            {
383d26
                 nbd_send_opt_abort(ioc);
383d26
                 return -1;
383d26
             }
383d26
-            info->opt_block = be32_to_cpu(info->opt_block);
383d26
             if (!is_power_of_2(info->opt_block) ||
383d26
                 info->opt_block < info->min_block) {
383d26
                 error_setg(errp, "server preferred block size %" PRIu32
383d26
@@ -475,13 +460,12 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32_t opt,
383d26
                 nbd_send_opt_abort(ioc);
383d26
                 return -1;
383d26
             }
383d26
-            if (nbd_read(ioc, &info->max_block, sizeof(info->max_block),
383d26
-                         errp) < 0) {
383d26
-                error_prepend(errp, "failed to read info maximum block size: ");
383d26
+            if (nbd_read32(ioc, &info->max_block, "info maximum block size",
383d26
+                           errp) < 0)
383d26
+            {
383d26
                 nbd_send_opt_abort(ioc);
383d26
                 return -1;
383d26
             }
383d26
-            info->max_block = be32_to_cpu(info->max_block);
383d26
             if (info->max_block < info->min_block) {
383d26
                 error_setg(errp, "server maximum block size %" PRIu32
383d26
                            " is not valid", info->max_block);
383d26
@@ -731,14 +715,13 @@ static int nbd_receive_one_meta_context(QIOChannel *ioc,
383d26
         return -1;
383d26
     }
383d26
 
383d26
-    if (nbd_read(ioc, &local_id, sizeof(local_id), errp) < 0) {
383d26
+    if (nbd_read32(ioc, &local_id, "context id", errp) < 0) {
383d26
         return -1;
383d26
     }
383d26
-    local_id = be32_to_cpu(local_id);
383d26
 
383d26
     reply.length -= sizeof(local_id);
383d26
     local_name = g_malloc(reply.length + 1);
383d26
-    if (nbd_read(ioc, local_name, reply.length, errp) < 0) {
383d26
+    if (nbd_read(ioc, local_name, reply.length, "context name", errp) < 0) {
383d26
         g_free(local_name);
383d26
         return -1;
383d26
     }
383d26
@@ -896,11 +879,9 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
383d26
         return -EINVAL;
383d26
     }
383d26
 
383d26
-    if (nbd_read(ioc, &magic, sizeof(magic), errp) < 0) {
383d26
-        error_prepend(errp, "Failed to read initial magic: ");
383d26
+    if (nbd_read64(ioc, &magic, "initial magic", errp) < 0) {
383d26
         return -EINVAL;
383d26
     }
383d26
-    magic = be64_to_cpu(magic);
383d26
     trace_nbd_receive_negotiate_magic(magic);
383d26
 
383d26
     if (magic != NBD_INIT_MAGIC) {
383d26
@@ -908,11 +889,9 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
383d26
         return -EINVAL;
383d26
     }
383d26
 
383d26
-    if (nbd_read(ioc, &magic, sizeof(magic), errp) < 0) {
383d26
-        error_prepend(errp, "Failed to read server magic: ");
383d26
+    if (nbd_read64(ioc, &magic, "server magic", errp) < 0) {
383d26
         return -EINVAL;
383d26
     }
383d26
-    magic = be64_to_cpu(magic);
383d26
     trace_nbd_receive_negotiate_magic(magic);
383d26
 
383d26
     if (magic == NBD_OPTS_MAGIC) {
383d26
@@ -920,11 +899,9 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
383d26
         uint16_t globalflags;
383d26
         bool fixedNewStyle = false;
383d26
 
383d26
-        if (nbd_read(ioc, &globalflags, sizeof(globalflags), errp) < 0) {
383d26
-            error_prepend(errp, "Failed to read server flags: ");
383d26
+        if (nbd_read16(ioc, &globalflags, "server flags", errp) < 0) {
383d26
             return -EINVAL;
383d26
         }
383d26
-        globalflags = be16_to_cpu(globalflags);
383d26
         trace_nbd_receive_negotiate_server_flags(globalflags);
383d26
         if (globalflags & NBD_FLAG_FIXED_NEWSTYLE) {
383d26
             fixedNewStyle = true;
383d26
@@ -992,17 +969,13 @@ static int nbd_negotiate_finish_oldstyle(QIOChannel *ioc, NBDExportInfo *info,
383d26
 {
383d26
     uint32_t oldflags;
383d26
 
383d26
-    if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) {
383d26
-        error_prepend(errp, "Failed to read export length: ");
383d26
+    if (nbd_read64(ioc, &info->size, "export length", errp) < 0) {
383d26
         return -EINVAL;
383d26
     }
383d26
-    info->size = be64_to_cpu(info->size);
383d26
 
383d26
-    if (nbd_read(ioc, &oldflags, sizeof(oldflags), errp) < 0) {
383d26
-        error_prepend(errp, "Failed to read export flags: ");
383d26
+    if (nbd_read32(ioc, &oldflags, "export flags", errp) < 0) {
383d26
         return -EINVAL;
383d26
     }
383d26
-    oldflags = be32_to_cpu(oldflags);
383d26
     if (oldflags & ~0xffff) {
383d26
         error_setg(errp, "Unexpected export flags %0x" PRIx32, oldflags);
383d26
         return -EINVAL;
383d26
@@ -1079,17 +1052,13 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
383d26
         }
383d26
 
383d26
         /* Read the response */
383d26
-        if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) {
383d26
-            error_prepend(errp, "Failed to read export length: ");
383d26
+        if (nbd_read64(ioc, &info->size, "export length", errp) < 0) {
383d26
             return -EINVAL;
383d26
         }
383d26
-        info->size = be64_to_cpu(info->size);
383d26
 
383d26
-        if (nbd_read(ioc, &info->flags, sizeof(info->flags), errp) < 0) {
383d26
-            error_prepend(errp, "Failed to read export flags: ");
383d26
+        if (nbd_read16(ioc, &info->flags, "export flags", errp) < 0) {
383d26
             return -EINVAL;
383d26
         }
383d26
-        info->flags = be16_to_cpu(info->flags);
383d26
         break;
383d26
     case 0: /* oldstyle, parse length and flags */
383d26
         if (*info->name) {
383d26
@@ -1379,7 +1348,7 @@ static int nbd_receive_simple_reply(QIOChannel *ioc, NBDSimpleReply *reply,
383d26
     assert(reply->magic == NBD_SIMPLE_REPLY_MAGIC);
383d26
 
383d26
     ret = nbd_read(ioc, (uint8_t *)reply + sizeof(reply->magic),
383d26
-                   sizeof(*reply) - sizeof(reply->magic), errp);
383d26
+                   sizeof(*reply) - sizeof(reply->magic), "reply", errp);
383d26
     if (ret < 0) {
383d26
         return ret;
383d26
     }
383d26
@@ -1404,7 +1373,8 @@ static int nbd_receive_structured_reply_chunk(QIOChannel *ioc,
383d26
     assert(chunk->magic == NBD_STRUCTURED_REPLY_MAGIC);
383d26
 
383d26
     ret = nbd_read(ioc, (uint8_t *)chunk + sizeof(chunk->magic),
383d26
-                   sizeof(*chunk) - sizeof(chunk->magic), errp);
383d26
+                   sizeof(*chunk) - sizeof(chunk->magic), "structured chunk",
383d26
+                   errp);
383d26
     if (ret < 0) {
383d26
         return ret;
383d26
     }
383d26
diff --git a/nbd/common.c b/nbd/common.c
383d26
index 41f5ed8..cc8b278 100644
383d26
--- a/nbd/common.c
383d26
+++ b/nbd/common.c
383d26
@@ -31,7 +31,7 @@ int nbd_drop(QIOChannel *ioc, size_t size, Error **errp)
383d26
     buffer = sizeof(small) >= size ? small : g_malloc(MIN(65536, size));
383d26
     while (size > 0) {
383d26
         ssize_t count = MIN(65536, size);
383d26
-        ret = nbd_read(ioc, buffer, MIN(65536, size), errp);
383d26
+        ret = nbd_read(ioc, buffer, MIN(65536, size), NULL, errp);
383d26
 
383d26
         if (ret < 0) {
383d26
             goto cleanup;
383d26
diff --git a/nbd/server.c b/nbd/server.c
383d26
index cb0d563..838c150 100644
383d26
--- a/nbd/server.c
383d26
+++ b/nbd/server.c
383d26
@@ -438,8 +438,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *client,
383d26
         error_setg(errp, "Bad length received");
383d26
         return -EINVAL;
383d26
     }
383d26
-    if (nbd_read(client->ioc, name, client->optlen, errp) < 0) {
383d26
-        error_prepend(errp, "read failed: ");
383d26
+    if (nbd_read(client->ioc, name, client->optlen, "export name", errp) < 0) {
383d26
         return -EIO;
383d26
     }
383d26
     name[client->optlen] = '\0';
383d26
@@ -1046,11 +1045,9 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
383d26
         ...           Rest of request
383d26
     */
383d26
 
383d26
-    if (nbd_read(client->ioc, &flags, sizeof(flags), errp) < 0) {
383d26
-        error_prepend(errp, "read failed: ");
383d26
+    if (nbd_read32(client->ioc, &flags, "flags", errp) < 0) {
383d26
         return -EIO;
383d26
     }
383d26
-    flags = be32_to_cpu(flags);
383d26
     trace_nbd_negotiate_options_flags(flags);
383d26
     if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) {
383d26
         fixedNewstyle = true;
383d26
@@ -1070,30 +1067,23 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
383d26
         uint32_t option, length;
383d26
         uint64_t magic;
383d26
 
383d26
-        if (nbd_read(client->ioc, &magic, sizeof(magic), errp) < 0) {
383d26
-            error_prepend(errp, "read failed: ");
383d26
+        if (nbd_read64(client->ioc, &magic, "opts magic", errp) < 0) {
383d26
             return -EINVAL;
383d26
         }
383d26
-        magic = be64_to_cpu(magic);
383d26
         trace_nbd_negotiate_options_check_magic(magic);
383d26
         if (magic != NBD_OPTS_MAGIC) {
383d26
             error_setg(errp, "Bad magic received");
383d26
             return -EINVAL;
383d26
         }
383d26
 
383d26
-        if (nbd_read(client->ioc, &option,
383d26
-                     sizeof(option), errp) < 0) {
383d26
-            error_prepend(errp, "read failed: ");
383d26
+        if (nbd_read32(client->ioc, &option, "option", errp) < 0) {
383d26
             return -EINVAL;
383d26
         }
383d26
-        option = be32_to_cpu(option);
383d26
         client->opt = option;
383d26
 
383d26
-        if (nbd_read(client->ioc, &length, sizeof(length), errp) < 0) {
383d26
-            error_prepend(errp, "read failed: ");
383d26
+        if (nbd_read32(client->ioc, &length, "option length", errp) < 0) {
383d26
             return -EINVAL;
383d26
         }
383d26
-        length = be32_to_cpu(length);
383d26
         assert(!client->optlen);
383d26
         client->optlen = length;
383d26
 
383d26
@@ -1306,7 +1296,7 @@ static int nbd_receive_request(QIOChannel *ioc, NBDRequest *request,
383d26
     uint32_t magic;
383d26
     int ret;
383d26
 
383d26
-    ret = nbd_read(ioc, buf, sizeof(buf), errp);
383d26
+    ret = nbd_read(ioc, buf, sizeof(buf), "request", errp);
383d26
     if (ret < 0) {
383d26
         return ret;
383d26
     }
383d26
@@ -2111,8 +2101,9 @@ static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request,
383d26
         }
383d26
     }
383d26
     if (request->type == NBD_CMD_WRITE) {
383d26
-        if (nbd_read(client->ioc, req->data, request->len, errp) < 0) {
383d26
-            error_prepend(errp, "reading from socket failed: ");
383d26
+        if (nbd_read(client->ioc, req->data, request->len, "CMD_WRITE data",
383d26
+                     errp) < 0)
383d26
+        {
383d26
             return -EIO;
383d26
         }
383d26
         req->complete = true;
383d26
-- 
383d26
1.8.3.1
383d26