All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>, qemu-block@nongnu.org
Subject: [Qemu-devel] [PATCH v4 07/14] nbd: make client request fixed new style if advertized
Date: Thu, 21 Jan 2016 16:37:20 +0000	[thread overview]
Message-ID: <1453394247-2267-8-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1453394247-2267-1-git-send-email-berrange@redhat.com>

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 <berrange@redhat.com>
---
 nbd/client.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/nbd/client.c b/nbd/client.c
index 65c8a27..22d69ff 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -75,7 +75,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.");
@@ -116,19 +115,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 */
@@ -164,11 +170,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

  parent reply	other threads:[~2016-01-21 16:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-21 16:37 [Qemu-devel] [PATCH v4 00/14] Implement TLS support to QEMU NBD server & client Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 01/14] nbd: convert block client to use I/O channels for connection setup Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 02/14] nbd: convert qemu-nbd server " Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 03/14] nbd: convert blockdev NBD " Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 04/14] nbd: convert to using I/O channels for actual socket I/O Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 05/14] nbd: invert client logic for negotiating protocol version Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 06/14] nbd: make server compliant with fixed newstyle spec Daniel P. Berrange
2016-01-21 16:37 ` Daniel P. Berrange [this message]
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 08/14] nbd: allow setting of an export name for qemu-nbd server Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 09/14] nbd: always query export list in fixed new style protocol Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 10/14] nbd: use "" as a default export name if none provided Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 11/14] nbd: implement TLS support in the protocol negotiation Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 12/14] nbd: enable use of TLS with NBD block driver Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 13/14] nbd: enable use of TLS with qemu-nbd server Daniel P. Berrange
2016-01-21 16:37 ` [Qemu-devel] [PATCH v4 14/14] nbd: enable use of TLS with nbd-server-start command Daniel P. Berrange
2016-01-26 12:56 ` [Qemu-devel] [PATCH v4 00/14] Implement TLS support to QEMU NBD server & client Paolo Bonzini

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=1453394247-2267-8-git-send-email-berrange@redhat.com \
    --to=berrange@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.