@@ -26,6 +26,36 @@ Example:
Note: If action is "stop", a STOP event will eventually follow the
BLOCK_IO_ERROR event.
+BLOCK_TRAY_CLOSE
+----------------
+
+Emitted when a removable disk media tray is closed.
+
+Data:
+
+- "device": device name (json-string)
+
+Example:
+
+{ "event": "BLOCK_TRAY_CLOSE",
+ "data": { "device": "ide1-cd0" },
+ "timestamp": { "seconds": 1265044280, "microseconds": 450456 } }
+
+BLOCK_TRAY_OPEN
+---------------
+
+Emitted when a removable disk media tray is opened.
+
+Data:
+
+- "device": device name (json-string)
+
+Example:
+
+{ "event": "BLOCK_TRAY_OPEN",
+ "data": { "device": "ide1-cd0" },
+ "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
+
RESET
-----
@@ -1656,6 +1656,17 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum);
}
+static void bdrv_eject_mon_event(const BlockDriverState *bdrv, int tray_open)
+{
+ QObject *data;
+ int event;
+
+ data = qobject_from_jsonf("{ 'device': %s }", bdrv->device_name);
+ event = tray_open ? QEVENT_BLOCK_TRAY_OPEN : QEVENT_BLOCK_TRAY_CLOSE;
+ monitor_protocol_event(event, data);
+ qobject_decref(data);
+}
+
void bdrv_error_mon_event(const BlockDriverState *bdrv,
BlockMonEventAction action, int is_read)
{
@@ -2776,6 +2787,17 @@ int bdrv_eject(BlockDriverState *bs, int eject_flag, int force)
ret = 0;
}
if (ret >= 0) {
+ if (bs->tray_open != eject_flag) {
+ if (bs->device_name[0] != '\0') {
+ /*
+ * FIXME: raw_eject() calls bdrv_eject(), which makes the
+ * event be emitted twice. The check above will prevent that
+ * from happening, * but we need a better way to deal with
+ * this...
+ */
+ bdrv_eject_mon_event(bs, eject_flag);
+ }
+ }
bs->tray_open = eject_flag;
}
@@ -453,6 +453,12 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)
case QEVENT_BLOCK_IO_ERROR:
event_name = "BLOCK_IO_ERROR";
break;
+ case QEVENT_BLOCK_TRAY_OPEN:
+ event_name = "BLOCK_TRAY_OPEN";
+ break;
+ case QEVENT_BLOCK_TRAY_CLOSE:
+ event_name = "BLOCK_TRAY_CLOSE";
+ break;
case QEVENT_RTC_CHANGE:
event_name = "RTC_CHANGE";
break;
@@ -30,6 +30,8 @@ typedef enum MonitorEvent {
QEVENT_VNC_INITIALIZED,
QEVENT_VNC_DISCONNECTED,
QEVENT_BLOCK_IO_ERROR,
+ QEVENT_BLOCK_TRAY_OPEN,
+ QEVENT_BLOCK_TRAY_CLOSE,
QEVENT_RTC_CHANGE,
QEVENT_WATCHDOG,
QEVENT_SPICE_CONNECTED,
They are emitted when the tray is opened or closed, either by the guest or by monitor commands. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> --- QMP/qmp-events.txt | 30 ++++++++++++++++++++++++++++++ block.c | 22 ++++++++++++++++++++++ monitor.c | 6 ++++++ monitor.h | 2 ++ 4 files changed, 60 insertions(+), 0 deletions(-)