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>
This commit is contained in:
Luiz Capitulino 2012-02-14 13:41:13 -02:00
parent bde25388d1
commit 6f382ed226
4 changed files with 46 additions and 0 deletions

View File

@ -26,6 +26,24 @@ Example:
Note: If action is "stop", a STOP event will eventually follow the Note: If action is "stop", a STOP event will eventually follow the
BLOCK_IO_ERROR event. BLOCK_IO_ERROR event.
DEVICE_TRAY_MOVED
-----------------
It's emitted whenever the tray of a removable device is moved by the guest
or by HMP/QMP commands.
Data:
- "device": device name (json-string)
- "tray-open": true if the tray has been opened or false if it has been closed
(json-bool)
{ "event": "DEVICE_TRAY_MOVED",
"data": { "device": "ide1-cd0",
"tray-open": true
},
"timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
RESET RESET
----- -----

24
block.c
View File

@ -972,10 +972,30 @@ void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
qobject_decref(data); 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) static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
{ {
if (bs->dev_ops && bs->dev_ops->change_media_cb) { 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); 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) { if (drv && drv->bdrv_eject) {
drv->bdrv_eject(bs, eject_flag); drv->bdrv_eject(bs, eject_flag);
} }
if (bs->device_name[0] != '\0') {
bdrv_emit_qmp_eject_event(bs, eject_flag);
}
} }
/** /**

View File

@ -485,6 +485,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)
case QEVENT_BLOCK_JOB_CANCELLED: case QEVENT_BLOCK_JOB_CANCELLED:
event_name = "BLOCK_JOB_CANCELLED"; event_name = "BLOCK_JOB_CANCELLED";
break; break;
case QEVENT_DEVICE_TRAY_MOVED:
event_name = "DEVICE_TRAY_MOVED";
break;
default: default:
abort(); abort();
break; break;

View File

@ -38,6 +38,7 @@ typedef enum MonitorEvent {
QEVENT_SPICE_DISCONNECTED, QEVENT_SPICE_DISCONNECTED,
QEVENT_BLOCK_JOB_COMPLETED, QEVENT_BLOCK_JOB_COMPLETED,
QEVENT_BLOCK_JOB_CANCELLED, QEVENT_BLOCK_JOB_CANCELLED,
QEVENT_DEVICE_TRAY_MOVED,
QEVENT_MAX, QEVENT_MAX,
} MonitorEvent; } MonitorEvent;