: QMP: Introduce BLOCK_MEDIA_EJECT event
cover : QMP: Introduce BLOCK_MEDIA_EJECT event
Not very well tested, but I'm sending for early review.
Please, check individual patches for details. The event spec can be found in patch 0/2.
QMP/qmp-events.txt | 15 +++++++++++++++ block.c | 16 ++++++++++++++-- block.h | 5 +++-- blockdev.c | 5 +++++ hw/ide/core.c | 6 +++--- hw/scsi-disk.c | 6 +++--- hw/virtio-blk.c | 6 +++--- monitor.c | 3 +++ monitor.h | 1 + 9 files changed, 50 insertions(+), 13 deletions(-)
PATCH 1/3 block: Rename bdrv_mon_event()
It's too generic and next commits will add a new event, rename it to bdrv_error_mon_event() then.
--- block.c | 4 ++-- block.h | 4 ++-- hw/ide/core.c | 6 +++--- hw/scsi-disk.c | 6 +++--- hw/virtio-blk.c | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-)
block.c +2 -2
@@ -1553,8 +1553,8 @@ 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); } -void bdrv_mon_event (const BlockDriverState *bdrv, -BlockMonEventAction action,int is_read) +void bdrv_error_mon_event (const BlockDriverState *bdrv, +BlockMonEventAction action,int is_read) {QObject *data;const char *action_str;
block.h +2 -2
@@ -50,8 +50,8 @@ typedef enum { BDRV_ACTION_REPORT, BDRV_ACTION_IGNORE, BDRV_ACTION_STOP } BlockMonEventAction; -void bdrv_mon_event (const BlockDriverState *bdrv, -BlockMonEventAction action,int is_read); +void bdrv_error_mon_event (const BlockDriverState *bdrv, +BlockMonEventAction action,int is_read);void bdrv_info_print (Monitor *mon,const QObject *data);void bdrv_info (Monitor *mon,QObject **ret_data);void bdrv_stats_print (Monitor *mon,const QObject *data);
hw/ide/core.c +3 -3
@@ -464,7 +464,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int op)BlockErrorAction action =bdrv_get_on_error (s->bs, is_read);if (action ==BLOCK_ERR_IGNORE ) { -bdrv_mon_event (s->bs,BDRV_ACTION_IGNORE , is_read); +bdrv_error_mon_event (s->bs,BDRV_ACTION_IGNORE , is_read);return 0 ; }
@@ -472,7 +472,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int op) || action == BLOCK_ERR_STOP_ANY) { s->bus->dma->ops->set_unit(s->bus->dma, s->unit); s->bus->dma->ops->add_status(s->bus->dma, op); - bdrv_mon_event(s->bs, BDRV_ACTION_STOP, is_read); + bdrv_error_mon_event(s->bs, BDRV_ACTION_STOP, is_read); vm_stop(0); } else {if (op &BM_STATUS_DMA_RETRY ) {
@@ -481,7 +481,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int op) }else {ide_rw_error (s); } -bdrv_mon_event (s->bs,BDRV_ACTION_REPORT , is_read); +bdrv_error_mon_event (s->bs,BDRV_ACTION_REPORT , is_read); }return 1 ;
hw/scsi-disk.c +3 -3
@@ -227,7 +227,7 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type)BlockErrorAction action =bdrv_get_on_error (s->bs, is_read);if (action ==BLOCK_ERR_IGNORE ) { -bdrv_mon_event (s->bs,BDRV_ACTION_IGNORE , is_read); +bdrv_error_mon_event (s->bs,BDRV_ACTION_IGNORE , is_read);return 0 ; }
@@ -237,7 +237,7 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type) type &=SCSI_REQ_STATUS_RETRY_TYPE_MASK ; r->status |=SCSI_REQ_STATUS_RETRY | type; -bdrv_mon_event (s->bs,BDRV_ACTION_STOP , is_read); +bdrv_error_mon_event (s->bs,BDRV_ACTION_STOP , is_read);vm_stop (0 ); }else {if (type ==SCSI_REQ_STATUS_RETRY_READ ) {
@@ -245,7 +245,7 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type) }scsi_command_complete (r,CHECK_CONDITION ,HARDWARE_ERROR ); -bdrv_mon_event (s->bs,BDRV_ACTION_REPORT , is_read); +bdrv_error_mon_event (s->bs,BDRV_ACTION_REPORT , is_read); }return 1 ;
hw/virtio-blk.c +3 -3
@@ -69,7 +69,7 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,VirtIOBlock *s = req->dev;if (action ==BLOCK_ERR_IGNORE ) { -bdrv_mon_event (s->bs,BDRV_ACTION_IGNORE , is_read); +bdrv_error_mon_event (s->bs,BDRV_ACTION_IGNORE , is_read);return 0 ; }
@@ -77,11 +77,11 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, || action == BLOCK_ERR_STOP_ANY) { req->next = s->rq; s->rq = req; - bdrv_mon_event(s->bs, BDRV_ACTION_STOP, is_read); + bdrv_error_mon_event(s->bs, BDRV_ACTION_STOP, is_read); vm_stop(0); } else {virtio_blk_req_complete (req,VIRTIO_BLK_S_IOERR ); -bdrv_mon_event (s->bs,BDRV_ACTION_REPORT , is_read); +bdrv_error_mon_event (s->bs,BDRV_ACTION_REPORT , is_read); }return 1 ;
Signature · 1 line
1.7.4.rc1.14.g7fad99
PATCH 2/3 QMP: Documentation for the BLOCK_MEDIA_EJECT event
In reply to Luiz Capitulino--- QMP/qmp-events.txt | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
QMP/qmp-events.txt +15 -0
@@ -1,6 +1,21 @@ QEMU Monitor Protocol Events ============================ +BLOCK_MEDIA_EJECT +----------------- + +Emitted when a disk media (such as a CDROM or floppy) is ejected. + +Data: + +- "device": device name (json-string) + +Example: + +{ "event": "BLOCK_MEDIA_EJECT", + "data": { "device": "ide1-cd0" }, + "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } + BLOCK_IO_ERROR --------------
Signature · 1 line
1.7.4.rc1.14.g7fad99
PATCH 3/3 QMP: Introduce the BLOCK_MEDIA_EJECT event
In reply to Luiz CapitulinoConforms to the event specification defined in the QMP/qmp-events.txt file.
Please, note the following (very important) details:
o The event should be emitted only by devices which support the eject operation, which (afaik) are: CDROMs (IDE and SCSI) and floppies
o Human monitor commands "eject" and "change" also cause the event to be emitted
o The event is only emitted when there's a tray transition from closed to opened. To implement this in the human monitor, we only emit the event if the device is removable and a media is present
--- block.c | 12 ++++++++++++ block.h | 1 + blockdev.c | 5 +++++ monitor.c | 3 +++ monitor.h | 1 + 5 files changed, 22 insertions(+), 0 deletions(-)
block.c +12 -0
@@ -1553,6 +1553,15 @@ 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); } +void bdrv_eject_mon_event (const BlockDriverState *bdrv) +{ +QObject *data; + + data =qobject_from_jsonf ("{ 'device': %s }" , bdrv->device_name); +monitor_protocol_event (QEVENT_BLOCK_MEDIA_EJECT , data); +qobject_decref (data); +} +void bdrv_error_mon_event (const BlockDriverState *bdrv,BlockMonEventAction action,int is_read) {
@@ -2671,6 +2680,9 @@ int bdrv_eject(BlockDriverState *bs, int eject_flag) ret =0 ; }if (ret >=0 ) { +if (eject_flag && !bs->tray_open) { +bdrv_eject_mon_event (bs); + } bs->tray_open = eject_flag; }
block.h +1 -0
@@ -50,6 +50,7 @@ typedef enum { BDRV_ACTION_REPORT, BDRV_ACTION_IGNORE, BDRV_ACTION_STOP } BlockMonEventAction; +void bdrv_eject_mon_event (const BlockDriverState *bdrv);void bdrv_error_mon_event (const BlockDriverState *bdrv,BlockMonEventAction action,int is_read);void bdrv_info_print (Monitor *mon,const QObject *data);
blockdev.c +5 -0
@@ -591,6 +591,11 @@ static int eject_device(Monitor *mon, BlockDriverState *bs, int force)return -1 ; } } + +if (bdrv_is_removable (bs) &&bdrv_is_inserted (bs)) { +bdrv_eject_mon_event (bs); + } +bdrv_close (bs);return 0 ; }
monitor.c +3 -0
@@ -450,6 +450,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)case QEVENT_VNC_DISCONNECTED : event_name ="VNC_DISCONNECTED" ;break ; +case QEVENT_BLOCK_MEDIA_EJECT : + event_name ="BLOCK_MEDIA_EJECT" ; +break ;case QEVENT_BLOCK_IO_ERROR : event_name ="BLOCK_IO_ERROR" ;break ;
monitor.h +1 -0
@@ -29,6 +29,7 @@ typedef enum MonitorEvent {QEVENT_VNC_CONNECTED ,QEVENT_VNC_INITIALIZED ,QEVENT_VNC_DISCONNECTED , +QEVENT_BLOCK_MEDIA_EJECT ,QEVENT_BLOCK_IO_ERROR ,QEVENT_RTC_CHANGE , QEVENT_WATCHDOG,
Signature · 1 line
1.7.4.rc1.14.g7fad99