nbd/server: Simplify nbd_negotiate_options loop

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>
This commit is contained in:
Eric Blake 2017-10-27 12:40:30 +02:00
parent 8fb48b8b38
commit 8cbee49ed7
1 changed files with 4 additions and 15 deletions

View File

@ -678,6 +678,7 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
if (!tioc) { if (!tioc) {
return -EIO; return -EIO;
} }
ret = 0;
object_unref(OBJECT(client->ioc)); object_unref(OBJECT(client->ioc));
client->ioc = QIO_CHANNEL(tioc); client->ioc = QIO_CHANNEL(tioc);
break; break;
@ -698,9 +699,6 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
"Option 0x%" PRIx32 "Option 0x%" PRIx32
"not permitted before TLS", "not permitted before TLS",
option); option);
if (ret < 0) {
return ret;
}
/* Let the client keep trying, unless they asked to /* Let the client keep trying, unless they asked to
* quit. In this mode, we've already sent an error, so * quit. In this mode, we've already sent an error, so
* we can't ack the abort. */ * we can't ack the abort. */
@ -713,9 +711,6 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
switch (option) { switch (option) {
case NBD_OPT_LIST: case NBD_OPT_LIST:
ret = nbd_negotiate_handle_list(client, length, errp); ret = nbd_negotiate_handle_list(client, length, errp);
if (ret < 0) {
return ret;
}
break; break;
case NBD_OPT_ABORT: case NBD_OPT_ABORT:
@ -738,9 +733,6 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
assert(option == NBD_OPT_GO); assert(option == NBD_OPT_GO);
return 0; return 0;
} }
if (ret) {
return ret;
}
break; break;
case NBD_OPT_STARTTLS: case NBD_OPT_STARTTLS:
@ -758,9 +750,6 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
option, errp, option, errp,
"TLS not configured"); "TLS not configured");
} }
if (ret < 0) {
return ret;
}
break; break;
default: default:
if (nbd_drop(client->ioc, length, errp) < 0) { 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%" "Unsupported option 0x%"
PRIx32 " (%s)", option, PRIx32 " (%s)", option,
nbd_opt_lookup(option)); nbd_opt_lookup(option));
if (ret < 0) {
return ret;
}
break; break;
} }
} else { } else {
@ -794,6 +780,9 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
return -EINVAL; return -EINVAL;
} }
} }
if (ret < 0) {
return ret;
}
} }
} }