This command closes a removable media drive's tray. It's only available in QMP.
Please, check the command's documentation (being introduced in this commit) for a detailed description. XXX: Should we return an error if the tray is already closed? Signed-off-by: Luiz Capitulino <lcapitul...@redhat.com> --- blockdev.c | 22 ++++++++++++++++++++++ blockdev.h | 1 + qmp-commands.hx | 23 +++++++++++++++++++++++ 3 files changed, 46 insertions(+), 0 deletions(-) diff --git a/blockdev.c b/blockdev.c index b1c705c..943905d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -704,6 +704,28 @@ static int tray_open(const char *device, int remove, int force) return 0; } +static int tray_close(const char *device) +{ + BlockDriverState *bs; + + bs = bdrv_removable_find(device); + if (!bs) { + return -1; + } + + if (bdrv_eject(bs, 0, 0) < 0) { + /* FIXME: will report undefined error in QMP */ + return -1; + } + + return 0; +} + +int do_tray_close(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + return tray_close(qdict_get_str(qdict, "device")); +} + int do_tray_open(Monitor *mon, const QDict *qdict, QObject **ret_data) { return tray_open(qdict_get_str(qdict, "device"), diff --git a/blockdev.h b/blockdev.h index 5e46aae..975e91a 100644 --- a/blockdev.h +++ b/blockdev.h @@ -66,5 +66,6 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_tray_open(Monitor *mon, const QDict *qdict, QObject **ret_data); +int do_tray_close(Monitor *mon, const QDict *qdict, QObject **ret_data); #endif diff --git a/qmp-commands.hx b/qmp-commands.hx index 58ab132..fdf9750 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -153,6 +153,29 @@ Examples: EQMP { + .name = "blockdev-tray-close", + .args_type = "device:B", + .mhandler.cmd_new = do_tray_close, + }, + +SQMP +blockdev-tray-close +------------------- + +Close a removable media drive's tray. + +Arguments: + +- device: device name (json-string) + +Example: + +-> { "execute": "blockdev-tray-close", "arguments": { "device": "ide1-cd0" } } +<- { "return": {} } + +EQMP + + { .name = "blockdev-tray-open", .args_type = "device:B,force:-f,remove:-r", .mhandler.cmd_new = do_tray_open, -- 1.7.4.4