Skip to content

Commit

Permalink
block: GRAPH_RDLOCK for functions only called by co_wrappers
Browse files Browse the repository at this point in the history
The generated coroutine wrappers already take care to take the lock in
the non-coroutine path, and assume that the lock is already taken in the
coroutine path.

The only thing we need to do for the wrapped function is adding the
GRAPH_RDLOCK annotation. Doing so also allows us to mark the
corresponding callbacks in BlockDriver as GRAPH_RDLOCK_PTR.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-19-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
kevmw committed Dec 14, 2022
1 parent 1ad1fce commit 2ad19e5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions block.c
Expand Up @@ -5402,6 +5402,7 @@ int coroutine_fn bdrv_co_check(BlockDriverState *bs,
BdrvCheckResult *res, BdrvCheckMode fix)
{
IO_CODE();
assert_bdrv_graph_readable();
if (bs->drv == NULL) {
return -ENOMEDIUM;
}
Expand Down Expand Up @@ -6617,6 +6618,7 @@ int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp)
IO_CODE();

assert(!(bs->open_flags & BDRV_O_INACTIVE));
assert_bdrv_graph_readable();

if (bs->drv->bdrv_co_invalidate_cache) {
bs->drv->bdrv_co_invalidate_cache(bs, &local_err);
Expand Down
17 changes: 10 additions & 7 deletions block/coroutines.h
Expand Up @@ -37,9 +37,11 @@
* the I/O API.
*/

int coroutine_fn bdrv_co_check(BlockDriverState *bs,
BdrvCheckResult *res, BdrvCheckMode fix);
int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp);
int coroutine_fn GRAPH_RDLOCK
bdrv_co_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);

int coroutine_fn GRAPH_RDLOCK
bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp);

int coroutine_fn
bdrv_co_common_block_status_above(BlockDriverState *bs,
Expand All @@ -53,10 +55,11 @@ bdrv_co_common_block_status_above(BlockDriverState *bs,
BlockDriverState **file,
int *depth);

int coroutine_fn bdrv_co_readv_vmstate(BlockDriverState *bs,
QEMUIOVector *qiov, int64_t pos);
int coroutine_fn bdrv_co_writev_vmstate(BlockDriverState *bs,
QEMUIOVector *qiov, int64_t pos);
int coroutine_fn GRAPH_RDLOCK
bdrv_co_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);

int coroutine_fn GRAPH_RDLOCK
bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);

int coroutine_fn
nbd_co_do_establish_connection(BlockDriverState *bs, bool blocking,
Expand Down
2 changes: 2 additions & 0 deletions block/io.c
Expand Up @@ -2697,6 +2697,7 @@ bdrv_co_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
BlockDriverState *child_bs = bdrv_primary_bs(bs);
int ret;
IO_CODE();
assert_bdrv_graph_readable();

ret = bdrv_check_qiov_request(pos, qiov->size, qiov, 0, NULL);
if (ret < 0) {
Expand Down Expand Up @@ -2729,6 +2730,7 @@ bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
BlockDriverState *child_bs = bdrv_primary_bs(bs);
int ret;
IO_CODE();
assert_bdrv_graph_readable();

ret = bdrv_check_qiov_request(pos, qiov->size, qiov, 0, NULL);
if (ret < 0) {
Expand Down
20 changes: 9 additions & 11 deletions include/block/block_int-common.h
Expand Up @@ -641,8 +641,8 @@ struct BlockDriver {
/*
* Invalidate any cached meta-data.
*/
void coroutine_fn (*bdrv_co_invalidate_cache)(BlockDriverState *bs,
Error **errp);
void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_invalidate_cache)(
BlockDriverState *bs, Error **errp);

/*
* Flushes all data for all layers by calling bdrv_co_flush for underlying
Expand Down Expand Up @@ -701,12 +701,11 @@ struct BlockDriver {
Error **errp);
BlockStatsSpecific *(*bdrv_get_specific_stats)(BlockDriverState *bs);

int coroutine_fn (*bdrv_save_vmstate)(BlockDriverState *bs,
QEMUIOVector *qiov,
int64_t pos);
int coroutine_fn (*bdrv_load_vmstate)(BlockDriverState *bs,
QEMUIOVector *qiov,
int64_t pos);
int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_save_vmstate)(
BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);

int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_load_vmstate)(
BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);

/* removable device specific */
bool (*bdrv_is_inserted)(BlockDriverState *bs);
Expand All @@ -724,9 +723,8 @@ struct BlockDriver {
* Returns 0 for completed check, -errno for internal errors.
* The check results are stored in result.
*/
int coroutine_fn (*bdrv_co_check)(BlockDriverState *bs,
BdrvCheckResult *result,
BdrvCheckMode fix);
int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_check)(
BlockDriverState *bs, BdrvCheckResult *result, BdrvCheckMode fix);

void (*bdrv_debug_event)(BlockDriverState *bs, BlkdebugEvent event);

Expand Down

0 comments on commit 2ad19e5

Please sign in to comment.