qemu-devel
[Top][All Lists]
Advanced

[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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]