[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 06/21] block-coroutine-wrapper: Add no_co_wrapper_bdrv_wrlock
From: |
Kevin Wolf |
Subject: |
[PATCH v2 06/21] block-coroutine-wrapper: Add no_co_wrapper_bdrv_wrlock functions |
Date: |
Mon, 11 Sep 2023 11:46:05 +0200 |
Add a new wrapper type for GRAPH_WRLOCK functions that should be called
from coroutine context.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/block/block-common.h | 4 ++++
scripts/block-coroutine-wrapper.py | 11 +++++++++++
2 files changed, 15 insertions(+)
diff --git a/include/block/block-common.h b/include/block/block-common.h
index df5ffc8d09..3bbc5d9294 100644
--- a/include/block/block-common.h
+++ b/include/block/block-common.h
@@ -66,10 +66,14 @@
* 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.
+ *
* 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_wrlock
#include "block/blockjob.h"
diff --git a/scripts/block-coroutine-wrapper.py
b/scripts/block-coroutine-wrapper.py
index d4a183db61..fa01c06567 100644
--- a/scripts/block-coroutine-wrapper.py
+++ b/scripts/block-coroutine-wrapper.py
@@ -71,10 +71,13 @@ def __init__(self, wrapper_type: str, return_type: str,
name: str,
self.args = [ParamDecl(arg.strip()) for arg in args.split(',')]
self.create_only_co = 'mixed' not in variant
self.graph_rdlock = 'bdrv_rdlock' in variant
+ self.graph_wrlock = 'bdrv_wrlock' in variant
self.wrapper_type = wrapper_type
if wrapper_type == 'co':
+ if self.graph_wrlock:
+ raise ValueError(f"co function can't be wrlock: {self.name}")
subsystem, subname = self.name.split('_', 1)
self.target_name = f'{subsystem}_co_{subname}'
else:
@@ -250,6 +253,12 @@ def gen_no_co_wrapper(func: FuncDecl) -> str:
name = func.target_name
struct_name = func.struct_name
+ graph_lock=''
+ graph_unlock=''
+ if func.graph_wrlock:
+ graph_lock=' bdrv_graph_wrlock(NULL);'
+ graph_unlock=' bdrv_graph_wrunlock();'
+
return f"""\
/*
* Wrappers for {name}
@@ -266,9 +275,11 @@ def gen_no_co_wrapper(func: FuncDecl) -> str:
{struct_name} *s = opaque;
AioContext *ctx = {func.gen_ctx('s->')};
+{graph_lock}
aio_context_acquire(ctx);
{func.get_result}{name}({ func.gen_list('s->{name}') });
aio_context_release(ctx);
+{graph_unlock}
aio_co_wake(s->co);
}}
--
2.41.0
- [PATCH v2 00/21] Graph locking part 4 (node management), Kevin Wolf, 2023/09/11
- [PATCH v2 01/21] block: Remove unused BlockReopenQueueEntry.perms_checked, Kevin Wolf, 2023/09/11
- [PATCH v2 02/21] preallocate: Factor out preallocate_truncate_to_real_size(), Kevin Wolf, 2023/09/11
- [PATCH v2 03/21] preallocate: Don't poll during permission updates, Kevin Wolf, 2023/09/11
- [PATCH v2 06/21] block-coroutine-wrapper: Add no_co_wrapper_bdrv_wrlock functions,
Kevin Wolf <=
- [PATCH v2 07/21] block-coroutine-wrapper: Allow arbitrary parameter names, Kevin Wolf, 2023/09/11
- [PATCH v2 04/21] block: Take AioContext lock for bdrv_append() more consistently, Kevin Wolf, 2023/09/11
- [PATCH v2 05/21] block: Introduce bdrv_schedule_unref(), Kevin Wolf, 2023/09/11
- [PATCH v2 09/21] block: Mark bdrv_replace_child_tran() GRAPH_WRLOCK, Kevin Wolf, 2023/09/11
- [PATCH v2 08/21] block: Mark bdrv_replace_child_noperm() GRAPH_WRLOCK, Kevin Wolf, 2023/09/11
- [PATCH v2 11/21] block: Call transaction callbacks with lock held, Kevin Wolf, 2023/09/11
- [PATCH v2 12/21] block: Mark bdrv_attach_child() GRAPH_WRLOCK, Kevin Wolf, 2023/09/11
- [PATCH v2 10/21] block: Mark bdrv_attach_child_common() GRAPH_WRLOCK, Kevin Wolf, 2023/09/11
- [PATCH v2 14/21] block: Mark bdrv_get_cumulative_perm() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/11