[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 05/10] QMP: Introduce the blockdev-tray-open command
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [RFC 05/10] QMP: Introduce the blockdev-tray-open command |
Date: |
Fri, 3 Jun 2011 16:03:57 -0300 |
This command opens a removable media drive's tray. It's only available
in QMP.
The do_tray_open() function is split into two smaller functions because
next commits will also use them.
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 open?
Signed-off-by: Luiz Capitulino <address@hidden>
---
blockdev.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
blockdev.h | 1 +
qmp-commands.hx | 27 +++++++++++++++++++++++++++
3 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 6e0eb83..b1c705c 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -665,6 +665,52 @@ static int eject_device(Monitor *mon, BlockDriverState
*bs, int force)
return 0;
}
+static BlockDriverState *bdrv_removable_find(const char *name)
+{
+ BlockDriverState *bs;
+
+ bs = bdrv_find(name);
+ if (!bs) {
+ qerror_report(QERR_DEVICE_NOT_FOUND, name);
+ return NULL;
+ }
+
+ if (!bdrv_is_removable(bs)) {
+ qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
+ return NULL;
+ }
+
+ return bs;
+}
+
+static int tray_open(const char *device, int remove, int force)
+{
+ BlockDriverState *bs;
+
+ bs = bdrv_removable_find(device);
+ if (!bs) {
+ return -1;
+ }
+
+ if (bdrv_eject(bs, 1, force) < 0) {
+ /* FIXME: will report undefined error in QMP */
+ return -1;
+ }
+
+ if (remove) {
+ bdrv_close(bs);
+ }
+
+ return 0;
+}
+
+int do_tray_open(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+ return tray_open(qdict_get_str(qdict, "device"),
+ qdict_get_try_bool(qdict, "remove", 0),
+ qdict_get_try_bool(qdict, "force", 0));
+}
+
int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
BlockDriverState *bs;
diff --git a/blockdev.h b/blockdev.h
index 3587786..5e46aae 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -65,5 +65,6 @@ int do_change_block(Monitor *mon, const char *device,
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);
#endif
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 8393f22..58ab132 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -153,6 +153,33 @@ Examples:
EQMP
{
+ .name = "blockdev-tray-open",
+ .args_type = "device:B,force:-f,remove:-r",
+ .mhandler.cmd_new = do_tray_open,
+ },
+
+SQMP
+blockdev-tray-open
+------------------
+
+Open a removable media drive's tray.
+
+Arguments:
+
+- device: device name (json-string)
+- force: force ejection (json-bool, optional)
+- remove: remove the media (json-bool, optional)
+
+Example:
+
+-> { "execute": "blockdev-tray-open", "arguments": { "device": "ide1-cd0" } }
+<- { "return": {} }
+
+Note: The tray remains open after this command is issued
+
+EQMP
+
+ {
.name = "screendump",
.args_type = "filename:F",
.params = "filename",
--
1.7.4.4
- [Qemu-devel] [RFC 02/10] block: Rename bdrv_mon_event(), (continued)
- [Qemu-devel] [RFC 02/10] block: Rename bdrv_mon_event(), Luiz Capitulino, 2011/06/03
- [Qemu-devel] [RFC 03/10] QMP: query-block: Add the 'tray-open' key, Luiz Capitulino, 2011/06/03
- [Qemu-devel] [RFC 04/10] HMP: info block: Print the 'tray-open' key, Luiz Capitulino, 2011/06/03
- [Qemu-devel] [RFC 06/10] QMP: Introduce the blockdev-tray-close command, Luiz Capitulino, 2011/06/03
- [Qemu-devel] [RFC 07/10] QMP: Introduce the blockdev-media-insert command, Luiz Capitulino, 2011/06/03
- [Qemu-devel] [RFC 05/10] QMP: Introduce the blockdev-tray-open command,
Luiz Capitulino <=
- Re: [Qemu-devel] [RFC 05/10] QMP: Introduce the blockdev-tray-open command, Markus Armbruster, 2011/06/06
[Qemu-devel] [RFC 08/10] QMP: Introduce the BLOCK_TRAY_OPEN and BLOCK_TRAY_CLOSE events, Luiz Capitulino, 2011/06/03
[Qemu-devel] [RFC 09/10] QMP/HMP: eject: Use blockdev-tray-open, Luiz Capitulino, 2011/06/03
[Qemu-devel] [RFC 10/10] QMP/HMP: change: Use QMP tray commands, Luiz Capitulino, 2011/06/03