From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ansCS-0007L4-0v for qemu-devel@nongnu.org; Wed, 06 Apr 2016 14:29:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ansCR-0006uI-2f for qemu-devel@nongnu.org; Wed, 06 Apr 2016 14:29:07 -0400 From: Max Reitz Date: Wed, 6 Apr 2016 20:28:40 +0200 Message-Id: <1459967330-4573-5-git-send-email-mreitz@redhat.com> In-Reply-To: <1459967330-4573-1-git-send-email-mreitz@redhat.com> References: <1459967330-4573-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v3 04/14] block/nbd: Default port in nbd_refresh_filename() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: Kevin Wolf , Markus Armbruster , qemu-devel@nongnu.org, Max Reitz , Paolo Bonzini , Luiz Capitulino Instead of not emitting the port in nbd_refresh_filename(), just set it to the default if the user did not specify it. This makes the logic a bit simpler. Signed-off-by: Max Reitz --- block/nbd.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 2112ec0..efa5d3d 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -433,6 +433,10 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) 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); + } + qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("nbd"))); if (path && export) { @@ -441,27 +445,19 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) } else if (path && !export) { snprintf(bs->exact_filename, sizeof(bs->exact_filename), "nbd+unix://?socket=%s", path); - } else if (!path && export && port) { + } else if (!path && export) { 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) { + } else if (!path && !export) { 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", 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))); + qdict_put_obj(opts, "port", QOBJECT(qstring_from_str(port))); } if (export) { qdict_put_obj(opts, "export", QOBJECT(qstring_from_str(export))); -- 2.8.0