[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/11] block: Make bdrv_child_get_parent_aio_context I/O
From: |
Kevin Wolf |
Subject: |
[PULL 08/11] block: Make bdrv_child_get_parent_aio_context I/O |
Date: |
Fri, 11 Nov 2022 16:27:41 +0100 |
From: Hanna Reitz <hreitz@redhat.com>
We want to use bdrv_child_get_parent_aio_context() from
bdrv_parent_drained_{begin,end}_single(), both of which are "I/O or GS"
functions.
Prior to 3ed4f708fe1, all the implementations were I/O code anyway.
3ed4f708fe1 has put block jobs' AioContext field under the job mutex, so
to make child_job_get_parent_aio_context() work in an I/O context, we
need to take that lock there.
Furthermore, blk_root_get_parent_aio_context() is not marked as
anything, but is safe to run in an I/O context, so mark it that way now.
(blk_get_aio_context() is an I/O code function.)
With that done, all implementations explicitly are I/O code, so we can
mark bdrv_child_get_parent_aio_context() as I/O code, too, so callers
know it is safe to run from both GS and I/O contexts.
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221107151321.211175-2-hreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/block/block-global-state.h | 1 -
include/block/block-io.h | 2 ++
include/block/block_int-common.h | 4 ++--
block.c | 2 +-
block/block-backend.c | 1 +
blockjob.c | 3 ++-
6 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/include/block/block-global-state.h
b/include/block/block-global-state.h
index bb42ed9559..c7bd4a2088 100644
--- a/include/block/block-global-state.h
+++ b/include/block/block-global-state.h
@@ -220,7 +220,6 @@ void coroutine_fn bdrv_co_lock(BlockDriverState *bs);
*/
void coroutine_fn bdrv_co_unlock(BlockDriverState *bs);
-AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c);
bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx,
GHashTable *visited, Transaction *tran,
Error **errp);
diff --git a/include/block/block-io.h b/include/block/block-io.h
index 770ddeb7c8..b099d7db45 100644
--- a/include/block/block-io.h
+++ b/include/block/block-io.h
@@ -171,6 +171,8 @@ void bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent
event);
*/
AioContext *bdrv_get_aio_context(BlockDriverState *bs);
+AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c);
+
/**
* Move the current coroutine to the AioContext of @bs and return the old
* AioContext of the coroutine. Increase bs->in_flight so that draining @bs
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
index 5a2cc077a0..31ae91e56e 100644
--- a/include/block/block_int-common.h
+++ b/include/block/block_int-common.h
@@ -911,8 +911,6 @@ struct BdrvChildClass {
GHashTable *visited, Transaction *tran,
Error **errp);
- AioContext *(*get_parent_aio_context)(BdrvChild *child);
-
/*
* I/O API functions. These functions are thread-safe.
*
@@ -929,6 +927,8 @@ struct BdrvChildClass {
*/
const char *(*get_name)(BdrvChild *child);
+ AioContext *(*get_parent_aio_context)(BdrvChild *child);
+
/*
* If this pair of functions is implemented, the parent doesn't issue new
* requests after returning from .drained_begin() until .drained_end() is
diff --git a/block.c b/block.c
index c5e20c0bea..a18f052374 100644
--- a/block.c
+++ b/block.c
@@ -1543,7 +1543,7 @@ const BdrvChildClass child_of_bds = {
AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c)
{
- GLOBAL_STATE_CODE();
+ IO_CODE();
return c->klass->get_parent_aio_context(c);
}
diff --git a/block/block-backend.c b/block/block-backend.c
index c0c7d56c8d..ed2f4b67a2 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -311,6 +311,7 @@ static void blk_root_detach(BdrvChild *child)
static AioContext *blk_root_get_parent_aio_context(BdrvChild *c)
{
BlockBackend *blk = c->opaque;
+ IO_CODE();
return blk_get_aio_context(blk);
}
diff --git a/blockjob.c b/blockjob.c
index 2d86014fa5..f51d4e18f3 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -173,7 +173,8 @@ static bool child_job_change_aio_ctx(BdrvChild *c,
AioContext *ctx,
static AioContext *child_job_get_parent_aio_context(BdrvChild *c)
{
BlockJob *job = c->opaque;
- GLOBAL_STATE_CODE();
+ IO_CODE();
+ JOB_LOCK_GUARD();
return job->job.aio_context;
}
--
2.38.1
- [PULL 00/11] Block layer patches, Kevin Wolf, 2022/11/11
- [PULL 03/11] block/mirror: Fix NULL s->job in active writes, Kevin Wolf, 2022/11/11
- [PULL 04/11] iotests/151: Test that active mirror progresses, Kevin Wolf, 2022/11/11
- [PULL 02/11] block/mirror: Drop mirror_wait_for_any_operation(), Kevin Wolf, 2022/11/11
- [PULL 01/11] block/mirror: Do not wait for active writes, Kevin Wolf, 2022/11/11
- [PULL 06/11] qapi/block-core: Fix BlockdevOptionsNvmeIoUring @path description, Kevin Wolf, 2022/11/11
- [PULL 05/11] iotests/151: Test active requests on mirror start, Kevin Wolf, 2022/11/11
- [PULL 07/11] block/blkio: Set BlockDriver::has_variable_length to false, Kevin Wolf, 2022/11/11
- [PULL 08/11] block: Make bdrv_child_get_parent_aio_context I/O,
Kevin Wolf <=
- [PULL 09/11] block-backend: Update ctx immediately after root, Kevin Wolf, 2022/11/11
- [PULL 11/11] tests/stream-under-throttle: New test, Kevin Wolf, 2022/11/11
- [PULL 10/11] block: Start/end drain on correct AioContext, Kevin Wolf, 2022/11/11
- Re: [PULL 00/11] Block layer patches, Stefan Hajnoczi, 2022/11/11