diff mbox

xen_disk: add discard support

Message ID 20140204165819.GA28066@aepfle.de
State New
Headers show

Commit Message

Olaf Hering Feb. 4, 2014, 4:58 p.m. UTC
On Tue, Feb 04, Olaf Hering wrote:

> On Tue, Feb 04, Kevin Wolf wrote:
> 
> > Now you call bdrv_acct_done() in the callback without having a matching
> > bdrv_acct_start(). You need to make it conditional in the callback.

> Stefano,
> Is ioreq_runio_qemu_aio symetric in this regard anyway? In case of
> BLKIF_OP_WRITE|BLKIF_OP_FLUSH_DISKCACHE and no ioreq->req.nr_segments
> then qemu_aio_complete is called anyway. Will qemu_aio_complete get down
> to the bdrv_acct_done call at all in this case?

What I have in mind is something like the (not compile tested) change below.

Olaf

Comments

Stefano Stabellini Feb. 5, 2014, 6:07 p.m. UTC | #1
On Tue, 4 Feb 2014, Olaf Hering wrote:
> On Tue, Feb 04, Olaf Hering wrote:
> 
> > On Tue, Feb 04, Kevin Wolf wrote:
> > 
> > > Now you call bdrv_acct_done() in the callback without having a matching
> > > bdrv_acct_start(). You need to make it conditional in the callback.
> 
> > Stefano,
> > Is ioreq_runio_qemu_aio symetric in this regard anyway? In case of
> > BLKIF_OP_WRITE|BLKIF_OP_FLUSH_DISKCACHE and no ioreq->req.nr_segments
> > then qemu_aio_complete is called anyway. Will qemu_aio_complete get down
> > to the bdrv_acct_done call at all in this case?

Right, you spotted a bug there: if !ioreq->req.nr_segments,
qemu_aio_complete is called without bdrv_acct_start being called first. 


> What I have in mind is something like the (not compile tested) change below.
> 
> diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
> index e74efc7..99d36b8 100644
> --- a/hw/block/xen_disk.c
> +++ b/hw/block/xen_disk.c
> @@ -486,7 +486,16 @@ 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_DISCARD:
> +        break;
> +    case BLKIF_OP_WRITE:
> +    case BLKIF_OP_FLUSH_DISKCACHE:

What about BLKIF_OP_READ?


> +        if (!ioreq->req.nr_segments) {
> +            break;
> +        }
> +        bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
> +    }
>      qemu_bh_schedule(ioreq->blkdev->bh);
>  }
>  
>
diff mbox

Patch

diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index e74efc7..99d36b8 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -486,7 +486,16 @@  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_DISCARD:
+        break;
+    case BLKIF_OP_WRITE:
+    case BLKIF_OP_FLUSH_DISKCACHE:
+        if (!ioreq->req.nr_segments) {
+            break;
+        }
+        bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
+    }
     qemu_bh_schedule(ioreq->blkdev->bh);
 }