Patchwork [3/5] virtio-blk: Support I/O status

login
register
mail settings
Submitter Luiz Capitulino
Date Aug. 3, 2011, 3:19 p.m.
Message ID <1312384765-721-4-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/108300/
State New
Headers show

Comments

Luiz Capitulino - Aug. 3, 2011, 3:19 p.m.
TODO: migration

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hw/virtio-blk.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 265c795..a008956 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -29,6 +29,7 @@  typedef struct VirtIOBlock
     QEMUBH *bh;
     BlockConf *conf;
     char *serial;
+    BlockDevIOStatus iostatus;
     unsigned short sector_mask;
     DeviceState *qdev;
 } VirtIOBlock;
@@ -90,9 +91,11 @@  static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
 static void virtio_blk_rw_complete(void *opaque, int ret)
 {
     VirtIOBlockReq *req = opaque;
+    VirtIOBlock *s = req->dev;
 
     trace_virtio_blk_rw_complete(req, ret);
 
+    s->iostatus = bdrv_iostatus_from_error(ret);
     if (ret) {
         int is_read = !(ldl_p(&req->out->type) & VIRTIO_BLK_T_OUT);
         if (virtio_blk_handle_rw_error(req, -ret, is_read))
@@ -105,7 +108,9 @@  static void virtio_blk_rw_complete(void *opaque, int ret)
 static void virtio_blk_flush_complete(void *opaque, int ret)
 {
     VirtIOBlockReq *req = opaque;
+    VirtIOBlock *s = req->dev;
 
+    s->iostatus = bdrv_iostatus_from_error(ret);
     if (ret) {
         if (virtio_blk_handle_rw_error(req, -ret, 0)) {
             return;
@@ -535,8 +540,16 @@  static void virtio_blk_resize(void *opaque)
     virtio_notify_config(&s->vdev);
 }
 
+static BlockDevIOStatus virtio_blk_iostatus(void *opaque)
+{
+    VirtIOBlock *s = opaque;
+
+    return s->iostatus;
+}
+
 static const BlockDevOps virtio_block_ops = {
     .resize_cb = virtio_blk_resize,
+    .get_iostatus = virtio_blk_iostatus,
 };
 
 VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
@@ -575,6 +588,7 @@  VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
     s->conf = conf;
     s->serial = *serial;
     s->rq = NULL;
+    s->iostatus = BDRV_IOS_INVAL;
     s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
     bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);