From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34932) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHdnU-0000xA-MN for qemu-devel@nongnu.org; Mon, 18 Mar 2013 13:24:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UHdnM-0004dZ-9X for qemu-devel@nongnu.org; Mon, 18 Mar 2013 13:24:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49957) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHdnL-0004c6-V2 for qemu-devel@nongnu.org; Mon, 18 Mar 2013 13:24:24 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2IHON4I027798 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 18 Mar 2013 13:24:23 -0400 From: Kevin Wolf Date: Mon, 18 Mar 2013 18:24:01 +0100 Message-Id: <1363627441-8297-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1363627441-8297-1-git-send-email-kwolf@redhat.com> References: <1363627441-8297-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 11/11] nbd: Use default port if only host is specified List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com The URL method already takes care to apply the default port when none is specfied. Directly specifying driver-specific options required the port number until now. Allow leaving it out and apply the default. Signed-off-by: Kevin Wolf --- block/nbd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 218df6a..ac61b6d 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -119,20 +119,17 @@ static int nbd_parse_uri(const char *filename, QDict *options) qdict_put(options, "path", qstring_from_str(qp->p[0].value)); } else { /* nbd[+tcp]://host:port/export */ - char *port_str; - if (!uri->server) { ret = -EINVAL; goto out; } - if (!uri->port) { - uri->port = NBD_DEFAULT_PORT; - } - port_str = g_strdup_printf("%d", uri->port); qdict_put(options, "host", qstring_from_str(uri->server)); - qdict_put(options, "port", qstring_from_str(port_str)); - g_free(port_str); + if (uri->port) { + char* port_str = g_strdup_printf("%d", uri->port); + qdict_put(options, "port", qstring_from_str(port_str)); + g_free(port_str); + } } out: @@ -222,6 +219,10 @@ static int nbd_config(BDRVNBDState *s, QDict *options) return -EINVAL; } + if (!qemu_opt_get(s->socket_opts, "port")) { + qemu_opt_set_number(s->socket_opts, "port", NBD_DEFAULT_PORT); + } + s->export_name = g_strdup(qdict_get_try_str(options, "export")); if (s->export_name) { qdict_del(options, "export"); -- 1.8.1.4