diff mbox series

[3/6] block: convert bdrv_graph_wrlock() to AIO_WAIT_WHILE_UNLOCKED()

Message ID 20230301205801.2453491-4-stefanha@redhat.com
State New
Headers show
Series block: switch to AIO_WAIT_WHILE_UNLOCKED() where possible | expand

Commit Message

Stefan Hajnoczi March 1, 2023, 8:57 p.m. UTC
The following conversion is safe and does not change behavior:

     GLOBAL_STATE_CODE();
     ...
  -  AIO_WAIT_WHILE(qemu_get_aio_context(), ...);
  +  AIO_WAIT_WHILE_UNLOCKED(NULL, ...);

Since we're in GLOBAL_STATE_CODE(), qemu_get_aio_context() is our home
thread's AioContext. Thus AIO_WAIT_WHILE() does not unlock the
AioContext:

  if (ctx_ && in_aio_context_home_thread(ctx_)) {                \
      while ((cond)) {                                           \
          aio_poll(ctx_, true);                                  \
          waited_ = true;                                        \
      }                                                          \

And that means AIO_WAIT_WHILE_UNLOCKED(NULL, ...) can be substituted.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/graph-lock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé March 2, 2023, 10:19 a.m. UTC | #1
On 1/3/23 21:57, Stefan Hajnoczi wrote:
> The following conversion is safe and does not change behavior:
> 
>       GLOBAL_STATE_CODE();
>       ...
>    -  AIO_WAIT_WHILE(qemu_get_aio_context(), ...);
>    +  AIO_WAIT_WHILE_UNLOCKED(NULL, ...);
> 
> Since we're in GLOBAL_STATE_CODE(), qemu_get_aio_context() is our home
> thread's AioContext. Thus AIO_WAIT_WHILE() does not unlock the
> AioContext:
> 
>    if (ctx_ && in_aio_context_home_thread(ctx_)) {                \
>        while ((cond)) {                                           \
>            aio_poll(ctx_, true);                                  \
>            waited_ = true;                                        \
>        }                                                          \
> 
> And that means AIO_WAIT_WHILE_UNLOCKED(NULL, ...) can be substituted.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>   block/graph-lock.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Philippe Mathieu-Daudé March 7, 2023, 8:37 p.m. UTC | #2
On 2/3/23 11:19, Philippe Mathieu-Daudé wrote:
> On 1/3/23 21:57, Stefan Hajnoczi wrote:
>> The following conversion is safe and does not change behavior:
>>
>>       GLOBAL_STATE_CODE();
>>       ...
>>    -  AIO_WAIT_WHILE(qemu_get_aio_context(), ...);
>>    +  AIO_WAIT_WHILE_UNLOCKED(NULL, ...);
>>
>> Since we're in GLOBAL_STATE_CODE(), qemu_get_aio_context() is our home
>> thread's AioContext. Thus AIO_WAIT_WHILE() does not unlock the
>> AioContext:
>>
>>    if (ctx_ && in_aio_context_home_thread(ctx_)) {                \
>>        while ((cond)) {                                           \
>>            aio_poll(ctx_, true);                                  \
>>            waited_ = true;                                        \
>>        }                                                          \
>>
>> And that means AIO_WAIT_WHILE_UNLOCKED(NULL, ...) can be substituted.
>>
>> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
>> ---
>>   block/graph-lock.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/block/graph-lock.c b/block/graph-lock.c
index 454c31e691..639526608f 100644
--- a/block/graph-lock.c
+++ b/block/graph-lock.c
@@ -127,7 +127,7 @@  void bdrv_graph_wrlock(void)
          * reader lock.
          */
         qatomic_set(&has_writer, 0);
-        AIO_WAIT_WHILE(qemu_get_aio_context(), reader_count() >= 1);
+        AIO_WAIT_WHILE_UNLOCKED(NULL, reader_count() >= 1);
         qatomic_set(&has_writer, 1);
 
         /*