Re: [PATCH v2 2/9] block-copy: add missing coroutine_fn annotations

2022-11-15 Thread Emanuele Giuseppe Esposito
> On Wed, Nov 9, 2022 at 1:24 PM Emanuele Giuseppe Esposito > wrote: >>>> What I do know is that it's extremely confusing to understand if a >>>> function that is *not* marked as coroutine_fn is actually being called >>>> also from coroutines or not. &

[PATCH v3 1/8] block-copy: add missing coroutine_fn annotations

2022-11-16 Thread Emanuele Giuseppe Esposito
block_copy_reset_unallocated and block_copy_is_cluster_allocated are only called by backup_run, a corotuine_fn itself. Same applies to block_copy_block_status, called by block_copy_dirty_clusters. Therefore mark them as coroutine too. Signed-off-by: Emanuele Giuseppe Esposito --- block/block

[PATCH v3 6/8] block: bdrv_create_file is a coroutine_fn

2022-11-16 Thread Emanuele Giuseppe Esposito
It is always called in coroutine_fn callbacks, therefore it can directly call bdrv_co_create(). Signed-off-by: Emanuele Giuseppe Esposito --- block.c| 6 -- include/block/block-global-state.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a

[PATCH v3 5/8] block/vmdk: add missing coroutine_fn annotations

2022-11-16 Thread Emanuele Giuseppe Esposito
vmdk_co_create_opts() is a coroutine_fn, and calls vmdk_co_do_create() which in turn can call two callbacks: vmdk_co_create_opts_cb and vmdk_co_create_cb. Mark all these functions as coroutine_fn, since vmdk_co_create_opts() is the only caller. Signed-off-by: Emanuele Giuseppe Esposito

[PATCH v3 4/8] block: distinguish between bdrv_create running in coroutine and not

2022-11-16 Thread Emanuele Giuseppe Esposito
graph rdlock to the coroutine case. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 74 - 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/block.c b/block.c index 577639c7e0..375c8056a3 100644 --- a/block.c +++ b

[PATCH v3 7/8] block: bdrv_create is never called in coroutine context

2022-11-16 Thread Emanuele Giuseppe Esposito
Delete the if case and make sure it won't be called again in coroutines. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 37 - 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/block.c b/block.c index dcac28756c..7a4ce7948c 100644

[PATCH v3 2/8] nbd/server.c: add missing coroutine_fn annotations

2022-11-16 Thread Emanuele Giuseppe Esposito
There are probably more missing, but right now it is necessary that we extend coroutine_fn to block{allock/status}_to_extents, because they use bdrv_* functions calling the generated_co_wrapper API, which checks for the qemu_in_coroutine() case. Signed-off-by: Emanuele Giuseppe Esposito --- nbd

[PATCH v3 3/8] block-backend: replace bdrv_*_above with blk_*_above

2022-11-16 Thread Emanuele Giuseppe Esposito
Avoid mixing bdrv_* functions with blk_*, so create blk_* counterparts for: - bdrv_block_status_above - bdrv_is_allocated_above Note that these functions will take the rdlock, so they must always run in a coroutine. Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c

[PATCH v3 0/8] Still more coroutine and various fixes in block layer

2022-11-16 Thread Emanuele Giuseppe Esposito
redhat.com> Emanuele --- v3: * Remove patch 1, base on kevin "drain semplification serie" v2: * clarified commit message in patches 2/3/6 on why we add coroutine_fn Emanuele Giuseppe Esposito (8): block-copy: add missing coroutine_fn annotations nbd/server.c: add missing coroutin

[PATCH v3 8/8] block/dirty-bitmap: remove unnecessary qemu_in_coroutine() case

2022-11-16 Thread Emanuele Giuseppe Esposito
Some functions check if they are running in a coroutine, calling the coroutine callback directly if it's the case. Except that no coroutine calls such functions, therefore that case can be removed. Signed-off-by: Emanuele Giuseppe Esposito --- block/dirty-bitmap.c

Re: [PATCH v3 0/8] Still more coroutine and various fixes in block layer

2022-11-16 Thread Emanuele Giuseppe Esposito
ock: Simplify drain". > > Based-on: <20221108123738.530873-1-kw...@redhat.com> > > Emanuele > --- > v3: > * Remove patch 1, base on kevin "drain semplification serie" > > v2: > * clarified commit message in patches 2/3/6 on why we add coroutine_fn

[PATCH v4 06/11] block-coroutine-wrapper.py: support also basic return types

2022-11-16 Thread Emanuele Giuseppe Esposito
Extend the regex to cover also return type, pointers included. This implies that the value returned by the function cannot be a simple "int" anymore, but the custom return type. Therefore remove poll_state->ret and instead use a per-function custom "ret" field. Signed-of

[PATCH v4 02/11] nbd/server.c: add missing coroutine_fn annotations

2022-11-16 Thread Emanuele Giuseppe Esposito
in other words call qemu_coroutine_yield()). Therefore we need to mark such functions coroutine_fn too. Signed-off-by: Emanuele Giuseppe Esposito --- nbd/server.c | 21 - 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index

[PATCH v4 01/11] block-copy: add missing coroutine_fn annotations

2022-11-16 Thread Emanuele Giuseppe Esposito
suspend (or in other words call qemu_coroutine_yield()). Therefore we need to mark such functions coroutine_fn too. Signed-off-by: Emanuele Giuseppe Esposito --- block/block-copy.c | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/block/block-copy.c b/block/block

[PATCH v4 07/11] block/vmdk: add missing coroutine_fn annotations

2022-11-16 Thread Emanuele Giuseppe Esposito
suspend (or in other words call qemu_coroutine_yield()). Therefore we need to mark such functions coroutine_fn too. Signed-off-by: Emanuele Giuseppe Esposito --- block/vmdk.c | 36 +++- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/block/vmdk.c b/block

[PATCH v4 00/11] Still more coroutine and various fixes in block layer

2022-11-16 Thread Emanuele Giuseppe Esposito
redhat.com> Emanuele --- v4: * use v2 commit messages * introduce generated_co_wrapper_simple to simplify patches v3: * Remove patch 1, base on kevin "drain semplification serie" v2: * clarified commit message in patches 2/3/6 on why we add coroutine_fn Emanuele Giuseppe Esposito (11

[PATCH v4 04/11] block-coroutine-wrapper.py: introduce generated_co_wrapper_simple

2022-11-16 Thread Emanuele Giuseppe Esposito
functions will be substituted on g_c_w_simple. Signed-off-by: Emanuele Giuseppe Esposito --- include/block/block-common.h | 1 + scripts/block-coroutine-wrapper.py | 87 ++ 2 files changed, 66 insertions(+), 22 deletions(-) diff --git a/include/block/block

[PATCH v4 05/11] block-coroutine-wrapper.py: default to main loop aiocontext if function does not have a BlockDriverState parameter

2022-11-16 Thread Emanuele Giuseppe Esposito
ain loop. Signed-off-by: Emanuele Giuseppe Esposito --- scripts/block-coroutine-wrapper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-wrapper.py index f88ef53964..0f842386d4 100644 --- a/scripts/bl

[PATCH v4 09/11] block: bdrv_create_file is a coroutine_fn

2022-11-16 Thread Emanuele Giuseppe Esposito
It is always called in coroutine_fn callbacks, therefore it can directly call bdrv_co_create(). Signed-off-by: Emanuele Giuseppe Esposito --- block.c| 6 -- include/block/block-global-state.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a

[PATCH v4 08/11] block: distinguish between bdrv_create running in coroutine and not

2022-11-16 Thread Emanuele Giuseppe Esposito
Call two different functions depending on whether bdrv_create is in coroutine or not, following the same pattern as generated_co_wrapper functions. This allows to also call the coroutine function directly, without using CreateCo or relying in bdrv_create(). Signed-off-by: Emanuele Giuseppe

[PATCH v4 10/11] block: convert bdrv_create to generated_co_wrapper_simple

2022-11-16 Thread Emanuele Giuseppe Esposito
This function is never called in coroutine context, therefore instead of manually creating a new coroutine, delegate it to the block-coroutine-wrapper script, defining it as g_c_w_simple. Signed-off-by: Emanuele Giuseppe Esposito --- block.c| 38

[PATCH v4 03/11] block-backend: replace bdrv_*_above with blk_*_above

2022-11-16 Thread Emanuele Giuseppe Esposito
Avoid mixing bdrv_* functions with blk_*, so create blk_* counterparts for: - bdrv_block_status_above - bdrv_is_allocated_above Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c | 21 + block/commit.c| 4 ++-- include/sysemu

[PATCH v4 11/11] block/dirty-bitmap: convert coroutine-only functions to generated_co_wrapper_simple

2022-11-16 Thread Emanuele Giuseppe Esposito
ed to g_c_w_simple. Signed-off-by: Emanuele Giuseppe Esposito --- block/dirty-bitmap.c | 88 +--- block/meson.build| 1 + include/block/block-common.h | 5 +- include/block/block-io.h | 9 +++- include/block/dirty-bitmap.h | 10 +++- 5

[PATCH 00/20] Protect the block layer with a rwlock: part 1

2022-11-16 Thread Emanuele Giuseppe Esposito
56527-1-eespo...@redhat.com> Thank you, Emanuele Emanuele Giuseppe Esposito (19): graph-lock: introduce BdrvGraphRWlock structure async: register/unregister aiocontext in graph lock list block.c: wrlock in bdrv_replace_child_noperm block: remove unnecessary assert_bdrv_graph_writable() bl

[PATCH 00/20] Protect the block layer with a rwlock: part 1

2022-11-16 Thread Emanuele Giuseppe Esposito
56527-1-eespo...@redhat.com> Thank you, Emanuele Emanuele Giuseppe Esposito (19): graph-lock: introduce BdrvGraphRWlock structure async: register/unregister aiocontext in graph lock list block.c: wrlock in bdrv_replace_child_noperm block: remove unnecessary assert_bdrv_graph_writable() bl

[PATCH 20/20] block-gen: assert that nbd_co_do_establish_connection is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
The only caller of this function is nbd_do_establish_connection, a generated_co_wrapper that already take the graph read lock. Signed-off-by: Emanuele Giuseppe Esposito --- block/nbd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/nbd.c b/block/nbd.c index 7d485c86d2..5cad58aaf6

[PATCH 16/20] block-gen: assert that bdrv_co_{read/write}v_vmstate are always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
-by: Emanuele Giuseppe Esposito --- block/io.c | 2 ++ include/block/block_int-common.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/block/io.c b/block/io.c index 0bf3919939..c9b451fecd 100644 --- a/block/io.c +++ b/block/io.c @@ -2633,6 +2633,7 @@ bdrv_co_readv_vmst

[PATCH 11/20] block-gen: assert that bdrv_co_{check/invalidate_cache} are always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
The only callers of these functions are the respective generated_co_wrapper, and they already take the lock. Protecting bdrv_co_{check/invalidate_cache}() implies that BlockDriver->bdrv_co_{check/invalidate_cache}() is always called with graph rdlock taken. Signed-off-by: Emanuele Giuse

[PATCH 05/20] block: remove unnecessary assert_bdrv_graph_writable()

2022-11-16 Thread Emanuele Giuseppe Esposito
We don't protect bdrv->aio_context with the graph rwlock, so these assertions are not needed Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/block.c b/block.c index 4ef537a9f2..afab74d4da 100644 --- a/block.c +++ b/block.c @@

[PATCH 17/20] block-gen: assert that bdrv_co_pdiscard is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
BlockDriver callbacks always called with graph rdlock taken: - bdrv_co_pdiscard - bdrv_aio_pdiscard - bdrv_co_pdiscard_snapshot Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c| 1 + block/io.c | 2 ++ include/block/block_int-common.h | 3 +++ 3 files

[PATCH 03/20] async: register/unregister aiocontext in graph lock list

2022-11-16 Thread Emanuele Giuseppe Esposito
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 --- util/async.c | 4 util/meson.build | 1 + 2 files changed, 5 insertions(+) diff --git a/util/async.c b/util/async.c index

[PATCH 12/20] block-gen: assert that bdrv_co_pwrite is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
: - bdrv_aio_pwritev - bdrv_co_writev - bdrv_co_pwritev - bdrv_co_pwritev_part - bdrv_co_pwritev_compressed - bdrv_co_pwritev_compressed_part Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c| 1 + block/block-copy.c | 8 ++-- block/io.c

[PATCH 02/20] graph-lock: introduce BdrvGraphRWlock structure

2022-11-16 Thread Emanuele Giuseppe Esposito
Just a wrapper to simplify what is available to the struct AioContext. Signed-off-by: Emanuele Giuseppe Esposito --- block/graph-lock.c | 59 ++ include/block/aio.h| 12 include/block/graph-lock.h | 1 + 3 files changed, 48

[PATCH 07/20] graph-lock: implement WITH_GRAPH_RDLOCK_GUARD and GRAPH_RDLOCK_GUARD macros

2022-11-16 Thread Emanuele Giuseppe Esposito
Similar to the implementation in lockable.h, implement macros to automatically take and release the rdlock. Create the empty GraphLockable struct only to use it as a type for G_DEFINE_AUTOPTR_CLEANUP_FUNC. Signed-off-by: Emanuele Giuseppe Esposito --- include/block/graph-lock.h | 35

[PATCH 14/20] block-gen: assert that bdrv_co_pread is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
other generated_co_wrappers: blk_co_pread blk_co_preadv blk_co_preadv_part Protecting bdrv_driver_preadv() implies that the following BlockDriver callbacks always called with graph rdlock taken: - bdrv_co_preadv_part - bdrv_co_preadv - bdrv_aio_preadv - bdrv_co_readv Signed-off-by: Emanuele Giuseppe

[PATCH 15/20] block-gen: assert that {bdrv/blk}_co_flush is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
always called with graph rdlock taken: - bdrv_co_flush - bdrv_co_flush_to_os - bdrv_co_flush_to_disk Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c| 3 ++- block/io.c | 1 + include/block/block_int-common.h | 6 ++ 3 files changed, 9

[PATCH 5/6] block/io: assert that BlockDriver->bdrv_co_*_snapshot_* are always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
The only callers are other callback functions that already run with the graph rdlock taken. Signed-off-by: Emanuele Giuseppe Esposito --- block/io.c | 2 ++ include/block/block_int-common.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/block/io.c b/block/io.c

[PATCH 09/20] block-backend: introduce new generated_co_wrapper_blk annotation

2022-11-16 Thread Emanuele Giuseppe Esposito
This annotation will be used to distinguish the blk_* API from the bdrv_* API in block-gen.c. The reason for this distinction is that blk_* API eventually result in always calling bdrv_*, which has implications when we introduce the read graph lock. Signed-off-by: Emanuele Giuseppe Esposito

[PATCH 08/20] block-coroutine-wrapper.py: take the graph rdlock in bdrv_* functions

2022-11-16 Thread Emanuele Giuseppe Esposito
assume that the graph rdlock is taken at the coroutine creation, i.e. in g_c_w or in specific coroutines (right now we just consider the g_c_w case). All the blk_co_* are responsible of taking the rdlock (at this point is still a TBD). Suggested-by: Kevin Wolf Signed-off-by: Emanuele Giuseppe

[PATCH 00/20] Protect the block layer with a rwlock: part 1

2022-11-16 Thread Emanuele Giuseppe Esposito
56527-1-eespo...@redhat.com> Thank you, Emanuele Emanuele Giuseppe Esposito (19): graph-lock: introduce BdrvGraphRWlock structure async: register/unregister aiocontext in graph lock list block.c: wrlock in bdrv_replace_child_noperm block: remove unnecessary assert_bdrv_graph_writable() bl

[PATCH 6/6] block: assert that BlockDriver->bdrv_co_delete_file is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
The only callers are other callback functions that already run with the graph rdlock taken. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 1 + include/block/block_int-common.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/block.c b

[PATCH 10/20] block-gen: assert that {bdrv/blk}_co_truncate is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
ate() is always called with graph rdlock taken. Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c| 1 + block/io.c | 1 + include/block/block_int-common.h | 2 ++ 3 files changed, 4 insertions(+) diff --git a/block/block-backend.c b/block/bl

[PATCH 2/6] block: assert that BlockDriver->bdrv_co_{amend/create} are called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
Both functions are only called by Job->run() callbacks, therefore they must take the lock in the *_run() implementation. Signed-off-by: Emanuele Giuseppe Esposito --- block/amend.c| 1 + block/create.c | 1 + include/block/block_int-common.h | 2 ++ 3 fi

[PATCH 0/6] Protect the block layer with a rwlock: part 2

2022-11-16 Thread Emanuele Giuseppe Esposito
y traverse the BlockDriverState graph, therefore they need to be protected with the rdlock. Based-on: <20221116134850.3051419-1-eespo...@redhat.com> Thank you, Emanuele Emanuele Giuseppe Esposito (6): block: assert that bdrv_co_create is always called with graph rdlock taken bl

[PATCH 06/20] block: assert that graph read and writes are performed correctly

2022-11-16 Thread Emanuele Giuseppe Esposito
Remove the old assert_bdrv_graph_writable, and replace it with the new version using graph-lock API. See the function documentation for more information. Signed-off-by: Emanuele Giuseppe Esposito --- block.c| 4 ++-- block/graph-lock.c | 11

[PATCH 1/6] block: assert that bdrv_co_create is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
ver->bdrv_co_create_opts is always called with graph rdlock taken. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 1 + include/block/block_int-common.h | 1 + 2 files changed, 2 insertions(+) diff --git a/block.c b/block.c index c7611bed9e..e54ed300d7 100644 --- a/block.c

[PATCH 13/20] block-gen: assert that bdrv_co_pwrite_{zeros/sync} is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
Already protected by bdrv_co_pwrite callers. Protecting bdrv_co_do_pwrite_zeroes() implies that BlockDriver->bdrv_co_pwrite_zeroes() is always called with graph rdlock taken. Signed-off-by: Emanuele Giuseppe Esposito --- block/io.c | 3 +++ include/block/block_

[PATCH 19/20] block-gen: assert that bdrv_co_ioctl is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
called too with rdlock taken). Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c| 1 + block/io.c | 1 + include/block/block_int-common.h | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block

[PATCH 3/6] block: assert that BlockDriver->bdrv_co_copy_range_{from/to} is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
The only non-protected caller is convert_co_copy_range(), all other callers are BlockDriver callbacks that already take the rdlock. Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c| 2 ++ block/io.c | 5 + include/block/block_int-common.h

[PATCH 01/20] block: introduce a lock to protect graph operations

2022-11-16 Thread Emanuele Giuseppe Esposito
we transfer the count to a global shared counter so that the writer is always aware of all readers. Co-developed-with: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- block/graph-lock.c | 221 + block/meson.buil

[PATCH 04/20] block.c: wrlock in bdrv_replace_child_noperm

2022-11-16 Thread Emanuele Giuseppe Esposito
Protect the main function where graph is modified. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 6 -- include/block/block_int-common.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index d3e168408a..4ef537a9f2

[PATCH 18/20] block-gen: assert that bdrv_co_common_block_status_above is always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
() implies that BlockDriver->bdrv_co_block_status() is always called with graph rdlock taken. Signed-off-by: Emanuele Giuseppe Esposito --- block/backup.c | 3 +++ block/block-backend.c| 2 ++ block/block-copy.c | 2 ++ block/i

[PATCH 4/6] block/dirty-bitmap: assert that BlockDriver->bdrv_co_*_dirty_bitmap are always called with graph rdlock taken

2022-11-16 Thread Emanuele Giuseppe Esposito
The only callers are the respective bdrv_*_dirty_bitmap() functions that take care of creating a new coroutine (that already takes the graph rdlock). Signed-off-by: Emanuele Giuseppe Esposito --- block/dirty-bitmap.c | 2 ++ include/block/block_int-common.h | 2 ++ 2 files changed

[PATCH 13/15] block: convert bdrv_io_plug in generated_co_wrapper_simple

2022-11-16 Thread Emanuele Giuseppe Esposito
k_plug a generated_co_wrapper_simple, so that it always creates a new coroutine, and then make bdrv_plug coroutine_fn. Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c | 5 +++-- block/io.c| 5 +++-- include/block/block-io.h | 3 ++- include/block/b

[PATCH 09/15] block-coroutine-wrapper: support void functions

2022-11-16 Thread Emanuele Giuseppe Esposito
Just omit the various 'return' when the return type is void. Signed-off-by: Emanuele Giuseppe Esposito --- scripts/block-coroutine-wrapper.py | 19 ++- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block

[PATCH 12/15] block: convert bdrv_debug_event in generated_co_wrapper

2022-11-16 Thread Emanuele Giuseppe Esposito
ame name. Unfortunately we cannot use a generated_co_wrapper_simple, because the function is called by mixed functions that run both in coroutine and non-coroutine context (for example blkdebug_open). Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 4 +++- bl

[PATCH 00/15] Protect the block layer with a rwlock: part 3

2022-11-16 Thread Emanuele Giuseppe Esposito
s run in a coroutine. Based-on: <20221116135331.3052923-1-eespo...@redhat.com> Thank you, Emanuele Emanuele Giuseppe Esposito (15): block/qed: add missing graph rdlock in qed_need_check_timer_entry block: rename refresh_total_sectors in bdrv_refresh_total_sectors block-backend: use

[PATCH 03/15] block-backend: use bdrv_getlength instead of blk_getlength

2022-11-16 Thread Emanuele Giuseppe Esposito
Giuseppe Esposito --- 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 6f0dd15808..4af9a3179e 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1253,7 +1253,7 @@ static int

[PATCH 04/15] block: convert bdrv_refresh_total_sectors in generated_co_wrapper

2022-11-16 Thread Emanuele Giuseppe Esposito
oContext lock. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 29 - block/block-backend.c | 12 block/commit.c| 4 ++-- block/meson.build | 1 + block/

[PATCH 08/15] block: convert bdrv_is_inserted in generated_co_wrapper_simple

2022-11-16 Thread Emanuele Giuseppe Esposito
ry place it needs to be, we will poll using AIO_WAIT_WHILE_UNLOCKED and remove the AioContext lock. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 5 +++-- block/block-backend.c | 5 +++-- block/io.c| 12 ++-- bl

[PATCH 01/15] block/qed: add missing graph rdlock in qed_need_check_timer_entry

2022-11-16 Thread Emanuele Giuseppe Esposito
graph rdlock. Signed-off-by: Emanuele Giuseppe Esposito --- block/qed.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/qed.c b/block/qed.c index c2691a85b1..778b23d0f6 100644 --- a/block/qed.c +++ b/block/qed.c @@ -282,11 +282,13 @@ static void coroutine_fn

[PATCH 07/15] block: convert bdrv_get_info in generated_co_wrapper

2022-11-16 Thread Emanuele Giuseppe Esposito
ame name. Unfortunately we cannot use a generated_co_wrapper_simple, because the function is called by mixed functions that run both in coroutine and non-coroutine context (for example block_load in migration/block.c). Signed-off-by: Emanuele Giuseppe Esposito --- block.c

[PATCH 06/15] block: convert bdrv_get_allocated_file_size in generated_co_wrapper_simple

2022-11-16 Thread Emanuele Giuseppe Esposito
wrapper with the same name that will take care of always calling the function in a coroutine. This is a generated_co_wrapper_simple callback, which means it assumes that bdrv_get_allocated_file_size is never caled in a coroutine context. Signed-off-by: Emanuele Giuseppe Esposito ---

[PATCH 10/15] block: convert bdrv_eject in generated_co_wrapper_simple

2022-11-16 Thread Emanuele Giuseppe Esposito
_eject a generated_co_wrapper_simple, so that it always creates a new coroutine, and then make bdrv_eject coroutine_fn. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 3 ++- block/block-backend.c | 5 +++-- block/copy-on-read.c | 2 +- block/filter-co

[PATCH 14/15] block: convert bdrv_io_unplug in generated_co_wrapper_simple

2022-11-16 Thread Emanuele Giuseppe Esposito
unplug a generated_co_wrapper_simple, so that it always creates a new coroutine, and then make bdrv_unplug coroutine_fn. Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c | 5 +++-- block/io.c| 5 +++-- include/block/block-io.h | 3 +-- inclu

[PATCH 02/15] block: rename refresh_total_sectors in bdrv_refresh_total_sectors

2022-11-16 Thread Emanuele Giuseppe Esposito
Name is not right, since we are going to convert this in a generated_co_wrapper. No functional change intended. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 8 block/io.c | 8 +--- include/block/block_int-io.h | 2 +- 3 files

[PATCH 15/15] block: rename newly converted BlockDriver IO coroutine functions

2022-11-16 Thread Emanuele Giuseppe Esposito
Since these functions alwayas run in coroutine context, adjust their name to include "_co_", just like all other BlockDriver callbacks. No functional change intended. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 32 ++--- block/

[PATCH 11/15] block: convert bdrv_lock_medium in generated_co_wrapper_simple

2022-11-16 Thread Emanuele Giuseppe Esposito
medium a generated_co_wrapper_simple, so that it always creates a new coroutine, and then make bdrv_lock_medium coroutine_fn. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 3 ++- block/block-backend.c | 5 +++-- block/copy-on-read.c | 2 +

[PATCH 05/15] block: use bdrv_co_refresh_total_sectors when possible

2022-11-16 Thread Emanuele Giuseppe Esposito
In some places we are sure we are always running in a coroutine, therefore it's useless to call the generated_co_wrapper, instead call directly the _co_ function. Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c | 6 +++--- block/copy-on-read.c | 2 +- block

Re: [PATCH v3 2/3] KVM: keep track of running ioctls

2022-11-18 Thread Emanuele Giuseppe Esposito
Am 17/11/2022 um 20:27 schrieb David Hildenbrand: > On 11.11.22 16:47, Emanuele Giuseppe Esposito wrote: >> Using the new accel-blocker API, mark where ioctls are being called >> in KVM. Next, we will implement the critical section that will take >> care of performing m

Re: [PATCH 00/15] Protect the block layer with a rwlock: part 3

2022-11-18 Thread Emanuele Giuseppe Esposito
Am 18/11/2022 um 11:57 schrieb Paolo Bonzini: > On 11/16/22 15:07, Emanuele Giuseppe Esposito wrote: >> Here we introduce generated_co_wrapper_simple, a simplification of >> g_c_w that >> only considers the case where the caller is not in a coroutine. >> This simplifi

Re: [PATCH v4 01/11] block-copy: add missing coroutine_fn annotations

2022-11-21 Thread Emanuele Giuseppe Esposito
Am 18/11/2022 um 20:05 schrieb Kevin Wolf: > Am 16.11.2022 um 13:22 hat Emanuele Giuseppe Esposito geschrieben: >> These functions end up calling bdrv_common_block_status_above(), a >> generated_co_wrapper function. >> In addition, they also happen to be always called

Re: [PATCH v4 01/11] block-copy: add missing coroutine_fn annotations

2022-11-21 Thread Emanuele Giuseppe Esposito
Am 21/11/2022 um 09:32 schrieb Emanuele Giuseppe Esposito: > > > Am 18/11/2022 um 20:05 schrieb Kevin Wolf: >> Am 16.11.2022 um 13:22 hat Emanuele Giuseppe Esposito geschrieben: >>> These functions end up calling bdrv_common_block_status_above(), a >>> gene

Re: [PATCH v4 01/11] block-copy: add missing coroutine_fn annotations

2022-11-21 Thread Emanuele Giuseppe Esposito
Am 21/11/2022 um 12:50 schrieb Kevin Wolf: > Am 21.11.2022 um 09:51 hat Emanuele Giuseppe Esposito geschrieben: >> >> >> Am 21/11/2022 um 09:32 schrieb Emanuele Giuseppe Esposito: >>> >>> >>> Am 18/11/2022 um 20:05 schrieb Kevin Wolf: >>&g

Re: [PATCH 00/15] Protect the block layer with a rwlock: part 3

2022-11-21 Thread Emanuele Giuseppe Esposito
rotect the block layer with a rwlock: part 3 Thank you, Emanuele Am 16/11/2022 um 15:07 schrieb Emanuele Giuseppe Esposito: > Please read "Protect the block layer with a rwlock: part 1" and > "Protect the block layer with a rwlock: part 2" for an > additional intro

Re: [PATCH 00/20] Protect the block layer with a rwlock: part 1

2022-11-21 Thread Emanuele Giuseppe Esposito
rotect the block layer with a rwlock: part 3 Thank you, Emanuele Am 16/11/2022 um 14:48 schrieb Emanuele Giuseppe Esposito: > This serie is the first of four series that aim to introduce and use a new > graph rwlock in the QEMU block layer. > The aim is to replace the current AioContext

Re: [PATCH 0/6] Protect the block layer with a rwlock: part 2

2022-11-21 Thread Emanuele Giuseppe Esposito
rotect the block layer with a rwlock: part 3 Thank you, Emanuele Am 16/11/2022 um 14:53 schrieb Emanuele Giuseppe Esposito: > Please read "Protect the block layer with a rwlock: part 1" for an additional > introduction and aim of this series. > > This second part aim

Re: [PATCH v4 05/11] block-coroutine-wrapper.py: default to main loop aiocontext if function does not have a BlockDriverState parameter

2022-11-21 Thread Emanuele Giuseppe Esposito
Am 21/11/2022 um 16:30 schrieb Kevin Wolf: > Am 16.11.2022 um 13:22 hat Emanuele Giuseppe Esposito geschrieben: >> Basically BdrvPollCo->bs is only used by bdrv_poll_co(), and the >> functions that it uses are both using bdrv_get_aio_context, that >> defaults to qemu_ge

Re: [PATCH v4 07/11] block/vmdk: add missing coroutine_fn annotations

2022-11-21 Thread Emanuele Giuseppe Esposito
Am 21/11/2022 um 17:01 schrieb Kevin Wolf: > Am 16.11.2022 um 13:22 hat Emanuele Giuseppe Esposito geschrieben: >> These functions end up calling bdrv_create() implemented as >> generated_co_wrapper >> functions. >> In addition, they also happen to be always

Re: [PATCH v4 09/11] block: bdrv_create_file is a coroutine_fn

2022-11-22 Thread Emanuele Giuseppe Esposito
Am 22/11/2022 um 09:58 schrieb Kevin Wolf: > Am 16.11.2022 um 13:22 hat Emanuele Giuseppe Esposito geschrieben: >> It is always called in coroutine_fn callbacks, therefore >> it can directly call bdrv_co_create(). >> >> Signed-off-by: Emanuele Giuseppe E

[PATCH v5 01/15] block-io: introduce coroutine_fn duplicates for bdrv_common_block_status_above callers

2022-11-23 Thread Emanuele Giuseppe Esposito
ppers that take care of directly calling the same coroutine functions called in the g_c_w. Signed-off-by: Emanuele Giuseppe Esposito --- block/io.c | 64 ++-- include/block/block-io.h | 15 ++ 2 files changed, 76 insertions(+), 3 deletion

[PATCH v5 14/15] block: convert bdrv_create to generated_co_wrapper_simple

2022-11-23 Thread Emanuele Giuseppe Esposito
This function is never called in coroutine context, therefore instead of manually creating a new coroutine, delegate it to the block-coroutine-wrapper script, defining it as g_c_w_simple. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf --- block.c

[PATCH v5 06/15] block: avoid duplicating filename string in bdrv_create

2022-11-23 Thread Emanuele Giuseppe Esposito
We know that the string will stay around until the function returns, and the parameter of drv->bdrv_co_create_opts is const char*, so it must not be modified either. Suggested-by: Kevin Wolf Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 7 ++- 1 file changed, 2 insertions(+)

[PATCH v5 08/15] block: distinguish between bdrv_create running in coroutine and not

2022-11-23 Thread Emanuele Giuseppe Esposito
Call two different functions depending on whether bdrv_create is in coroutine or not, following the same pattern as generated_co_wrapper functions. This allows to also call the coroutine function directly, without using CreateCo or relying in bdrv_create(). Signed-off-by: Emanuele Giuseppe

[PATCH v5 10/15] block-coroutine-wrapper.py: introduce generated_co_wrapper_simple

2022-11-23 Thread Emanuele Giuseppe Esposito
functions will be substituted on g_c_w_simple. Signed-off-by: Emanuele Giuseppe Esposito --- include/block/block-common.h | 1 + scripts/block-coroutine-wrapper.py | 105 - 2 files changed, 75 insertions(+), 31 deletions(-) diff --git a/include/block/block

[PATCH v5 02/15] block-copy: add missing coroutine_fn annotations

2022-11-23 Thread Emanuele Giuseppe Esposito
suspend (or in other words call qemu_coroutine_yield()). Therefore we need to mark such functions coroutine_fn too. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Paolo Bonzini --- block/block-copy.c | 21 - include/block/block-copy.h | 5 +++-- 2 files

[PATCH v5 03/15] nbd/server.c: add missing coroutine_fn annotations

2022-11-23 Thread Emanuele Giuseppe Esposito
in other words call qemu_coroutine_yield()). Therefore we need to mark such functions coroutine_fn too. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Paolo Bonzini --- nbd/server.c | 29 - 1 file changed, 16 insertions(+), 13

[PATCH v5 07/15] block: introduce QEMU_IN_COROUTINE macro

2022-11-23 Thread Emanuele Giuseppe Esposito
context. Signed-off-by: Emanuele Giuseppe Esposito --- include/block/block-common.h | 11 +++ 1 file changed, 11 insertions(+) diff --git a/include/block/block-common.h b/include/block/block-common.h index 297704c1e9..24de1d63fd 100644 --- a/include/block/block-common.h +++ b/include/block

[PATCH v5 00/15] Still more coroutine and various fixes in block layer

2022-11-23 Thread Emanuele Giuseppe Esposito
drain" v4: * use v2 commit messages * introduce generated_co_wrapper_simple to simplify patches v3: * Remove patch 1, base on kevin "drain semplification serie" v2: * clarified commit message in patches 2/3/6 on why we add coroutine_fn Emanuele Giuseppe Esposito (15)

[PATCH v5 04/15] block-backend: replace bdrv_*_above with blk_*_above

2022-11-23 Thread Emanuele Giuseppe Esposito
bdrv_co_common_block_status_above() to avoid using a g_c_w. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Paolo Bonzini --- block/block-backend.c | 21 block/commit.c| 4 ++-- include/sysemu/block-backend-io.h | 9 + nbd/server.c

[PATCH v5 05/15] block/vmdk: add missing coroutine_fn annotations

2022-11-23 Thread Emanuele Giuseppe Esposito
suspend (or in other words call qemu_coroutine_yield()). Therefore we need to mark such functions coroutine_fn too. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Paolo Bonzini Reviewed-by: Kevin Wolf --- block/vmdk.c | 36 +++- 1 file changed, 19 insertions

[PATCH v5 15/15] block/dirty-bitmap: convert coroutine-only functions to generated_co_wrapper_simple

2022-11-23 Thread Emanuele Giuseppe Esposito
ed to g_c_w_simple. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf --- block/dirty-bitmap.c | 88 +--- block/meson.build| 1 + include/block/block-common.h | 5 +- include/block/block-io.h | 9 +++- include/block/

[PATCH v5 11/15] block-coroutine-wrapper.py: default to main loop aiocontext if function does not have a BlockDriverState parameter

2022-11-23 Thread Emanuele Giuseppe Esposito
ain loop. Signed-off-by: Emanuele Giuseppe Esposito --- scripts/block-coroutine-wrapper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-wrapper.py index 2fa3d01898..7e8f2da84b 100644 --- a/scripts/bl

[PATCH v5 09/15] block: bdrv_create_file is a coroutine_fn

2022-11-23 Thread Emanuele Giuseppe Esposito
It is always called in coroutine_fn callbacks, therefore it can directly call bdrv_co_create(). Rename it to bdrv_co_create_file too. Signed-off-by: Emanuele Giuseppe Esposito --- block.c| 5 +++-- block/crypto.c | 2 +- block/parallels.c

[PATCH v5 13/15] block-coroutine-wrapper.py: support also basic return types

2022-11-23 Thread Emanuele Giuseppe Esposito
Extend the regex to cover also return type, pointers included. This implies that the value returned by the function cannot be a simple "int" anymore, but the custom return type. Therefore remove poll_state->ret and instead use a per-function custom "ret" field. Signed-of

[PATCH v5 12/15] block-coroutine-wrapper.py: default to main loop aiocontext if function does not have a BlockDriverState parameter

2022-11-23 Thread Emanuele Giuseppe Esposito
, and default to the main loop if no BlockDriverState is passed as parameter. Signed-off-by: Emanuele Giuseppe Esposito --- block/block-gen.h | 6 +++--- scripts/block-coroutine-wrapper.py | 14 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/block

Re: [PATCH 00/15] Protect the block layer with a rwlock: part 3

2022-11-23 Thread Emanuele Giuseppe Esposito
Am 18/11/2022 um 11:57 schrieb Paolo Bonzini: > On 11/16/22 15:07, Emanuele Giuseppe Esposito wrote: >> Here we introduce generated_co_wrapper_simple, a simplification of >> g_c_w that >> only considers the case where the caller is not in a coroutine. >> This simplifi

[PATCH v6 02/14] block-copy: add missing coroutine_fn annotations

2022-11-25 Thread Emanuele Giuseppe Esposito
suspend (or in other words call qemu_coroutine_yield()). Therefore we need to mark such functions coroutine_fn too. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Paolo Bonzini Reviewed-by: Kevin Wolf --- block/block-copy.c | 21 - include/block/block-copy.h

[PATCH v6 13/14] block: convert bdrv_create to co_wrapper

2022-11-25 Thread Emanuele Giuseppe Esposito
This function is never called in coroutine context, therefore instead of manually creating a new coroutine, delegate it to the block-coroutine-wrapper script, defining it as co_wrapper. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf --- block.c

[PATCH v6 09/14] block: rename generated_co_wrapper in co_wrapper_mixed

2022-11-25 Thread Emanuele Giuseppe Esposito
In preparation to the incoming new function specifiers, rename g_c_w with a more meaningful name and document it. Signed-off-by: Emanuele Giuseppe Esposito --- block/coroutines.h | 4 +- docs/devel/block-coroutine-wrapper.rst | 6 +-- include/block/block-common.h

  1   2   3   4   5   6   7   8   9   10   >