[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 20/28] nbd: make server compliant with fixed newstyle
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 20/28] nbd: make server compliant with fixed newstyle spec |
Date: |
Tue, 16 Feb 2016 17:34:38 +0100 |
From: "Daniel P. Berrange" <address@hidden>
If the client does not request the fixed new style protocol,
then we should only accept NBD_OPT_EXPORT_NAME. All other
options are only valid when fixed new style has been activated.
The qemu-nbd client doesn't currently request fixed new style
protocol, but this change won't break qemu-nbd, because it
fortunately only ever uses NBD_OPT_EXPORT_NAME, so was never
triggering the non-compliant server behaviour.
Signed-off-by: Daniel P. Berrange <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
nbd/server.c | 69 ++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 46 insertions(+), 23 deletions(-)
diff --git a/nbd/server.c b/nbd/server.c
index 15aa03d..074a1e6 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -310,6 +310,7 @@ fail:
static int nbd_negotiate_options(NBDClient *client)
{
uint32_t flags;
+ bool fixedNewstyle = false;
/* Client sends:
[ 0 .. 3] client flags
@@ -332,14 +333,19 @@ static int nbd_negotiate_options(NBDClient *client)
}
TRACE("Checking client flags");
be32_to_cpus(&flags);
- if (flags != 0 && flags != NBD_FLAG_C_FIXED_NEWSTYLE) {
- LOG("Bad client flags received");
+ if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) {
+ TRACE("Support supports fixed newstyle handshake");
+ fixedNewstyle = true;
+ flags &= ~NBD_FLAG_C_FIXED_NEWSTYLE;
+ }
+ if (flags != 0) {
+ TRACE("Unknown client flags 0x%x received", flags);
return -EIO;
}
while (1) {
int ret;
- uint32_t tmp, length;
+ uint32_t clientflags, length;
uint64_t magic;
if (nbd_negotiate_read(client->ioc, &magic, sizeof(magic)) !=
@@ -353,10 +359,12 @@ static int nbd_negotiate_options(NBDClient *client)
return -EINVAL;
}
- if (nbd_negotiate_read(client->ioc, &tmp, sizeof(tmp)) != sizeof(tmp))
{
+ if (nbd_negotiate_read(client->ioc, &clientflags,
+ sizeof(clientflags)) != sizeof(clientflags)) {
LOG("read failed");
return -EINVAL;
}
+ clientflags = be32_to_cpu(clientflags);
if (nbd_negotiate_read(client->ioc, &length, sizeof(length)) !=
sizeof(length)) {
@@ -365,26 +373,41 @@ static int nbd_negotiate_options(NBDClient *client)
}
length = be32_to_cpu(length);
- TRACE("Checking option");
- switch (be32_to_cpu(tmp)) {
- case NBD_OPT_LIST:
- ret = nbd_negotiate_handle_list(client, length);
- if (ret < 0) {
- return ret;
+ TRACE("Checking option 0x%x", clientflags);
+ if (fixedNewstyle) {
+ switch (clientflags) {
+ case NBD_OPT_LIST:
+ ret = nbd_negotiate_handle_list(client, length);
+ if (ret < 0) {
+ return ret;
+ }
+ break;
+
+ case NBD_OPT_ABORT:
+ return -EINVAL;
+
+ case NBD_OPT_EXPORT_NAME:
+ return nbd_negotiate_handle_export_name(client, length);
+
+ default:
+ TRACE("Unsupported option 0x%x", clientflags);
+ nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_UNSUP,
+ clientflags);
+ return -EINVAL;
+ }
+ } else {
+ /*
+ * If broken new-style we should drop the connection
+ * for anything except NBD_OPT_EXPORT_NAME
+ */
+ switch (clientflags) {
+ case NBD_OPT_EXPORT_NAME:
+ return nbd_negotiate_handle_export_name(client, length);
+
+ default:
+ TRACE("Unsupported option 0x%x", clientflags);
+ return -EINVAL;
}
- break;
-
- case NBD_OPT_ABORT:
- return -EINVAL;
-
- case NBD_OPT_EXPORT_NAME:
- return nbd_negotiate_handle_export_name(client, length);
-
- default:
- tmp = be32_to_cpu(tmp);
- LOG("Unsupported option 0x%x", tmp);
- nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_UNSUP, tmp);
- return -EINVAL;
}
}
}
--
2.5.0
- [Qemu-devel] [PULL 12/28] ipmi: sensor number should not exceed MAX_SENSORS, (continued)
- [Qemu-devel] [PULL 12/28] ipmi: sensor number should not exceed MAX_SENSORS, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 10/28] mptsas: fix memory leak, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 11/28] mptsas: fix wrong formula, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 09/28] mptsas: add missing va_end, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 14/28] qemu-nbd: add support for --object command line arg, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 16/28] nbd: convert qemu-nbd server to use I/O channels for connection setup, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 13/28] qom: add helpers for UserCreatable object types, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 15/28] nbd: convert block client to use I/O channels for connection setup, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 17/28] nbd: convert blockdev NBD server to use I/O channels for connection setup, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 19/28] nbd: invert client logic for negotiating protocol version, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 20/28] nbd: make server compliant with fixed newstyle spec,
Paolo Bonzini <=
- [Qemu-devel] [PULL 21/28] nbd: make client request fixed new style if advertised, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 23/28] nbd: always query export list in fixed new style protocol, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 18/28] nbd: convert to using I/O channels for actual socket I/O, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 24/28] nbd: use "" as a default export name if none provided, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 22/28] nbd: allow setting of an export name for qemu-nbd server, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 26/28] nbd: enable use of TLS with NBD block driver, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 25/28] nbd: implement TLS support in the protocol negotiation, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 27/28] nbd: enable use of TLS with qemu-nbd server, Paolo Bonzini, 2016/02/16
- [Qemu-devel] [PULL 28/28] nbd: enable use of TLS with nbd-server-start command, Paolo Bonzini, 2016/02/16
- Re: [Qemu-devel] [PULL 00/28] Bug fixes + NBD-over-TLS support patches for 2016-02-16, Peter Maydell, 2016/02/16