[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 02/22] block-coroutine-wrapper: Add no_co_wrapper_bdrv_rdlock fun
From: |
Kevin Wolf |
Subject: |
[PATCH 02/22] block-coroutine-wrapper: Add no_co_wrapper_bdrv_rdlock functions |
Date: |
Fri, 29 Sep 2023 16:51:37 +0200 |
Add a new wrapper type for GRAPH_RDLOCK functions that should be called
from coroutine context.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/block/block-common.h | 7 +++++--
scripts/block-coroutine-wrapper.py | 10 +++++++---
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/include/block/block-common.h b/include/block/block-common.h
index 2d2af7230d..d7599564db 100644
--- a/include/block/block-common.h
+++ b/include/block/block-common.h
@@ -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"
diff --git a/scripts/block-coroutine-wrapper.py
b/scripts/block-coroutine-wrapper.py
index 685d0b4ed4..a601c3c672 100644
--- a/scripts/block-coroutine-wrapper.py
+++ b/scripts/block-coroutine-wrapper.py
@@ -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()
@@ -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();'
--
2.41.0
- [PATCH 00/22] block: Graph locking part 5 (protect children/parent links), Kevin Wolf, 2023/09/29
- [PATCH 03/22] block: Take graph rdlock in bdrv_inactivate_all(), Kevin Wolf, 2023/09/29
- [PATCH 02/22] block-coroutine-wrapper: Add no_co_wrapper_bdrv_rdlock functions,
Kevin Wolf <=
- [PATCH 01/22] test-bdrv-drain: Don't call bdrv_graph_wrlock() in coroutine context, Kevin Wolf, 2023/09/29
- [PATCH 04/22] block: Mark bdrv_first_blk() and bdrv_is_root_node() GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 06/22] block: Mark bdrv_parent_cb_resize() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 05/22] block: Mark drain related functions GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 09/22] block: Mark bdrv_get_xdbg_block_graph() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 08/22] block: Take graph rdlock in parts of reopen, Kevin Wolf, 2023/09/29
- [PATCH 10/22] block: Mark bdrv_refresh_filename() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 11/22] block: Mark bdrv_primary_child() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 12/22] block: Mark bdrv_get_parent_name() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 07/22] block: Mark bdrv_snapshot_fallback() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29