This commit rewrites eject as a special case of the blockdev-tray-open
command. In other words, do_eject() just calls tray_open().

This brings the following behavior *changes* to both QMP and HMP:

 1. Before this commit eject was capable of closing the BlockDriverState
    associated with *any* device (ie. removable or not, by using '-f').
    Now it's only capable of closing the BlockDriverState of removable
    devices

 2. Ejecting the host's cdrom now works

 3. After the eject command is ran the tray is left open

Please, also note that the use of this command will emit the
BLOCK_TRAY_OPEN event in QMP.

Signed-off-by: Luiz Capitulino <lcapitul...@redhat.com>
---
 blockdev.c |   12 ++----------
 1 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 14c8312..36c56fd 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -787,16 +787,8 @@ int do_tray_open(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 
 int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
-    BlockDriverState *bs;
-    int force = qdict_get_try_bool(qdict, "force", 0);
-    const char *filename = qdict_get_str(qdict, "device");
-
-    bs = bdrv_find(filename);
-    if (!bs) {
-        qerror_report(QERR_DEVICE_NOT_FOUND, filename);
-        return -1;
-    }
-    return eject_device(mon, bs, force);
+    return tray_open(qdict_get_str(qdict, "device"), 1,
+                     qdict_get_try_bool(qdict, "force", 0));
 }
 
 int do_block_set_passwd(Monitor *mon, const QDict *qdict,
-- 
1.7.4.4


Reply via email to