Skip to contentSkip to conversation

xen_disk: fix io accounting

PATCH In review Olaf Hering 3 participants 4 messages Feb 7, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen_disk: fix io accounting

bdrv_acct_done was called unconditional. But in case the ioreq has no segments there is no matching bdrv_acct_start call. This could lead to bogus accounting values.

Found by code inspection.

---
v2:
add comment /* fall through */

 hw/block/xen_disk.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
hw/block/xen_disk.c +13 -1
index 098f6c6..fb4ca4a 100644
@@ -483,7 +483,19 @@ static void qemu_aio_complete(void *opaque, int ret)
     ioreq->status = ioreq->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY;
     ioreq_unmap(ioreq);
     ioreq_finish(ioreq);
-    bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
+    switch (ioreq->req.operation) {
+    case BLKIF_OP_WRITE:
+    case BLKIF_OP_FLUSH_DISKCACHE:
+        if (!ioreq->req.nr_segments) {
+            break;
+        }
+	/* fall through */
+    case BLKIF_OP_READ:
+        bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
+        break;
+    default:
+        break;
+    }
     qemu_bh_schedule(ioreq->blkdev->bh);
 }
 
#1 lore raw
Quoted 7 lines · Olaf Hering

bdrv_acct_done was called unconditional. But in case the ioreq has no segments there is no matching bdrv_acct_start call. This could lead to bogus accounting values.

Found by code inspection.

added to my queue, I'll fix the tab manually

Quoted 32 lines

v2:
add comment /* fall through */

 hw/block/xen_disk.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
hw/block/xen_disk.c +13 -1
index 098f6c6..fb4ca4a 100644
@@ -483,7 +483,19 @@ static void qemu_aio_complete(void *opaque, int ret)
     ioreq->status = ioreq->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY;
     ioreq_unmap(ioreq);
     ioreq_finish(ioreq);
-    bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
+    switch (ioreq->req.operation) {
+    case BLKIF_OP_WRITE:
+    case BLKIF_OP_FLUSH_DISKCACHE:
+        if (!ioreq->req.nr_segments) {
+            break;
+        }
+	/* fall through */
+    case BLKIF_OP_READ:
+        bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
+        break;
+    default:
+        break;
+    }
     qemu_bh_schedule(ioreq->blkdev->bh);
 }
 
#2 lore raw
Quoted 1 line · Stefano Stabellini

added to my queue, I'll fix the tab manually

Thanks, sorry for the TAB.

Olaf

Acked-by on v2 1/1
#3 lore raw
In reply to Olaf Hering

Am 07.02.2014 um 15:47 hat Olaf Hering geschrieben:

Quoted 28 lines

bdrv_acct_done was called unconditional. But in case the ioreq has no segments there is no matching bdrv_acct_start call. This could lead to bogus accounting values.

Found by code inspection.

---
v2:
add comment /* fall through */

 hw/block/xen_disk.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
hw/block/xen_disk.c +5 -1
index 098f6c6..fb4ca4a 100644
@@ -483,7 +483,19 @@ static void qemu_aio_complete(void *opaque, int ret)
     ioreq->status = ioreq->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY;
     ioreq_unmap(ioreq);
     ioreq_finish(ioreq);
-    bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
+    switch (ioreq->req.operation) {
+    case BLKIF_OP_WRITE:
+    case BLKIF_OP_FLUSH_DISKCACHE:
+        if (!ioreq->req.nr_segments) {
+            break;

hw/block/xen_disk.c static void qemu_aio_complete(void *opaque, int ret) · line 500

Quoted 10 lines
hw/block/xen_disk.c +8 -0
+        }
+	/* fall through */
+    case BLKIF_OP_READ:
+        bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
+        break;
+    default:
+        break;
+    }
     qemu_bh_schedule(ioreq->blkdev->bh);
 }

I think the default case could actually be abort() because it should never happen. But either way, you can add: