[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 08/10] QMP: Introduce the BLOCK_TRAY_OPEN and BLOCK_TR
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [RFC 08/10] QMP: Introduce the BLOCK_TRAY_OPEN and BLOCK_TRAY_CLOSE events |
Date: |
Fri, 3 Jun 2011 16:04:00 -0300 |
They are emitted when the tray is opened or closed, either by the
guest or by monitor commands.
Signed-off-by: Luiz Capitulino <address@hidden>
---
QMP/qmp-events.txt | 30 ++++++++++++++++++++++++++++++
block.c | 22 ++++++++++++++++++++++
monitor.c | 6 ++++++
monitor.h | 2 ++
4 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
index 0ce5d4e..51a93d0 100644
--- a/QMP/qmp-events.txt
+++ b/QMP/qmp-events.txt
@@ -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
-----
diff --git a/block.c b/block.c
index 3df5a4f..9224f22 100644
--- a/block.c
+++ b/block.c
@@ -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;
}
diff --git a/monitor.c b/monitor.c
index f63cce0..22353b5 100644
--- a/monitor.c
+++ b/monitor.c
@@ -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;
diff --git a/monitor.h b/monitor.h
index 4f2d328..fca1e18 100644
--- a/monitor.h
+++ b/monitor.h
@@ -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,
--
1.7.4.4
[Qemu-devel] [RFC 08/10] QMP: Introduce the BLOCK_TRAY_OPEN and BLOCK_TRAY_CLOSE events,
Luiz Capitulino <=
[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
Re: [Qemu-devel] [RFC 00/10]: QMP/HMP: Introduce tray handling commands, Markus Armbruster, 2011/06/06