From patchwork Tue Apr 26 21:32:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 8945861 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 1633ABF29F for ; Tue, 26 Apr 2016 21:37:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 68EEF201EC for ; Tue, 26 Apr 2016 21:37:27 +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 A57D3201BB for ; Tue, 26 Apr 2016 21:37:26 +0000 (UTC) Received: from localhost ([::1]:39742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avAfd-0007Wx-Vm for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Apr 2016 17:37:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avAbO-0007Zi-K9 for qemu-devel@nongnu.org; Tue, 26 Apr 2016 17:33:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avAbN-00044t-N4 for qemu-devel@nongnu.org; Tue, 26 Apr 2016 17:33:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avAbJ-00042r-0I; Tue, 26 Apr 2016 17:32:57 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A470980B56; Tue, 26 Apr 2016 21:32:56 +0000 (UTC) Received: from localhost (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3QLWtpQ024297 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 26 Apr 2016 17:32:56 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 26 Apr 2016 23:32:15 +0200 Message-Id: <1461706338-20219-17-git-send-email-mreitz@redhat.com> In-Reply-To: <1461706338-20219-1-git-send-email-mreitz@redhat.com> References: <1461706338-20219-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 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 16/19] block/nbd: Implement bdrv_dirname() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 The idea behind this implementation is that the export name might be interpreted as a path (which is the only apparent interpretation of relative filenames for NBD paths). The default implementation of bdrv_dirname() would handle that just fine for nbd+tcp, but not for nbd+unix, because in that case, the last element of the path is the Unix socket path and not the export name. Therefore, we need to implement an own bdrv_dirname() which uses the legacy NBD URL which has the export name at the end. Signed-off-by: Max Reitz --- block/nbd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index f7ea3b3..64534bb 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -469,6 +469,32 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) bs->full_open_options = opts; } +static char *nbd_dirname(BlockDriverState *bs, Error **errp) +{ + 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"); + + if (path && export) { + return g_strdup_printf("nbd:unix:%s:exportname=%s/", path, export); + } else if (path && !export) { + return g_strdup_printf("nbd:unix:%s:exportname=", path); + } else if (!path && export && port) { + return g_strdup_printf("nbd://%s:%s/%s/", host, port, export); + } else if (!path && export && !port) { + return g_strdup_printf("nbd://%s/%s/", host, export); + } else if (!path && !export && port) { + return g_strdup_printf("nbd://%s:%s/", host, port); + } else if (!path && !export && !port) { + return g_strdup_printf("nbd://%s/", host); + } + + error_setg(errp, "Cannot generate a base directory for NBD node '%s'", + bs->filename); + return NULL; +} + static BlockDriver bdrv_nbd = { .format_name = "nbd", .protocol_name = "nbd", @@ -487,6 +513,7 @@ static BlockDriver bdrv_nbd = { .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, .bdrv_refresh_filename = nbd_refresh_filename, + .bdrv_dirname = nbd_dirname, }; static BlockDriver bdrv_nbd_tcp = { @@ -507,6 +534,7 @@ static BlockDriver bdrv_nbd_tcp = { .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, .bdrv_refresh_filename = nbd_refresh_filename, + .bdrv_dirname = nbd_dirname, }; static BlockDriver bdrv_nbd_unix = { @@ -527,6 +555,7 @@ static BlockDriver bdrv_nbd_unix = { .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, .bdrv_refresh_filename = nbd_refresh_filename, + .bdrv_dirname = nbd_dirname, }; static void bdrv_nbd_init(void)