diff options
author | Luiz Capitulino <lcapitulino@redhat.com> | 2012-02-14 13:41:13 -0200 |
---|---|---|
committer | Luiz Capitulino <lcapitulino@redhat.com> | 2012-02-22 17:23:50 -0200 |
commit | 6f382ed226f3a408825d882e6c4b47499baaa15b (patch) | |
tree | 842957696f2497c86b3fd04170762969756c7a8c /block.c | |
parent | bde25388d1cee6576ff12dd40f9abf489f0031ed (diff) |
qmp: add DEVICE_TRAY_MOVED event
It's emitted whenever the tray is moved by the guest or by HMP/QMP
commands.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -972,10 +972,30 @@ void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv, qobject_decref(data); } +static void bdrv_emit_qmp_eject_event(BlockDriverState *bs, bool ejected) +{ + QObject *data; + + data = qobject_from_jsonf("{ 'device': %s, 'tray-open': %i }", + bdrv_get_device_name(bs), ejected); + monitor_protocol_event(QEVENT_DEVICE_TRAY_MOVED, data); + + qobject_decref(data); +} + static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load) { if (bs->dev_ops && bs->dev_ops->change_media_cb) { + bool tray_was_closed = !bdrv_dev_is_tray_open(bs); bs->dev_ops->change_media_cb(bs->dev_opaque, load); + if (tray_was_closed) { + /* tray open */ + bdrv_emit_qmp_eject_event(bs, true); + } + if (load) { + /* tray close */ + bdrv_emit_qmp_eject_event(bs, false); + } } } @@ -3616,6 +3636,10 @@ void bdrv_eject(BlockDriverState *bs, bool eject_flag) if (drv && drv->bdrv_eject) { drv->bdrv_eject(bs, eject_flag); } + + if (bs->device_name[0] != '\0') { + bdrv_emit_qmp_eject_event(bs, eject_flag); + } } /** |