From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTZht-0006iT-4m for qemu-devel@nongnu.org; Wed, 10 Feb 2016 13:41:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTZhs-0005mQ-2C for qemu-devel@nongnu.org; Wed, 10 Feb 2016 13:41:40 -0500 From: "Daniel P. Berrange" Date: Wed, 10 Feb 2016 18:41:07 +0000 Message-Id: <1455129674-17255-10-git-send-email-berrange@redhat.com> In-Reply-To: <1455129674-17255-1-git-send-email-berrange@redhat.com> References: <1455129674-17255-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH v6 09/16] nbd: make client request fixed new style if advertized List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org If the server advertizes support for the fixed new style negotiation, the client should in turn enable new style. This will allow the client to negotiate further NBD options besides the export name. Signed-off-by: Daniel P. Berrange --- nbd/client.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 5064788..88f2ada 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -76,7 +76,6 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint32_t *flags, { char buf[256]; uint64_t magic, s; - uint16_t tmp; int rc; TRACE("Receiving negotiation."); @@ -117,19 +116,26 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint32_t *flags, TRACE("Magic is 0x%" PRIx64, magic); if (magic == NBD_OPTS_MAGIC) { - uint32_t reserved = 0; + uint32_t clientflags = 0; uint32_t opt; uint32_t namesize; + uint16_t globalflags; + uint16_t exportflags; - if (read_sync(ioc, &tmp, sizeof(tmp)) != sizeof(tmp)) { + if (read_sync(ioc, &globalflags, sizeof(globalflags)) != + sizeof(globalflags)) { error_setg(errp, "Failed to read server flags"); goto fail; } - *flags = be16_to_cpu(tmp) << 16; - /* reserved for future use */ - if (write_sync(ioc, &reserved, sizeof(reserved)) != - sizeof(reserved)) { - error_setg(errp, "Failed to read reserved field"); + *flags = be16_to_cpu(globalflags) << 16; + if (globalflags & NBD_FLAG_FIXED_NEWSTYLE) { + TRACE("Server supports fixed new style"); + clientflags |= NBD_FLAG_C_FIXED_NEWSTYLE; + } + /* client requested flags */ + if (write_sync(ioc, &clientflags, sizeof(clientflags)) != + sizeof(clientflags)) { + error_setg(errp, "Failed to send clientflags field"); goto fail; } /* write the export name */ @@ -165,11 +171,12 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint32_t *flags, *size = be64_to_cpu(s); TRACE("Size is %" PRIu64, *size); - if (read_sync(ioc, &tmp, sizeof(tmp)) != sizeof(tmp)) { + if (read_sync(ioc, &exportflags, sizeof(exportflags)) != + sizeof(exportflags)) { error_setg(errp, "Failed to read export flags"); goto fail; } - *flags |= be16_to_cpu(tmp); + *flags |= be16_to_cpu(exportflags); } else if (magic == NBD_CLIENT_MAGIC) { if (name) { error_setg(errp, "Server does not support export names"); -- 2.5.0