[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v4 05/14] nbd: invert client logic for negotiating p
From: |
Daniel P. Berrange |
Subject: |
[Qemu-block] [PATCH v4 05/14] nbd: invert client logic for negotiating protocol version |
Date: |
Thu, 21 Jan 2016 16:37:18 +0000 |
The nbd_receive_negotiate() method takes different code
paths based on whether 'name == NULL', and then checks
the expected protocol version in each branch.
This patch inverts the logic, so that it takes different
code paths based on what protocol version it receives and
then checks if name is NULL or not as needed.
This facilitates later code which allows the client to
be capable of using the new style protocol regardless
of whether an export name is listed or not.
Signed-off-by: Daniel P. Berrange <address@hidden>
---
nbd/client.c | 60 +++++++++++++++++++++++++++++-------------------------------
1 file changed, 29 insertions(+), 31 deletions(-)
diff --git a/nbd/client.c b/nbd/client.c
index 07e1fed..65c8a27 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -115,20 +115,11 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char
*name, uint32_t *flags,
magic = be64_to_cpu(magic);
TRACE("Magic is 0x%" PRIx64, magic);
- if (name) {
+ if (magic == NBD_OPTS_MAGIC) {
uint32_t reserved = 0;
uint32_t opt;
uint32_t namesize;
- TRACE("Checking magic (opts_magic)");
- if (magic != NBD_OPTS_MAGIC) {
- if (magic == NBD_CLIENT_MAGIC) {
- error_setg(errp, "Server does not support export names");
- } else {
- error_setg(errp, "Bad magic received");
- }
- goto fail;
- }
if (read_sync(ioc, &tmp, sizeof(tmp)) != sizeof(tmp)) {
error_setg(errp, "Failed to read server flags");
goto fail;
@@ -141,6 +132,10 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char
*name, uint32_t *flags,
goto fail;
}
/* write the export name */
+ if (!name) {
+ error_setg(errp, "Server requires an export name");
+ goto fail;
+ }
magic = cpu_to_be64(magic);
if (write_sync(ioc, &magic, sizeof(magic)) != sizeof(magic)) {
error_setg(errp, "Failed to send export name magic");
@@ -161,39 +156,42 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char
*name, uint32_t *flags,
error_setg(errp, "Failed to send export name");
goto fail;
}
- } else {
- TRACE("Checking magic (cli_magic)");
- if (magic != NBD_CLIENT_MAGIC) {
- if (magic == NBD_OPTS_MAGIC) {
- error_setg(errp, "Server requires an export name");
- } else {
- error_setg(errp, "Bad magic received");
- }
+ if (read_sync(ioc, &s, sizeof(s)) != sizeof(s)) {
+ error_setg(errp, "Failed to read export length");
goto fail;
}
- }
+ *size = be64_to_cpu(s);
+ TRACE("Size is %" PRIu64, *size);
- if (read_sync(ioc, &s, sizeof(s)) != sizeof(s)) {
- error_setg(errp, "Failed to read export length");
- goto fail;
- }
- *size = be64_to_cpu(s);
- TRACE("Size is %" PRIu64, *size);
+ if (read_sync(ioc, &tmp, sizeof(tmp)) != sizeof(tmp)) {
+ error_setg(errp, "Failed to read export flags");
+ goto fail;
+ }
+ *flags |= be16_to_cpu(tmp);
+ } else if (magic == NBD_CLIENT_MAGIC) {
+ if (name) {
+ error_setg(errp, "Server does not support export names");
+ goto fail;
+ }
+
+ if (read_sync(ioc, &s, sizeof(s)) != sizeof(s)) {
+ error_setg(errp, "Failed to read export length");
+ goto fail;
+ }
+ *size = be64_to_cpu(s);
+ TRACE("Size is %" PRIu64, *size);
- if (!name) {
if (read_sync(ioc, flags, sizeof(*flags)) != sizeof(*flags)) {
error_setg(errp, "Failed to read export flags");
goto fail;
}
*flags = be32_to_cpup(flags);
} else {
- if (read_sync(ioc, &tmp, sizeof(tmp)) != sizeof(tmp)) {
- error_setg(errp, "Failed to read export flags");
- goto fail;
- }
- *flags |= be16_to_cpu(tmp);
+ error_setg(errp, "Bad magic received");
+ goto fail;
}
+
if (read_sync(ioc, &buf, 124) != 124) {
error_setg(errp, "Failed to read reserved block");
goto fail;
--
2.5.0
- [Qemu-block] [PATCH v4 00/14] Implement TLS support to QEMU NBD server & client, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 03/14] nbd: convert blockdev NBD server to use I/O channels for connection setup, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 01/14] nbd: convert block client to use I/O channels for connection setup, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 02/14] nbd: convert qemu-nbd server to use I/O channels for connection setup, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 05/14] nbd: invert client logic for negotiating protocol version,
Daniel P. Berrange <=
- [Qemu-block] [PATCH v4 06/14] nbd: make server compliant with fixed newstyle spec, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 04/14] nbd: convert to using I/O channels for actual socket I/O, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 07/14] nbd: make client request fixed new style if advertized, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 08/14] nbd: allow setting of an export name for qemu-nbd server, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 09/14] nbd: always query export list in fixed new style protocol, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 10/14] nbd: use "" as a default export name if none provided, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 11/14] nbd: implement TLS support in the protocol negotiation, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 13/14] nbd: enable use of TLS with qemu-nbd server, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 12/14] nbd: enable use of TLS with NBD block driver, Daniel P. Berrange, 2016/01/21
- [Qemu-block] [PATCH v4 14/14] nbd: enable use of TLS with nbd-server-start command, Daniel P. Berrange, 2016/01/21