qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PULL 04/28] nbd: Fix filename generation
Date: Mon, 20 Oct 2014 15:35:30 +0200	[thread overview]
Message-ID: <1413812154-11153-5-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1413812154-11153-1-git-send-email-kwolf@redhat.com>

From: Max Reitz <mreitz@redhat.com>

Export names may be used with nbd+unix, too, fix nbd_refresh_filename()
accordingly. Also, for nbd+tcp, the documented path schema is
"nbd://host[:port]/export", so use it. Furthermore, as can be seen from
that schema, the port is optional.

That makes six single cases for how the filename can be formatted; it is
not easy to generalize these cases without the resulting statement being
completely unreadable, thus there is simply one snprintf() per case.

Finally, taking the options from BDRVNBDState::socket_opts is wrong,
because those will not contain the export name. Just use
BlockDriverState::options instead.

Reported-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/nbd.c | 44 +++++++++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 15 deletions(-)

diff --git a/block/nbd.c b/block/nbd.c
index 89775e1..04cc845 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -342,30 +342,44 @@ static void nbd_attach_aio_context(BlockDriverState *bs,
 
 static void nbd_refresh_filename(BlockDriverState *bs)
 {
-    BDRVNBDState *s = bs->opaque;
     QDict *opts = qdict_new();
-    const char *path   = qemu_opt_get(s->socket_opts, "path");
-    const char *host   = qemu_opt_get(s->socket_opts, "host");
-    const char *port   = qemu_opt_get(s->socket_opts, "port");
-    const char *export = qemu_opt_get(s->socket_opts, "export");
+    const char *path   = qdict_get_try_str(bs->options, "path");
+    const char *host   = qdict_get_try_str(bs->options, "host");
+    const char *port   = qdict_get_try_str(bs->options, "port");
+    const char *export = qdict_get_try_str(bs->options, "export");
 
     qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("nbd")));
 
-    if (path) {
+    if (path && export) {
         snprintf(bs->exact_filename, sizeof(bs->exact_filename),
-                 "nbd+unix:%s", path);
-        qdict_put_obj(opts, "path", QOBJECT(qstring_from_str(path)));
-    } else if (export) {
+                 "nbd+unix:///%s?socket=%s", export, path);
+    } else if (path && !export) {
         snprintf(bs->exact_filename, sizeof(bs->exact_filename),
-                 "nbd:%s:%s/%s", host, port, export);
-        qdict_put_obj(opts, "host",   QOBJECT(qstring_from_str(host)));
-        qdict_put_obj(opts, "port",   QOBJECT(qstring_from_str(port)));
-        qdict_put_obj(opts, "export", QOBJECT(qstring_from_str(export)));
-    } else {
+                 "nbd+unix://?socket=%s", path);
+    } else if (!path && export && port) {
+        snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+                 "nbd://%s:%s/%s", host, port, export);
+    } else if (!path && export && !port) {
+        snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+                 "nbd://%s/%s", host, export);
+    } else if (!path && !export && port) {
+        snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+                 "nbd://%s:%s", host, port);
+    } else if (!path && !export && !port) {
         snprintf(bs->exact_filename, sizeof(bs->exact_filename),
-                 "nbd:%s:%s", host, port);
+                 "nbd://%s", host);
+    }
+
+    if (path) {
+        qdict_put_obj(opts, "path", QOBJECT(qstring_from_str(path)));
+    } else if (port) {
         qdict_put_obj(opts, "host", QOBJECT(qstring_from_str(host)));
         qdict_put_obj(opts, "port", QOBJECT(qstring_from_str(port)));
+    } else {
+        qdict_put_obj(opts, "host", QOBJECT(qstring_from_str(host)));
+    }
+    if (export) {
+        qdict_put_obj(opts, "export", QOBJECT(qstring_from_str(export)));
     }
 
     bs->full_open_options = opts;
-- 
1.8.3.1

  parent reply	other threads:[~2014-10-20 13:36 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-20 13:35 [Qemu-devel] [PULL 00/28] Block patches Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 01/28] qcow2: fix leak of Qcow2DiscardRegion in update_refcount_discard Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 02/28] block/raw-posix: Fix disk corruption in try_fiemap Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 03/28] block/raw-posix: use seek_hole ahead of fiemap Kevin Wolf
2014-10-20 13:35 ` Kevin Wolf [this message]
2014-10-20 13:35 ` [Qemu-devel] [PULL 05/28] block: Split bdrv_new_root() off bdrv_new() Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 06/28] block: New BlockBackend Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 07/28] block: Connect BlockBackend to BlockDriverState Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 08/28] block: Connect BlockBackend and DriveInfo Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 09/28] block: Code motion to get rid of stubs/blockdev.c Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 10/28] block: Make BlockBackend own its BlockDriverState Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 11/28] blockdev: Eliminate drive_del() Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 12/28] block: Eliminate bdrv_iterate(), use bdrv_next() Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 13/28] block: Eliminate BlockDriverState member device_name[] Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 14/28] block: Merge BlockBackend and BlockDriverState name spaces Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 15/28] block: Eliminate DriveInfo member bdrv, use blk_by_legacy_dinfo() Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 16/28] block: Rename BlockDriverAIOCB* to BlockAIOCB* Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 17/28] block: Rename BlockDriverCompletionFunc to BlockCompletionFunc Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 18/28] virtio-blk: Drop redundant VirtIOBlock member conf Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 19/28] virtio-blk: Rename VirtIOBlkConf variables to conf Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 20/28] hw: Convert from BlockDriverState to BlockBackend, mostly Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 21/28] ide: Complete conversion from BlockDriverState to BlockBackend Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 22/28] pc87312: Drop unused members of PC87312State Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 23/28] blockdev: Drop superfluous DriveInfo member id Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 24/28] blockdev: Fix blockdev-add not to create DriveInfo Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 25/28] block/qapi: Convert qmp_query_block() to BlockBackend Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 26/28] blockdev: Convert qmp_eject(), qmp_change_blockdev() " Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 27/28] block: Lift device model API into BlockBackend Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 28/28] block: Make device model's references to BlockBackend strong Kevin Wolf
2014-10-22 17:30 ` [Qemu-devel] [PULL 00/28] Block patches Peter Maydell

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=1413812154-11153-5-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --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).