Skip to content

Commit

Permalink
block: Make bdrv_child_get_parent_aio_context I/O
Browse files Browse the repository at this point in the history
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 3ed4f70, all the implementations were I/O code anyway.
3ed4f70 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 <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Kevin Wolf <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
XanClic authored and kevmw committed Nov 10, 2022
1 parent e56b0c6 commit d5f8d79
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions block/block-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion blockjob.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion include/block/block-global-state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions include/block/block-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions include/block/block_int-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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
Expand Down

0 comments on commit d5f8d79

Please sign in to comment.