Skip to contentSkip to conversation

: BLOCK_IO_ERROR QMP event

PATCH In review Luiz Capitulino 3 participants 12 messages Feb 2, 2010 – Feb 3, 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,
I have made some improvements after Kevin's feedback and hope it's in better shape now.

The only small issue is that I couldn't get a read error. I've followed Kevin's
advices wrt NFS, but got only write errors...

I've tested with ide and virtio.

Thanks.

#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.

NOTE: Adding a small reference in QMP/qmp-events.txt, but this file is wrong and will be replaced by proper documentation shortly.

---
 QMP/qmp-events.txt |    7 +++++++
 monitor.c          |    3 +++
 monitor.h          |    1 +
 3 files changed, 11 insertions(+), 0 deletions(-)
QMP/qmp-events.txt +7 -0
index dc48ccc..7886192 100644
@@ -43,3 +43,10 @@ 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), 'action' (action to be taken),
+      'operation' ("read" or "write")
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

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

Am 02.02.2010 22:10, schrieb Luiz Capitulino:

Quoted 19 lines

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

NOTE: Adding a small reference in QMP/qmp-events.txt, but this file is wrong and will be replaced by proper documentation shortly.

---
 QMP/qmp-events.txt |    7 +++++++
 monitor.c          |    3 +++
 monitor.h          |    1 +
 3 files changed, 11 insertions(+), 0 deletions(-)
QMP/qmp-events.txt +0 -0
index dc48ccc..7886192 100644

QMP/qmp-events.txt Data: 'server' and 'client' keys with the same keys as 'query-vnc'. · line 52

Quoted 10 lines
QMP/qmp-events.txt +7 -0
@@ -43,3 +43,10 @@ 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), 'action' (action to be taken),
+      'operation' ("read" or "write")

I think we should document what allowed values for action are and what their meaning is. And isn't it actually "action that has been taken"?

Kevin

#3 lore raw

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

Quoted 21 lines · On Wed, 03 Feb 2010 10:18:37 +0100 Kevin Wolf <[email protected]> wrote:

Am 02.02.2010 22:10, schrieb Luiz Capitulino:

Quoted 20 lines

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

NOTE: Adding a small reference in QMP/qmp-events.txt, but this file is wrong and will be replaced by proper documentation shortly.

---
 QMP/qmp-events.txt |    7 +++++++
 monitor.c          |    3 +++
 monitor.h          |    1 +
 3 files changed, 11 insertions(+), 0 deletions(-)
QMP/qmp-events.txt +0 -0
index dc48ccc..7886192 100644
@@ -43,3 +43,10 @@ Data: 'server' and 'client' keys with the same keys as 'query-vnc'.
 
Quoted 12 lines

QMP/qmp-events.txt Data: 'server' and 'client' keys with the same keys as 'query-vnc'. · line 52

Quoted 9 lines
QMP/qmp-events.txt +7 -0
 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), 'action' (action to be taken),
+      'operation' ("read" or "write")

I think we should document what allowed values for action are and what their meaning is. And isn't it actually "action that has been taken"?

Right, sometimes I don't know how to document this stuff
because this file is going to be replaced soon...

#4 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
#5 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
#6 lore raw

Re: [Qemu-devel] [PATCH 3/5] ide: Generate BLOCK_IO_ERROR QMP event

Quoted 17 lines · 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 +1 -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) {

hw/ide/core.c static int ide_handle_rw_error(IDEState *s, int error, int op) · line 493

Quoted 10 lines
hw/ide/core.c +3 -0
+        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);

Why isn't the event directly sent from drive_get_on_error? Having to opencode this in every driver is a sure way to make sure it's going to be broken somewhere.

#7 lore raw

Re: [Qemu-devel] [PATCH 3/5] ide: Generate BLOCK_IO_ERROR QMP event

Am 03.02.2010 09:31, schrieb Christoph Hellwig:

Quoted 22 lines · Luiz Capitulino
Quoted 21 lines

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 +3 -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;
+    }
 
Quoted 10 lines

hw/ide/core.c static int ide_handle_rw_error(IDEState *s, int error, int op) · line 493

Quoted 6 lines
hw/ide/core.c +1 -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);

Why isn't the event directly sent from drive_get_on_error? Having to opencode this in every driver is a sure way to make sure it's going to be broken somewhere.

Because drive_get_on_error isn't an event handler and shouldn't have any side effects. It might be called anywhere. And it doesn't know the error code, so it can't even decide if the VM has stopped or not.

Maybe we could look at writing a generic handle_rw_error function for all block devices. They look pretty much the same in every driver, even without the monitor event.

Kevin

#8 lore raw

Re: [Qemu-devel] [PATCH 3/5] ide: Generate BLOCK_IO_ERROR QMP event

Quoted 34 lines · On Wed, 03 Feb 2010 10:10:59 +0100 Kevin Wolf <[email protected]> wrote:

Am 03.02.2010 09:31, schrieb Christoph Hellwig:

Quoted 22 lines · Luiz Capitulino
Quoted 21 lines

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 +3 -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;
+    }
 
Quoted 10 lines

hw/ide/core.c static int ide_handle_rw_error(IDEState *s, int error, int op) · line 493

Quoted 6 lines
hw/ide/core.c +1 -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);

Why isn't the event directly sent from drive_get_on_error? Having to opencode this in every driver is a sure way to make sure it's going to be broken somewhere.

Quoted 7 lines

Because drive_get_on_error isn't an event handler and shouldn't have any side effects. It might be called anywhere. And it doesn't know the error code, so it can't even decide if the VM has stopped or not.

Maybe we could look at writing a generic handle_rw_error function for all block devices. They look pretty much the same in every driver, even without the monitor event.

Any design in mind? I could try this later (preferably after the
event series is merged).

What if block devices register the following callbacks somewhere:

- handle_rw_error_ignore()
- handle_rw_error_stop()
- handle_rw_error_report()

But then they'd have to trigger their call by calling, say,
block_handle_rw_error() from the error site.

#9 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
#10 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
#11 lore raw
In reply to Luiz Capitulino

Am 02.02.2010 22:10, schrieb Luiz Capitulino:

Quoted 8 lines

Hi,

This series adds the BLOCK_IO_ERROR event libvirt guys have requested,
I have made some improvements after Kevin's feedback and hope it's in better shape now.

The only small issue is that I couldn't get a read error. I've followed Kevin's
advices wrt NFS, but got only write errors...

I should have explained in more detail what I'm doing to produce a read error... I boot the system from a local image that won't go away when NFS is down. I add another image (can be empty) stored on NFS and with cache=off. Then I turn NFS off and start something like a dd if=/dev/vdb of=/dev/null iflag=direct. This way you produce only reads.

Kevin