From nobody Mon May 6 08:28:34 2024 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 From nobody Mon May 6 08:28:34 2024 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 1516983256419409.7706123087843; Fri, 26 Jan 2018 08:14:16 -0800 (PST) Received: from localhost ([::1]:36147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6dr-0002qE-Az for importer@patchew.org; Fri, 26 Jan 2018 11:14:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6Zq-0008QB-6J for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:10:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef6Zm-0006Md-Vl for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:10:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40998) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ef6Zm-0006Ly-R1 for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:10:02 -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 4E5CBC068382 for ; Fri, 26 Jan 2018 16:04:19 +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 0B3F95D720; Fri, 26 Jan 2018 16:04:17 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 10:04:05 -0600 Message-Id: <20180126160411.4033-3-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.32]); Fri, 26 Jan 2018 16:04:19 +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 2/8] hmp: 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: "Dr. David Alan Gilbert" 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" Extend the flexibility of the previous QMP patch to also work in HMP. Signed-off-by: Eric Blake Reviewed-by: Dr. David Alan Gilbert Message-Id: <20180109192802.17167-1-eblake@redhat.com> --- hmp.c | 3 ++- hmp-commands.hx | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/hmp.c b/hmp.c index 5bcfc36de10..7a64dd59c5c 100644 --- a/hmp.c +++ b/hmp.c @@ -2221,10 +2221,11 @@ exit: void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) { const char *device =3D qdict_get_str(qdict, "device"); + const char *name =3D qdict_get_try_str(qdict, "name"); bool writable =3D qdict_get_try_bool(qdict, "writable", false); Error *local_err =3D NULL; - qmp_nbd_server_add(device, false, NULL, true, writable, &local_err); + qmp_nbd_server_add(device, !!name, name, true, writable, &local_err); if (local_err !=3D NULL) { hmp_handle_error(mon, &local_err); diff --git a/hmp-commands.hx b/hmp-commands.hx index 6d5ebdf6ab1..b8b6fb91848 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1553,17 +1553,18 @@ ETEXI { .name =3D "nbd_server_add", - .args_type =3D "writable:-w,device:B", - .params =3D "nbd_server_add [-w] device", + .args_type =3D "writable:-w,device:B,name:s?", + .params =3D "nbd_server_add [-w] device [name]", .help =3D "export a block device via NBD", .cmd =3D hmp_nbd_server_add, }, STEXI -@item nbd_server_add @var{device} +@item nbd_server_add @var{device} [ @var{name} ] @findex nbd_server_add Export a block device through QEMU's NBD server, which must be started beforehand with @command{nbd_server_start}. The @option{-w} option makes = the -exported device writable too. +exported device writable too. The export name is controlled by @var{name}, +defaulting to @var{device}. ETEXI { --=20 2.14.3 From nobody Mon May 6 08:28:34 2024 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 151698279998251.94823073869145; Fri, 26 Jan 2018 08:06:39 -0800 (PST) Received: from localhost ([::1]:35686 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6WV-00054Z-5H for importer@patchew.org; Fri, 26 Jan 2018 11:06:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6UN-00030x-09 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-0002ax-Rw for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:04:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ef6UJ-0002YV-7n; Fri, 26 Jan 2018 11:04:23 -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 8135E1752C2; Fri, 26 Jan 2018 16:04:22 +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 8F4E75D720; Fri, 26 Jan 2018 16:04:19 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 10:04:06 -0600 Message-Id: <20180126160411.4033-4-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.38]); Fri, 26 Jan 2018 16:04:22 +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 3/8] qapi: 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 removing an export. It is needed for cases when we don't want to keep the export after the operation on it was completed. The other example is a temporary node, created with blockdev-add. If we want to delete it we should firstly remove any corresponding NBD export. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180119135719.24745-3-vsementsov@virtuozzo.com> [eblake: drop dead nb_clients code] Signed-off-by: Eric Blake --- qapi/block.json | 41 +++++++++++++++++++++++++++++++++++++++++ include/block/nbd.h | 1 + blockdev-nbd.c | 24 ++++++++++++++++++++++++ nbd/server.c | 13 +++++++++++++ 4 files changed, 79 insertions(+) diff --git a/qapi/block.json b/qapi/block.json index 353e3a45bdf..c6945240029 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -227,6 +227,47 @@ { 'command': 'nbd-server-add', 'data': {'device': 'str', '*name': 'str', '*writable': 'bool'} } +## +# @NbdServerRemoveMode: +# +# Mode for removing an NBD export. +# +# @safe: Remove export if there are no existing connections, fail otherwis= e. +# +# @hard: Drop all connections immediately and remove export. +# +# Potential additional modes to be added in the future: +# +# hide: Just hide export from new clients, leave existing connections as i= s. +# Remove export after all clients are disconnected. +# +# soft: Hide export from new clients, answer with ESHUTDOWN for all further +# requests from existing clients. +# +# Since: 2.12 +## +{'enum': 'NbdServerRemoveMode', 'data': ['safe', 'hard']} + +## +# @nbd-server-remove: +# +# Remove NBD export by name. +# +# @name: Export name. +# +# @mode: Mode of command operation. See @NbdServerRemoveMode description. +# Default is 'safe'. +# +# Returns: error if +# - the server is not running +# - export is not found +# - mode is 'safe' and there are existing connections +# +# Since: 2.12 +## +{ 'command': 'nbd-server-remove', + 'data': {'name': 'str', '*mode': 'NbdServerRemoveMode'} } + ## # @nbd-server-stop: # diff --git a/include/block/nbd.h b/include/block/nbd.h index 978e4433664..ee74ec391a8 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -261,6 +261,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t d= ev_offset, off_t size, bool writethrough, BlockBackend *on_eject_blk, Error **errp); void nbd_export_close(NBDExport *exp); +void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **e= rrp); void nbd_export_get(NBDExport *exp); void nbd_export_put(NBDExport *exp); diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 104789e521c..a9f79c6778e 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -189,6 +189,30 @@ void qmp_nbd_server_add(const char *device, bool has_n= ame, const char *name, nbd_export_put(exp); } +void qmp_nbd_server_remove(const char *name, + bool has_mode, NbdServerRemoveMode mode, + Error **errp) +{ + NBDExport *exp; + + if (!nbd_server) { + error_setg(errp, "NBD server not running"); + return; + } + + exp =3D nbd_export_find(name); + if (exp =3D=3D NULL) { + error_setg(errp, "Export '%s' is not found", name); + return; + } + + if (!has_mode) { + mode =3D NBD_SERVER_REMOVE_MODE_SAFE; + } + + nbd_export_remove(exp, mode, errp); +} + void qmp_nbd_server_stop(Error **errp) { nbd_export_close_all(); diff --git a/nbd/server.c b/nbd/server.c index 6caa8d17be7..112e3f69dff 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1177,6 +1177,19 @@ void nbd_export_close(NBDExport *exp) nbd_export_put(exp); } +void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **e= rrp) +{ + if (mode =3D=3D NBD_SERVER_REMOVE_MODE_HARD || QTAILQ_EMPTY(&exp->clie= nts)) { + nbd_export_close(exp); + return; + } + + assert(mode =3D=3D NBD_SERVER_REMOVE_MODE_SAFE); + + error_setg(errp, "export '%s' still in use", exp->name); + error_append_hint(errp, "Use mode=3D'hard' to force client disconnect\= n"); +} + void nbd_export_get(NBDExport *exp) { assert(exp->refcount > 0); --=20 2.14.3 From nobody Mon May 6 08:28:34 2024 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 1516987416683762.8941776568739; Fri, 26 Jan 2018 09:23:36 -0800 (PST) Received: from localhost ([::1]:40300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef7ix-0001Xy-C5 for importer@patchew.org; Fri, 26 Jan 2018 12:23:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef7f6-00073a-2s for qemu-devel@nongnu.org; Fri, 26 Jan 2018 12:19:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef7f4-0007iX-Sh for qemu-devel@nongnu.org; Fri, 26 Jan 2018 12:19:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47318) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ef7ex-0007UP-Ry; Fri, 26 Jan 2018 12:19:28 -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 8BC8ACF634; Fri, 26 Jan 2018 16:04:24 +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 BF7F15D720; Fri, 26 Jan 2018 16:04:22 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 10:04:07 -0600 Message-Id: <20180126160411.4033-5-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.39]); Fri, 26 Jan 2018 16:04:24 +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/8] iotest 147: add cases to test new @name parameter of 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" , 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 Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20180119135719.24745-4-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- tests/qemu-iotests/147 | 68 +++++++++++++++++++++++++++++++++++++-----= ---- tests/qemu-iotests/147.out | 4 +-- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/tests/qemu-iotests/147 b/tests/qemu-iotests/147 index 90f40ed2457..d2081df84b0 100755 --- a/tests/qemu-iotests/147 +++ b/tests/qemu-iotests/147 @@ -38,8 +38,8 @@ def flatten_sock_addr(crumpled_address): class NBDBlockdevAddBase(iotests.QMPTestCase): - def blockdev_add_options(self, address, export=3DNone): - options =3D { 'node-name': 'nbd-blockdev', + def blockdev_add_options(self, address, export, node_name): + options =3D { 'node-name': node_name, 'driver': 'raw', 'file': { 'driver': 'nbd', @@ -50,23 +50,28 @@ class NBDBlockdevAddBase(iotests.QMPTestCase): options['file']['export'] =3D export return options - def client_test(self, filename, address, export=3DNone): - bao =3D self.blockdev_add_options(address, export) + def client_test(self, filename, address, export=3DNone, + node_name=3D'nbd-blockdev', delete=3DTrue): + bao =3D self.blockdev_add_options(address, export, node_name) result =3D self.vm.qmp('blockdev-add', **bao) self.assert_qmp(result, 'return', {}) + found =3D False result =3D self.vm.qmp('query-named-block-nodes') for node in result['return']: - if node['node-name'] =3D=3D 'nbd-blockdev': + if node['node-name'] =3D=3D node_name: + found =3D True if isinstance(filename, str): self.assert_qmp(node, 'image/filename', filename) else: self.assert_json_filename_equal(node['image']['filenam= e'], filename) break + self.assertTrue(found) - result =3D self.vm.qmp('blockdev-del', node_name=3D'nbd-blockdev') - self.assert_qmp(result, 'return', {}) + if delete: + result =3D self.vm.qmp('blockdev-del', node_name=3Dnode_name) + self.assert_qmp(result, 'return', {}) class QemuNBD(NBDBlockdevAddBase): @@ -125,26 +130,63 @@ class BuiltinNBD(NBDBlockdevAddBase): except OSError: pass - def _server_up(self, address): + def _server_up(self, address, export_name=3DNone, export_name2=3DNone): result =3D self.server.qmp('nbd-server-start', addr=3Daddress) self.assert_qmp(result, 'return', {}) - result =3D self.server.qmp('nbd-server-add', device=3D'nbd-export') + if export_name is None: + result =3D self.server.qmp('nbd-server-add', device=3D'nbd-exp= ort') + else: + result =3D self.server.qmp('nbd-server-add', device=3D'nbd-exp= ort', + name=3Dexport_name) self.assert_qmp(result, 'return', {}) + if export_name2 is not None: + result =3D self.server.qmp('nbd-server-add', device=3D'nbd-exp= ort', + name=3Dexport_name2) + self.assert_qmp(result, 'return', {}) + + def _server_down(self): result =3D self.server.qmp('nbd-server-stop') self.assert_qmp(result, 'return', {}) - def test_inet(self): + def do_test_inet(self, export_name=3DNone): address =3D { 'type': 'inet', 'data': { 'host': 'localhost', 'port': str(NBD_PORT) } } - self._server_up(address) - self.client_test('nbd://localhost:%i/nbd-export' % NBD_PORT, - flatten_sock_addr(address), 'nbd-export') + self._server_up(address, export_name) + export_name =3D export_name or 'nbd-export' + self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, export_name), + flatten_sock_addr(address), export_name) + self._server_down() + + def test_inet_default_export_name(self): + self.do_test_inet() + + def test_inet_same_export_name(self): + self.do_test_inet('nbd-export') + + def test_inet_different_export_name(self): + self.do_test_inet('shadow') + + def test_inet_two_exports(self): + address =3D { 'type': 'inet', + 'data': { + 'host': 'localhost', + 'port': str(NBD_PORT) + } } + self._server_up(address, 'exp1', 'exp2') + self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, 'exp1'), + flatten_sock_addr(address), 'exp1', 'node1', Fals= e) + self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, 'exp2'), + flatten_sock_addr(address), 'exp2', 'node2', Fals= e) + result =3D self.vm.qmp('blockdev-del', node_name=3D'node1') + self.assert_qmp(result, 'return', {}) + result =3D self.vm.qmp('blockdev-del', node_name=3D'node2') + self.assert_qmp(result, 'return', {}) self._server_down() def test_inet6(self): diff --git a/tests/qemu-iotests/147.out b/tests/qemu-iotests/147.out index 3f8a935a082..dae404e2786 100644 --- a/tests/qemu-iotests/147.out +++ b/tests/qemu-iotests/147.out @@ -1,5 +1,5 @@ -...... +......... ---------------------------------------------------------------------- -Ran 6 tests +Ran 9 tests OK --=20 2.14.3 From nobody Mon May 6 08:28:34 2024 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 1516983261668548.1091890992026; Fri, 26 Jan 2018 08:14:21 -0800 (PST) Received: from localhost ([::1]:36148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6dt-0002s1-1I for importer@patchew.org; Fri, 26 Jan 2018 11:14:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6c6-0001r8-TC for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:12:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef6c3-00084M-2e for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:12:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60788) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ef6bt-0007yL-QT; Fri, 26 Jan 2018 11:12:13 -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 B4DC7C05B019; Fri, 26 Jan 2018 16:04:25 +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 CCFAF5D720; Fri, 26 Jan 2018 16:04:24 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 10:04:08 -0600 Message-Id: <20180126160411.4033-6-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.31]); Fri, 26 Jan 2018 16:04:25 +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 5/8] iotests: implement QemuIoInteractive class 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" , 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 Implement QemuIoInteractive to test nbd-server-remove command when there are active connections. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180119135719.24745-5-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- tests/qemu-iotests/iotests.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 44477e92958..5a10b2d5345 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -93,6 +93,44 @@ def qemu_io(*args): sys.stderr.write('qemu-io received signal %i: %s\n' % (-exitcode, = ' '.join(args))) return subp.communicate()[0] + +class QemuIoInteractive: + def __init__(self, *args): + self.args =3D qemu_io_args + list(args) + self._p =3D subprocess.Popen(self.args, stdin=3Dsubprocess.PIPE, + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT) + assert self._p.stdout.read(9) =3D=3D 'qemu-io> ' + + def close(self): + self._p.communicate('q\n') + + def _read_output(self): + pattern =3D 'qemu-io> ' + n =3D len(pattern) + pos =3D 0 + s =3D [] + while pos !=3D n: + c =3D self._p.stdout.read(1) + # check unexpected EOF + assert c !=3D '' + s.append(c) + if c =3D=3D pattern[pos]: + pos +=3D 1 + else: + pos =3D 0 + + return ''.join(s[:-n]) + + def cmd(self, cmd): + # quit command is in close(), '\n' is added automatically + assert '\n' not in cmd + cmd =3D cmd.strip() + assert cmd !=3D 'q' and cmd !=3D 'quit' + self._p.stdin.write(cmd + '\n') + return self._read_output() + + def qemu_nbd(*args): '''Run qemu-nbd in daemon mode and return the parent's exit code''' return subprocess.call(qemu_nbd_args + ['--fork'] + list(args)) --=20 2.14.3 From nobody Mon May 6 08:28:34 2024 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 1516983015033203.7752356511446; Fri, 26 Jan 2018 08:10:15 -0800 (PST) Received: from localhost ([::1]:35875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6Zy-0008Ee-6u for importer@patchew.org; Fri, 26 Jan 2018 11:10:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6UV-0003KQ-Vm for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:04:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef6UU-0002gt-CL for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:04:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48302) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ef6UO-0002cv-25; Fri, 26 Jan 2018 11:04:28 -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 36909D69C5; Fri, 26 Jan 2018 16:04:27 +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 013125D720; Fri, 26 Jan 2018 16:04:25 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 10:04:09 -0600 Message-Id: <20180126160411.4033-7-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.27]); Fri, 26 Jan 2018 16:04:27 +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 6/8] iotest 205: new test for qmp 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" , 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 Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180119135719.24745-6-vsementsov@virtuozzo.com> [eblake: adjust to next available test number] Signed-off-by: Eric Blake --- tests/qemu-iotests/205 | 156 +++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/205.out | 5 ++ tests/qemu-iotests/group | 1 + 3 files changed, 162 insertions(+) create mode 100644 tests/qemu-iotests/205 create mode 100644 tests/qemu-iotests/205.out diff --git a/tests/qemu-iotests/205 b/tests/qemu-iotests/205 new file mode 100644 index 00000000000..10388920dc3 --- /dev/null +++ b/tests/qemu-iotests/205 @@ -0,0 +1,156 @@ +#!/usr/bin/env python +# +# Tests for qmp command nbd-server-remove. +# +# Copyright (c) 2017 Virtuozzo International GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os +import sys +import iotests +import time +from iotests import qemu_img, qemu_io, filter_qemu_io, QemuIoInteractive + +nbd_sock =3D 'nbd_sock' +nbd_uri =3D 'nbd+unix:///exp?socket=3D' + nbd_sock +disk =3D os.path.join(iotests.test_dir, 'disk') + + +class TestNbdServerRemove(iotests.QMPTestCase): + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, disk, '1M') + + self.vm =3D iotests.VM().add_drive(disk) + self.vm.launch() + + address =3D { + 'type': 'unix', + 'data': { + 'path': nbd_sock + } + } + + result =3D self.vm.qmp('nbd-server-start', addr=3Daddress) + self.assert_qmp(result, 'return', {}) + result =3D self.vm.qmp('nbd-server-add', device=3D'drive0', name= =3D'exp') + self.assert_qmp(result, 'return', {}) + + def tearDown(self): + self.vm.shutdown() + os.remove(nbd_sock) + os.remove(disk) + + def remove_export(self, name, mode=3DNone): + if mode is None: + return self.vm.qmp('nbd-server-remove', name=3Dname) + else: + return self.vm.qmp('nbd-server-remove', name=3Dname, mode=3Dmo= de) + + def assertExportNotFound(self, name): + result =3D self.vm.qmp('nbd-server-remove', name=3Dname) + self.assert_qmp(result, 'error/desc', "Export 'exp' is not found") + + def assertExistingClients(self, result): + self.assert_qmp(result, 'error/desc', "export 'exp' still in use") + + def assertReadOk(self, qemu_io_output): + self.assertEqual( + filter_qemu_io(qemu_io_output).strip(), + 'read 512/512 bytes at offset 0\n' + + '512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec= )') + + def assertReadFailed(self, qemu_io_output): + self.assertEqual(filter_qemu_io(qemu_io_output).strip(), + 'read failed: Input/output error') + + def assertConnectFailed(self, qemu_io_output): + self.assertEqual(filter_qemu_io(qemu_io_output).strip(), + "can't open device " + nbd_uri + + ": Requested export not available\n" + "server reported: export 'exp' not present") + + def do_test_connect_after_remove(self, mode=3DNone): + args =3D ('-r', '-f', 'raw', '-c', 'read 0 512', nbd_uri) + self.assertReadOk(qemu_io(*args)) + + result =3D self.remove_export('exp', mode) + self.assert_qmp(result, 'return', {}) + + self.assertExportNotFound('exp') + self.assertConnectFailed(qemu_io(*args)) + + def test_connect_after_remove_default(self): + self.do_test_connect_after_remove() + + def test_connect_after_remove_safe(self): + self.do_test_connect_after_remove('safe') + + def test_connect_after_remove_force(self): + self.do_test_connect_after_remove('hard') + + def do_test_remove_during_connect_safe(self, mode=3DNone): + qio =3D QemuIoInteractive('-r', '-f', 'raw', nbd_uri) + self.assertReadOk(qio.cmd('read 0 512')) + + result =3D self.remove_export('exp', mode) + self.assertExistingClients(result) + + self.assertReadOk(qio.cmd('read 0 512')) + + qio.close() + + result =3D self.remove_export('exp', mode) + self.assert_qmp(result, 'return', {}) + + self.assertExportNotFound('exp') + + def test_remove_during_connect_default(self): + self.do_test_remove_during_connect_safe() + + def test_remove_during_connect_safe(self): + self.do_test_remove_during_connect_safe('safe') + + def test_remove_during_connect_hard(self): + qio =3D QemuIoInteractive('-r', '-f', 'raw', nbd_uri) + self.assertReadOk(qio.cmd('read 0 512')) + + result =3D self.remove_export('exp', 'hard') + self.assert_qmp(result, 'return', {}) + + self.assertReadFailed(qio.cmd('read 0 512')) + self.assertExportNotFound('exp') + + qio.close() + + def test_remove_during_connect_safe_hard(self): + qio =3D QemuIoInteractive('-r', '-f', 'raw', nbd_uri) + self.assertReadOk(qio.cmd('read 0 512')) + + result =3D self.remove_export('exp', 'safe') + self.assertExistingClients(result) + + self.assertReadOk(qio.cmd('read 0 512')) + + result =3D self.remove_export('exp', 'hard') + self.assert_qmp(result, 'return', {}) + + self.assertExportNotFound('exp') + self.assertReadFailed(qio.cmd('read 0 512')) + qio.close() + + +if __name__ =3D=3D '__main__': + iotests.main() diff --git a/tests/qemu-iotests/205.out b/tests/qemu-iotests/205.out new file mode 100644 index 00000000000..2f7d3902f23 --- /dev/null +++ b/tests/qemu-iotests/205.out @@ -0,0 +1,5 @@ +....... +---------------------------------------------------------------------- +Ran 7 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 8fc4f62cca6..a2dfe79d862 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -201,3 +201,4 @@ 202 rw auto quick 203 rw auto 204 rw auto quick +205 rw auto quick --=20 2.14.3 From nobody Mon May 6 08:28:34 2024 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 15169829705461014.7817918643677; Fri, 26 Jan 2018 08:09:30 -0800 (PST) Received: from localhost ([::1]:35823 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6ZF-0007fC-Jh for importer@patchew.org; Fri, 26 Jan 2018 11:09:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6US-0003Cd-E1 for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:04:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef6UP-0002e4-Ei for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:04:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26808) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ef6UP-0002dl-7A for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:04:29 -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 7F33B72663 for ; Fri, 26 Jan 2018 16:04:28 +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 747205D720; Fri, 26 Jan 2018 16:04:27 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 10:04:10 -0600 Message-Id: <20180126160411.4033-8-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.28]); Fri, 26 Jan 2018 16:04:28 +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 7/8] hmp: Add nbd_server_remove to mirror QMP command 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: "Dr. David Alan Gilbert" 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" Since everything else about the nbd-server-* QMP commands is accessible from HMP, we might as well make removing an export available as well. For now, I went with a bool flag rather than a mode string for choosing between safe (default) and hard modes. Signed-off-by: Eric Blake Message-Id: <20180125144557.25502-1-eblake@redhat.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Eric Blake --- hmp.h | 1 + hmp.c | 14 +++++++++++--- hmp-commands.hx | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/hmp.h b/hmp.h index a6f56b1f29e..536cb91caa4 100644 --- a/hmp.h +++ b/hmp.h @@ -101,6 +101,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict); void hmp_screendump(Monitor *mon, const QDict *qdict); void hmp_nbd_server_start(Monitor *mon, const QDict *qdict); void hmp_nbd_server_add(Monitor *mon, const QDict *qdict); +void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict); void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict); void hmp_chardev_add(Monitor *mon, const QDict *qdict); void hmp_chardev_change(Monitor *mon, const QDict *qdict); diff --git a/hmp.c b/hmp.c index 7a64dd59c5c..b3de32d219b 100644 --- a/hmp.c +++ b/hmp.c @@ -2226,10 +2226,18 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *= qdict) Error *local_err =3D NULL; qmp_nbd_server_add(device, !!name, name, true, writable, &local_err); + hmp_handle_error(mon, &local_err); +} - if (local_err !=3D NULL) { - hmp_handle_error(mon, &local_err); - } +void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) +{ + const char *name =3D qdict_get_str(qdict, "name"); + bool force =3D qdict_get_try_bool(qdict, "force", false); + Error *err =3D NULL; + + /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */ + qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err); + hmp_handle_error(mon, &err); } void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) diff --git a/hmp-commands.hx b/hmp-commands.hx index b8b6fb91848..c36a9ec4657 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1565,6 +1565,23 @@ Export a block device through QEMU's NBD server, whi= ch must be started beforehand with @command{nbd_server_start}. The @option{-w} option makes = the exported device writable too. The export name is controlled by @var{name}, defaulting to @var{device}. +ETEXI + + { + .name =3D "nbd_server_remove", + .args_type =3D "force:-f,name:s", + .params =3D "nbd_server_remove [-f] name", + .help =3D "remove an export previously exposed via NBD", + .cmd =3D hmp_nbd_server_remove, + }, +STEXI +@item nbd_server_remove [-f] @var{name} +@findex nbd_server_remove +Stop exporting a block device through QEMU's NBD server, which was +previously started with @command{nbd_server_add}. The @option{-f} +option forces the server to drop the export immediately even if +clients are connected; otherwise the command fails unless there are no +clients. ETEXI { --=20 2.14.3 From nobody Mon May 6 08:28:34 2024 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 1516987886482578.2830338746043; Fri, 26 Jan 2018 09:31:26 -0800 (PST) Received: from localhost ([::1]:40826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef7qX-0008KU-49 for importer@patchew.org; Fri, 26 Jan 2018 12:31:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef7hk-0000zo-8j for qemu-devel@nongnu.org; Fri, 26 Jan 2018 12:22:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef7hj-00039K-Bs for qemu-devel@nongnu.org; Fri, 26 Jan 2018 12:22:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38144) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ef7hd-00031W-Ug; Fri, 26 Jan 2018 12:22:14 -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 286F7C0ADB62; Fri, 26 Jan 2018 16:04:32 +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 190EF5D724; Fri, 26 Jan 2018 16:04:28 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 10:04:11 -0600 Message-Id: <20180126160411.4033-9-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.31]); Fri, 26 Jan 2018 16:04:32 +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 8/8] nbd: implement bdrv_get_info callback 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 , Paolo Bonzini , Edgar Kaziakhmedov , "open list:Network Block Dev..." , 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: Edgar Kaziakhmedov Since mirror job supports efficient zero out target mechanism (see in mirror_dirty_init()), implement bdrv_get_info to make it work over NBD. Such improvement will allow using the largest chunk possible and will decrease the number of NBD_CMD_WRITE_ZEROES requests on the wire. Signed-off-by: Edgar Kaziakhmedov Message-Id: <20180118115158.17219-1-edgar.kaziakhmedov@virtuozzo.com> Reviewed-by: Paolo Bonzini Signed-off-by: Eric Blake --- block/nbd.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index 8b8ba56cdd0..94220f6d143 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -566,6 +566,14 @@ static void nbd_refresh_filename(BlockDriverState *bs,= QDict *options) bs->full_open_options =3D opts; } +static int nbd_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +{ + if (bs->supported_zero_flags & BDRV_REQ_MAY_UNMAP) { + bdi->can_write_zeroes_with_unmap =3D true; + } + return 0; +} + static BlockDriver bdrv_nbd =3D { .format_name =3D "nbd", .protocol_name =3D "nbd", @@ -583,6 +591,7 @@ static BlockDriver bdrv_nbd =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_get_info =3D nbd_get_info, }; static BlockDriver bdrv_nbd_tcp =3D { @@ -602,6 +611,7 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_get_info =3D nbd_get_info, }; static BlockDriver bdrv_nbd_unix =3D { @@ -621,6 +631,7 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_get_info =3D nbd_get_info, }; static void bdrv_nbd_init(void) --=20 2.14.3