Skip to contentSkip to conversation

: BLOCK_IO_ERROR QMP event

PATCH Applied Luiz Capitulino 2 participants 7 messages Feb 3, 2010 – Feb 10, 2010

lore
Share & tools
lore
#0 lore raw

cover : BLOCK_IO_ERROR QMP event

Hi,

This series adds the BLOCK_IO_ERROR event libvirt guys have requested.

changelog
---------

v0 -> v1

- Improve event documentation

#1 lore raw

PATCH 1/5 QMP: BLOCK_IO_ERROR event handling

This commit adds the basic definitions for the BLOCK_IO_ERROR event, but actual event emission will be introduced by the next commits.

---
 QMP/qmp-events.txt |   21 +++++++++++++++++++++
 monitor.c          |    3 +++
 monitor.h          |    1 +
 3 files changed, 25 insertions(+), 0 deletions(-)
QMP/qmp-events.txt +21 -0
index dc48ccc..d585a8d 100644
@@ -43,3 +43,24 @@ Data: 'server' and 'client' keys with the same keys as 'query-vnc'.
 
 Description: Issued when the VNC session is made active.
 Data: 'server' and 'client' keys with the same keys as 'query-vnc'.
+
+7 BLOCK_IO_ERROR
+----------------
+
+Description: Issued when a disk I/O error occurs
+Data:
+
+- 'device': device name (json-string)
+- 'operation': I/O operation (json-string, "read" or "write")
+- 'action': action that has been taken, it's one of the following:
+    "ignore": error has been ignored
+    "report": error has been reported to the device
+    "stop": error caused VM to be stopped
+
+Example:
+
+{ "event": "BLOCK_IO_ERROR",
+    "data": { "device": "ide0-hd1",
+              "operation": "write",
+              "action": "stop" },
+    "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
monitor.c +3 -0
index fb7c572..6e688ac 100644
@@ -378,6 +378,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)
         case QEVENT_VNC_DISCONNECTED:
             event_name = "VNC_DISCONNECTED";
             break;
+        case QEVENT_BLOCK_IO_ERROR:
+            event_name = "BLOCK_IO_ERROR";
+            break;
         default:
             abort();
             break;
monitor.h +1 -0
index b0f9270..e35f1e4 100644
@@ -23,6 +23,7 @@ typedef enum MonitorEvent {
     QEVENT_VNC_CONNECTED,
     QEVENT_VNC_INITIALIZED,
     QEVENT_VNC_DISCONNECTED,
+    QEVENT_BLOCK_IO_ERROR,
     QEVENT_MAX,
 } MonitorEvent;
 
Signature · 1 line
1.6.6
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] QMP: BLOCK_IO_ERROR event handling

Quoted 6 lines · Luiz Capitulino

This commit adds the basic definitions for the BLOCK_IO_ERROR event, but actual event emission will be introduced by the next commits.

Applied all. Thanks.

Regards,

Anthony Liguori

Quoted 62 lines
---
  QMP/qmp-events.txt |   21 +++++++++++++++++++++
  monitor.c          |    3 +++
  monitor.h          |    1 +
  3 files changed, 25 insertions(+), 0 deletions(-)
QMP/qmp-events.txt +21 -0
index dc48ccc..d585a8d 100644
@@ -43,3 +43,24 @@ Data: 'server' and 'client' keys with the same keys as 'query-vnc'.
 
  Description: Issued when the VNC session is made active.
  Data: 'server' and 'client' keys with the same keys as 'query-vnc'.
+
+7 BLOCK_IO_ERROR
+----------------
+
+Description: Issued when a disk I/O error occurs
+Data:
+
+- 'device': device name (json-string)
+- 'operation': I/O operation (json-string, "read" or "write")
+- 'action': action that has been taken, it's one of the following:
+    "ignore": error has been ignored
+    "report": error has been reported to the device
+    "stop": error caused VM to be stopped
+
+Example:
+
+{ "event": "BLOCK_IO_ERROR",
+    "data": { "device": "ide0-hd1",
+              "operation": "write",
+              "action": "stop" },
+    "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
monitor.c +3 -0
index fb7c572..6e688ac 100644
@@ -378,6 +378,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)
          case QEVENT_VNC_DISCONNECTED:
              event_name = "VNC_DISCONNECTED";
              break;
+        case QEVENT_BLOCK_IO_ERROR:
+            event_name = "BLOCK_IO_ERROR";
+            break;
          default:
              abort();
              break;
monitor.h +1 -0
index b0f9270..e35f1e4 100644
@@ -23,6 +23,7 @@ typedef enum MonitorEvent {
      QEVENT_VNC_CONNECTED,
      QEVENT_VNC_INITIALIZED,
      QEVENT_VNC_DISCONNECTED,
+    QEVENT_BLOCK_IO_ERROR,
      QEVENT_MAX,
  } MonitorEvent;
 
#3 lore raw

PATCH 2/5 block: BLOCK_IO_ERROR QMP event

In reply to Luiz Capitulino

This commit introduces the bdrv_mon_event() function, which should be called by block subsystems (eg. IDE) when a I/O error occurs, so that an QMP event is emitted.

The following information is currently provided in the event:

- device name
- operation (ie. "read" or "write")
- action taken (eg. "stop")

Event example:

{ "event": "BLOCK_IO_ERROR",

    "data": { "device": "ide0-hd1",
              "operation": "write",
              "action": "stop" },
    "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
---
 block.c |   29 +++++++++++++++++++++++++++++
 block.h |    6 ++++++
 2 files changed, 35 insertions(+), 0 deletions(-)
block.c +29 -0
index 1919d19..2913124 100644
@@ -1164,6 +1164,35 @@ 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)
+{
+    QObject *data;
+    const char *action_str;
+
+    switch (action) {
+    case BDRV_ACTION_REPORT:
+        action_str = "report";
+        break;
+    case BDRV_ACTION_IGNORE:
+        action_str = "ignore";
+        break;
+    case BDRV_ACTION_STOP:
+        action_str = "stop";
+        break;
+    default:
+        abort();
+    }
+
+    data = qobject_from_jsonf("{ 'device': %s, 'action': %s, 'operation': %s }",
+                              bdrv->device_name,
+                              action_str,
+                              is_read ? "read" : "write");
+    monitor_protocol_event(QEVENT_BLOCK_IO_ERROR, data);
+
+    qobject_decref(data);
+}
+
 static void bdrv_print_dict(QObject *obj, void *opaque)
 {
     QDict *bs_dict;
block.h +6 -0
index ecf66c5..a834300 100644
@@ -44,6 +44,12 @@ typedef struct QEMUSnapshotInfo {
 #define BDRV_SECTOR_SIZE   (1 << BDRV_SECTOR_BITS)
 #define BDRV_SECTOR_MASK   ~(BDRV_SECTOR_SIZE - 1);
 
+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_info_print(Monitor *mon, const QObject *data);
 void bdrv_info(Monitor *mon, QObject **ret_data);
 void bdrv_stats_print(Monitor *mon, const QObject *data);
Signature · 1 line
1.6.6
#4 lore raw

PATCH 3/5 ide: Generate BLOCK_IO_ERROR QMP event

In reply to Luiz Capitulino

Just call bdrv_mon_event() in the right place.

---
 hw/ide/core.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
hw/ide/core.c +5 -1
index b6643e8..603e537 100644
@@ -480,14 +480,17 @@ static int ide_handle_rw_error(IDEState *s, int error, int op)
     int is_read = (op & BM_STATUS_RETRY_READ);
     BlockInterfaceErrorAction action = drive_get_on_error(s->bs, is_read);
 
-    if (action == BLOCK_ERR_IGNORE)
+    if (action == BLOCK_ERR_IGNORE) {
+        bdrv_mon_event(s->bs, BDRV_ACTION_IGNORE, is_read);
         return 0;
+    }
 
     if ((error == ENOSPC && action == BLOCK_ERR_STOP_ENOSPC)
             || action == BLOCK_ERR_STOP_ANY) {
         s->bus->bmdma->unit = s->unit;
         s->bus->bmdma->status |= op;
         vm_stop(0);
+        bdrv_mon_event(s->bs, BDRV_ACTION_STOP, is_read);
     } else {
         if (op & BM_STATUS_DMA_RETRY) {
             dma_buf_commit(s, 0);
@@ -495,6 +498,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);
     }
 
     return 1;
Signature · 1 line
1.6.6
#5 lore raw

PATCH 4/5 scsi: Generate BLOCK_IO_ERROR QMP event

In reply to Luiz Capitulino

Just call bdrv_mon_event() in the right place.

---
 hw/scsi-disk.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
hw/scsi-disk.c +5 -1
index b34fbaa..1285122 100644
@@ -182,16 +182,20 @@ static int scsi_handle_write_error(SCSIDiskReq *r, int error)
     BlockInterfaceErrorAction action =
         drive_get_on_error(s->qdev.dinfo->bdrv, 0);
 
-    if (action == BLOCK_ERR_IGNORE)
+    if (action == BLOCK_ERR_IGNORE) {
+        bdrv_mon_event(s->qdev.dinfo->bdrv, BDRV_ACTION_IGNORE, 0);
         return 0;
+    }
 
     if ((error == ENOSPC && action == BLOCK_ERR_STOP_ENOSPC)
             || action == BLOCK_ERR_STOP_ANY) {
         r->status |= SCSI_REQ_STATUS_RETRY;
         vm_stop(0);
+        bdrv_mon_event(s->qdev.dinfo->bdrv, BDRV_ACTION_STOP, 0);
     } else {
         scsi_command_complete(r, CHECK_CONDITION,
                 HARDWARE_ERROR);
+        bdrv_mon_event(s->qdev.dinfo->bdrv, BDRV_ACTION_REPORT, 0);
     }
 
     return 1;
Signature · 1 line
1.6.6
#6 lore raw

PATCH 5/5 virtio-blk: Generate BLOCK_IO_ERROR QMP event

In reply to Luiz Capitulino

Just call bdrv_mon_event() in the right place.

---
 hw/virtio-blk.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
hw/virtio-blk.c +5 -1
index 037a79c..75adbec 100644
@@ -105,16 +105,20 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
         drive_get_on_error(req->dev->bs, is_read);
     VirtIOBlock *s = req->dev;
 
-    if (action == BLOCK_ERR_IGNORE)
+    if (action == BLOCK_ERR_IGNORE) {
+        bdrv_mon_event(req->dev->bs, BDRV_ACTION_IGNORE, is_read);
         return 0;
+    }
 
     if ((error == ENOSPC && action == BLOCK_ERR_STOP_ENOSPC)
             || action == BLOCK_ERR_STOP_ANY) {
         req->next = s->rq;
         s->rq = req;
         vm_stop(0);
+        bdrv_mon_event(req->dev->bs, BDRV_ACTION_STOP, is_read);
     } else {
         virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
+        bdrv_mon_event(req->dev->bs, BDRV_ACTION_REPORT, is_read);
     }
 
     return 1;
Signature · 1 line
1.6.6