From patchwork Wed Mar 20 18:39:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 229454 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B53D12C008C for ; Thu, 21 Mar 2013 05:42:05 +1100 (EST) Received: from localhost ([::1]:57565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UINxb-0004FX-Uw for incoming@patchwork.ozlabs.org; Wed, 20 Mar 2013 14:42:03 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UINvw-0002am-TD for qemu-devel@nongnu.org; Wed, 20 Mar 2013 14:40:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UINvv-0004Ku-Ag for qemu-devel@nongnu.org; Wed, 20 Mar 2013 14:40:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15301) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UINvv-0004Kj-16 for qemu-devel@nongnu.org; Wed, 20 Mar 2013 14:40:19 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2KIeI0I003537 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 20 Mar 2013 14:40:18 -0400 Received: from dhcp-200-207.str.redhat.com (ovpn-116-51.ams2.redhat.com [10.36.116.51]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2KIdoxd024016; Wed, 20 Mar 2013 14:40:17 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 20 Mar 2013 19:39:47 +0100 Message-Id: <1363804788-18535-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1363804788-18535-1-git-send-email-kwolf@redhat.com> References: <1363804788-18535-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH v2 11/12] nbd: Use default port if only host is specified X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Eric Blake --- block/nbd.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 9858f06..67f1df2 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -118,21 +118,18 @@ 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; - + /* nbd[+tcp]://host[:port]/export */ 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: @@ -223,6 +220,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");