[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 04/11] bdrv_child_try_change_aio_context: add transaction para
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH v2 04/11] bdrv_child_try_change_aio_context: add transaction parameter |
Date: |
Mon, 25 Jul 2022 08:21:13 -0400 |
This enables the caller to use the same transaction to also
keep track of aiocontext changes.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block.c | 31 ++++++++++++++++++++++++------
include/block/block-global-state.h | 5 +++++
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index c02a628336..221bf90268 100644
--- a/block.c
+++ b/block.c
@@ -7643,17 +7643,16 @@ int bdrv_child_try_set_aio_context(BlockDriverState
*bs, AioContext *ctx,
* For the same reason, it temporarily holds also the new AioContext, since
* bdrv_drained_end calls BDRV_POLL_WHILE that assumes the lock is taken too.
*/
-int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ctx,
- BdrvChild *ignore_child, Error **errp)
+int bdrv_child_try_change_aio_context_tran(BlockDriverState *bs,
+ AioContext *ctx,
+ BdrvChild *ignore_child,
+ Transaction *tran,
+ Error **errp)
{
- Transaction *tran;
GHashTable *visited;
int ret;
- AioContext *old_context = bdrv_get_aio_context(bs);
GLOBAL_STATE_CODE();
- /* Recursion phase: go through all nodes of the graph */
- tran = tran_new();
visited = g_hash_table_new(NULL, NULL);
if (ignore_child) {
g_hash_table_add(visited, ignore_child);
@@ -7661,6 +7660,26 @@ int bdrv_child_try_change_aio_context(BlockDriverState
*bs, AioContext *ctx,
ret = bdrv_change_aio_context(bs, ctx, visited, tran, errp);
g_hash_table_destroy(visited);
+ return ret;
+}
+
+/*
+ * See bdrv_child_try_change_aio_context_tran for invariants on
+ * AioContext locks.
+ */
+int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ctx,
+ BdrvChild *ignore_child, Error **errp)
+{
+ Transaction *tran;
+ int ret;
+ AioContext *old_context = bdrv_get_aio_context(bs);
+ GLOBAL_STATE_CODE();
+
+ /* Recursion phase: go through all nodes of the graph */
+ tran = tran_new();
+ ret = bdrv_child_try_change_aio_context_tran(bs, ctx, ignore_child, tran,
+ errp);
+
/* Linear phase: go through all callbacks collected in the transaction */
if (!ret) {
diff --git a/include/block/block-global-state.h
b/include/block/block-global-state.h
index ceecf0aa8e..1bd445b507 100644
--- a/include/block/block-global-state.h
+++ b/include/block/block-global-state.h
@@ -234,6 +234,11 @@ bool bdrv_child_change_aio_context(BdrvChild *c,
AioContext *ctx,
Error **errp);
int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ctx,
BdrvChild *ignore_child, Error **errp);
+int bdrv_child_try_change_aio_context_tran(BlockDriverState *bs,
+ AioContext *ctx,
+ BdrvChild *ignore_child,
+ Transaction *tran,
+ Error **errp);
int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz);
int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo);
--
2.31.1
- [PATCH v2 00/11] Refactor bdrv_try_set_aio_context using transactions, Emanuele Giuseppe Esposito, 2022/07/25
- [PATCH v2 04/11] bdrv_child_try_change_aio_context: add transaction parameter,
Emanuele Giuseppe Esposito <=
- [PATCH v2 10/11] block: rename bdrv_child_try_change_aio_context in bdrv_try_change_aio_context, Emanuele Giuseppe Esposito, 2022/07/25
- [PATCH v2 05/11] blockjob: implement .change_aio_ctx in child_job, Emanuele Giuseppe Esposito, 2022/07/25
- [PATCH v2 01/11] block.c: assert bs->aio_context is written under BQL and drains, Emanuele Giuseppe Esposito, 2022/07/25
- [PATCH v2 08/11] block: use the new _change_ API instead of _can_set_ and _set_, Emanuele Giuseppe Esposito, 2022/07/25
- [PATCH v2 07/11] block-backend: implement .change_aio_ctx in child_root, Emanuele Giuseppe Esposito, 2022/07/25
- [PATCH v2 06/11] block: implement .change_aio_ctx in child_of_bds, Emanuele Giuseppe Esposito, 2022/07/25
- [PATCH v2 09/11] block: remove all unused ->can_set_aio_ctx and ->set_aio_ctx callbacks, Emanuele Giuseppe Esposito, 2022/07/25
- [PATCH v2 02/11] block: use transactions as a replacement of ->{can_}set_aio_context(), Emanuele Giuseppe Esposito, 2022/07/25
- [PATCH v2 03/11] bdrv_change_aio_context: use hash table instead of list of visited nodes, Emanuele Giuseppe Esposito, 2022/07/25
- [PATCH v2 11/11] block: remove bdrv_try_set_aio_context and replace it with bdrv_try_change_aio_context, Emanuele Giuseppe Esposito, 2022/07/25