From nobody Tue Feb 10 19:14:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516982800970497.6104874331876; Fri, 26 Jan 2018 08:06:40 -0800 (PST) Received: from localhost ([::1]:35685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6WT-00052W-5s for importer@patchew.org; Fri, 26 Jan 2018 11:06:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6UM-0002zg-Hk for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:04:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef6UL-0002aT-HW for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:04:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45792) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ef6UE-0002SR-Mx; Fri, 26 Jan 2018 11:04:18 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9A43D556F; Fri, 26 Jan 2018 16:04:17 +0000 (UTC) Received: from red.redhat.com (ovpn-124-3.rdu2.redhat.com [10.10.124.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 470A74DC51; Fri, 26 Jan 2018 16:04:14 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 10:04:04 -0600 Message-Id: <20180126160411.4033-2-eblake@redhat.com> In-Reply-To: <20180126160411.4033-1-eblake@redhat.com> References: <20180126160411.4033-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 26 Jan 2018 16:04:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/8] qapi: add name parameter to nbd-server-add 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 , Vladimir Sementsov-Ogievskiy , "open list:Block layer core" , "Dr. David Alan Gilbert" , Markus Armbruster , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Allow user to specify name for new export, to not reuse internal node name and to not show it to clients. This also allows creating several exports per device. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20180119135719.24745-2-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- qapi/block.json | 9 +++++++-- blockdev-nbd.c | 14 +++++++++----- hmp.c | 5 +++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/qapi/block.json b/qapi/block.json index f093fa3f276..353e3a45bdf 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -213,14 +213,19 @@ # # @device: The device name or node name of the node to be exported # +# @name: Export name. If unspecified, the @device parameter is used as the +# export name. (Since 2.12) +# # @writable: Whether clients should be able to write to the device via the # NBD connection (default false). # -# Returns: error if the device is already marked for export. +# Returns: error if the server is not running, or export with the same name +# already exists. # # Since: 1.3.0 ## -{ 'command': 'nbd-server-add', 'data': {'device': 'str', '*writable': 'boo= l'} } +{ 'command': 'nbd-server-add', + 'data': {'device': 'str', '*name': 'str', '*writable': 'bool'} } ## # @nbd-server-stop: diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 9e3c22109c6..104789e521c 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -140,8 +140,8 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr, qapi_free_SocketAddress(addr_flat); } -void qmp_nbd_server_add(const char *device, bool has_writable, bool writab= le, - Error **errp) +void qmp_nbd_server_add(const char *device, bool has_name, const char *nam= e, + bool has_writable, bool writable, Error **errp) { BlockDriverState *bs =3D NULL; BlockBackend *on_eject_blk; @@ -152,8 +152,12 @@ void qmp_nbd_server_add(const char *device, bool has_w= ritable, bool writable, return; } - if (nbd_export_find(device)) { - error_setg(errp, "NBD server already exporting device '%s'", devic= e); + if (!has_name) { + name =3D device; + } + + if (nbd_export_find(name)) { + error_setg(errp, "NBD server already has export named '%s'", name); return; } @@ -177,7 +181,7 @@ void qmp_nbd_server_add(const char *device, bool has_wr= itable, bool writable, return; } - nbd_export_set_name(exp, device); + nbd_export_set_name(exp, name); /* The list of named exports has a strong reference to this export now= and * our only way of accessing it is through nbd_export_find(), so we ca= n drop diff --git a/hmp.c b/hmp.c index 056bf70cf1e..5bcfc36de10 100644 --- a/hmp.c +++ b/hmp.c @@ -2203,7 +2203,8 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *= qdict) continue; } - qmp_nbd_server_add(info->value->device, true, writable, &local_err= ); + qmp_nbd_server_add(info->value->device, false, NULL, + true, writable, &local_err); if (local_err !=3D NULL) { qmp_nbd_server_stop(NULL); @@ -2223,7 +2224,7 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qd= ict) bool writable =3D qdict_get_try_bool(qdict, "writable", false); Error *local_err =3D NULL; - qmp_nbd_server_add(device, true, writable, &local_err); + qmp_nbd_server_add(device, false, NULL, true, writable, &local_err); if (local_err !=3D NULL) { hmp_handle_error(mon, &local_err); --=20 2.14.3