mirror: hold aio_context before bdrv_drain
PATCH 1/1 mirror: hold aio_context before bdrv_drain
From: Bin Wu <[email protected]>
--- block/mirror.c | 2 ++ 1 file changed, 2 insertions(+)
block/mirror.c +2 -0
@@ -530,7 +530,9 @@ static void coroutine_fn mirror_run(void *opaque)* mirror_populate runs. */ trace_mirror_before_drain (s, cnt); +aio_context_acquire (bdrv_get_aio_context (bs));bdrv_drain (bs); +aio_context_release (bdrv_get_aio_context (bs)); cnt =bdrv_get_dirty_count (bs, s->dirty_bitmap); }
Signature · 1 line
1.7.12.4
Quoted 1 line · Bin Wu
From: Bin Wu <[email protected]>
What's the issue are you fixing? I think the coroutine already is running in the AioContext of bs.
Fam
Quoted 25 lines
Signed-off-by Bin Wu <[email protected]>--- block/mirror.c | 2 ++ 1 file changed, 2 insertions(+)block/mirror.c +2
-0@@ -530,7 +530,9 @@ static void coroutine_fn mirror_run(void *opaque)* mirror_populate runs. */ trace_mirror_before_drain (s, cnt); +aio_context_acquire (bdrv_get_aio_context (bs));bdrv_drain (bs); +aio_context_release (bdrv_get_aio_context (bs)); cnt =bdrv_get_dirty_count (bs, s->dirty_bitmap); }Signature · 1 line
1.7.12.4
Quoted 8 lines · Fam Zheng
Quoted 1 line · Bin Wu
From: Bin Wu <[email protected]>
What's the issue are you fixing? I think the coroutine already is running in the AioContext of bs.
Fam
In the current implementation of bdrv_drain, it should be placed in a critical section as suggested in the comments above the function: "Note that unlike bdrv_drain_all(), the caller must hold the BlockDriverState AioContext".
However, the mirror coroutine starting with mirror_run doesn't do this. I just found qmp_drive_mirror protects the AioCentext, but it is out of the scope of the mirror coroutine.
Bin
Quoted 28 lines
Quoted 25 lines
Signed-off-by Bin Wu <[email protected]>--- block/mirror.c | 2 ++ 1 file changed, 2 insertions(+)block/mirror.c +2
-0@@ -530,7 +530,9 @@ static void coroutine_fn mirror_run(void *opaque)* mirror_populate runs. */ trace_mirror_before_drain (s, cnt); +aio_context_acquire (bdrv_get_aio_context (bs));bdrv_drain (bs); +aio_context_release (bdrv_get_aio_context (bs)); cnt =bdrv_get_dirty_count (bs, s->dirty_bitmap); }Signature · 1 line
1.7.12.4.
Quoted 10 lines · Bin Wu
Quoted 8 lines · Fam Zheng
Quoted 1 line · Bin Wu
From: Bin Wu <[email protected]>
What's the issue are you fixing? I think the coroutine already is running in the AioContext of bs.
Fam
Quoted 7 lines
In the current implementation of
bdrv_drain, it should be placed in a critical section as suggested in the comments above the function: "Note that unlikebdrv_drain_all(), the caller must hold the BlockDriverState AioContext".However, the mirror coroutine starting with
mirror_rundoesn't do this. I just foundqmp_drive_mirrorprotects the AioCentext, but it is out of the scope of the mirror coroutine.
There are 3 possibilities:
1. qmp_drive_mirror() under QEMU main loop thread. AioContext is held.
2. IOThread aio_poll(). AioContext is held.
3. QEMU main loop thread when IOThread (dataplane) is not used. Here the AioContext is the global qemu_aio_context. We don't need to acquire it explicitly, we're protected by the global mutex.
If #3 was a problem then virtio-blk.c's bdrv_aio_writev() would also be a problem, for example.
This patch is unnecessary.
Stefan
Quoted 29 lines · Stefan Hajnoczi
Quoted 10 lines · Bin Wu
Quoted 8 lines · Fam Zheng
Quoted 1 line · Bin Wu
From: Bin Wu <[email protected]>
What's the issue are you fixing? I think the coroutine already is running in the AioContext of bs.
Fam
Quoted 7 lines
In the current implementation of
bdrv_drain, it should be placed in a critical section as suggested in the comments above the function: "Note that unlikebdrv_drain_all(), the caller must hold the BlockDriverState AioContext".However, the mirror coroutine starting with
mirror_rundoesn't do this. I just foundqmp_drive_mirrorprotects the AioCentext, but it is out of the scope of the mirror coroutine.There are 3 possibilities:
1.
qmp_drive_mirror()under QEMU main loop thread. AioContext is held.2. IOThread
aio_poll(). AioContext is held.3. QEMU main loop thread when IOThread (dataplane) is not used. Here the AioContext is the global
qemu_aio_context. We don't need to acquire it explicitly, we're protected by the global mutex.
Quoted 7 lines
If #3 was a problem then virtio-blk.c's
bdrv_aio_writev()would also be a problem, for example.This patch is unnecessary.
Stefan
OK, I see. Thanks
Signature · 1 line
Bin Wu