All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, edgar.kaziakhmedov@virtuozzo.com,
	vsementsov@virtuozzo.com, Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH 2/4] nbd/client: Refactor in preparation for more limits
Date: Tue,  1 May 2018 16:13:34 -0500	[thread overview]
Message-ID: <20180501211336.986372-3-eblake@redhat.com> (raw)
In-Reply-To: <20180501211336.986372-1-eblake@redhat.com>

The next patch will ask the server for more items of NBD_INFO.
However, the server is free to respond with INFO items in a
different order than what we request, so performing any sanity
checks about constraints that occur between multiple INFO items
must be done after all items have been received.  Make it easier
to see that such checks are last by sinking the final processing
after the while loop, rather than embedded in the NBD_REP_ACK
processing that occurs textually within the loop before other
INFO processing.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 nbd/client.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/nbd/client.c b/nbd/client.c
index 232ff4f46da..0abb195b856 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2016-2017 Red Hat, Inc.
+ *  Copyright (C) 2016-2018 Red Hat, Inc.
  *  Copyright (C) 2005  Anthony Liguori <anthony@codemonkey.ws>
  *
  *  Network Block Device Client Side
@@ -365,17 +365,12 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wantname,

         if (reply.type == NBD_REP_ACK) {
             /* Server is done sending info and moved into transmission
-               phase, but make sure it sent flags */
+               phase */
             if (len) {
                 error_setg(errp, "server sent invalid NBD_REP_ACK");
                 return -1;
             }
-            if (!info->flags) {
-                error_setg(errp, "broken server omitted NBD_INFO_EXPORT");
-                return -1;
-            }
-            trace_nbd_opt_go_success();
-            return 1;
+            break;
         }
         if (reply.type != NBD_REP_INFO) {
             error_setg(errp, "unexpected reply type %" PRIu32
@@ -482,6 +477,14 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wantname,
             break;
         }
     }
+
+    /* Sanity check that server's responses make sense */
+    if (!info->flags) {
+        error_setg(errp, "broken server omitted NBD_INFO_EXPORT");
+        return -1;
+    }
+    trace_nbd_opt_go_success();
+    return 1;
 }

 /* Return -1 on failure, 0 if wantname is an available export. */
-- 
2.14.3

  parent reply	other threads:[~2018-05-01 21:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-01 21:13 [Qemu-devel] [PATCH 0/4] Support larger NBD_CMD_WRITE_ZEROES Eric Blake
2018-05-01 21:13 ` [Qemu-devel] [PATCH 1/4] nbd: Prepare for additional block sizing info Eric Blake
2018-05-03  8:20   ` Vladimir Sementsov-Ogievskiy
2018-05-01 21:13 ` Eric Blake [this message]
2018-05-03  8:29   ` [Qemu-devel] [PATCH 2/4] nbd/client: Refactor in preparation for more limits Vladimir Sementsov-Ogievskiy
2018-05-01 21:13 ` [Qemu-devel] [PATCH 3/4] nbd/client: Support requests of additional block sizing info Eric Blake
2018-05-03  9:17   ` Vladimir Sementsov-Ogievskiy
2018-05-03 14:49     ` Eric Blake
2018-05-03 15:51       ` Vladimir Sementsov-Ogievskiy
2018-05-22 15:33   ` Vladimir Sementsov-Ogievskiy
2018-05-23 15:40     ` Eric Blake
2018-05-01 21:13 ` [Qemu-devel] [PATCH 4/4] nbd/server: " Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180501211336.986372-3-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=edgar.kaziakhmedov@virtuozzo.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.