block: Add missing GRAPH_RDLOCK annotations

This adds GRAPH_RDLOCK to some driver callbacks that are already called
with the graph lock held, and which will need the annotation because
they access bs->file, but don't have it yet.

This also covers a few callbacks that were not marked GRAPH_RDLOCK
before, but where updating BlockDriver is trivially possible.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20231027155333.420094-21-kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Kevin Wolf 2023-10-27 17:53:29 +02:00
parent e2dd273754
commit 79a5586648
16 changed files with 55 additions and 60 deletions

View File

@ -746,13 +746,10 @@ blkdebug_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes)
return bdrv_co_pdiscard(bs->file, offset, bytes); return bdrv_co_pdiscard(bs->file, offset, bytes);
} }
static int coroutine_fn blkdebug_co_block_status(BlockDriverState *bs, static int coroutine_fn GRAPH_RDLOCK
bool want_zero, blkdebug_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset,
int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map,
int64_t bytes, BlockDriverState **file)
int64_t *pnum,
int64_t *map,
BlockDriverState **file)
{ {
int err; int err;
@ -973,7 +970,7 @@ blkdebug_co_getlength(BlockDriverState *bs)
return bdrv_co_getlength(bs->file->bs); return bdrv_co_getlength(bs->file->bs);
} }
static void blkdebug_refresh_filename(BlockDriverState *bs) static void GRAPH_RDLOCK blkdebug_refresh_filename(BlockDriverState *bs)
{ {
BDRVBlkdebugState *s = bs->opaque; BDRVBlkdebugState *s = bs->opaque;
const QDictEntry *e; const QDictEntry *e;

View File

@ -288,7 +288,7 @@ blkverify_recurse_can_replace(BlockDriverState *bs,
bdrv_recurse_can_replace(s->test_file->bs, to_replace); bdrv_recurse_can_replace(s->test_file->bs, to_replace);
} }
static void blkverify_refresh_filename(BlockDriverState *bs) static void GRAPH_RDLOCK blkverify_refresh_filename(BlockDriverState *bs)
{ {
BDRVBlkverifyState *s = bs->opaque; BDRVBlkverifyState *s = bs->opaque;

View File

@ -335,7 +335,7 @@ cbw_co_pdiscard_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes)
return bdrv_co_pdiscard(s->target, offset, bytes); return bdrv_co_pdiscard(s->target, offset, bytes);
} }
static void cbw_refresh_filename(BlockDriverState *bs) static void GRAPH_RDLOCK cbw_refresh_filename(BlockDriverState *bs)
{ {
pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), pstrcpy(bs->exact_filename, sizeof(bs->exact_filename),
bs->file->bs->filename); bs->file->bs->filename);

View File

@ -97,7 +97,8 @@ compress_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes)
} }
static void compress_refresh_limits(BlockDriverState *bs, Error **errp) static void GRAPH_RDLOCK
compress_refresh_limits(BlockDriverState *bs, Error **errp)
{ {
BlockDriverInfo bdi; BlockDriverInfo bdi;
int ret; int ret;

View File

@ -3685,6 +3685,8 @@ out:
void bdrv_cancel_in_flight(BlockDriverState *bs) void bdrv_cancel_in_flight(BlockDriverState *bs)
{ {
GLOBAL_STATE_CODE(); GLOBAL_STATE_CODE();
GRAPH_RDLOCK_GUARD_MAINLOOP();
if (!bs || !bs->drv) { if (!bs || !bs->drv) {
return; return;
} }

View File

@ -415,14 +415,10 @@ parallels_co_flush_to_os(BlockDriverState *bs)
return 0; return 0;
} }
static int coroutine_fn GRAPH_RDLOCK
static int coroutine_fn parallels_co_block_status(BlockDriverState *bs, parallels_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset,
bool want_zero, int64_t bytes, int64_t *pnum, int64_t *map,
int64_t offset, BlockDriverState **file)
int64_t bytes,
int64_t *pnum,
int64_t *map,
BlockDriverState **file)
{ {
BDRVParallelsState *s = bs->opaque; BDRVParallelsState *s = bs->opaque;
int count; int count;

View File

@ -541,8 +541,8 @@ static void preallocate_drop_resize_bh(void *opaque)
preallocate_drop_resize(opaque, NULL); preallocate_drop_resize(opaque, NULL);
} }
static void preallocate_set_perm(BlockDriverState *bs, static void GRAPH_RDLOCK
uint64_t perm, uint64_t shared) preallocate_set_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared)
{ {
BDRVPreallocateState *s = bs->opaque; BDRVPreallocateState *s = bs->opaque;

View File

@ -1024,7 +1024,7 @@ fail:
return ret; return ret;
} }
static int qcow_make_empty(BlockDriverState *bs) static int GRAPH_RDLOCK qcow_make_empty(BlockDriverState *bs)
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState *s = bs->opaque;
uint32_t l1_length = s->l1_size * sizeof(uint64_t); uint32_t l1_length = s->l1_size * sizeof(uint64_t);

View File

@ -5226,8 +5226,8 @@ qcow2_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
return 0; return 0;
} }
static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs, static ImageInfoSpecific * GRAPH_RDLOCK
Error **errp) qcow2_get_specific_info(BlockDriverState *bs, Error **errp)
{ {
BDRVQcow2State *s = bs->opaque; BDRVQcow2State *s = bs->opaque;
ImageInfoSpecific *spec_info; ImageInfoSpecific *spec_info;

View File

@ -972,11 +972,12 @@ int GRAPH_RDLOCK
qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id, qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id,
const char *name, Error **errp); const char *name, Error **errp);
int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab); int GRAPH_RDLOCK
int qcow2_snapshot_load_tmp(BlockDriverState *bs, qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
const char *snapshot_id,
const char *name, int GRAPH_RDLOCK
Error **errp); qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_id,
const char *name, Error **errp);
void qcow2_free_snapshots(BlockDriverState *bs); void qcow2_free_snapshots(BlockDriverState *bs);
int coroutine_fn GRAPH_RDLOCK int coroutine_fn GRAPH_RDLOCK

View File

@ -1443,12 +1443,10 @@ bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes,
QED_AIOCB_WRITE | QED_AIOCB_ZERO); QED_AIOCB_WRITE | QED_AIOCB_ZERO);
} }
static int coroutine_fn bdrv_qed_co_truncate(BlockDriverState *bs, static int coroutine_fn GRAPH_RDLOCK
int64_t offset, bdrv_qed_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
bool exact, PreallocMode prealloc, BdrvRequestFlags flags,
PreallocMode prealloc, Error **errp)
BdrvRequestFlags flags,
Error **errp)
{ {
BDRVQEDState *s = bs->opaque; BDRVQEDState *s = bs->opaque;
uint64_t old_image_size; uint64_t old_image_size;

View File

@ -279,11 +279,10 @@ fail:
return ret; return ret;
} }
static int coroutine_fn raw_co_block_status(BlockDriverState *bs, static int coroutine_fn GRAPH_RDLOCK
bool want_zero, int64_t offset, raw_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset,
int64_t bytes, int64_t *pnum, int64_t bytes, int64_t *pnum, int64_t *map,
int64_t *map, BlockDriverState **file)
BlockDriverState **file)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
*pnum = bytes; *pnum = bytes;
@ -397,7 +396,7 @@ raw_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
return bdrv_co_get_info(bs->file->bs, bdi); return bdrv_co_get_info(bs->file->bs, bdi);
} }
static void raw_refresh_limits(BlockDriverState *bs, Error **errp) static void GRAPH_RDLOCK raw_refresh_limits(BlockDriverState *bs, Error **errp)
{ {
bs->bl.has_variable_length = bs->file->bs->bl.has_variable_length; bs->bl.has_variable_length = bs->file->bs->bl.has_variable_length;
@ -561,7 +560,8 @@ raw_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz)
return 0; return 0;
} }
static int raw_probe_geometry(BlockDriverState *bs, HDGeometry *geo) static int GRAPH_RDLOCK
raw_probe_geometry(BlockDriverState *bs, HDGeometry *geo)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
if (s->offset || s->has_size) { if (s->offset || s->has_size) {
@ -611,7 +611,7 @@ static const char *const raw_strong_runtime_opts[] = {
NULL NULL
}; };
static void raw_cancel_in_flight(BlockDriverState *bs) static void GRAPH_RDLOCK raw_cancel_in_flight(BlockDriverState *bs)
{ {
bdrv_cancel_in_flight(bs->file->bs); bdrv_cancel_in_flight(bs->file->bs);
} }

View File

@ -73,7 +73,7 @@ snapshot_access_co_pwritev_part(BlockDriverState *bs,
} }
static void snapshot_access_refresh_filename(BlockDriverState *bs) static void GRAPH_RDLOCK snapshot_access_refresh_filename(BlockDriverState *bs)
{ {
pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), pstrcpy(bs->exact_filename, sizeof(bs->exact_filename),
bs->file->bs->filename); bs->file->bs->filename);

View File

@ -520,11 +520,10 @@ static int vdi_reopen_prepare(BDRVReopenState *state,
return 0; return 0;
} }
static int coroutine_fn vdi_co_block_status(BlockDriverState *bs, static int coroutine_fn GRAPH_RDLOCK
bool want_zero, vdi_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset,
int64_t offset, int64_t bytes, int64_t bytes, int64_t *pnum, int64_t *map,
int64_t *pnum, int64_t *map, BlockDriverState **file)
BlockDriverState **file)
{ {
BDRVVdiState *s = (BDRVVdiState *)bs->opaque; BDRVVdiState *s = (BDRVVdiState *)bs->opaque;
size_t bmap_index = offset / s->block_size; size_t bmap_index = offset / s->block_size;

View File

@ -2163,9 +2163,9 @@ fail:
* r/w and any log has already been replayed, so there is nothing (currently) * r/w and any log has already been replayed, so there is nothing (currently)
* for us to do here * for us to do here
*/ */
static int coroutine_fn vhdx_co_check(BlockDriverState *bs, static int coroutine_fn GRAPH_RDLOCK
BdrvCheckResult *result, vhdx_co_check(BlockDriverState *bs, BdrvCheckResult *result,
BdrvCheckMode fix) BdrvCheckMode fix)
{ {
BDRVVHDXState *s = bs->opaque; BDRVVHDXState *s = bs->opaque;

View File

@ -310,7 +310,7 @@ struct BlockDriver {
* One example usage is to avoid waiting for an nbd target node reconnect * One example usage is to avoid waiting for an nbd target node reconnect
* timeout during job-cancel with force=true. * timeout during job-cancel with force=true.
*/ */
void (*bdrv_cancel_in_flight)(BlockDriverState *bs); void GRAPH_RDLOCK_PTR (*bdrv_cancel_in_flight)(BlockDriverState *bs);
int GRAPH_RDLOCK_PTR (*bdrv_inactivate)(BlockDriverState *bs); int GRAPH_RDLOCK_PTR (*bdrv_inactivate)(BlockDriverState *bs);
@ -324,12 +324,12 @@ struct BlockDriver {
BlockDriverState *bs, const char *snapshot_id, const char *name, BlockDriverState *bs, const char *snapshot_id, const char *name,
Error **errp); Error **errp);
int (*bdrv_snapshot_list)(BlockDriverState *bs, int GRAPH_RDLOCK_PTR (*bdrv_snapshot_list)(
QEMUSnapshotInfo **psn_info); BlockDriverState *bs, QEMUSnapshotInfo **psn_info);
int (*bdrv_snapshot_load_tmp)(BlockDriverState *bs,
const char *snapshot_id, int GRAPH_RDLOCK_PTR (*bdrv_snapshot_load_tmp)(
const char *name, BlockDriverState *bs, const char *snapshot_id, const char *name,
Error **errp); Error **errp);
int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_change_backing_file)( int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_change_backing_file)(
BlockDriverState *bs, const char *backing_file, BlockDriverState *bs, const char *backing_file,
@ -396,7 +396,8 @@ struct BlockDriver {
* Only drivers that want to override guest geometry implement this * Only drivers that want to override guest geometry implement this
* callback; see hd_geometry_guess(). * callback; see hd_geometry_guess().
*/ */
int (*bdrv_probe_geometry)(BlockDriverState *bs, HDGeometry *geo); int GRAPH_RDLOCK_PTR (*bdrv_probe_geometry)(
BlockDriverState *bs, HDGeometry *geo);
void GRAPH_WRLOCK_PTR (*bdrv_add_child)( void GRAPH_WRLOCK_PTR (*bdrv_add_child)(
BlockDriverState *parent, BlockDriverState *child, Error **errp); BlockDriverState *parent, BlockDriverState *child, Error **errp);