From nobody Sun Oct 5 21:12:43 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547484096183870.1444846529992; Mon, 14 Jan 2019 08:41:36 -0800 (PST) Received: from localhost ([127.0.0.1]:42097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj5It-0007QZ-3W for importer@patchew.org; Mon, 14 Jan 2019 11:41:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj550-0004JO-OS for qemu-devel@nongnu.org; Mon, 14 Jan 2019 11:27:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gj54z-0005ft-S3 for qemu-devel@nongnu.org; Mon, 14 Jan 2019 11:27:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51928) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gj54w-0005dH-Sf; Mon, 14 Jan 2019 11:27:11 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41810C0CB12E; Mon, 14 Jan 2019 16:27:08 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-16.phx2.redhat.com [10.3.117.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECFE85C6D4; Mon, 14 Jan 2019 16:26:45 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 10:25:59 -0600 Message-Id: <20190114162605.5330-15-eblake@redhat.com> In-Reply-To: <20190114162605.5330-1-eblake@redhat.com> References: <20190114162605.5330-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 14 Jan 2019 16:27:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 14/20] nbd: Forbid nbd-server-stop when server is not running 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" Content-Type: text/plain; charset="utf-8" Since we already forbid other nbd-server commands when not in the right state, it is unlikely that any caller was relying on a second stop to behave as a silent no-op. Update iotest 223 to show the improved behavior. Signed-off-by: Eric Blake Message-Id: <20190111194720.15671-3-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy --- blockdev-nbd.c | 5 +++++ tests/qemu-iotests/223 | 2 +- tests/qemu-iotests/223.out | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 1d170c80b82..ca584919194 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -214,6 +214,11 @@ void qmp_nbd_server_remove(const char *name, void qmp_nbd_server_stop(Error **errp) { + if (!nbd_server) { + error_setg(errp, "NBD server not running"); + return; + } + nbd_export_close_all(); nbd_server_free(nbd_server); diff --git a/tests/qemu-iotests/223 b/tests/qemu-iotests/223 index 61b46a2f066..a4016091b21 100755 --- a/tests/qemu-iotests/223 +++ b/tests/qemu-iotests/223 @@ -172,7 +172,7 @@ _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-rem= ove", _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove", "arguments":{"name":"n2"}}' "error" # Attempt duplicate clean _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return" -_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return" # Oops +_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "error" # Again _send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return" # success, all done diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out index e6ede0591cd..8a4d63a4fc2 100644 --- a/tests/qemu-iotests/223.out +++ b/tests/qemu-iotests/223.out @@ -69,6 +69,6 @@ read 2097152/2097152 bytes at offset 2097152 {"return": {}} {"error": {"class": "GenericError", "desc": "Export 'n2' is not found"}} {"return": {}} -{"return": {}} +{"error": {"class": "GenericError", "desc": "NBD server not running"}} {"return": {}} *** done --=20 2.20.1