From patchwork Wed Oct 8 17:55:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 397680 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C753F1400DE for ; Thu, 9 Oct 2014 04:55:52 +1100 (EST) Received: from localhost ([::1]:37704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbvSn-0002BW-MM for incoming@patchwork.ozlabs.org; Wed, 08 Oct 2014 13:55:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbvSQ-0001oL-Hy for qemu-devel@nongnu.org; Wed, 08 Oct 2014 13:55:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XbvSK-0002Wz-Cf for qemu-devel@nongnu.org; Wed, 08 Oct 2014 13:55:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18557) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbvSK-0002Wv-4x for qemu-devel@nongnu.org; Wed, 08 Oct 2014 13:55:20 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s98HtIl7019248 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 8 Oct 2014 13:55:18 -0400 Received: from localhost (ovpn-116-73.ams2.redhat.com [10.36.116.73]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s98HtGXv006348 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Wed, 8 Oct 2014 13:55:18 -0400 From: Max Reitz To: qemu-devel@nongnu.org Date: Wed, 8 Oct 2014 19:55:15 +0200 Message-Id: <1412790915-28605-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH v1.5] nbd: Fix filename generation 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 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 Signed-off-by: Max Reitz Reviewed-by: Paolo Bonzini --- This is exactly the same patch as patch 1 from my series "[PATCH 0/3] block: Fix filename generation for blkdebug and nbd", except I added Paolo's R-b. The reason I split it off from the series is that is an actual bug fix and therefore I want to get it merged regardless of when the blkdebug patches are getting reviewed. --- 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;