From nobody Tue Feb 10 15:01:09 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513820297684165.1285666920013; Wed, 20 Dec 2017 17:38:17 -0800 (PST) Received: from localhost ([::1]:51957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRpoD-00006b-Nz for importer@patchew.org; Wed, 20 Dec 2017 20:38:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33768) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRpmO-0007Lk-34 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 20:36:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRpmN-0001XJ-5i for qemu-devel@nongnu.org; Wed, 20 Dec 2017 20:36:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRpmK-0001Uq-PN; Wed, 20 Dec 2017 20:36:08 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA4BAC047B62; Thu, 21 Dec 2017 01:36:07 +0000 (UTC) Received: from red.redhat.com (ovpn-120-109.rdu2.redhat.com [10.10.120.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EDD85C88F; Thu, 21 Dec 2017 01:36:06 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 20 Dec 2017 19:36:00 -0600 Message-Id: <20171221013600.17648-5-eblake@redhat.com> In-Reply-To: <20171221013600.17648-1-eblake@redhat.com> References: <20171221013600.17648-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 21 Dec 2017 01:36:07 +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 4/4] qmp: add nbd-server-remove 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" , Markus Armbruster , Max Reitz , Paolo Bonzini 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 Add command for export removing. It is needed for cases when we don't want to keep export after the operation on it was completed. The other example is temporary node, created with blockdev-add. If we want to delete it we should firstly remove corresponding NBD export. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20171109154049.42386-3-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- qapi/block.json | 20 ++++++++++++++++++++ blockdev-nbd.c | 27 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/qapi/block.json b/qapi/block.json index f093fa3f27..1827940717 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -222,6 +222,26 @@ ## { 'command': 'nbd-server-add', 'data': {'device': 'str', '*writable': 'boo= l'} } +## +# @nbd-server-remove: +# +# Stop exporting block node through QEMU's embedded NBD server. +# +# @device: The device name or node name of the exported node. Should be eq= ual +# to @device parameter for corresponding nbd-server-add command c= all. +# +# @force: Whether active connections to the export should be closed. If th= is +# parameter is false the export is only removed from named exports= list, +# so new connetions are impossible and it would be freed after all +# clients are disconnected (default false). +# +# Returns: error if the server is not running or the device is not marked = for +# export. +# +# Since: 2.12 +## +{ 'command': 'nbd-server-remove', 'data': {'device': 'str', '*force': 'boo= l'} } + ## # @nbd-server-stop: # diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 28f551a7b0..5f66951c33 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -203,6 +203,33 @@ void qmp_nbd_server_add(const char *device, bool has_w= ritable, bool writable, nbd_export_put(exp); } +void qmp_nbd_server_remove(const char *device, bool has_force, bool force, + Error **errp) +{ + NBDExport *exp; + + if (!nbd_server) { + error_setg(errp, "NBD server not running"); + return; + } + + exp =3D nbd_export_find(device); + if (exp =3D=3D NULL) { + error_setg(errp, "'%s' is not exported", device); + return; + } + + if (!has_force) { + force =3D false; + } + + if (force) { + nbd_export_close(exp); + } else { + nbd_export_set_name(exp, NULL); + } +} + void qmp_nbd_server_stop(Error **errp) { nbd_export_close_all(); --=20 2.14.3