From 08fb10a7292637eb5836b8ac07b7ef8267db03be Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 25 Jan 2018 08:45:57 -0600 Subject: [PATCH] hmp: Add nbd_server_remove to mirror QMP command 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-commands.hx | 17 +++++++++++++++++ hmp.c | 14 +++++++++++--- hmp.h | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index b8b6fb9184..c36a9ec465 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1565,6 +1565,23 @@ 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. The export name is controlled by @var{name}, defaulting to @var{device}. +ETEXI + + { + .name = "nbd_server_remove", + .args_type = "force:-f,name:s", + .params = "nbd_server_remove [-f] name", + .help = "remove an export previously exposed via NBD", + .cmd = 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 { diff --git a/hmp.c b/hmp.c index 7a64dd59c5..b3de32d219 100644 --- a/hmp.c +++ b/hmp.c @@ -2226,10 +2226,18 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) Error *local_err = NULL; qmp_nbd_server_add(device, !!name, name, true, writable, &local_err); + hmp_handle_error(mon, &local_err); +} - if (local_err != NULL) { - hmp_handle_error(mon, &local_err); - } +void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) +{ + const char *name = qdict_get_str(qdict, "name"); + bool force = qdict_get_try_bool(qdict, "force", false); + Error *err = 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.h b/hmp.h index a6f56b1f29..536cb91caa 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); -- 2.39.2