Skip to content

Commit

Permalink
block-coroutine-wrapper: Add no_co_wrapper_bdrv_rdlock functions
Browse files Browse the repository at this point in the history
Add a new wrapper type for GRAPH_RDLOCK functions that should be called
from coroutine context.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20230929145157.45443-3-kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
kevmw committed Oct 12, 2023
1 parent 903df11 commit e84c07b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions include/block/block-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@
* function. The coroutine yields after scheduling the BH and is reentered when
* the wrapped function returns.
*
* A no_co_wrapper_bdrv_wrlock function is a no_co_wrapper function that
* automatically takes the graph wrlock when calling the wrapped function.
* A no_co_wrapper_bdrv_rdlock function is a no_co_wrapper function that
* automatically takes the graph rdlock when calling the wrapped function. In
* the same way, no_co_wrapper_bdrv_wrlock functions automatically take the
* graph wrlock.
*
* If the first parameter of the function is a BlockDriverState, BdrvChild or
* BlockBackend pointer, the AioContext lock for it is taken in the wrapper.
*/
#define no_co_wrapper
#define no_co_wrapper_bdrv_rdlock
#define no_co_wrapper_bdrv_wrlock

#include "block/blockjob.h"
Expand Down
10 changes: 7 additions & 3 deletions scripts/block-coroutine-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def __init__(self, wrapper_type: str, return_type: str, name: str,
raise ValueError(f"Invalid no_co function name: {self.name}")
if not self.create_only_co:
raise ValueError(f"no_co function can't be mixed: {self.name}")
if self.graph_rdlock:
raise ValueError(f"no_co function can't be rdlock: {self.name}")
if self.graph_rdlock and self.graph_wrlock:
raise ValueError("function can't be both rdlock and wrlock: "
f"{self.name}")
self.target_name = f'{subsystem}_{subname}'

self.ctx = self.gen_ctx()
Expand Down Expand Up @@ -256,7 +257,10 @@ def gen_no_co_wrapper(func: FuncDecl) -> str:

graph_lock=''
graph_unlock=''
if func.graph_wrlock:
if func.graph_rdlock:
graph_lock=' bdrv_graph_rdlock_main_loop();'
graph_unlock=' bdrv_graph_rdunlock_main_loop();'
elif func.graph_wrlock:
graph_lock=' bdrv_graph_wrlock(NULL);'
graph_unlock=' bdrv_graph_wrunlock();'

Expand Down

0 comments on commit e84c07b

Please sign in to comment.