qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Luiz Capitulino <lcapitulino@redhat.com>
Subject: [Qemu-devel] [PATCH v2 09/16] block/nbd: "address" in nbd_refresh_filename()
Date: Tue,  1 Mar 2016 00:19:26 +0100	[thread overview]
Message-ID: <1456787973-19348-10-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1456787973-19348-1-git-send-email-mreitz@redhat.com>

As of a future patch, the NBD block driver will accept a SocketAddress
structure for a new "address" option. In order to support this,
nbd_refresh_filename() needs some changes.

The two TODOs introduced by this patch will be removed in the very next
one. They exist to explain that it is currently impossible for
nbd_refresh_filename() to emit an "address.*" option (which the NBD
block driver does not handle yet). The next patch will arm these code
paths, but it will also enable handling of these options.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/nbd.c | 80 +++++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 59 insertions(+), 21 deletions(-)

diff --git a/block/nbd.c b/block/nbd.c
index 2d96dd1..86907bc 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -419,37 +419,75 @@ static void nbd_attach_aio_context(BlockDriverState *bs,
 static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
 {
     QDict *opts = qdict_new();
-    const char *path   = qdict_get_try_str(options, "path");
-    const char *host   = qdict_get_try_str(options, "host");
-    const char *port   = qdict_get_try_str(options, "port");
+    bool can_generate_filename = true;
+    const char *path = NULL, *host = NULL, *port = NULL;
     const char *export = qdict_get_try_str(options, "export");
     const char *tlscreds = qdict_get_try_str(options, "tls-creds");
 
-    if (host && !port) {
-        port = stringify(NBD_DEFAULT_PORT);
+    if (qdict_get_try_str(options, "address.type")) {
+        /* This path will only be possible as of a future patch;
+         * TODO: Remove this note once it is */
+
+        const char *type = qdict_get_str(options, "address.type");
+
+        if (!strcmp(type, "unix")) {
+            path = qdict_get_str(options, "address.data.path");
+        } else if (!strcmp(type, "inet")) {
+            host = qdict_get_str(options, "address.data.host");
+            port = qdict_get_str(options, "address.data.port");
+
+            can_generate_filename = !qdict_haskey(options, "address.data.to")
+                                 && !qdict_haskey(options, "address.data.ipv4")
+                                 && !qdict_haskey(options, "address.data.ipv6");
+        } else {
+            can_generate_filename = false;
+        }
+    } else {
+        path = qdict_get_try_str(options, "path");
+        host = qdict_get_try_str(options, "host");
+        port = qdict_get_try_str(options, "port");
+
+        if (host && !port) {
+            port = stringify(NBD_DEFAULT_PORT);
+        }
     }
 
     qdict_put(opts, "driver", qstring_from_str("nbd"));
 
-    if (path && export) {
-        snprintf(bs->exact_filename, sizeof(bs->exact_filename),
-                 "nbd+unix:///%s?socket=%s", export, path);
-    } else if (path && !export) {
-        snprintf(bs->exact_filename, sizeof(bs->exact_filename),
-                 "nbd+unix://?socket=%s", path);
-    } else if (!path && export) {
-        snprintf(bs->exact_filename, sizeof(bs->exact_filename),
-                 "nbd://%s:%s/%s", host, port, export);
-    } else if (!path && !export) {
-        snprintf(bs->exact_filename, sizeof(bs->exact_filename),
-                 "nbd://%s:%s", host, port);
+    if (can_generate_filename) {
+        if (path && export) {
+            snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+                     "nbd+unix:///%s?socket=%s", export, path);
+        } else if (path && !export) {
+            snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+                     "nbd+unix://?socket=%s", path);
+        } else if (!path && export) {
+            snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+                     "nbd://%s:%s/%s", host, port, export);
+        } else if (!path && !export) {
+            snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+                     "nbd://%s:%s", host, port);
+        }
     }
 
-    if (path) {
-        qdict_put(opts, "path", qstring_from_str(path));
+    if (qdict_get_try_str(options, "address.type")) {
+        /* This path will only be possible as of a future patch;
+         * TODO: Remove this note once it is */
+
+        const QDictEntry *e;
+        for (e = qdict_first(options); e; e = qdict_next(options, e)) {
+            if (!strncmp(e->key, "address.", 8)) {
+                qobject_incref(e->value);
+                qdict_put_obj(opts, e->key, e->value);
+            }
+        }
     } else {
-        qdict_put(opts, "host", qstring_from_str(host));
-        qdict_put(opts, "port", qstring_from_str(port));
+        if (path) {
+            qdict_put(opts, "path", qstring_from_str(path));
+        } else {
+            qdict_put(opts, "host", qstring_from_str(host));
+            qdict_put(opts, "port", qstring_from_str(port));
+        }
     }
     if (export) {
         qdict_put(opts, "export", qstring_from_str(export));
-- 
2.7.1

  parent reply	other threads:[~2016-02-29 23:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-29 23:19 [Qemu-devel] [PATCH v2 00/16] qapi: Allow blockdev-add for NBD Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 01/16] qdict: Add qdict_change_key() Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 02/16] qdict: Add qdict_unflatten() Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 03/16] check-qdict: Add a test for qdict_unflatten() Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 04/16] block/nbd: Drop trailing "." in error messages Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 05/16] block/nbd: Reject port parameter without host Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 06/16] block/nbd: Default port in nbd_refresh_filename() Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 07/16] block/nbd: Use qdict_put() Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 08/16] block/nbd: Add nbd_has_filename_options_conflict() Max Reitz
2016-02-29 23:19 ` Max Reitz [this message]
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 10/16] block/nbd: Accept SocketAddress Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 11/16] block/nbd: Use SocketAddress options Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 12/16] qapi: Allow blockdev-add for NBD Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 13/16] iotests.py: Add qemu_nbd function Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 14/16] iotests.py: Allow concurrent qemu instances Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 15/16] socket_scm_helper: Accept fd directly Max Reitz
2016-02-29 23:19 ` [Qemu-devel] [PATCH v2 16/16] iotests: Add test for NBD's blockdev-add interface Max Reitz
2016-02-29 23:24 ` [Qemu-devel] [PATCH v2 00/16] qapi: Allow blockdev-add for NBD Eric Blake
2016-02-29 23:37   ` Max Reitz
2016-03-01 10:00     ` Daniel P. Berrange
2016-03-01 10:12       ` Kevin Wolf

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=1456787973-19348-10-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).