diff mbox series

[11/13] block/fuse: take AioContext lock around blk_exp_ref/unref()

Message ID 20230403183004.347205-12-stefanha@redhat.com (mailing list archive)
State Superseded
Headers show
Series block: remove aio_disable_external() API | expand

Commit Message

Stefan Hajnoczi April 3, 2023, 6:30 p.m. UTC
These functions must be called with the AioContext acquired:

  /* Callers must hold exp->ctx lock */
  void blk_exp_ref(BlockExport *exp)
  ...
  /* Callers must hold exp->ctx lock */
  void blk_exp_unref(BlockExport *exp)

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/export/fuse.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Paolo Bonzini April 4, 2023, 1:46 p.m. UTC | #1
On 4/3/23 20:30, Stefan Hajnoczi wrote:
> These functions must be called with the AioContext acquired:
> 
>    /* Callers must hold exp->ctx lock */
>    void blk_exp_ref(BlockExport *exp)
>    ...
>    /* Callers must hold exp->ctx lock */
>    void blk_exp_unref(BlockExport *exp)
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>   block/export/fuse.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/block/export/fuse.c b/block/export/fuse.c
> index 06fa41079e..18394f9e07 100644
> --- a/block/export/fuse.c
> +++ b/block/export/fuse.c
> @@ -244,7 +244,9 @@ static void read_from_fuse_export(void *opaque)
>       FuseExport *exp = opaque;
>       int ret;
>   
> +    aio_context_acquire(exp->common.ctx);
>       blk_exp_ref(&exp->common);
> +    aio_context_release(exp->common.ctx);
>   
>       do {
>           ret = fuse_session_receive_buf(exp->fuse_session, &exp->fuse_buf);
> @@ -256,7 +258,9 @@ static void read_from_fuse_export(void *opaque)
>       fuse_session_process_buf(exp->fuse_session, &exp->fuse_buf);
>   
>   out:
> +    aio_context_acquire(exp->common.ctx);
>       blk_exp_unref(&exp->common);
> +    aio_context_release(exp->common.ctx);
>   }

Since the actual thread-unsafe work is done in a bottom half, perhaps 
instead you can use qatomic_inc and qatomic_fetch_dec in 
blk_exp_{ref,unref}?

Paolo
Stefan Hajnoczi April 4, 2023, 9:01 p.m. UTC | #2
On Tue, Apr 04, 2023 at 03:46:34PM +0200, Paolo Bonzini wrote:
> On 4/3/23 20:30, Stefan Hajnoczi wrote:
> > These functions must be called with the AioContext acquired:
> > 
> >    /* Callers must hold exp->ctx lock */
> >    void blk_exp_ref(BlockExport *exp)
> >    ...
> >    /* Callers must hold exp->ctx lock */
> >    void blk_exp_unref(BlockExport *exp)
> > 
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> >   block/export/fuse.c | 4 ++++
> >   1 file changed, 4 insertions(+)
> > 
> > diff --git a/block/export/fuse.c b/block/export/fuse.c
> > index 06fa41079e..18394f9e07 100644
> > --- a/block/export/fuse.c
> > +++ b/block/export/fuse.c
> > @@ -244,7 +244,9 @@ static void read_from_fuse_export(void *opaque)
> >       FuseExport *exp = opaque;
> >       int ret;
> > +    aio_context_acquire(exp->common.ctx);
> >       blk_exp_ref(&exp->common);
> > +    aio_context_release(exp->common.ctx);
> >       do {
> >           ret = fuse_session_receive_buf(exp->fuse_session, &exp->fuse_buf);
> > @@ -256,7 +258,9 @@ static void read_from_fuse_export(void *opaque)
> >       fuse_session_process_buf(exp->fuse_session, &exp->fuse_buf);
> >   out:
> > +    aio_context_acquire(exp->common.ctx);
> >       blk_exp_unref(&exp->common);
> > +    aio_context_release(exp->common.ctx);
> >   }
> 
> Since the actual thread-unsafe work is done in a bottom half, perhaps
> instead you can use qatomic_inc and qatomic_fetch_dec in
> blk_exp_{ref,unref}?

Sure, I'll give that a try in the next revision.

Stefan
diff mbox series

Patch

diff --git a/block/export/fuse.c b/block/export/fuse.c
index 06fa41079e..18394f9e07 100644
--- a/block/export/fuse.c
+++ b/block/export/fuse.c
@@ -244,7 +244,9 @@  static void read_from_fuse_export(void *opaque)
     FuseExport *exp = opaque;
     int ret;
 
+    aio_context_acquire(exp->common.ctx);
     blk_exp_ref(&exp->common);
+    aio_context_release(exp->common.ctx);
 
     do {
         ret = fuse_session_receive_buf(exp->fuse_session, &exp->fuse_buf);
@@ -256,7 +258,9 @@  static void read_from_fuse_export(void *opaque)
     fuse_session_process_buf(exp->fuse_session, &exp->fuse_buf);
 
 out:
+    aio_context_acquire(exp->common.ctx);
     blk_exp_unref(&exp->common);
+    aio_context_release(exp->common.ctx);
 }
 
 static void fuse_export_shutdown(BlockExport *blk_exp)