qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	"open list:Network Block Dev..." <qemu-block@nongnu.org>
Subject: [Qemu-devel] [PULL 05/12] nbd/server: Simplify nbd_negotiate_options loop
Date: Mon, 30 Oct 2017 21:56:29 +0100	[thread overview]
Message-ID: <20171030205636.14236-6-eblake@redhat.com> (raw)
In-Reply-To: <20171030205636.14236-1-eblake@redhat.com>

Instead of making each caller check whether a transmission error
occurred, we can sink a common error check to the end of the loop.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20171027104037.8319-6-eblake@redhat.com>
[eblake: squash in compiler warning fix]
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 nbd/server.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/nbd/server.c b/nbd/server.c
index 05ff7470d5..2f03059b4c 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -678,6 +678,7 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
                 if (!tioc) {
                     return -EIO;
                 }
+                ret = 0;
                 object_unref(OBJECT(client->ioc));
                 client->ioc = QIO_CHANNEL(tioc);
                 break;
@@ -698,9 +699,6 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
                                                  "Option 0x%" PRIx32
                                                  "not permitted before TLS",
                                                  option);
-                if (ret < 0) {
-                    return ret;
-                }
                 /* Let the client keep trying, unless they asked to
                  * quit. In this mode, we've already sent an error, so
                  * we can't ack the abort.  */
@@ -713,9 +711,6 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
             switch (option) {
             case NBD_OPT_LIST:
                 ret = nbd_negotiate_handle_list(client, length, errp);
-                if (ret < 0) {
-                    return ret;
-                }
                 break;

             case NBD_OPT_ABORT:
@@ -738,9 +733,6 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
                     assert(option == NBD_OPT_GO);
                     return 0;
                 }
-                if (ret) {
-                    return ret;
-                }
                 break;

             case NBD_OPT_STARTTLS:
@@ -758,9 +750,6 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
                                                      option, errp,
                                                      "TLS not configured");
                 }
-                if (ret < 0) {
-                    return ret;
-                }
                 break;
             default:
                 if (nbd_drop(client->ioc, length, errp) < 0) {
@@ -772,9 +761,6 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
                                                  "Unsupported option 0x%"
                                                  PRIx32 " (%s)", option,
                                                  nbd_opt_lookup(option));
-                if (ret < 0) {
-                    return ret;
-                }
                 break;
             }
         } else {
@@ -794,6 +780,9 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
                 return -EINVAL;
             }
         }
+        if (ret < 0) {
+            return ret;
+        }
     }
 }

-- 
2.13.6

  parent reply	other threads:[~2017-10-30 20:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-30 20:56 [Qemu-devel] [PULL 00/12] NBD patches prior to 2.11 soft freeze Eric Blake
2017-10-30 20:56 ` [Qemu-devel] [PULL 01/12] nbd: Include error names in trace messages Eric Blake
2017-10-30 20:56 ` [Qemu-devel] [PULL 02/12] nbd: Move nbd_errno_to_system_errno() to public header Eric Blake
2017-10-30 20:56 ` [Qemu-devel] [PULL 03/12] nbd: Expose constants and structs for structured read Eric Blake
2017-10-30 20:56 ` [Qemu-devel] [PULL 04/12] nbd/server: Report error for write to read-only export Eric Blake
2017-10-30 20:56 ` Eric Blake [this message]
2017-10-30 20:56 ` [Qemu-devel] [PULL 06/12] nbd/server: Refactor zero-length option check Eric Blake
2017-10-30 20:56 ` [Qemu-devel] [PULL 07/12] nbd: Minimal structured read for server Eric Blake
2017-10-30 20:56 ` [Qemu-devel] [PULL 08/12] nbd/server: Include human-readable message in structured errors Eric Blake
2017-10-30 20:56 ` [Qemu-devel] [PULL 09/12] nbd/client: refactor nbd_receive_starttls Eric Blake
2017-10-30 20:56 ` [Qemu-devel] [PULL 10/12] nbd/client: prepare nbd_receive_reply for structured reply Eric Blake
2017-10-30 20:56 ` [Qemu-devel] [PULL 11/12] nbd: Move nbd_read() to common header Eric Blake
2017-10-30 20:56 ` [Qemu-devel] [PULL 12/12] nbd: Minimal structured read for client Eric Blake
2017-10-31 14:27 ` [Qemu-devel] [PULL 00/12] NBD patches prior to 2.11 soft freeze Peter Maydell

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=20171030205636.14236-6-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).