diff mbox series

[v3,11/19] block-backend: Decrease in_flight only after callback

Message ID 20180920161958.27453-12-kwolf@redhat.com
State New
Headers show
Series Fix some jobs/drain/aio_poll related hangs | expand

Commit Message

Kevin Wolf Sept. 20, 2018, 4:19 p.m. UTC
Request callbacks can do pretty much anything, including operations that
will yield from the coroutine (such as draining the backend). In that
case, a decreased in_flight would be visible to other code and could
lead to a drain completing while the callback hasn't actually completed
yet.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
 block/block-backend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Paolo Bonzini Sept. 20, 2018, 4:29 p.m. UTC | #1
On 20/09/2018 18:19, Kevin Wolf wrote:
> Request callbacks can do pretty much anything, including operations that
> will yield from the coroutine (such as draining the backend). In that
> case, a decreased in_flight would be visible to other code and could
> lead to a drain completing while the callback hasn't actually completed
> yet.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> Reviewed-by: Fam Zheng <famz@redhat.com>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/block-backend.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block/block-backend.c b/block/block-backend.c
> index 63eb2d10cd..5e5e60ff8d 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -1340,8 +1340,8 @@ static const AIOCBInfo blk_aio_em_aiocb_info = {
>  static void blk_aio_complete(BlkAioEmAIOCB *acb)
>  {
>      if (acb->has_returned) {
> -        blk_dec_in_flight(acb->rwco.blk);
>          acb->common.cb(acb->common.opaque, acb->rwco.ret);
> +        blk_dec_in_flight(acb->rwco.blk);
>          qemu_aio_unref(acb);
>      }
>  }
> 

If you'd like to include something in the commit message from my last
email on the subject it would be nice, otherwise

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo
diff mbox series

Patch

diff --git a/block/block-backend.c b/block/block-backend.c
index 63eb2d10cd..5e5e60ff8d 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1340,8 +1340,8 @@  static const AIOCBInfo blk_aio_em_aiocb_info = {
 static void blk_aio_complete(BlkAioEmAIOCB *acb)
 {
     if (acb->has_returned) {
-        blk_dec_in_flight(acb->rwco.blk);
         acb->common.cb(acb->common.opaque, acb->rwco.ret);
+        blk_dec_in_flight(acb->rwco.blk);
         qemu_aio_unref(acb);
     }
 }