[RFC PATCH v2 4/8] async: register/unregister aiocontext in graph lock list

Emanuele Giuseppe Esposito posted 8 patches 3 years, 9 months ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, John Snow <jsnow@redhat.com>, Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>, Stefan Hajnoczi <stefanha@redhat.com>, Fam Zheng <fam@euphon.net>
[RFC PATCH v2 4/8] async: register/unregister aiocontext in graph lock list
Posted by Emanuele Giuseppe Esposito 3 years, 9 months ago
Add/remove the AioContext in aio_context_list in graph-lock.c only when
it is being effectively created/destroyed.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 util/async.c     | 4 ++++
 util/meson.build | 1 +
 2 files changed, 5 insertions(+)

diff --git a/util/async.c b/util/async.c
index 2ea1172f3e..3a73f83910 100644
--- a/util/async.c
+++ b/util/async.c
@@ -27,6 +27,7 @@
 #include "qapi/error.h"
 #include "block/aio.h"
 #include "block/thread-pool.h"
+#include "block/graph-lock.h"
 #include "qemu/main-loop.h"
 #include "qemu/atomic.h"
 #include "qemu/rcu_queue.h"
@@ -368,6 +369,7 @@ aio_ctx_finalize(GSource     *source)
     qemu_rec_mutex_destroy(&ctx->lock);
     qemu_lockcnt_destroy(&ctx->list_lock);
     timerlistgroup_deinit(&ctx->tlg);
+    unregister_aiocontext(ctx);
     aio_context_destroy(ctx);
 }
 
@@ -563,6 +565,8 @@ AioContext *aio_context_new(Error **errp)
 
     ctx->aio_max_batch = 0;
 
+    register_aiocontext(ctx);
+
     return ctx;
 fail:
     g_source_destroy(&ctx->source);
diff --git a/util/meson.build b/util/meson.build
index 3736988b9f..c85d8695de 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -64,6 +64,7 @@ endif
 
 if have_block
   util_ss.add(files('aiocb.c', 'async.c', 'aio-wait.c'))
+  util_ss.add(files('../block/graph-lock.c'))
   util_ss.add(files('base64.c'))
   util_ss.add(files('buffer.c'))
   util_ss.add(files('bufferiszero.c'))
-- 
2.31.1
Re: [RFC PATCH v2 4/8] async: register/unregister aiocontext in graph lock list
Posted by Stefan Hajnoczi 3 years, 9 months ago
On Tue, Apr 26, 2022 at 04:51:10AM -0400, Emanuele Giuseppe Esposito wrote:
> diff --git a/util/meson.build b/util/meson.build
> index 3736988b9f..c85d8695de 100644
> --- a/util/meson.build
> +++ b/util/meson.build
> @@ -64,6 +64,7 @@ endif
>  
>  if have_block
>    util_ss.add(files('aiocb.c', 'async.c', 'aio-wait.c'))
> +  util_ss.add(files('../block/graph-lock.c'))

Why is it in block/ if it needs to be built into libqemuutil?
Re: [RFC PATCH v2 4/8] async: register/unregister aiocontext in graph lock list
Posted by Paolo Bonzini 3 years, 9 months ago
On 4/28/22 15:46, Stefan Hajnoczi wrote:
>>   
>>   if have_block
>>     util_ss.add(files('aiocb.c', 'async.c', 'aio-wait.c'))
>> +  util_ss.add(files('../block/graph-lock.c'))
> Why is it in block/ if it needs to be built into libqemuutil?
Maybe register_aiocontext, unregister_aiocontext and 
aio_context_list_lock can be placed in util/async.c?

Paolo
Re: [RFC PATCH v2 4/8] async: register/unregister aiocontext in graph lock list
Posted by Emanuele Giuseppe Esposito 3 years, 9 months ago

Am 29/04/2022 um 00:19 schrieb Paolo Bonzini:
> On 4/28/22 15:46, Stefan Hajnoczi wrote:
>>>     if have_block
>>>     util_ss.add(files('aiocb.c', 'async.c', 'aio-wait.c'))
>>> +  util_ss.add(files('../block/graph-lock.c'))
>> Why is it in block/ if it needs to be built into libqemuutil?
> Maybe register_aiocontext, unregister_aiocontext and
> aio_context_list_lock can be placed in util/async.c?
> 

Yes the above functions are added in util/async.c. It's the best way to
automatically add an AioContext when it is created and destroyed.

Not really sure where to put it honestly, it's a block layer graph lock
so it made sense putting it in block/ but it is not reachable from async.

Should I put graph-lock.c in util/? But then won't block/meson.build
need it anyways to use it in block/?

Emanuele