diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 1d170c80b8..ca58491919 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 61b46a2f06..a4016091b2 100755 --- a/tests/qemu-iotests/223 +++ b/tests/qemu-iotests/223 @@ -172,7 +172,7 @@ _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove", _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 e6ede0591c..8a4d63a4fc 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