From patchwork Mon Feb 29 23:19:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 8460261 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BDB74C0553 for ; Mon, 29 Feb 2016 23:23:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0BD6A2024C for ; Mon, 29 Feb 2016 23:23:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 570E720204 for ; Mon, 29 Feb 2016 23:23:55 +0000 (UTC) Received: from localhost ([::1]:39663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaXAQ-00009F-LB for patchwork-qemu-devel@patchwork.kernel.org; Mon, 29 Feb 2016 18:23:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaX6Y-0001g6-2A for qemu-devel@nongnu.org; Mon, 29 Feb 2016 18:19:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aaX6X-0006Bu-3l for qemu-devel@nongnu.org; Mon, 29 Feb 2016 18:19:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50702) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaX6U-0006B9-Qd; Mon, 29 Feb 2016 18:19:50 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 83DDF600F; Mon, 29 Feb 2016 23:19:50 +0000 (UTC) Received: from localhost (ovpn-116-81.ams2.redhat.com [10.36.116.81]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1TNJm8L018706 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 29 Feb 2016 18:19:50 -0500 From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 1 Mar 2016 00:19:23 +0100 Message-Id: <1456787973-19348-7-git-send-email-mreitz@redhat.com> In-Reply-To: <1456787973-19348-1-git-send-email-mreitz@redhat.com> References: <1456787973-19348-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 29 Feb 2016 23:19:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Markus Armbruster , qemu-devel@nongnu.org, Max Reitz , Paolo Bonzini , Luiz Capitulino Subject: [Qemu-devel] [PATCH v2 06/16] block/nbd: Default port in nbd_refresh_filename() 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 6a2fc27..8d9a217 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -411,6 +411,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) { @@ -419,27 +423,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)));