Skip to contentSkip to conversation

xen_disk: fix io accounting

PATCH Superseded Olaf Hering 3 participants 3 messages Feb 6, 2014 – Feb 7, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

---
 hw/block/xen_disk.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
hw/block/xen_disk.c +12 -1
index 098f6c6..7f0f14a 100644
@@ -483,7 +483,18 @@ 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;
+        }
+    case BLKIF_OP_READ:
+        bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
+        break;
+    default:
+        break;
+    }
     qemu_bh_schedule(ioreq->blkdev->bh);
 }
 
#1 lore raw

Am 06.02.2014 16:55, schrieb Olaf Hering:

Quoted 16 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.

---
 hw/block/xen_disk.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
hw/block/xen_disk.c +0 -0
index 098f6c6..7f0f14a 100644

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

Quoted 10 lines
hw/block/xen_disk.c +6 -1
@@ -483,7 +483,18 @@ 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;
+        }

This will need a /* fall through */ comment for static analysis tools.

Andreas

Quoted 10 lines
hw/block/xen_disk.c +6 -0
+    case BLKIF_OP_READ:
+        bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
+        break;
+    default:
+        break;
+    }
     qemu_bh_schedule(ioreq->blkdev->bh);
 }
 
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#2 lore raw
Quoted 21 lines · Andreas Färber

Am 06.02.2014 16:55, schrieb Olaf Hering:

Quoted 20 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.

---
 hw/block/xen_disk.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
hw/block/xen_disk.c +0 -1
index 098f6c6..7f0f14a 100644
@@ -483,7 +483,18 @@ 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);
Quoted 9 lines

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

Quoted 6 lines
hw/block/xen_disk.c +6 -0
+    switch (ioreq->req.operation) {
+    case BLKIF_OP_WRITE:
+    case BLKIF_OP_FLUSH_DISKCACHE:
+        if (!ioreq->req.nr_segments) {
+            break;
+        }

This will need a /* fall through */ comment for static analysis tools.

Aside from this, I think that the patch is OK.
Can you please resend it with the comment?

Quoted 16 lines
Quoted 10 lines
hw/block/xen_disk.c +6 -0
+    case BLKIF_OP_READ:
+        bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
+        break;
+    default:
+        break;
+    }
     qemu_bh_schedule(ioreq->blkdev->bh);
 }
 
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg