block: Lock the graph, part 2 (BlockDriver callbacks)
PATCH 3/23 block: Mark bdrv_co_truncate() and callers GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_truncate() need to hold a reader lock for the graph.
For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated.
--- include/block/block-io.h | 6 +++--- include/block/block_int-common.h | 7 ++++--- block/block-backend.c | 1 + block/crypto.c | 2 +- block/io.c | 1 + block/parallels.c | 14 ++++++++------ block/preallocate.c | 2 +- block/qcow.c | 17 ++++++++++++----- block/qcow2.c | 14 ++++++++------ block/raw-format.c | 6 +++--- block/vmdk.c | 2 ++ 11 files changed, 44 insertions(+), 28 deletions(-)
include/block/block-io.h +3 -3
@@ -72,9 +72,9 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset, int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset,int64_t bytes,BdrvRequestFlags flags); -int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact, -PreallocMode prealloc,BdrvRequestFlags flags, -Error **errp); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_truncate (BdrvChild *child,int64_t offset,bool exact, +PreallocMode prealloc,BdrvRequestFlags flags,Error **errp); int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs); int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState *bs);
include/block/block_int-common.h +4 -3
@@ -677,9 +677,10 @@ struct BlockDriver {* If @exact is true and this function fails but would succeed * with @exact = false, it should return -ENOTSUP. */ - int coroutine_fn (*bdrv_co_truncate)(BlockDriverState *bs, int64_t offset, -bool exact,PreallocMode prealloc, -BdrvRequestFlags flags,Error **errp); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_truncate)( +BlockDriverState *bs,int64_t offset,bool exact, +PreallocMode prealloc,BdrvRequestFlags flags,Error **errp); + int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs); int64_t coroutine_fn (*bdrv_co_get_allocated_file_size)(BlockDriverState *bs);
block/block-backend.c +1 -0
@@ -2372,6 +2372,7 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact, Error **errp) {IO_OR_GS_CODE (); +GRAPH_RDLOCK_GUARD ();if (!blk_is_available (blk)) {error_setg (errp,"No medium inserted" );return -ENOMEDIUM ;
block/crypto.c +1 -1
@@ -360,7 +360,7 @@ static int block_crypto_co_create_generic(BlockDriverState *bs,return ret; } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblock_crypto_co_truncate (BlockDriverState *bs,int64_t offset,bool exact,PreallocMode prealloc,BdrvRequestFlags flags,Error **errp)
block/io.c +1 -0
@@ -3377,6 +3377,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,int64_t old_size, new_bytes;int ret;IO_CODE (); +assert_bdrv_graph_readable ();/* if bs->drv == NULL, bs is closed, so there's nothing to do here */ if (!drv) {
block/parallels.c +8 -6
@@ -165,9 +165,9 @@ static int64_t block_status(BDRVParallelsState *s, int64_t sector_num,return start_off; } -static coroutine_fn int64_t allocate_clusters(BlockDriverState *bs, -int64_t sector_num, -int nb_sectors,int *pnum) +static int64_t coroutine_fn GRAPH_RDLOCK +allocate_clusters (BlockDriverState *bs,int64_t sector_num, +int nb_sectors,int *pnum) {int ret =0 ;BDRVParallelsState *s = bs->opaque;
@@ -329,6 +329,8 @@ static coroutine_fn int parallels_co_writev(BlockDriverState *bs,QEMUIOVector hd_qiov;int ret =0 ; +assume_graph_lock ();/* FIXME */ +qemu_iovec_init (&hd_qiov, qiov->niov);while (nb_sectors >0 ) {
@@ -414,9 +416,9 @@ static coroutine_fn int parallels_co_readv(BlockDriverState *bs, } -static int coroutine_fn parallels_co_check(BlockDriverState *bs, -BdrvCheckResult *res, -BdrvCheckMode fix) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_check (BlockDriverState *bs,BdrvCheckResult *res, +BdrvCheckMode fix) {BDRVParallelsState *s = bs->opaque;int64_t size, prev_off, high_off;
block/preallocate.c +1 -1
@@ -370,7 +370,7 @@ static coroutine_fn int preallocate_co_pwritev_part(BlockDriverState *bs, flags); } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKpreallocate_co_truncate (BlockDriverState *bs,int64_t offset,bool exact,PreallocMode prealloc,BdrvRequestFlags flags,Error **errp)
block/qcow.c +12 -5
@@ -350,11 +350,10 @@ static int qcow_reopen_prepare(BDRVReopenState *state,* return 0 if not allocated, 1 if *result is assigned, and negative * errno on failure. */ -static int coroutine_fn get_cluster_offset(BlockDriverState *bs, -uint64_t offset,int allocate, -int compressed_size, -int n_start,int n_end, -uint64_t *result) +static int coroutine_fn GRAPH_RDLOCK +get_cluster_offset (BlockDriverState *bs,uint64_t offset,int allocate, +int compressed_size,int n_start,int n_end, +uint64_t *result) {BDRVQcowState *s = bs->opaque;int min_index, i, j, l1_index, l2_index, ret;
@@ -536,6 +535,8 @@ static int coroutine_fn qcow_co_block_status(BlockDriverState *bs,int64_t n;uint64_t cluster_offset; +assume_graph_lock ();/* FIXME */ +qemu_co_mutex_lock (&s->lock); ret =get_cluster_offset (bs, offset,0 ,0 ,0 ,0 , &cluster_offset);qemu_co_mutex_unlock (&s->lock);
@@ -630,6 +631,8 @@ static coroutine_fn int qcow_co_preadv(BlockDriverState *bs, int64_t offset,uint8_t *buf;void *orig_buf; +assume_graph_lock ();/* FIXME */ +if (qiov->niov >1 ) { buf = orig_buf =qemu_try_blockalign (bs, qiov->size);if (buf ==NULL ) {
@@ -726,6 +729,8 @@ static coroutine_fn int qcow_co_pwritev(BlockDriverState *bs, int64_t offset,uint8_t *buf;void *orig_buf; +assume_graph_lock ();/* FIXME */ + s->cluster_cache_offset =-1 ;/* disable compressed cache */ /* We must always copy the iov when encrypting, so we
@@ -1056,6 +1061,8 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes,uint8_t *buf, *out_buf;uint64_t cluster_offset; +assume_graph_lock ();/* FIXME */ + buf =qemu_blockalign (bs, s->cluster_size);if (bytes != s->cluster_size) { if (bytes > s->cluster_size ||
block/qcow2.c +8 -6
@@ -3183,9 +3183,9 @@ static int qcow2_set_up_encryption(BlockDriverState *bs,* * Returns: 0 on success, -errno on failure. */ -static int coroutine_fn preallocate_co(BlockDriverState *bs, uint64_t offset, -uint64_t new_length,PreallocMode mode, -Error **errp) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co (BlockDriverState *bs,uint64_t offset,uint64_t new_length, +PreallocMode mode,Error **errp) {BDRVQcow2State *s = bs->opaque;uint64_t bytes;
@@ -4209,9 +4209,9 @@ fail:return ret; } -static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset, -bool exact,PreallocMode prealloc, -BdrvRequestFlags flags,Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_truncate (BlockDriverState *bs,int64_t offset,bool exact, +PreallocMode prealloc,BdrvRequestFlags flags,Error **errp) {BDRVQcow2State *s = bs->opaque;uint64_t old_length;
@@ -4672,6 +4672,8 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs,AioTaskPool *aio =NULL ;int ret =0 ; +assume_graph_lock ();/* FIXME */ +if (has_data_file (bs)) {return -ENOTSUP ; }
block/raw-format.c +3 -3
@@ -384,9 +384,9 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) } } -static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset, -bool exact,PreallocMode prealloc, -BdrvRequestFlags flags,Error **errp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_truncate (BlockDriverState *bs,int64_t offset,bool exact, +PreallocMode prealloc,BdrvRequestFlags flags,Error **errp) {BDRVRawState *s = bs->opaque;
block/vmdk.c +2 -0
@@ -2130,6 +2130,8 @@ static int coroutine_fn vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov) { +assume_graph_lock ();/* FIXME */ +if (bytes ==0 ) {/* The caller will write bytes 0 to signal EOF. * When receive it, we align EOF to a sector boundary. */
Signature · 1 line
2.38.1
PATCH 19/23 block: Mark bdrv_co_eject/lock_medium() and callers GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_eject() and bdrv_co_lock_medium() need to hold a reader lock for the graph.
--- include/block/block-io.h | 7 +++++-- include/block/block_int-common.h | 6 ++++-- block.c | 2 ++ block/block-backend.c | 2 ++ block/copy-on-read.c | 6 ++++-- block/filter-compress.c | 4 ++-- block/raw-format.c | 6 ++++-- 7 files changed, 23 insertions(+), 10 deletions(-)
include/block/block-io.h +5 -2
@@ -148,8 +148,11 @@ int bdrv_get_flags(BlockDriverState *bs); bool coroutine_fn GRAPH_RDLOCK bdrv_co_is_inserted(BlockDriverState *bs); bool co_wrapper_bdrv_rdlock bdrv_is_inserted(BlockDriverState *bs); -void coroutine_fn bdrv_co_lock_medium(BlockDriverState *bs, bool locked); -void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag); +void coroutine_fn GRAPH_RDLOCK +bdrv_co_lock_medium (BlockDriverState *bs,bool locked); + +void coroutine_fn GRAPH_RDLOCK +bdrv_co_eject (BlockDriverState *bs,bool eject_flag);const char *bdrv_get_format_name (BlockDriverState *bs);
include/block/block_int-common.h +4 -2
@@ -714,8 +714,10 @@ struct BlockDriver {/* removable device specific */ bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)( BlockDriverState *bs); - void coroutine_fn (*bdrv_co_eject)(BlockDriverState *bs, bool eject_flag); - void coroutine_fn (*bdrv_co_lock_medium)(BlockDriverState *bs, bool locked); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_eject)( +BlockDriverState *bs,bool eject_flag); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_lock_medium)( +BlockDriverState *bs,bool locked);/* to control generic scsi devices */ BlockAIOCB *coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_aio_ioctl)(
block.c +2 -0
@@ -6826,6 +6826,7 @@ void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag) {BlockDriver *drv = bs->drv;IO_CODE (); +assert_bdrv_graph_readable ();if (drv && drv->bdrv_co_eject) { drv->bdrv_co_eject (bs, eject_flag);
@@ -6840,6 +6841,7 @@ void coroutine_fn bdrv_co_lock_medium(BlockDriverState *bs, bool locked) {BlockDriver *drv = bs->drv;IO_CODE (); +assert_bdrv_graph_readable ();trace_bdrv_lock_medium (bs, locked);if (drv && drv->bdrv_co_lock_medium) {
block/block-backend.c +2 -0
@@ -2013,6 +2013,7 @@ void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked) {BlockDriverState *bs =blk_bs (blk);IO_CODE (); +GRAPH_RDLOCK_GUARD ();if (bs) {bdrv_co_lock_medium (bs, locked);
@@ -2024,6 +2025,7 @@ void coroutine_fn blk_co_eject(BlockBackend *blk, bool eject_flag)BlockDriverState *bs =blk_bs (blk);char *id;IO_CODE (); +GRAPH_RDLOCK_GUARD ();if (bs) {bdrv_co_eject (bs, eject_flag);
block/copy-on-read.c +4 -2
@@ -213,13 +213,15 @@ cor_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes, } -static void coroutine_fn cor_co_eject(BlockDriverState *bs, bool eject_flag) +static void coroutine_fn GRAPH_RDLOCK +cor_co_eject (BlockDriverState *bs,bool eject_flag) {bdrv_co_eject (bs->file->bs, eject_flag); } -static void coroutine_fn cor_co_lock_medium(BlockDriverState *bs, bool locked) +static void coroutine_fn GRAPH_RDLOCK +cor_co_lock_medium (BlockDriverState *bs,bool locked) {bdrv_co_lock_medium (bs->file->bs, locked); }
block/filter-compress.c +2 -2
@@ -114,14 +114,14 @@ static void compress_refresh_limits(BlockDriverState *bs, Error **errp) } -static void coroutine_fn +static void coroutine_fn GRAPH_RDLOCKcompress_co_eject (BlockDriverState *bs,bool eject_flag) {bdrv_co_eject (bs->file->bs, eject_flag); } -static void coroutine_fn +static void coroutine_fn GRAPH_RDLOCKcompress_co_lock_medium (BlockDriverState *bs,bool locked) {bdrv_co_lock_medium (bs->file->bs, locked);
block/raw-format.c +4 -2
@@ -405,12 +405,14 @@ raw_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,return bdrv_co_truncate (bs->file, offset, exact, prealloc, flags, errp); } -static void coroutine_fn raw_co_eject(BlockDriverState *bs, bool eject_flag) +static void coroutine_fn GRAPH_RDLOCK +raw_co_eject (BlockDriverState *bs,bool eject_flag) {bdrv_co_eject (bs->file->bs, eject_flag); } -static void coroutine_fn raw_co_lock_medium(BlockDriverState *bs, bool locked) +static void coroutine_fn GRAPH_RDLOCK +raw_co_lock_medium (BlockDriverState *bs,bool locked) {bdrv_co_lock_medium (bs->file->bs, locked); }
Signature · 1 line
2.38.1
PATCH 13/23 block: Mark bdrv_co_do_pwrite_zeroes() GRAPH_RDLOCK
In reply to Kevin WolfAll callers are already GRAPH_RDLOCK, so just add the annotation and remove assume_graph_lock().
--- block/io.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
block/io.c +3 -4
@@ -1672,8 +1672,9 @@ fail:return ret; } -static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_co_do_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags) {BlockDriver *drv = bs->drv;QEMUIOVector qiov;
@@ -1683,8 +1684,6 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,int head =0 ;int tail =0 ; -assume_graph_lock ();/* FIXME */ -int64_t max_write_zeroes =MIN_NON_ZERO (bs->bl.max_pwrite_zeroes,INT64_MAX ); int alignment = MAX(bs->bl.pwrite_zeroes_alignment,
Signature · 1 line
2.38.1
PATCH 17/23 block: Mark bdrv_co_io_(un)plug() and callers GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_io_plug() and bdrv_co_io_unplug() need to hold a reader lock for the graph.
--- include/block/block-io.h | 4 ++-- include/block/block_int-common.h | 5 +++-- block/block-backend.c | 2 ++ block/io.c | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-)
include/block/block-io.h +2 -2
@@ -233,8 +233,8 @@ void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx);AioContext *child_of_bds_get_parent_aio_context (BdrvChild *c); -void coroutine_fn bdrv_co_io_plug(BlockDriverState *bs); -void coroutine_fn bdrv_co_io_unplug(BlockDriverState *bs); +void coroutine_fn GRAPH_RDLOCK bdrv_co_io_plug(BlockDriverState *bs); +void coroutine_fn GRAPH_RDLOCK bdrv_co_io_unplug(BlockDriverState *bs); bool coroutine_fn bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name,
include/block/block_int-common.h +3 -2
@@ -735,8 +735,9 @@ struct BlockDriver { BlkdebugEvent event);/* io queue for linux-aio */ - void coroutine_fn (*bdrv_co_io_plug)(BlockDriverState *bs); - void coroutine_fn (*bdrv_co_io_unplug)(BlockDriverState *bs); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_io_plug)(BlockDriverState *bs); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_io_unplug)( + BlockDriverState *bs);/** * bdrv_drain_begin is called if implemented in the beginning of a
block/block-backend.c +2 -0
@@ -2328,6 +2328,7 @@ void coroutine_fn blk_co_io_plug(BlockBackend *blk) {BlockDriverState *bs =blk_bs (blk);IO_CODE (); +GRAPH_RDLOCK_GUARD ();if (bs) {bdrv_co_io_plug (bs);
@@ -2338,6 +2339,7 @@ void coroutine_fn blk_co_io_unplug(BlockBackend *blk) {BlockDriverState *bs =blk_bs (blk);IO_CODE (); +GRAPH_RDLOCK_GUARD ();if (bs) {bdrv_co_io_unplug (bs);
block/io.c +2 -0
@@ -3150,6 +3150,7 @@ void coroutine_fn bdrv_co_io_plug(BlockDriverState *bs) {BdrvChild *child;IO_CODE (); +assert_bdrv_graph_readable (); QLIST_FOREACH(child, &bs->children, next) {bdrv_co_io_plug (child->bs);
@@ -3167,6 +3168,7 @@ void coroutine_fn bdrv_co_io_unplug(BlockDriverState *bs) {BdrvChild *child;IO_CODE (); +assert_bdrv_graph_readable ();assert (bs->io_plugged);if (qatomic_fetch_dec (&bs->io_plugged) ==1 ) {
Signature · 1 line
2.38.1
PATCH 15/23 block: Mark preadv_snapshot/snapshot_block_status GRAPH_RDLOCK
In reply to Kevin Wolf--- include/block/block_int-common.h | 12 +++++++----- include/block/block_int-io.h | 8 ++++---- block/copy-before-write.c | 6 ++---- block/io.c | 2 ++ block/snapshot-access.c | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-)
include/block/block_int-common.h +7 -5
@@ -624,11 +624,13 @@ struct BlockDriver {* - receive the snapshot's actual length (which may differ from bs's * length) */ - int coroutine_fn (*bdrv_co_preadv_snapshot)(BlockDriverState *bs, -int64_t offset,int64_t bytes,QEMUIOVector *qiov,size_t qiov_offset); - int coroutine_fn (*bdrv_co_snapshot_block_status)(BlockDriverState *bs, -bool want_zero,int64_t offset,int64_t bytes,int64_t *pnum, -int64_t *map,BlockDriverState **file); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_preadv_snapshot)( +BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,size_t qiov_offset); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_snapshot_block_status)( +BlockDriverState *bs,bool want_zero,int64_t offset,int64_t bytes, +int64_t *pnum,int64_t *map,BlockDriverState **file); int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard_snapshot)(BlockDriverState *bs,int64_t offset,int64_t bytes);
include/block/block_int-io.h +4 -4
@@ -35,11 +35,11 @@* the I/O API. */ -int coroutine_fn bdrv_co_preadv_snapshot(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv_snapshot(BdrvChild *child,int64_t offset,int64_t bytes,QEMUIOVector *qiov,size_t qiov_offset); -int coroutine_fn bdrv_co_snapshot_block_status(BlockDriverState *bs, -bool want_zero,int64_t offset,int64_t bytes,int64_t *pnum, -int64_t *map,BlockDriverState **file); +int coroutine_fn GRAPH_RDLOCK bdrv_co_snapshot_block_status( +BlockDriverState *bs,bool want_zero,int64_t offset,int64_t bytes, +int64_t *pnum,int64_t *map,BlockDriverState **file); int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard_snapshot(BlockDriverState *bs,int64_t offset,int64_t bytes);
block/copy-before-write.c +2 -4
@@ -256,7 +256,7 @@ cbw_snapshot_read_unlock(BlockDriverState *bs, BlockReq *req)g_free (req); } -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCKcbw_co_preadv_snapshot (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,size_t qiov_offset) {
@@ -264,8 +264,6 @@ cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes,BdrvChild *file;int ret; -assume_graph_lock ();/* FIXME */ -/* TODO: upgrade to async loop using AioTask */ while (bytes) {int64_t cur_bytes;
@@ -290,7 +288,7 @@ cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes,return 0 ; } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK cbw_co_snapshot_block_status(BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map,
block/io.c +2 -0
@@ -3529,6 +3529,7 @@ bdrv_co_preadv_snapshot(BdrvChild *child, int64_t offset, int64_t bytes,BlockDriver *drv = bs->drv;int ret;IO_CODE (); +assert_bdrv_graph_readable ();if (!drv) {return -ENOMEDIUM ;
@@ -3554,6 +3555,7 @@ bdrv_co_snapshot_block_status(BlockDriverState *bs,BlockDriver *drv = bs->drv;int ret;IO_CODE (); +assert_bdrv_graph_readable ();if (!drv) {return -ENOMEDIUM ;
block/snapshot-access.c +2 -2
@@ -26,7 +26,7 @@#include "qemu/cutils.h" #include "block/block_int.h" -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK snapshot_access_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset,
@@ -39,7 +39,7 @@ snapshot_access_co_preadv_part(BlockDriverState *bs,return bdrv_co_preadv_snapshot (bs->file, offset, bytes, qiov, qiov_offset); } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK snapshot_access_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum,
Signature · 1 line
2.38.1
PATCH 6/23 block/qed: add missing graph rdlock in qed_need_check_timer_entry
In reply to Kevin WolfFrom: Emanuele Giuseppe Esposito <[email protected]>
This function is called in two different places:
- timer callback, which does not take the graph rdlock.
- bdrv_qed_drain_begin(), which is .bdrv_drain_begin() callback documented as function that does not take the lock.
Since it calls recursive functions that traverse the graph, we need to protect them with the graph rdlock.
--- block/qed.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
block/qed.c +3 -1
@@ -282,11 +282,12 @@ static void coroutine_fn qed_unplug_allocating_write_reqs(BDRVQEDState *s)qemu_co_mutex_unlock (&s->table_lock); } -static void coroutine_fn qed_need_check_timer(BDRVQEDState *s) +static void coroutine_fn GRAPH_RDLOCK qed_need_check_timer(BDRVQEDState *s) {int ret;trace_qed_need_check_timer_cb (s); +assert_bdrv_graph_readable ();if (!qed_plug_allocating_write_reqs (s)) {return ;
@@ -312,6 +313,7 @@ static void coroutine_fn qed_need_check_timer(BDRVQEDState *s) static void coroutine_fn qed_need_check_timer_entry(void *opaque) {BDRVQEDState *s = opaque; +GRAPH_RDLOCK_GUARD ();qed_need_check_timer (opaque);bdrv_dec_in_flight (s->bs);
Signature · 1 line
2.38.1
PATCH 12/23 block: Mark bdrv_co_pwrite_sync() and callers GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pwrite_sync() need to hold a reader lock for the graph.
For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated.
--- block/qcow2.h | 2 +- include/block/block-io.h | 7 ++++--- block/io.c | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-)
block/qcow2.h +1 -1
@@ -893,7 +893,7 @@ int qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res,int qcow2_change_refcount_order (BlockDriverState *bs,int refcount_order,BlockDriverAmendStatusCB *status_cb,void *cb_opaque,Error **errp); -int coroutine_fn qcow2_shrink_reftable(BlockDriverState *bs); +int coroutine_fn GRAPH_RDLOCK qcow2_shrink_reftable(BlockDriverState *bs);int64_t qcow2_get_last_cluster (BlockDriverState *bs,int64_t size); int coroutine_fn qcow2_detect_metadata_preallocation(BlockDriverState *bs);
include/block/block-io.h +4 -3
@@ -60,9 +60,10 @@ int co_wrapper_mixed_bdrv_rdlock bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags); -int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset, -int64_t bytes,const void *buf, -BdrvRequestFlags flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pwrite_sync (BdrvChild *child,int64_t offset,int64_t bytes, +const void *buf,BdrvRequestFlags flags); +/* * Efficiently zero a region of the disk image. Note that this is a regular * I/O request like read or write and should have a reasonable size. This
block/io.c +1 -2
@@ -933,8 +933,7 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset, {int ret;IO_CODE (); - -assume_graph_lock ();/* FIXME */ +assert_bdrv_graph_readable (); ret =bdrv_co_pwrite (child, offset, bytes, buf, flags);if (ret <0 ) {
Signature · 1 line
2.38.1
PATCH 21/23 block: Mark bdrv_co_delete_file() and callers GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_delete_file() need to hold a reader lock for the graph.
--- include/block/block-io.h | 8 ++++++-- include/block/block_int-common.h | 4 ++-- block.c | 1 + 3 files changed, 9 insertions(+), 4 deletions(-)
include/block/block-io.h +6 -2
@@ -90,8 +90,12 @@ int64_t co_wrapper bdrv_get_allocated_file_size(BlockDriverState *bs);BlockMeasureInfo *bdrv_measure (BlockDriver *drv,QemuOpts *opts,BlockDriverState *in_bs,Error **errp);void bdrv_get_geometry (BlockDriverState *bs,uint64_t *nb_sectors_ptr); -int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp); -void coroutine_fn bdrv_co_delete_file_noerr(BlockDriverState *bs); + +int coroutine_fn GRAPH_RDLOCK +bdrv_co_delete_file (BlockDriverState *bs,Error **errp); + +void coroutine_fn GRAPH_RDLOCK +bdrv_co_delete_file_noerr (BlockDriverState *bs);/* async block I/O */
include/block/block_int-common.h +2 -2
@@ -649,8 +649,8 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush)(BlockDriverState *bs);/* Delete a created file. */ - int coroutine_fn (*bdrv_co_delete_file)(BlockDriverState *bs, -Error **errp); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_delete_file)( + BlockDriverState *bs, Error **errp);/* * Flushes all data that was already written to the OS all the way down to
block.c +1 -0
@@ -740,6 +740,7 @@ int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp)IO_CODE ();assert (bs !=NULL ); +assert_bdrv_graph_readable ();if (!bs->drv) {error_setg (errp,"Block node '%s' is not opened" , bs->filename);
Signature · 1 line
2.38.1
PATCH 22/23 block: Mark bdrv_*_dirty_bitmap() and callers GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_*_dirty_bitmap() need to hold a reader lock for the graph.
--- include/block/block-io.h | 14 ++++++-------- include/block/block_int-common.h | 6 ++++-- include/block/dirty-bitmap.h | 12 ++++++------ block/dirty-bitmap.c | 2 ++ 4 files changed, 18 insertions(+), 16 deletions(-)
include/block/block-io.h +6 -8
@@ -243,14 +243,12 @@ AioContext *child_of_bds_get_parent_aio_context(BdrvChild *c); void coroutine_fn GRAPH_RDLOCK bdrv_co_io_plug(BlockDriverState *bs); void coroutine_fn GRAPH_RDLOCK bdrv_co_io_unplug(BlockDriverState *bs); -bool coroutine_fn bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, -const char *name, -uint32_t granularity, -Error **errp); -bool co_wrapper bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, -const char *name, -uint32_t granularity, -Error **errp); +bool coroutine_fn GRAPH_RDLOCK +bdrv_co_can_store_new_dirty_bitmap (BlockDriverState *bs,const char *name, +uint32_t granularity,Error **errp); +bool co_wrapper_bdrv_rdlock +bdrv_can_store_new_dirty_bitmap (BlockDriverState *bs,const char *name, +uint32_t granularity,Error **errp);/** *
include/block/block_int-common.h +4 -2
@@ -759,10 +759,12 @@ struct BlockDriver {void (*bdrv_drain_end)(BlockDriverState *bs);bool (*bdrv_supports_persistent_dirty_bitmap)(BlockDriverState *bs); - bool coroutine_fn (*bdrv_co_can_store_new_dirty_bitmap)( + + bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_can_store_new_dirty_bitmap)(BlockDriverState *bs,const char *name,uint32_t granularity,Error **errp); - int coroutine_fn (*bdrv_co_remove_persistent_dirty_bitmap)( + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_remove_persistent_dirty_bitmap)(BlockDriverState *bs,const char *name,Error **errp); };
include/block/dirty-bitmap.h +6 -6
@@ -36,12 +36,12 @@ int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,void bdrv_release_dirty_bitmap (BdrvDirtyBitmap *bitmap);void bdrv_release_named_dirty_bitmaps (BlockDriverState *bs); -int coroutine_fn bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *bs, -const char *name, -Error **errp); -int co_wrapper bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, -const char *name, -Error **errp); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_remove_persistent_dirty_bitmap (BlockDriverState *bs,const char *name, +Error **errp); +int co_wrapper_bdrv_rdlock +bdrv_remove_persistent_dirty_bitmap (BlockDriverState *bs,const char *name, +Error **errp);void bdrv_disable_dirty_bitmap (BdrvDirtyBitmap *bitmap);void bdrv_enable_dirty_bitmap (BdrvDirtyBitmap *bitmap);
block/dirty-bitmap.c +2 -0
@@ -394,6 +394,7 @@ int coroutine_fn bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name, Error **errp) { +assert_bdrv_graph_readable ();if (bs->drv && bs->drv->bdrv_co_remove_persistent_dirty_bitmap) {return bs->drv->bdrv_co_remove_persistent_dirty_bitmap (bs, name, errp); }
@@ -415,6 +416,7 @@ bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name, uint32_t granularity, Error **errp) { BlockDriver *drv = bs->drv; +assert_bdrv_graph_readable ();if (!drv) { error_setg_errno(errp, ENOMEDIUM,
Signature · 1 line
2.38.1
PATCH 23/23 block: Mark bdrv_co_refresh_total_sectors() and callers GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_refresh_total_sectors() need to hold a reader lock for the graph.
--- include/block/block-io.h | 8 ++++---- include/block/block_int-common.h | 4 +++- include/block/block_int-io.h | 7 ++++--- block.c | 3 +++ block/blkdebug.c | 3 ++- block/blklogwrites.c | 3 ++- block/blkreplay.c | 3 ++- block/blkverify.c | 3 ++- block/copy-on-read.c | 2 +- block/crypto.c | 3 ++- block/filter-compress.c | 3 ++- block/mirror.c | 3 +++ block/preallocate.c | 3 ++- block/quorum.c | 3 ++- block/raw-format.c | 3 ++- block/replication.c | 3 ++- block/stream.c | 8 +++++--- block/throttle.c | 3 ++- 18 files changed, 45 insertions(+), 23 deletions(-)
include/block/block-io.h +4 -4
@@ -78,11 +78,11 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); -int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs); -int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState *bs); +int64_t coroutine_fn GRAPH_RDLOCK bdrv_co_nb_sectors(BlockDriverState *bs); +int64_t co_wrapper_mixed_bdrv_rdlock bdrv_nb_sectors(BlockDriverState *bs); -int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs); -int64_t co_wrapper_mixed bdrv_getlength(BlockDriverState *bs); +int64_t coroutine_fn GRAPH_RDLOCK bdrv_co_getlength(BlockDriverState *bs); +int64_t co_wrapper_mixed_bdrv_rdlock bdrv_getlength(BlockDriverState *bs); int64_t coroutine_fn bdrv_co_get_allocated_file_size(BlockDriverState *bs); int64_t co_wrapper bdrv_get_allocated_file_size(BlockDriverState *bs);
include/block/block_int-common.h +3 -1
@@ -684,7 +684,9 @@ struct BlockDriver { BlockDriverState *bs, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); - int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs); + int64_t coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_getlength)( + BlockDriverState *bs); + int64_t coroutine_fn (*bdrv_co_get_allocated_file_size)(BlockDriverState *bs);
include/block/block_int-io.h +4 -3
@@ -124,9 +124,10 @@ bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset, int64_t bytes, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); -int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs, -int64_t hint); -int co_wrapper_mixed +int coroutine_fn GRAPH_RDLOCK +bdrv_co_refresh_total_sectors (BlockDriverState *bs,int64_t hint); + +int co_wrapper_mixed_bdrv_rdlockbdrv_refresh_total_sectors (BlockDriverState *bs,int64_t hint);BdrvChild *bdrv_cow_child (BlockDriverState *bs);
block.c +3 -0
@@ -1042,6 +1042,7 @@ int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs, {BlockDriver *drv = bs->drv;IO_CODE (); +assert_bdrv_graph_readable ();if (!drv) {return -ENOMEDIUM ;
@@ -5820,6 +5821,7 @@ int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs) {BlockDriver *drv = bs->drv;IO_CODE (); +assert_bdrv_graph_readable ();if (!drv)return -ENOMEDIUM ;
@@ -5841,6 +5843,7 @@ int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs) {int64_t ret;IO_CODE (); +assert_bdrv_graph_readable (); ret =bdrv_co_nb_sectors (bs);if (ret <0 ) {
block/blkdebug.c +2 -1
@@ -967,7 +967,8 @@ static bool blkdebug_debug_is_suspended(BlockDriverState *bs, const char *tag)return false; } -static int64_t coroutine_fn blkdebug_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blkdebug_co_getlength (BlockDriverState *bs) {return bdrv_co_getlength (bs->file->bs); }
block/blklogwrites.c +2 -1
@@ -267,7 +267,8 @@ static void blk_log_writes_close(BlockDriverState *bs) s->log_file =NULL ; } -static int64_t coroutine_fn blk_log_writes_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_getlength (BlockDriverState *bs) {return bdrv_co_getlength (bs->file->bs); }
block/blkreplay.c +2 -1
@@ -40,7 +40,8 @@ fail:return ret; } -static int64_t coroutine_fn blkreplay_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blkreplay_co_getlength (BlockDriverState *bs) {return bdrv_co_getlength (bs->file->bs); }
block/blkverify.c +2 -1
@@ -155,7 +155,8 @@ static void blkverify_close(BlockDriverState *bs) s->test_file =NULL ; } -static int64_t coroutine_fn blkverify_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blkverify_co_getlength (BlockDriverState *bs) {BDRVBlkverifyState *s = bs->opaque;
block/copy-on-read.c +1 -1
@@ -121,7 +121,7 @@ static void cor_child_perm(BlockDriverState *bs, BdrvChild *c, } -static int64_t coroutine_fn cor_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK cor_co_getlength(BlockDriverState *bs) {return bdrv_co_getlength (bs->file->bs); }
block/crypto.c +2 -1
@@ -531,7 +531,8 @@ static void block_crypto_refresh_limits(BlockDriverState *bs, Error **errp) } -static int64_t coroutine_fn block_crypto_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +block_crypto_co_getlength (BlockDriverState *bs) {BlockCrypto *crypto = bs->opaque;int64_t len =bdrv_co_getlength (bs->file->bs);
block/filter-compress.c +2 -1
@@ -55,7 +55,8 @@ static int compress_open(BlockDriverState *bs, QDict *options, int flags, } -static int64_t coroutine_fn compress_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +compress_co_getlength (BlockDriverState *bs) {return bdrv_co_getlength (bs->file->bs); }
block/mirror.c +3 -0
@@ -917,7 +917,10 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) goto immediate_exit; } +bdrv_graph_co_rdlock (); s->bdev_length =bdrv_co_getlength (bs); +bdrv_graph_co_rdunlock (); +if (s->bdev_length <0 ) { ret = s->bdev_length; goto immediate_exit;
block/preallocate.c +2 -1
@@ -443,7 +443,8 @@ static int coroutine_fn GRAPH_RDLOCK preallocate_co_flush(BlockDriverState *bs)return bdrv_co_flush (bs->file->bs); } -static int64_t coroutine_fn preallocate_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +preallocate_co_getlength (BlockDriverState *bs) {int64_t ret;BDRVPreallocateState *s = bs->opaque;
block/quorum.c +2 -1
@@ -764,7 +764,8 @@ quorum_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, flags | BDRV_REQ_ZERO_WRITE); } -static int64_t coroutine_fn quorum_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +quorum_co_getlength (BlockDriverState *bs) {BDRVQuorumState *s = bs->opaque;int64_t result;
block/raw-format.c +2 -1
@@ -317,7 +317,8 @@ raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes)return bdrv_co_pdiscard (bs->file, offset, bytes); } -static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +raw_co_getlength (BlockDriverState *bs) {int64_t len;BDRVRawState *s = bs->opaque;
block/replication.c +2 -1
@@ -179,7 +179,8 @@ static void replication_child_perm(BlockDriverState *bs, BdrvChild *c,return ; } -static int64_t coroutine_fn replication_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +replication_co_getlength (BlockDriverState *bs) {return bdrv_co_getlength (bs->file->bs); }
block/stream.c +5 -3
@@ -141,9 +141,11 @@ static int coroutine_fn stream_run(Job *job, Error **errp)return 0 ; } - len =bdrv_getlength (s->target_bs); -if (len <0 ) { -return len; + WITH_GRAPH_RDLOCK_GUARD() { + len =bdrv_co_getlength (s->target_bs); +if (len <0 ) { +return len; + } }job_progress_set_remaining (&s->common.job, len);
block/throttle.c +2 -1
@@ -106,7 +106,8 @@ static void throttle_close(BlockDriverState *bs) } -static int64_t coroutine_fn throttle_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +throttle_co_getlength (BlockDriverState *bs) {return bdrv_co_getlength (bs->file->bs); }
Signature · 1 line
2.38.1
cover block: Lock the graph, part 2 (BlockDriver callbacks)
After introducing the graph lock in a previous series, this series actually starts making widespread use of it.
Most of the BlockDriver callbacks access the children list in some way, so you need to hold the graph lock to call them. The patches in this series add the corresponding GRAPH_RDLOCK annotations and take the lock in places where it doesn't happen yet - all of the bdrv_*() co_wrappers are already covered, but in particular BlockBackend coroutine_fns still need it.
There is no particularly good reason why exactly these patches and not others are included in the series. I couldn't find a self-contained part that could reasonable be addressed in a single series. So these just happen to be patches that are somewhat related (centered around the BlockDriver callback theme), are ready and their number looks manageable. You will still see some FIXMEs at the end of the series that will only be addressed in future patches.
Emanuele Giuseppe Esposito (5):
block/qed: add missing graph rdlock in qed_need_check_timer_entry
block: Mark bdrv_co_flush() and callers GRAPH_RDLOCK
block: Mark bdrv_co_pdiscard() and callers GRAPH_RDLOCK
block: Mark bdrv_co_copy_range() GRAPH_RDLOCK
block: Mark bdrv_co_is_inserted() and callers GRAPH_RDLOCK
Kevin Wolf (18):
block: Make bdrv_can_set_read_only() static
mirror: Fix access of uninitialised fields during start
block: Mark bdrv_co_truncate() and callers GRAPH_RDLOCK
block: Mark bdrv_co_block_status() and callers GRAPH_RDLOCK
block: Mark bdrv_co_ioctl() and callers GRAPH_RDLOCK
block: Mark bdrv_co_pwrite_zeroes() and callers GRAPH_RDLOCK
block: Mark read/write in block/io.c GRAPH_RDLOCK
block: Mark public read/write functions GRAPH_RDLOCK
block: Mark bdrv_co_pwrite_sync() and callers GRAPH_RDLOCK
block: Mark bdrv_co_do_pwrite_zeroes() GRAPH_RDLOCK
block: Mark preadv_snapshot/snapshot_block_status GRAPH_RDLOCK
block: Mark bdrv_co_create() and callers GRAPH_RDLOCK
block: Mark bdrv_co_io_(un)plug() and callers GRAPH_RDLOCK
block: Mark bdrv_co_eject/lock_medium() and callers GRAPH_RDLOCK
block: Mark bdrv_(un)register_buf() GRAPH_RDLOCK
block: Mark bdrv_co_delete_file() and callers GRAPH_RDLOCK
block: Mark bdrv_*_dirty_bitmap() and callers GRAPH_RDLOCK
block: Mark bdrv_co_refresh_total_sectors() and callers GRAPH_RDLOCK
block/coroutines.h | 2 +- block/qcow2.h | 27 +++-- block/qed.h | 45 ++++---- include/block/block-copy.h | 6 +- include/block/block-global-state.h | 14 ++- include/block/block-io.h | 110 +++++++++--------- include/block/block_int-common.h | 173 ++++++++++++++++------------- include/block/block_int-io.h | 53 ++++----- include/block/dirty-bitmap.h | 12 +- include/sysemu/block-backend-io.h | 7 +- block.c | 12 +- block/backup.c | 3 + block/blkdebug.c | 19 ++-- block/blklogwrites.c | 35 +++--- block/blkreplay.c | 24 ++-- block/blkverify.c | 5 +- block/block-backend.c | 39 +++++-- block/block-copy.c | 32 +++--- block/bochs.c | 2 +- block/commit.c | 5 +- block/copy-before-write.c | 33 +++--- block/copy-on-read.c | 44 ++++---- block/create.c | 9 +- block/crypto.c | 16 +-- block/dirty-bitmap.c | 2 + block/file-posix.c | 27 ++--- block/file-win32.c | 7 +- block/filter-compress.c | 36 +++--- block/io.c | 108 +++++++++++------- block/iscsi.c | 28 ++--- block/mirror.c | 59 ++++++---- block/parallels.c | 33 +++--- block/preallocate.c | 38 ++++--- block/qcow.c | 46 ++++---- block/qcow2-cluster.c | 17 ++- block/qcow2.c | 136 ++++++++++++----------- block/qed-check.c | 3 +- block/qed-table.c | 10 +- block/qed.c | 101 +++++++++-------- block/quorum.c | 62 ++++++----- block/raw-format.c | 76 ++++++------- block/replication.c | 18 ++- block/snapshot-access.c | 8 +- block/stream.c | 40 ++++--- block/throttle.c | 36 +++--- block/vdi.c | 11 +- block/vhdx.c | 18 +-- block/vmdk.c | 132 ++++++++++------------ block/vpc.c | 11 +- qemu-img.c | 8 +- tests/unit/test-bdrv-drain.c | 20 ++-- tests/unit/test-block-iothread.c | 3 +- 52 files changed, 983 insertions(+), 838 deletions(-)
Signature · 1 line
2.38.1
PATCH 4/23 block: Mark bdrv_co_block_status() and callers GRAPH_RDLOCK
This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_block_status() need to hold a reader lock for the graph.
For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated.
--- block/coroutines.h | 2 +- include/block/block-copy.h | 6 +++--- include/block/block-io.h | 22 +++++++++++----------- include/block/block_int-common.h | 3 ++- block/backup.c | 3 +++ block/block-backend.c | 2 ++ block/block-copy.c | 19 +++++++++++-------- block/io.c | 13 ++++++++----- block/mirror.c | 14 +++++++++----- block/qcow.c | 11 ++++------- block/quorum.c | 9 ++++----- block/stream.c | 32 ++++++++++++++++++-------------- qemu-img.c | 4 +++- tests/unit/test-block-iothread.c | 3 ++- 14 files changed, 81 insertions(+), 62 deletions(-)
block/coroutines.h +1 -1
@@ -43,7 +43,7 @@ bdrv_co_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix); int coroutine_fn GRAPH_RDLOCKbdrv_co_invalidate_cache (BlockDriverState *bs,Error **errp); -int coroutine_fn +int coroutine_fn GRAPH_RDLOCK bdrv_co_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool include_base,
include/block/block-copy.h +3 -3
@@ -36,9 +36,9 @@ void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm);void block_copy_state_free (BlockCopyState *s);void block_copy_reset (BlockCopyState *s,int64_t offset,int64_t bytes); -int64_t coroutine_fn block_copy_reset_unallocated(BlockCopyState *s, -int64_t offset, -int64_t *count); + +int64_t coroutine_fn GRAPH_RDLOCK +block_copy_reset_unallocated (BlockCopyState *s,int64_t offset,int64_t *count); int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes, bool ignore_ratelimit, uint64_t timeout_ns,
include/block/block-io.h +11 -11
@@ -109,24 +109,24 @@ int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); -int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, -BlockDriverState *base, -int64_t offset,int64_t bytes, -int64_t *pnum,int64_t *map, -BlockDriverState **file); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_block_status_above (BlockDriverState *bs,BlockDriverState *base, +int64_t offset,int64_t bytes,int64_t *pnum, +int64_t *map,BlockDriverState **file);int bdrv_block_status_above (BlockDriverState *bs,BlockDriverState *base,int64_t offset,int64_t bytes,int64_t *pnum,int64_t *map,BlockDriverState **file); -int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t offset, -int64_t bytes,int64_t *pnum); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_is_allocated (BlockDriverState *bs,int64_t offset,int64_t bytes, +int64_t *pnum);int bdrv_is_allocated (BlockDriverState *bs,int64_t offset,int64_t bytes,int64_t *pnum); -int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, -BlockDriverState *base, -bool include_base,int64_t offset, -int64_t bytes,int64_t *pnum); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_is_allocated_above (BlockDriverState *top,BlockDriverState *base, +bool include_base,int64_t offset,int64_t bytes, +int64_t *pnum);int bdrv_is_allocated_above (BlockDriverState *top,BlockDriverState *base,bool include_base,int64_t offset,int64_t bytes,int64_t *pnum);
include/block/block_int-common.h +2 -1
@@ -606,7 +606,8 @@ struct BlockDriver {* *pnum value for the block-status cache on protocol nodes, prior * to clamping *pnum for return to its caller. */ - int coroutine_fn (*bdrv_co_block_status)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_block_status)( +BlockDriverState *bs,bool want_zero,int64_t offset,int64_t bytes,int64_t *pnum,int64_t *map,BlockDriverState **file);
block/backup.c +3 -0
@@ -270,7 +270,10 @@ static int coroutine_fn backup_run(Job *job, Error **errp)return -ECANCELED ; } +/* rdlock protects the subsequent call to bdrv_is_allocated() */ +bdrv_graph_co_rdlock (); ret =block_copy_reset_unallocated (s->bcs, offset, &count); +bdrv_graph_co_rdunlock ();if (ret <0 ) {return ret; }
block/block-backend.c +2 -0
@@ -1431,6 +1431,7 @@ int coroutine_fn blk_co_block_status_above(BlockBackend *blk, BlockDriverState **file) {IO_CODE (); +GRAPH_RDLOCK_GUARD ();return bdrv_co_block_status_above (blk_bs (blk), base, offset, bytes, pnum, map, file); }
@@ -1441,6 +1442,7 @@ int coroutine_fn blk_co_is_allocated_above(BlockBackend *blk, int64_t bytes, int64_t *pnum) {IO_CODE (); +GRAPH_RDLOCK_GUARD ();return bdrv_co_is_allocated_above (blk_bs (blk), base, include_base, offset, bytes, pnum); }
block/block-copy.c +11 -8
@@ -581,9 +581,9 @@ static coroutine_fn int block_copy_task_entry(AioTask *task)return ret; } -static coroutine_fn int block_copy_block_status(BlockCopyState *s, -int64_t offset, -int64_t bytes,int64_t *pnum) +static coroutine_fn GRAPH_RDLOCK +int block_copy_block_status (BlockCopyState *s,int64_t offset,int64_t bytes, +int64_t *pnum) {int64_t num;BlockDriverState *base;
@@ -618,9 +618,9 @@ static coroutine_fn int block_copy_block_status(BlockCopyState *s,* Check if the cluster starting at offset is allocated or not. * return via pnum the number of contiguous clusters sharing this allocation. */ -static int coroutine_fn block_copy_is_cluster_allocated(BlockCopyState *s, -int64_t offset, -int64_t *pnum) +static int coroutine_fn GRAPH_RDLOCK +block_copy_is_cluster_allocated (BlockCopyState *s,int64_t offset, +int64_t *pnum) {BlockDriverState *bs = s->source->bs;int64_t count, total_count =0 ;
@@ -630,6 +630,7 @@ static int coroutine_fn block_copy_is_cluster_allocated(BlockCopyState *s,assert (QEMU_IS_ALIGNED (offset, s->cluster_size));while (true) { +/* protected in backup_run() */ ret =bdrv_co_is_allocated (bs, offset, bytes, &count);if (ret <0 ) {return ret;
@@ -704,7 +705,7 @@ int64_t coroutine_fn block_copy_reset_unallocated(BlockCopyState *s,* Returns 1 if dirty clusters found and successfully copied, 0 if no dirty * clusters found and -errno on failure. */ -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblock_copy_dirty_clusters (BlockCopyCallState *call_state) {BlockCopyState *s = call_state->s;
@@ -827,7 +828,8 @@ void block_copy_kick(BlockCopyCallState *call_state)* it means that some I/O operation failed in context of _this_ block_copy call, * not some parallel operation. */ -static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) +static int coroutine_fn GRAPH_RDLOCK +block_copy_common (BlockCopyCallState *call_state) {int ret;BlockCopyState *s = call_state->s;
@@ -892,6 +894,7 @@ static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) static void coroutine_fn block_copy_async_co_entry(void *opaque) { +GRAPH_RDLOCK_GUARD ();block_copy_common (opaque); }
block/io.c +8 -5
@@ -2221,11 +2221,10 @@ int bdrv_flush_all(void)* BDRV_BLOCK_OFFSET_VALID bit is set, 'map' and 'file' (if non-NULL) are * set to the host mapping and BDS corresponding to the guest offset. */ -static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs, -bool want_zero, -int64_t offset,int64_t bytes, -int64_t *pnum,int64_t *map, -BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +bdrv_co_block_status (BlockDriverState *bs,bool want_zero, +int64_t offset,int64_t bytes, +int64_t *pnum,int64_t *map,BlockDriverState **file) {int64_t total_size;int64_t n;/* bytes */
@@ -2237,6 +2236,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,bool has_filtered_child;assert (pnum); +assert_bdrv_graph_readable (); *pnum =0 ; total_size =bdrv_getlength (bs);if (total_size <0 ) {
@@ -2467,6 +2467,7 @@ bdrv_co_common_block_status_above(BlockDriverState *bs,IO_CODE ();assert (!include_base || base);/* Can't include NULL base */ +assert_bdrv_graph_readable ();if (!depth) { depth = &dummy;
@@ -2592,6 +2593,8 @@ int coroutine_fn bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset,int64_t pnum = bytes;IO_CODE (); +assume_graph_lock ();/* FIXME */ +if (!bytes) {return 1 ; }
block/mirror.c +9 -5
@@ -558,9 +558,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)MirrorMethod mirror_method =MIRROR_METHOD_COPY ;assert (!(offset % s->granularity)); - ret =bdrv_block_status_above (source,NULL , offset, - nb_chunks * s->granularity, - &io_bytes,NULL ,NULL ); + WITH_GRAPH_RDLOCK_GUARD() { + ret =bdrv_block_status_above (source,NULL , offset, + nb_chunks * s->granularity, + &io_bytes,NULL ,NULL ); + }if (ret <0 ) { io_bytes =MIN (nb_chunks * s->granularity, max_io_bytes); }else if (ret &BDRV_BLOCK_DATA ) {
@@ -863,8 +865,10 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)return 0 ; } - ret =bdrv_is_allocated_above (bs, s->base_overlay, true, offset, bytes, - &count); + WITH_GRAPH_RDLOCK_GUARD() { + ret =bdrv_is_allocated_above (bs, s->base_overlay, true, offset, + bytes, &count); + }if (ret <0 ) {return ret; }
block/qcow.c +4 -7
@@ -524,19 +524,16 @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,return 1 ; } -static int coroutine_fn qcow_co_block_status(BlockDriverState *bs, -bool want_zero, -int64_t offset,int64_t bytes, -int64_t *pnum,int64_t *map, -BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_block_status (BlockDriverState *bs,bool want_zero, +int64_t offset,int64_t bytes,int64_t *pnum, +int64_t *map,BlockDriverState **file) {BDRVQcowState *s = bs->opaque;int index_in_cluster, ret;int64_t n;uint64_t cluster_offset; -assume_graph_lock ();/* FIXME */ -qemu_co_mutex_lock (&s->lock); ret =get_cluster_offset (bs, offset,0 ,0 ,0 ,0 , &cluster_offset);qemu_co_mutex_unlock (&s->lock);
block/quorum.c +4 -5
@@ -1217,11 +1217,10 @@ static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c,* return BDRV_BLOCK_ZERO if *all* children agree that a certain * region contains zeroes, and BDRV_BLOCK_DATA otherwise. */ -static int coroutine_fn quorum_co_block_status(BlockDriverState *bs, -bool want_zero, -int64_t offset,int64_t count, -int64_t *pnum,int64_t *map, -BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +quorum_co_block_status (BlockDriverState *bs,bool want_zero, +int64_t offset,int64_t count, +int64_t *pnum,int64_t *map,BlockDriverState **file) {BDRVQuorumState *s = bs->opaque;int i, ret;
block/stream.c +18 -14
@@ -161,21 +161,25 @@ static int coroutine_fn stream_run(Job *job, Error **errp) copy = false; - ret =bdrv_is_allocated (unfiltered_bs, offset,STREAM_CHUNK , &n); -if (ret ==1 ) { -/* Allocated in the top, no need to copy. */ - }else if (ret >=0 ) { -/* Copy if allocated in the intermediate images. Limit to the -* known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE). */ - ret =bdrv_is_allocated_above (bdrv_cow_bs (unfiltered_bs), - s->base_overlay, true, - offset, n, &n); -/* Finish early if end of backing file has been reached */ -if (ret ==0 && n ==0 ) { - n = len - offset; + WITH_GRAPH_RDLOCK_GUARD() { + ret =bdrv_is_allocated (unfiltered_bs, offset,STREAM_CHUNK , &n); +if (ret ==1 ) { +/* Allocated in the top, no need to copy. */ + }else if (ret >=0 ) { +/* +* Copy if allocated in the intermediate images. Limit to the +* known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE). +*/ + ret =bdrv_is_allocated_above (bdrv_cow_bs (unfiltered_bs), + s->base_overlay, true, + offset, n, &n); +/* Finish early if end of backing file has been reached */ +if (ret ==0 && n ==0 ) { + n = len - offset; + } + + copy = (ret >0 ); } - - copy = (ret >0 ); }trace_stream_one_iteration (s, offset, n, ret);if (copy) {
qemu-img.c +3 -1
@@ -1991,7 +1991,9 @@ static void coroutine_fn convert_co_do_copy(void *opaque)qemu_co_mutex_unlock (&s->lock);break ; } - n =convert_iteration_sectors (s, s->sector_num); + WITH_GRAPH_RDLOCK_GUARD() { + n =convert_iteration_sectors (s, s->sector_num); + }if (n <0 ) {qemu_co_mutex_unlock (&s->lock); s->ret = n;
tests/unit/test-block-iothread.c +2 -1
@@ -312,7 +312,8 @@ static void test_sync_op_blk_truncate(BlockBackend *blk) g_assert_cmpint(ret, ==, -EINVAL); } -static void test_sync_op_block_status (BdrvChild *c) +/* Disable TSA to make bdrv_test.bdrv_co_block_status writable */ +static void TSA_NO_TSA test_sync_op_block_status(BdrvChild *c) {int ret;int64_t n;
Signature · 1 line
2.38.1
PATCH 2/23 mirror: Fix access of uninitialised fields during start
In reply to Kevin Wolfbdrv_mirror_top_pwritev() accesses the job object when active mirroring is enabled. It disables this code during early initialisation while s->job isn't set yet.
However, s->job is still set way too early when the job object isn't fully initialised. For example, &s->ops_in_flight isn't initialised yet and the in_flight bitmap doesn't exist yet. This causes crashes when a write request comes in too early.
Move the assignment of s->job to when the mirror job is actually fully initialised to make sure that the mirror_top driver doesn't access it too early.
--- block/mirror.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
block/mirror.c +7 -1
@@ -896,6 +896,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) {MirrorBlockJob *s =container_of (job, MirrorBlockJob, common.job);BlockDriverState *bs = s->mirror_top_bs->backing->bs; +MirrorBDSOpaque *mirror_top_opaque = s->mirror_top_bs->opaque;BlockDriverState *target_bs =blk_bs (s->target);bool need_drain = true;BlockDeviceIoStatus iostatus;
@@ -985,6 +986,12 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) } } +/* +* Only now the job is fully initialised and mirror_top_bs should start +* accessing it. +*/ + mirror_top_opaque->job = s; +assert (!s->dbi); s->dbi =bdrv_dirty_iter_new (s->dirty_bitmap);for (;;) {
@@ -1704,7 +1711,6 @@ static BlockJob *mirror_start_job(if (!s) { goto fail; } - bs_opaque->job = s;/* The block job now has a reference to this node */ bdrv_unref (mirror_top_bs);
Signature · 1 line
2.38.1
PATCH 1/23 block: Make bdrv_can_set_read_only() static
In reply to Kevin WolfIt is never called outside of block.c.
--- include/block/block-io.h | 2 -- block.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-)
include/block/block-io.h +0 -2
@@ -134,8 +134,6 @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, int coroutine_fn bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset,int64_t bytes); -int bdrv_can_set_read_only (BlockDriverState *bs,bool read_only, -bool ignore_allow_rdw,Error **errp);int bdrv_apply_auto_read_only (BlockDriverState *bs,const char *errmsg,Error **errp);bool bdrv_is_read_only (BlockDriverState *bs);
block.c +2 -2
@@ -277,8 +277,8 @@ bool bdrv_is_read_only(BlockDriverState *bs)return !(bs->open_flags &BDRV_O_RDWR ); } -int bdrv_can_set_read_only (BlockDriverState *bs,bool read_only, -bool ignore_allow_rdw,Error **errp) +static int bdrv_can_set_read_only (BlockDriverState *bs,bool read_only, +bool ignore_allow_rdw,Error **errp) {IO_CODE ();
Signature · 1 line
2.38.1
PATCH 8/23 block: Mark bdrv_co_pdiscard() and callers GRAPH_RDLOCK
In reply to Kevin WolfFrom: Emanuele Giuseppe Esposito <[email protected]>
This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pdiscard() need to hold a reader lock for the graph.
For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated.
--- include/block/block-io.h | 5 +++-- include/block/block_int-common.h | 15 +++++++++------ include/block/block_int-io.h | 2 +- block/blkdebug.c | 4 ++-- block/blklogwrites.c | 5 ++--- block/blkreplay.c | 4 ++-- block/block-backend.c | 1 + block/copy-before-write.c | 8 ++++---- block/copy-on-read.c | 4 ++-- block/filter-compress.c | 4 ++-- block/io.c | 2 ++ block/mirror.c | 14 +++++++++----- block/preallocate.c | 4 ++-- block/raw-format.c | 4 ++-- block/snapshot-access.c | 4 ++-- block/throttle.c | 4 ++-- 16 files changed, 47 insertions(+), 37 deletions(-)
include/block/block-io.h +3 -2
@@ -103,8 +103,9 @@ bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);/* Ensure contents are flushed to disk. */ int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDriverState *bs); -int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, -int64_t bytes); +int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard(BdrvChild *child, int64_t offset, +int64_t bytes); +bool bdrv_can_write_zeroes_with_unmap (BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map,
include/block/block_int-common.h +9 -6
@@ -479,8 +479,9 @@ struct BlockDriver { BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); BlockAIOCB *GRAPH_RDLOCK_PTR (*bdrv_aio_flush)( BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque); -BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs, -int64_t offset,int bytes, + + BlockAIOCB *GRAPH_RDLOCK_PTR (*bdrv_aio_pdiscard)( + BlockDriverState *bs, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs,
@@ -543,8 +544,9 @@ struct BlockDriver {*/ int coroutine_fn (*bdrv_co_pwrite_zeroes)(BlockDriverState *bs,int64_t offset,int64_t bytes,BdrvRequestFlags flags); - int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs, -int64_t offset,int64_t bytes); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard)( +BlockDriverState *bs,int64_t offset,int64_t bytes);/* * Map [offset, offset + nbytes) range onto a child of @bs to copy from,
@@ -632,8 +634,9 @@ struct BlockDriver { int coroutine_fn (*bdrv_co_snapshot_block_status)(BlockDriverState *bs,bool want_zero,int64_t offset,int64_t bytes,int64_t *pnum,int64_t *map,BlockDriverState **file); - int coroutine_fn (*bdrv_co_pdiscard_snapshot)(BlockDriverState *bs, -int64_t offset,int64_t bytes); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard_snapshot)( +BlockDriverState *bs,int64_t offset,int64_t bytes);/* * Invalidate any cached meta-data.
include/block/block_int-io.h +1 -1
@@ -40,7 +40,7 @@ int coroutine_fn bdrv_co_preadv_snapshot(BdrvChild *child, int coroutine_fn bdrv_co_snapshot_block_status(BlockDriverState *bs,bool want_zero,int64_t offset,int64_t bytes,int64_t *pnum,int64_t *map,BlockDriverState **file); -int coroutine_fn bdrv_co_pdiscard_snapshot(BlockDriverState *bs, +int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard_snapshot(BlockDriverState *bs,int64_t offset,int64_t bytes);
block/blkdebug.c +2 -2
@@ -712,8 +712,8 @@ static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs,return bdrv_co_pwrite_zeroes (bs->file, offset, bytes, flags); } -static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +blkdebug_co_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) {uint32_t align = bs->bl.pdiscard_alignment;int err;
block/blklogwrites.c +2 -3
@@ -450,7 +450,7 @@ blk_log_writes_co_do_file_flush(BlkLogWritesFileReq *fr)return bdrv_co_flush (fr->bs->file->bs); } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblk_log_writes_co_do_file_pdiscard (BlkLogWritesFileReq *fr) {return bdrv_co_pdiscard (fr->bs->file, fr->offset, fr->bytes);
@@ -483,10 +483,9 @@ blk_log_writes_co_flush_to_disk(BlockDriverState *bs) LOG_FLUSH_FLAG, false); } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblk_log_writes_co_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) { -assume_graph_lock ();/* FIXME */ return blk_log_writes_co_log (bs, offset, bytes,NULL ,0 , blk_log_writes_co_do_file_pdiscard,LOG_DISCARD_FLAG , false);
block/blkreplay.c +2 -2
@@ -102,8 +102,8 @@ static int coroutine_fn blkreplay_co_pwrite_zeroes(BlockDriverState *bs,return ret; } -static int coroutine_fn blkreplay_co_pdiscard(BlockDriverState *bs, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) {uint64_t reqid =blkreplay_next_id ();int ret =bdrv_co_pdiscard (bs->file, offset, bytes);
block/block-backend.c +1 -0
@@ -1719,6 +1719,7 @@ blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes)IO_CODE ();blk_wait_while_drained (blk); +GRAPH_RDLOCK_GUARD (); ret =blk_check_byte_request (blk, offset, bytes);if (ret <0 ) {
block/copy-before-write.c +4 -4
@@ -149,8 +149,8 @@ static coroutine_fn int cbw_do_copy_before_write(BlockDriverState *bs,return 0 ; } -static int coroutine_fn cbw_co_pdiscard(BlockDriverState *bs, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) {int ret =cbw_do_copy_before_write (bs, offset, bytes,0 );if (ret <0 ) {
@@ -322,8 +322,8 @@ cbw_co_snapshot_block_status(BlockDriverState *bs,return ret; } -static int coroutine_fn cbw_co_pdiscard_snapshot(BlockDriverState *bs, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_pdiscard_snapshot (BlockDriverState *bs,int64_t offset,int64_t bytes) {BDRVCopyBeforeWriteState *s = bs->opaque;
block/copy-on-read.c +2 -2
@@ -200,8 +200,8 @@ static int coroutine_fn cor_co_pwrite_zeroes(BlockDriverState *bs, } -static int coroutine_fn cor_co_pdiscard(BlockDriverState *bs, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) {return bdrv_co_pdiscard (bs->file, offset, bytes); }
block/filter-compress.c +2 -2
@@ -92,8 +92,8 @@ static int coroutine_fn compress_co_pwrite_zeroes(BlockDriverState *bs, } -static int coroutine_fn compress_co_pdiscard(BlockDriverState *bs, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +compress_co_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) {return bdrv_co_pdiscard (bs->file, offset, bytes); }
block/io.c +2 -0
@@ -2968,6 +2968,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset,int head, tail, align;BlockDriverState *bs = child->bs;IO_CODE (); +assert_bdrv_graph_readable ();if (!bs || !bs->drv || !bdrv_co_is_inserted (bs)) {return -ENOMEDIUM ;
@@ -3574,6 +3575,7 @@ bdrv_co_pdiscard_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes)BlockDriver *drv = bs->drv;int ret;IO_CODE (); +assert_bdrv_graph_readable ();if (!drv) {return -ENOMEDIUM ;
block/mirror.c +9 -5
@@ -1443,9 +1443,10 @@ static int coroutine_fn bdrv_mirror_top_preadv(BlockDriverState *bs,return bdrv_co_preadv (bs->backing, offset, bytes, qiov, flags); } -static int coroutine_fn bdrv_mirror_top_do_write(BlockDriverState *bs, -MirrorMethod method,uint64_t offset,uint64_t bytes,QEMUIOVector *qiov, -int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_do_write (BlockDriverState *bs,MirrorMethod method, +uint64_t offset,uint64_t bytes,QEMUIOVector *qiov, +int flags) {MirrorOp *op =NULL ;MirrorBDSOpaque *s = bs->opaque;
@@ -1503,6 +1504,8 @@ static int coroutine_fn bdrv_mirror_top_pwritev(BlockDriverState *bs,int ret =0 ;bool copy_to_target = false; +assume_graph_lock ();/* FIXME */ +if (s->job) { copy_to_target = s->job->ret >=0 && !job_is_cancelled(&s->job->common.job) &&
@@ -1547,12 +1550,13 @@ static int coroutine_fn GRAPH_RDLOCK bdrv_mirror_top_flush(BlockDriverState *bs) static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs,int64_t offset,int64_t bytes,BdrvRequestFlags flags) { +assume_graph_lock ();/* FIXME */ return bdrv_mirror_top_do_write (bs,MIRROR_METHOD_ZERO , offset, bytes,NULL , flags); } -static int coroutine_fn bdrv_mirror_top_pdiscard(BlockDriverState *bs, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) {return bdrv_mirror_top_do_write (bs,MIRROR_METHOD_DISCARD , offset, bytes,NULL ,0 );
block/preallocate.c +2 -2
@@ -234,8 +234,8 @@ static coroutine_fn int preallocate_co_preadv_part( flags); } -static int coroutine_fn preallocate_co_pdiscard(BlockDriverState *bs, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) {return bdrv_co_pdiscard (bs->file, offset, bytes); }
block/raw-format.c +2 -2
@@ -305,8 +305,8 @@ static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs,return bdrv_co_pwrite_zeroes (bs->file, offset, bytes, flags); } -static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +raw_co_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) {int ret;
block/snapshot-access.c +2 -2
@@ -49,8 +49,8 @@ snapshot_access_co_block_status(BlockDriverState *bs, bytes, pnum, map, file); } -static int coroutine_fn snapshot_access_co_pdiscard(BlockDriverState *bs, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +snapshot_access_co_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) {return bdrv_co_pdiscard_snapshot (bs->file->bs, offset, bytes); }
block/throttle.c +2 -2
@@ -144,8 +144,8 @@ static int coroutine_fn throttle_co_pwrite_zeroes(BlockDriverState *bs,return bdrv_co_pwrite_zeroes (bs->file, offset, bytes, flags); } -static int coroutine_fn throttle_co_pdiscard(BlockDriverState *bs, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) {ThrottleGroupMember *tgm = bs->opaque;throttle_group_co_io_limits_intercept (tgm, bytes, true);
Signature · 1 line
2.38.1
PATCH 16/23 block: Mark bdrv_co_create() and callers GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_create() need to hold a reader lock for the graph.
--- include/block/block-global-state.h | 14 ++++--- include/block/block_int-common.h | 11 +++--- block.c | 1 + block/create.c | 9 ++++- block/crypto.c | 7 ++-- block/file-posix.c | 7 ++-- block/file-win32.c | 7 ++-- block/parallels.c | 7 ++-- block/qcow.c | 6 +-- block/qcow2.c | 7 ++-- block/qed.c | 7 ++-- block/raw-format.c | 7 ++-- block/vdi.c | 7 ++-- block/vhdx.c | 7 ++-- block/vmdk.c | 63 ++++++++++++++---------------- block/vpc.c | 7 ++-- 16 files changed, 84 insertions(+), 90 deletions(-)
include/block/block-global-state.h +8 -6
@@ -58,13 +58,15 @@ BlockDriver *bdrv_find_protocol(const char *filename, Error **errp);BlockDriver *bdrv_find_format (const char *format_name); -int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename, -QemuOpts *opts,Error **errp); -int co_wrapper bdrv_create(BlockDriver *drv, const char *filename, -QemuOpts *opts,Error **errp); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_create (BlockDriver *drv,const char *filename,QemuOpts *opts, +Error **errp); -int coroutine_fn bdrv_co_create_file(const char *filename, QemuOpts *opts, -Error **errp); +int co_wrapper_bdrv_rdlock bdrv_create(BlockDriver *drv, const char *filename, +QemuOpts *opts,Error **errp); + +int coroutine_fn GRAPH_RDLOCK +bdrv_co_create_file (const char *filename,QemuOpts *opts,Error **errp);BlockDriverState *bdrv_new (void ); int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
include/block/block_int-common.h +5 -6
@@ -246,12 +246,11 @@ struct BlockDriver { Error **errp);void (*bdrv_close)(BlockDriverState *bs); - int coroutine_fn (*bdrv_co_create)(BlockdevCreateOptions *opts, -Error **errp); - int coroutine_fn (*bdrv_co_create_opts)(BlockDriver *drv, -const char *filename, -QemuOpts *opts, -Error **errp); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create)( + BlockdevCreateOptions *opts, Error **errp); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create_opts)( +BlockDriver *drv,const char *filename,QemuOpts *opts,Error **errp); int (*bdrv_amend_options)(BlockDriverState *bs, QemuOpts *opts,
block.c +1 -0
@@ -533,6 +533,7 @@ int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename,int ret;GLOBAL_STATE_CODE ();ERRP_GUARD (); +assert_bdrv_graph_readable ();if (!drv->bdrv_co_create_opts) { error_setg(errp, "Driver '%s' does not support image creation",
block/create.c +8 -1
@@ -43,6 +43,7 @@ static int coroutine_fn blockdev_create_run(Job *job, Error **errp)int ret;GLOBAL_STATE_CODE (); +GRAPH_RDLOCK_GUARD ();job_progress_set_remaining (&s->common,1 ); ret = s->drv->bdrv_co_create (s->opts, errp);
@@ -59,6 +60,12 @@ static const JobDriver blockdev_create_job_driver = { .run = blockdev_create_run, }; +/* Checking whether the function is present doesn't require the graph lock */ +static inline bool TSA_NO_TSA has_bdrv_co_create(BlockDriver *drv) +{ +return drv->bdrv_co_create; +} +void qmp_blockdev_create (const char *job_id,BlockdevCreateOptions *options,Error **errp) {
@@ -79,7 +86,7 @@ void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *options, }/* Error out if the driver doesn't support .bdrv_co_create */ -if (!drv->bdrv_co_create) { +if (!has_bdrv_co_create (drv)) {error_setg (errp,"Driver does not support blockdev-create" );return ; }
block/crypto.c +3 -4
@@ -665,10 +665,9 @@ fail:return ret; } -static int coroutine_fn block_crypto_co_create_opts_luks(BlockDriver *drv, -const char *filename, -QemuOpts *opts, -Error **errp) +static int coroutine_fn GRAPH_RDLOCK +block_crypto_co_create_opts_luks (BlockDriver *drv,const char *filename, +QemuOpts *opts,Error **errp) {QCryptoBlockCreateOptions *create_opts =NULL ;BlockDriverState *bs =NULL ;
block/file-posix.c +3 -4
@@ -2607,10 +2607,9 @@ out:return result; } -static int coroutine_fn raw_co_create_opts(BlockDriver *drv, -const char *filename, -QemuOpts *opts, -Error **errp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_create_opts (BlockDriver *drv,const char *filename, +QemuOpts *opts,Error **errp) {BlockdevCreateOptions options;int64_t total_size =0 ;
block/file-win32.c +3 -4
@@ -613,10 +613,9 @@ static int raw_co_create(BlockdevCreateOptions *options, Error **errp)return 0 ; } -static int coroutine_fn raw_co_create_opts(BlockDriver *drv, -const char *filename, -QemuOpts *opts, -Error **errp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_create_opts (BlockDriver *drv,const char *filename, +QemuOpts *opts,Error **errp) {BlockdevCreateOptions options;int64_t total_size =0 ;
block/parallels.c +3 -4
@@ -622,10 +622,9 @@ exit: goto out; } -static int coroutine_fn parallels_co_create_opts(BlockDriver *drv, -const char *filename, -QemuOpts *opts, -Error **errp) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_create_opts (BlockDriver *drv,const char *filename, +QemuOpts *opts,Error **errp) {BlockdevCreateOptions *create_options =NULL ;BlockDriverState *bs =NULL ;
block/qcow.c +3 -3
@@ -921,9 +921,9 @@ exit:return ret; } -static int coroutine_fn qcow_co_create_opts(BlockDriver *drv, -const char *filename, -QemuOpts *opts,Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_create_opts (BlockDriver *drv,const char *filename, +QemuOpts *opts,Error **errp) {BlockdevCreateOptions *create_options =NULL ;BlockDriverState *bs =NULL ;
block/qcow2.c +3 -4
@@ -3816,10 +3816,9 @@ out:return ret; } -static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv, -const char *filename, -QemuOpts *opts, -Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_create_opts (BlockDriver *drv,const char *filename,QemuOpts *opts, +Error **errp) {BlockdevCreateOptions *create_options =NULL ;QDict *qdict;
block/qed.c +3 -4
@@ -754,10 +754,9 @@ out:return ret; } -static int coroutine_fn bdrv_qed_co_create_opts(BlockDriver *drv, -const char *filename, -QemuOpts *opts, -Error **errp) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_create_opts (BlockDriver *drv,const char *filename, +QemuOpts *opts,Error **errp) {BlockdevCreateOptions *create_options =NULL ;QDict *qdict;
block/raw-format.c +3 -4
@@ -430,10 +430,9 @@ static int raw_has_zero_init(BlockDriverState *bs)return bdrv_has_zero_init (bs->file->bs); } -static int coroutine_fn raw_co_create_opts(BlockDriver *drv, -const char *filename, -QemuOpts *opts, -Error **errp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_create_opts (BlockDriver *drv,const char *filename, +QemuOpts *opts,Error **errp) {return bdrv_co_create_file (filename, opts, errp); }
block/vdi.c +3 -4
@@ -898,10 +898,9 @@ static int coroutine_fn vdi_co_create(BlockdevCreateOptions *create_options,return vdi_co_do_create (create_options,DEFAULT_CLUSTER_SIZE , errp); } -static int coroutine_fn vdi_co_create_opts(BlockDriver *drv, -const char *filename, -QemuOpts *opts, -Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vdi_co_create_opts (BlockDriver *drv,const char *filename, +QemuOpts *opts,Error **errp) {QDict *qdict =NULL ;BlockdevCreateOptions *create_options =NULL ;
block/vhdx.c +3 -4
@@ -2059,10 +2059,9 @@ delete_and_exit:return ret; } -static int coroutine_fn vhdx_co_create_opts(BlockDriver *drv, -const char *filename, -QemuOpts *opts, -Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vhdx_co_create_opts (BlockDriver *drv,const char *filename, +QemuOpts *opts,Error **errp) {BlockdevCreateOptions *create_options =NULL ;QDict *qdict;
block/vmdk.c +29 -34
99 lines not on this page · raw message
block/vpc.c +3 -4
@@ -1087,10 +1087,9 @@ out:return ret; } -static int coroutine_fn vpc_co_create_opts(BlockDriver *drv, -const char *filename, -QemuOpts *opts, -Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vpc_co_create_opts (BlockDriver *drv,const char *filename, +QemuOpts *opts,Error **errp) {BlockdevCreateOptions *create_options =NULL ;QDict *qdict;
Signature · 1 line
2.38.1
PATCH 14/23 block: Mark bdrv_co_copy_range() GRAPH_RDLOCK
In reply to Kevin WolfFrom: Emanuele Giuseppe Esposito <[email protected]>
This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_copy_range() need to hold a reader lock for the graph.
--- include/block/block-io.h | 9 +++++---- include/block/block_int-common.h | 24 ++++++++---------------- include/block/block_int-io.h | 20 ++++++++++---------- block/block-backend.c | 2 ++ block/file-posix.c | 16 +++++++--------- block/io.c | 7 +++++-- block/iscsi.c | 28 ++++++++++++---------------- block/qcow2.c | 5 ++--- block/raw-format.c | 28 ++++++++++++---------------- qemu-img.c | 4 +++- 10 files changed, 66 insertions(+), 77 deletions(-)
include/block/block-io.h +5 -4
@@ -274,10 +274,11 @@ bool co_wrapper bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs,* * Returns: 0 if succeeded; negative error code if failed. **/ -int coroutine_fn bdrv_co_copy_range(BdrvChild *src, int64_t src_offset, -BdrvChild *dst,int64_t dst_offset, -int64_t bytes,BdrvRequestFlags read_flags, -BdrvRequestFlags write_flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_copy_range (BdrvChild *src,int64_t src_offset, +BdrvChild *dst,int64_t dst_offset, +int64_t bytes,BdrvRequestFlags read_flags, +BdrvRequestFlags write_flags);/* * "I/O or GS" API functions. These functions can run without
include/block/block_int-common.h +8 -16
@@ -559,14 +559,10 @@ struct BlockDriver {* See the comment of bdrv_co_copy_range for the parameter and return value * semantics. */ - int coroutine_fn (*bdrv_co_copy_range_from)(BlockDriverState *bs, -BdrvChild *src, -int64_t offset, -BdrvChild *dst, -int64_t dst_offset, -int64_t bytes, -BdrvRequestFlags read_flags, -BdrvRequestFlags write_flags); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_copy_range_from)( +BlockDriverState *bs,BdrvChild *src,int64_t offset, +BdrvChild *dst,int64_t dst_offset,int64_t bytes, +BdrvRequestFlags read_flags,BdrvRequestFlags write_flags);/* * Map [offset, offset + nbytes) range onto a child of bs to copy data to,
@@ -577,14 +573,10 @@ struct BlockDriver {* See the comment of bdrv_co_copy_range for the parameter and return value * semantics. */ - int coroutine_fn (*bdrv_co_copy_range_to)(BlockDriverState *bs, -BdrvChild *src, -int64_t src_offset, -BdrvChild *dst, -int64_t dst_offset, -int64_t bytes, -BdrvRequestFlags read_flags, -BdrvRequestFlags write_flags); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_copy_range_to)( +BlockDriverState *bs,BdrvChild *src,int64_t src_offset, +BdrvChild *dst,int64_t dst_offset,int64_t bytes, +BdrvRequestFlags read_flags,BdrvRequestFlags write_flags);/* * Building block for bdrv_block_status[_above] and
include/block/block_int-io.h +10 -10
@@ -113,16 +113,16 @@ void bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap *dest,void bdrv_inc_in_flight (BlockDriverState *bs);void bdrv_dec_in_flight (BlockDriverState *bs); -int coroutine_fn bdrv_co_copy_range_from(BdrvChild *src, int64_t src_offset, -BdrvChild *dst,int64_t dst_offset, -int64_t bytes, -BdrvRequestFlags read_flags, -BdrvRequestFlags write_flags); -int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset, -BdrvChild *dst,int64_t dst_offset, -int64_t bytes, -BdrvRequestFlags read_flags, -BdrvRequestFlags write_flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_copy_range_from (BdrvChild *src,int64_t src_offset, +BdrvChild *dst,int64_t dst_offset, +int64_t bytes,BdrvRequestFlags read_flags, +BdrvRequestFlags write_flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_copy_range_to (BdrvChild *src,int64_t src_offset, +BdrvChild *dst,int64_t dst_offset, +int64_t bytes,BdrvRequestFlags read_flags, +BdrvRequestFlags write_flags); int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs,int64_t hint);
block/block-backend.c +2 -0
@@ -2644,6 +2644,8 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,if (r) {return r; } + +GRAPH_RDLOCK_GUARD ();return bdrv_co_copy_range (blk_in->root, off_in, blk_out->root, off_out, bytes, read_flags, write_flags);
block/file-posix.c +7 -9
@@ -3272,7 +3272,7 @@ static void raw_abort_perm_update(BlockDriverState *bs)raw_handle_perm_lock (bs,RAW_PL_ABORT ,0 ,0 ,NULL ); } -static int coroutine_fn raw_co_copy_range_from( +static int coroutine_fn GRAPH_RDLOCK raw_co_copy_range_from(BlockDriverState *bs,BdrvChild *src,int64_t src_offset,BdrvChild *dst,int64_t dst_offset,int64_t bytes,BdrvRequestFlags read_flags,BdrvRequestFlags write_flags)
@@ -3281,14 +3281,12 @@ static int coroutine_fn raw_co_copy_range_from( read_flags, write_flags); } -static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, -BdrvChild *src, -int64_t src_offset, -BdrvChild *dst, -int64_t dst_offset, -int64_t bytes, -BdrvRequestFlags read_flags, -BdrvRequestFlags write_flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_copy_range_to (BlockDriverState *bs, +BdrvChild *src,int64_t src_offset, +BdrvChild *dst,int64_t dst_offset, +int64_t bytes,BdrvRequestFlags read_flags, +BdrvRequestFlags write_flags) {RawPosixAIOData acb;BDRVRawState *s = bs->opaque;
block/io.c +5 -2
@@ -3243,6 +3243,7 @@ static int coroutine_fn GRAPH_RDLOCK bdrv_co_copy_range_internal( {BdrvTrackedRequest req;int ret; +assert_bdrv_graph_readable ();/* TODO We can support BDRV_REQ_NO_FALLBACK here */ assert (!(read_flags &BDRV_REQ_NO_FALLBACK ));
@@ -3324,7 +3325,7 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *src, int64_t src_offset, BdrvRequestFlags write_flags) {IO_CODE (); -assume_graph_lock ();/* FIXME */ +assert_bdrv_graph_readable ();trace_bdrv_co_copy_range_from (src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset,
@@ -3342,7 +3343,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset, BdrvRequestFlags write_flags) {IO_CODE (); -assume_graph_lock ();/* FIXME */ +assert_bdrv_graph_readable ();trace_bdrv_co_copy_range_to (src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset,
@@ -3355,6 +3356,8 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, int64_t src_offset, BdrvRequestFlags write_flags) {IO_CODE (); +assert_bdrv_graph_readable (); +return bdrv_co_copy_range_from (src, src_offset, dst, dst_offset, bytes, read_flags, write_flags);
block/iscsi.c +12 -16
@@ -2186,14 +2186,12 @@ static void coroutine_fn iscsi_co_invalidate_cache(BlockDriverState *bs,iscsi_allocmap_invalidate (iscsilun); } -static int coroutine_fn iscsi_co_copy_range_from(BlockDriverState *bs, -BdrvChild *src, -int64_t src_offset, -BdrvChild *dst, -int64_t dst_offset, -int64_t bytes, -BdrvRequestFlags read_flags, -BdrvRequestFlags write_flags) +static int coroutine_fn GRAPH_RDLOCK +iscsi_co_copy_range_from (BlockDriverState *bs, +BdrvChild *src,int64_t src_offset, +BdrvChild *dst,int64_t dst_offset, +int64_t bytes,BdrvRequestFlags read_flags, +BdrvRequestFlags write_flags) {return bdrv_co_copy_range_to (src, src_offset, dst, dst_offset, bytes, read_flags, write_flags);
@@ -2327,14 +2325,12 @@ static void iscsi_xcopy_data(struct iscsi_data *data, src_lba, dst_lba); } -static int coroutine_fn iscsi_co_copy_range_to(BlockDriverState *bs, -BdrvChild *src, -int64_t src_offset, -BdrvChild *dst, -int64_t dst_offset, -int64_t bytes, -BdrvRequestFlags read_flags, -BdrvRequestFlags write_flags) +static int coroutine_fn GRAPH_RDLOCK +iscsi_co_copy_range_to (BlockDriverState *bs, +BdrvChild *src,int64_t src_offset, +BdrvChild *dst,int64_t dst_offset, +int64_t bytes,BdrvRequestFlags read_flags, +BdrvRequestFlags write_flags) {IscsiLun *dst_lun = dst->bs->opaque;IscsiLun *src_lun;
block/qcow2.c +2 -3
@@ -4065,7 +4065,7 @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs,return ret; } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK qcow2_co_copy_range_from(BlockDriverState *bs, BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset,
@@ -4148,7 +4148,7 @@ out:return ret; } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK qcow2_co_copy_range_to(BlockDriverState *bs, BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset,
@@ -4161,7 +4161,6 @@ qcow2_co_copy_range_to(BlockDriverState *bs,uint64_t host_offset;QCowL2Meta *l2meta =NULL ; -assume_graph_lock ();/* FIXME */ assert (!bs->encrypted);qemu_co_mutex_lock (&s->lock);
block/raw-format.c +12 -16
@@ -536,14 +536,12 @@ static int raw_probe_geometry(BlockDriverState *bs, HDGeometry *geo)return bdrv_probe_geometry (bs->file->bs, geo); } -static int coroutine_fn raw_co_copy_range_from(BlockDriverState *bs, -BdrvChild *src, -int64_t src_offset, -BdrvChild *dst, -int64_t dst_offset, -int64_t bytes, -BdrvRequestFlags read_flags, -BdrvRequestFlags write_flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_copy_range_from (BlockDriverState *bs, +BdrvChild *src,int64_t src_offset, +BdrvChild *dst,int64_t dst_offset, +int64_t bytes,BdrvRequestFlags read_flags, +BdrvRequestFlags write_flags) {int ret;
@@ -555,14 +553,12 @@ static int coroutine_fn raw_co_copy_range_from(BlockDriverState *bs, bytes, read_flags, write_flags); } -static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, -BdrvChild *src, -int64_t src_offset, -BdrvChild *dst, -int64_t dst_offset, -int64_t bytes, -BdrvRequestFlags read_flags, -BdrvRequestFlags write_flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_copy_range_to (BlockDriverState *bs, +BdrvChild *src,int64_t src_offset, +BdrvChild *dst,int64_t dst_offset, +int64_t bytes,BdrvRequestFlags read_flags, +BdrvRequestFlags write_flags) {int ret;
qemu-img.c +3 -1
@@ -2041,7 +2041,9 @@ retry:if (s->ret == -EINPROGRESS ) {if (copy_range) { - ret =convert_co_copy_range (s, sector_num, n); + WITH_GRAPH_RDLOCK_GUARD() { + ret =convert_co_copy_range (s, sector_num, n); + }if (ret) { s->copy_range = false; goto retry;
Signature · 1 line
2.38.1
PATCH 20/23 block: Mark bdrv_(un)register_buf() GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_register_buf() and bdrv_unregister_buf() need to hold a reader lock for the graph.
--- include/block/block_int-common.h | 7 ++++--- block/io.c | 14 ++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-)
include/block/block_int-common.h +4 -3
@@ -445,9 +445,10 @@ struct BlockDriver {* * Returns: true on success, false on failure */ -bool (*bdrv_register_buf)(BlockDriverState *bs,void *host,size_t size, -Error **errp); -void (*bdrv_unregister_buf)(BlockDriverState *bs,void *host,size_t size); + bool GRAPH_RDLOCK_PTR (*bdrv_register_buf)( +BlockDriverState *bs,void *host,size_t size,Error **errp); + void GRAPH_RDLOCK_PTR (*bdrv_unregister_buf)( +BlockDriverState *bs,void *host,size_t size);/* * This field is modified only under the BQL, and is part of
block/io.c +10 -4
@@ -3184,13 +3184,15 @@ void coroutine_fn bdrv_co_io_unplug(BlockDriverState *bs) }/* Helper that undoes bdrv_register_buf() when it fails partway through */ -static void bdrv_register_buf_rollback (BlockDriverState *bs, -void *host, -size_t size, -BdrvChild *final_child) +static void GRAPH_RDLOCK +bdrv_register_buf_rollback (BlockDriverState *bs,void *host,size_t size, +BdrvChild *final_child) {BdrvChild *child; +GLOBAL_STATE_CODE (); +assert_bdrv_graph_readable (); + QLIST_FOREACH(child, &bs->children, next) {if (child == final_child) {break ;
@@ -3210,6 +3212,8 @@ bool bdrv_register_buf(BlockDriverState *bs, void *host, size_t size,BdrvChild *child;GLOBAL_STATE_CODE (); +GRAPH_RDLOCK_GUARD_MAINLOOP (); +if (bs->drv && bs->drv->bdrv_register_buf) {if (!bs->drv->bdrv_register_buf (bs, host, size, errp)) {return false;
@@ -3229,6 +3233,8 @@ void bdrv_unregister_buf(BlockDriverState *bs, void *host, size_t size)BdrvChild *child;GLOBAL_STATE_CODE (); +GRAPH_RDLOCK_GUARD_MAINLOOP (); +if (bs->drv && bs->drv->bdrv_unregister_buf) { bs->drv->bdrv_unregister_buf (bs, host, size); }
Signature · 1 line
2.38.1
PATCH 7/23 block: Mark bdrv_co_flush() and callers GRAPH_RDLOCK
In reply to Kevin WolfFrom: Emanuele Giuseppe Esposito <[email protected]>
This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_flush() need to hold a reader lock for the graph.
For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated.
--- block/qcow2.h | 5 +++- block/qed.h | 29 +++++++++++++-------- include/block/block-io.h | 2 +- include/block/block_int-common.h | 12 +++++---- block/blkdebug.c | 2 +- block/blklogwrites.c | 21 ++++++++++----- block/blkreplay.c | 2 +- block/blkverify.c | 2 +- block/block-backend.c | 3 ++- block/copy-before-write.c | 2 +- block/file-posix.c | 4 +-- block/io.c | 7 +++++ block/mirror.c | 2 +- block/preallocate.c | 2 +- block/qed-check.c | 3 ++- block/qed-table.c | 6 ++--- block/qed.c | 44 +++++++++++++++++++------------- block/quorum.c | 2 +- block/throttle.c | 2 +- block/vmdk.c | 6 +++-- 20 files changed, 98 insertions(+), 60 deletions(-)
block/qcow2.h +4 -1
@@ -900,7 +900,10 @@ int coroutine_fn qcow2_detect_metadata_preallocation(BlockDriverState *bs);/* qcow2-cluster.c functions */ int qcow2_grow_l1_table (BlockDriverState *bs,uint64_t min_size,bool exact_size); -int coroutine_fn qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_size); + +int coroutine_fn GRAPH_RDLOCK +qcow2_shrink_l1_table (BlockDriverState *bs,uint64_t max_size); +int qcow2_write_l1_entry (BlockDriverState *bs,int l1_index);int qcow2_encrypt_sectors (BDRVQcow2State *s,int64_t sector_num,uint8_t *buf,int nb_sectors,bool enc,Error **errp);
block/qed.h +18 -11
@@ -201,20 +201,25 @@ void qed_commit_l2_cache_entry(L2TableCache *l2_cache, CachedL2Table *l2_table);* Table I/O functions */ int coroutine_fn qed_read_l1_table_sync(BDRVQEDState *s); -int coroutine_fn qed_write_l1_table(BDRVQEDState *s, unsigned int index, -unsigned int n); -int coroutine_fn qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, -unsigned int n); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l1_table (BDRVQEDState *s,unsigned int index,unsigned int n); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l1_table_sync (BDRVQEDState *s,unsigned int index,unsigned int n); + int coroutine_fn qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request,uint64_t offset); int coroutine_fn qed_read_l2_table(BDRVQEDState *s, QEDRequest *request,uint64_t offset); -int coroutine_fn qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, -unsigned int index,unsigned int n, -bool flush); -int coroutine_fn qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request, -unsigned int index,unsigned int n, -bool flush); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l2_table (BDRVQEDState *s,QEDRequest *request,unsigned int index, +unsigned int n,bool flush); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l2_table_sync (BDRVQEDState *s,QEDRequest *request, +unsigned int index,unsigned int n,bool flush);/** * Cluster functions
@@ -226,7 +231,9 @@ int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDRequest *request,/** * Consistency check */ -int coroutine_fn qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool fix); +int coroutine_fn GRAPH_RDLOCK +qed_check (BDRVQEDState *s,BdrvCheckResult *result,bool fix); +QEDTable *qed_alloc_table (BDRVQEDState *s);
include/block/block-io.h +1 -1
@@ -101,7 +101,7 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);/* Ensure contents are flushed to disk. */ -int coroutine_fn bdrv_co_flush(BlockDriverState *bs); +int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDriverState *bs); int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset,int64_t bytes);
include/block/block_int-common.h +7 -5
@@ -477,8 +477,8 @@ struct BlockDriver {BlockAIOCB *(*bdrv_aio_pwritev)(BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags,BlockCompletionFunc *cb,void *opaque); - BlockAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs, - BlockCompletionFunc *cb, void *opaque); + BlockAIOCB *GRAPH_RDLOCK_PTR (*bdrv_aio_flush)( + BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque);BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs,int64_t offset,int bytes,BlockCompletionFunc *cb,void *opaque);
@@ -646,7 +646,7 @@ struct BlockDriver {* layers, if needed. This function is needed for deterministic * synchronization of the flush finishing callback. */ - int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush)(BlockDriverState *bs);/* Delete a created file. */ int coroutine_fn (*bdrv_co_delete_file)(BlockDriverState *bs,
@@ -656,14 +656,16 @@ struct BlockDriver {* Flushes all data that was already written to the OS all the way down to * the disk (for example file-posix.c calls fsync()). */ - int coroutine_fn (*bdrv_co_flush_to_disk)(BlockDriverState *bs); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush_to_disk)( + BlockDriverState *bs);/* * Flushes all internal caches to the OS. The data may still sit in a * writeback cache of the host OS, but it will survive a crash of the qemu * process. */ - int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush_to_os)( + BlockDriverState *bs);/* * Truncate @bs to @offset bytes using the given @prealloc mode
block/blkdebug.c +1 -1
@@ -668,7 +668,7 @@ blkdebug_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,return bdrv_co_pwritev (bs->file, offset, bytes, qiov, flags); } -static int coroutine_fn blkdebug_co_flush(BlockDriverState *bs) +static int GRAPH_RDLOCK coroutine_fn blkdebug_co_flush(BlockDriverState *bs) {int err =rule_check (bs,0 ,0 ,BLKDEBUG_IO_TYPE_FLUSH );
block/blklogwrites.c +14 -7
@@ -307,7 +307,7 @@ typedef struct BlkLogWritesFileReq {uint64_t bytes;int file_flags;QEMUIOVector *qiov; -int (*func)(struct BlkLogWritesFileReq *r); + int GRAPH_RDLOCK_PTR (*func)(struct BlkLogWritesFileReq *r);int file_ret; } BlkLogWritesFileReq;
@@ -319,7 +319,8 @@ typedef struct {int log_ret; } BlkLogWritesLogReq; -static void coroutine_fn blk_log_writes_co_do_log(BlkLogWritesLogReq *lr) +static void coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_do_log (BlkLogWritesLogReq *lr) {BDRVBlkLogWritesState *s = lr->bs->opaque;uint64_t cur_log_offset = s->cur_log_sector << s->sectorbits;
@@ -368,15 +369,16 @@ static void coroutine_fn blk_log_writes_co_do_log(BlkLogWritesLogReq *lr) } } -static void coroutine_fn blk_log_writes_co_do_file(BlkLogWritesFileReq *fr) +static void coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_do_file (BlkLogWritesFileReq *fr) { fr->file_ret = fr->func (fr); } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblk_log_writes_co_log (BlockDriverState *bs,uint64_t offset,uint64_t bytes,QEMUIOVector *qiov,int flags, -int (*file_func)(BlkLogWritesFileReq *r), +int /*GRAPH_RDLOCK*/ (*file_func)(BlkLogWritesFileReq *r),uint64_t entry_flags,bool is_zero_write) {QEMUIOVector log_qiov;
@@ -442,7 +444,8 @@ blk_log_writes_co_do_file_pwrite_zeroes(BlkLogWritesFileReq *fr) fr->file_flags); } -static int coroutine_fn blk_log_writes_co_do_file_flush(BlkLogWritesFileReq *fr) +static int coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_do_file_flush (BlkLogWritesFileReq *fr) {return bdrv_co_flush (fr->bs->file->bs); }
@@ -457,6 +460,7 @@ static int coroutine_fn blk_log_writes_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { +assume_graph_lock ();/* FIXME */ return blk_log_writes_co_log (bs, offset, bytes, qiov, flags, blk_log_writes_co_do_file_pwritev,0 , false); }
@@ -465,12 +469,14 @@ static int coroutine_fn blk_log_writes_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, BdrvRequestFlags flags) { +assume_graph_lock ();/* FIXME */ return blk_log_writes_co_log (bs, offset, bytes,NULL , flags, blk_log_writes_co_do_file_pwrite_zeroes,0 , true); } -static int coroutine_fn blk_log_writes_co_flush_to_disk(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_flush_to_disk (BlockDriverState *bs) { return blk_log_writes_co_log(bs, 0, 0, NULL, 0, blk_log_writes_co_do_file_flush,
@@ -480,6 +486,7 @@ static int coroutine_fn blk_log_writes_co_flush_to_disk(BlockDriverState *bs) static int coroutine_fnblk_log_writes_co_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes) { +assume_graph_lock ();/* FIXME */ return blk_log_writes_co_log (bs, offset, bytes,NULL ,0 , blk_log_writes_co_do_file_pdiscard,LOG_DISCARD_FLAG , false);
block/blkreplay.c +1 -1
@@ -113,7 +113,7 @@ static int coroutine_fn blkreplay_co_pdiscard(BlockDriverState *bs,return ret; } -static int coroutine_fn blkreplay_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK blkreplay_co_flush(BlockDriverState *bs) {uint64_t reqid =blkreplay_next_id ();int ret =bdrv_co_flush (bs->file->bs);
block/blkverify.c +1 -1
@@ -256,7 +256,7 @@ blkverify_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,return blkverify_co_prwv (bs, &r, offset, bytes, qiov, qiov, flags, true); } -static int coroutine_fn blkverify_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK blkverify_co_flush(BlockDriverState *bs) {BDRVBlkverifyState *s = bs->opaque;
block/block-backend.c +2 -1
@@ -1762,8 +1762,9 @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,/* To be called between exactly one pair of blk_inc/dec_in_flight() */ static int coroutine_fn blk_co_do_flush(BlockBackend *blk) { -blk_wait_while_drained (blk);IO_CODE (); +blk_wait_while_drained (blk); +GRAPH_RDLOCK_GUARD ();if (!blk_is_available (blk)) {return -ENOMEDIUM ;
block/copy-before-write.c +1 -1
@@ -185,7 +185,7 @@ static coroutine_fn int cbw_co_pwritev(BlockDriverState *bs,return bdrv_co_pwritev (bs->file, offset, bytes, qiov, flags); } -static int coroutine_fn cbw_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK cbw_co_flush(BlockDriverState *bs) {if (!bs->file) {return 0 ;
block/file-posix.c +2 -2
@@ -2920,8 +2920,8 @@ static void coroutine_fn check_cache_dropped(BlockDriverState *bs, Error **errp) }#endif /* __linux__ */ -static void coroutine_fn raw_co_invalidate_cache(BlockDriverState *bs, -Error **errp) +static void coroutine_fn GRAPH_RDLOCK +raw_co_invalidate_cache (BlockDriverState *bs,Error **errp) {BDRVRawState *s = bs->opaque;int ret;
block/io.c +7 -0
@@ -933,6 +933,8 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset,int ret;IO_CODE (); +assume_graph_lock ();/* FIXME */ + ret =bdrv_co_pwrite (child, offset, bytes, buf, flags);if (ret <0 ) {return ret;
@@ -1041,6 +1043,8 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriverState *bs,QEMUIOVector local_qiov;int ret; +assume_graph_lock ();/* FIXME */ +bdrv_check_qiov_request (offset, bytes, qiov, qiov_offset, &error_abort);if (!drv) {
@@ -1680,6 +1684,8 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,int head =0 ;int tail =0 ; +assume_graph_lock ();/* FIXME */ +int64_t max_write_zeroes =MIN_NON_ZERO (bs->bl.max_pwrite_zeroes,INT64_MAX ); int alignment = MAX(bs->bl.pwrite_zeroes_alignment,
@@ -2836,6 +2842,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)int ret =0 ;IO_CODE (); +assert_bdrv_graph_readable ();bdrv_inc_in_flight (bs); if (!bdrv_co_is_inserted(bs) || bdrv_is_read_only(bs) ||
block/mirror.c +1 -1
@@ -1535,7 +1535,7 @@ static int coroutine_fn bdrv_mirror_top_pwritev(BlockDriverState *bs,return ret; } -static int coroutine_fn bdrv_mirror_top_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK bdrv_mirror_top_flush(BlockDriverState *bs) {if (bs->backing ==NULL ) {/* we can be here after failed bdrv_append in mirror_start_job */
block/preallocate.c +1 -1
@@ -437,7 +437,7 @@ preallocate_co_truncate(BlockDriverState *bs, int64_t offset,return 0 ; } -static int coroutine_fn preallocate_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK preallocate_co_flush(BlockDriverState *bs) {return bdrv_co_flush (bs->file->bs); }
block/qed-check.c +2 -1
@@ -107,7 +107,8 @@ static unsigned int qed_check_l2_table(QEDCheck *check, QEDTable *table)/** * Descend tables and check each cluster is referenced once only */ -static int coroutine_fn qed_check_l1_table(QEDCheck *check, QEDTable *table) +static int coroutine_fn GRAPH_RDLOCK +qed_check_l1_table (QEDCheck *check,QEDTable *table) {BDRVQEDState *s = check->s;unsigned int i, num_invalid_l1 =0 ;
block/qed-table.c +3 -3
@@ -63,9 +63,9 @@ out:* * Called with table_lock held. */ -static int coroutine_fn qed_write_table(BDRVQEDState *s, uint64_t offset, -QEDTable *table,unsigned int index, -unsigned int n,bool flush) +static int coroutine_fn GRAPH_RDLOCK +qed_write_table (BDRVQEDState *s,uint64_t offset,QEDTable *table, +unsigned int index,unsigned int n,bool flush) {unsigned int sector_mask =BDRV_SECTOR_SIZE /sizeof (uint64_t ) -1 ;unsigned int start, end, i;
block/qed.c +26 -18
134 lines not on this page · raw message
block/quorum.c +1 -1
@@ -778,7 +778,7 @@ static int64_t coroutine_fn quorum_co_getlength(BlockDriverState *bs)return result; } -static coroutine_fn int quorum_co_flush(BlockDriverState *bs) +static coroutine_fn GRAPH_RDLOCK int quorum_co_flush(BlockDriverState *bs) {BDRVQuorumState *s = bs->opaque;QuorumVoteVersion *winner =NULL ;
block/throttle.c +1 -1
@@ -162,7 +162,7 @@ static int coroutine_fn throttle_co_pwritev_compressed(BlockDriverState *bs, BDRV_REQ_WRITE_COMPRESSED); } -static int coroutine_fn throttle_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK throttle_co_flush(BlockDriverState *bs) {return bdrv_co_flush (bs->file->bs); }
block/vmdk.c +4 -2
@@ -1484,8 +1484,8 @@ exit:return ret; } -static int coroutine_fn vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, -uint32_t offset) +static int coroutine_fn GRAPH_RDLOCK +vmdk_L2update (VmdkExtent *extent,VmdkMetaData *m_data,uint32_t offset) { offset =cpu_to_le32 (offset);/* update L2 table */
@@ -2028,6 +2028,8 @@ static int coroutine_fn vmdk_pwritev(BlockDriverState *bs, uint64_t offset,uint64_t bytes_done =0 ;VmdkMetaData m_data; +assume_graph_lock ();/* FIXME */ +if (DIV_ROUND_UP (offset,BDRV_SECTOR_SIZE ) > bs->total_sectors) { error_report("Wrong offset: offset=0x%" PRIx64 " total_sectors=0x%" PRIx64,
Signature · 1 line
2.38.1
PATCH 18/23 block: Mark bdrv_co_is_inserted() and callers GRAPH_RDLOCK
In reply to Kevin WolfFrom: Emanuele Giuseppe Esposito <[email protected]>
This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_is_inserted() need to hold a reader lock for the graph.
blk_is_inserted() is done as a co_wrapper_mixed_bdrv_rdlock (unlike most other blk_* functions) because it is called a lot from other blk_co_*() functions that already hold the lock. These calls go through blk_is_available(), which becomes a co_wrapper_mixed_bdrv_rdlock, too, for the same reason.
Functions that run in a coroutine and can call bdrv_co_is_available() directly are changed to do so, which results in better TSA coverage.
--- include/block/block-io.h | 4 ++-- include/block/block_int-common.h | 3 ++- include/sysemu/block-backend-io.h | 7 ++++--- block.c | 1 + block/block-backend.c | 25 ++++++++++++++----------- 5 files changed, 23 insertions(+), 17 deletions(-)
include/block/block-io.h +2 -2
@@ -145,8 +145,8 @@ bool bdrv_is_writable(BlockDriverState *bs);bool bdrv_is_sg (BlockDriverState *bs);int bdrv_get_flags (BlockDriverState *bs); -bool coroutine_fn bdrv_co_is_inserted(BlockDriverState *bs); -bool co_wrapper bdrv_is_inserted(BlockDriverState *bs); +bool coroutine_fn GRAPH_RDLOCK bdrv_co_is_inserted(BlockDriverState *bs); +bool co_wrapper_bdrv_rdlock bdrv_is_inserted(BlockDriverState *bs); void coroutine_fn bdrv_co_lock_medium(BlockDriverState *bs, bool locked); void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag);
include/block/block_int-common.h +2 -1
@@ -712,7 +712,8 @@ struct BlockDriver { BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);/* removable device specific */ - bool coroutine_fn (*bdrv_co_is_inserted)(BlockDriverState *bs); + bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)( + BlockDriverState *bs); void coroutine_fn (*bdrv_co_eject)(BlockDriverState *bs, bool eject_flag); void coroutine_fn (*bdrv_co_lock_medium)(BlockDriverState *bs, bool locked);
include/sysemu/block-backend-io.h +4 -3
@@ -55,10 +55,11 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,void blk_inc_in_flight (BlockBackend *blk);void blk_dec_in_flight (BlockBackend *blk); -bool coroutine_fn blk_co_is_inserted(BlockBackend *blk); -bool co_wrapper_mixed blk_is_inserted(BlockBackend *blk); +bool coroutine_fn GRAPH_RDLOCK blk_co_is_inserted(BlockBackend *blk); +bool co_wrapper_mixed_bdrv_rdlock blk_is_inserted(BlockBackend *blk); -bool blk_is_available (BlockBackend *blk); +bool coroutine_fn GRAPH_RDLOCK blk_co_is_available(BlockBackend *blk); +bool co_wrapper_mixed_bdrv_rdlock blk_is_available(BlockBackend *blk); void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked); void co_wrapper blk_lock_medium(BlockBackend *blk, bool locked);
block.c +1 -0
@@ -6803,6 +6803,7 @@ bool coroutine_fn bdrv_co_is_inserted(BlockDriverState *bs)BlockDriver *drv = bs->drv;BdrvChild *child;IO_CODE (); +assert_bdrv_graph_readable ();if (!drv) {return false;
block/block-backend.c +14 -11
@@ -1235,8 +1235,8 @@ void blk_set_disable_request_queuing(BlockBackend *blk, bool disable) blk->disable_request_queuing = disable; } -static coroutine_fn int blk_check_byte_request(BlockBackend *blk, -int64_t offset,int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +blk_check_byte_request (BlockBackend *blk,int64_t offset,int64_t bytes) {int64_t len;
@@ -1244,7 +1244,7 @@ static coroutine_fn int blk_check_byte_request(BlockBackend *blk,return -EIO ; } -if (!blk_is_available (blk)) { +if (!blk_co_is_available (blk)) {return -ENOMEDIUM ; }
@@ -1606,8 +1606,9 @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t coroutine_fn blk_co_getlength(BlockBackend *blk) {IO_CODE (); +GRAPH_RDLOCK_GUARD (); -if (!blk_is_available (blk)) { +if (!blk_co_is_available (blk)) {return -ENOMEDIUM ; }
@@ -1627,8 +1628,9 @@ void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr) int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk) {IO_CODE (); +GRAPH_RDLOCK_GUARD (); -if (!blk_is_available (blk)) { +if (!blk_co_is_available (blk)) {return -ENOMEDIUM ; }
@@ -1676,7 +1678,7 @@ blk_co_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf)blk_wait_while_drained (blk);GRAPH_RDLOCK_GUARD (); -if (!blk_is_available (blk)) { +if (!blk_co_is_available (blk)) {return -ENOMEDIUM ; }
@@ -1769,7 +1771,7 @@ static int coroutine_fn blk_co_do_flush(BlockBackend *blk)blk_wait_while_drained (blk);GRAPH_RDLOCK_GUARD (); -if (!blk_is_available (blk)) { +if (!blk_co_is_available (blk)) {return -ENOMEDIUM ; }
@@ -1996,14 +1998,15 @@ bool coroutine_fn blk_co_is_inserted(BlockBackend *blk) {BlockDriverState *bs =blk_bs (blk);IO_CODE (); +assert_bdrv_graph_readable ();return bs &&bdrv_co_is_inserted (bs); } -bool blk_is_available (BlockBackend *blk) +bool coroutine_fn blk_co_is_available(BlockBackend *blk) {IO_CODE (); -return blk_is_inserted (blk) && !blk_dev_is_tray_open (blk); +return blk_co_is_inserted (blk) && !blk_dev_is_tray_open (blk); } void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked)
@@ -2382,7 +2385,7 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact, {IO_OR_GS_CODE ();GRAPH_RDLOCK_GUARD (); -if (!blk_is_available (blk)) { +if (!blk_co_is_available (blk)) {error_setg (errp,"No medium inserted" );return -ENOMEDIUM ; }
@@ -2637,6 +2640,7 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, {int r;IO_CODE (); +GRAPH_RDLOCK_GUARD (); r =blk_check_byte_request (blk_in, off_in, bytes);if (r) {
@@ -2647,7 +2651,6 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,return r; } -GRAPH_RDLOCK_GUARD ();return bdrv_co_copy_range (blk_in->root, off_in, blk_out->root, off_out, bytes, read_flags, write_flags);
Signature · 1 line
2.38.1
PATCH 9/23 block: Mark bdrv_co_pwrite_zeroes() and callers GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pwrite_zeroes() need to hold a reader lock for the graph.
For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated.
--- block/qcow2.h | 6 ++++-- include/block/block-io.h | 9 +++++---- include/block/block_int-common.h | 5 +++-- block/blkdebug.c | 6 +++--- block/blklogwrites.c | 5 ++--- block/blkreplay.c | 5 +++-- block/block-copy.c | 13 +++++++------ block/copy-before-write.c | 5 +++-- block/copy-on-read.c | 6 +++--- block/filter-compress.c | 6 +++--- block/io.c | 12 +++++++++--- block/mirror.c | 6 +++--- block/preallocate.c | 11 +++++++---- block/qcow2.c | 30 ++++++++++++++++++------------ block/qed.c | 9 +++------ block/quorum.c | 15 ++++++++++----- block/raw-format.c | 6 +++--- block/throttle.c | 6 +++--- 18 files changed, 92 insertions(+), 69 deletions(-)
block/qcow2.h +4 -2
@@ -927,8 +927,10 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m);int qcow2_cluster_discard (BlockDriverState *bs,uint64_t offset,uint64_t bytes,enum qcow2_discard_type type,bool full_discard); -int coroutine_fn qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t offset, -uint64_t bytes,int flags); + +int coroutine_fn GRAPH_RDLOCK +qcow2_subcluster_zeroize (BlockDriverState *bs,uint64_t offset,uint64_t bytes, +int flags); int qcow2_expand_zero_clusters(BlockDriverState *bs, BlockDriverAmendStatusCB *status_cb,
include/block/block-io.h +5 -4
@@ -69,8 +69,9 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset,* function is not suitable for zeroing the entire image in a single request * because it may allocate memory for the entire region. */ -int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, -int64_t bytes,BdrvRequestFlags flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pwrite_zeroes (BdrvChild *child,int64_t offset,int64_t bytes, +BdrvRequestFlags flags); int coroutine_fn GRAPH_RDLOCK bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
@@ -133,8 +134,8 @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, bool include_base, int64_t offset, int64_t bytes, int64_t *pnum); -int coroutine_fn bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset, -int64_t bytes); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_is_zero_fast (BlockDriverState *bs,int64_t offset,int64_t bytes);int bdrv_apply_auto_read_only (BlockDriverState *bs,const char *errmsg,Error **errp);
include/block/block_int-common.h +3 -2
@@ -542,8 +542,9 @@ struct BlockDriver {* function pointer may be NULL or return -ENOSUP and .bdrv_co_writev() * will be called instead. */ - int coroutine_fn (*bdrv_co_pwrite_zeroes)(BlockDriverState *bs, -int64_t offset,int64_t bytes,BdrvRequestFlags flags); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwrite_zeroes)( +BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags); int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard)(BlockDriverState *bs,int64_t offset,int64_t bytes);
block/blkdebug.c +3 -3
@@ -679,9 +679,9 @@ static int GRAPH_RDLOCK coroutine_fn blkdebug_co_flush(BlockDriverState *bs)return bdrv_co_flush (bs->file->bs); } -static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +blkdebug_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags) {uint32_t align =MAX (bs->bl.request_alignment, bs->bl.pwrite_zeroes_alignment);
block/blklogwrites.c +2 -3
@@ -437,7 +437,7 @@ blk_log_writes_co_do_file_pwritev(BlkLogWritesFileReq *fr) fr->qiov, fr->file_flags); } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblk_log_writes_co_do_file_pwrite_zeroes (BlkLogWritesFileReq *fr) { return bdrv_co_pwrite_zeroes(fr->bs->file, fr->offset, fr->bytes,
@@ -465,11 +465,10 @@ blk_log_writes_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, blk_log_writes_co_do_file_pwritev, 0, false); } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblk_log_writes_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes,BdrvRequestFlags flags) { -assume_graph_lock ();/* FIXME */ return blk_log_writes_co_log (bs, offset, bytes,NULL , flags, blk_log_writes_co_do_file_pwrite_zeroes,0 , true);
block/blkreplay.c +3 -2
@@ -91,8 +91,9 @@ static int coroutine_fn blkreplay_co_pwritev(BlockDriverState *bs,return ret; } -static int coroutine_fn blkreplay_co_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags) {uint64_t reqid =blkreplay_next_id ();int ret =bdrv_co_pwrite_zeroes (bs->file, offset, bytes, flags);
block/block-copy.c +7 -6
@@ -469,10 +469,9 @@ static coroutine_fn int block_copy_task_run(AioTaskPool *pool,* value of @method should be used for subsequent tasks. * Returns 0 on success. */ -static int coroutine_fn block_copy_do_copy(BlockCopyState *s, -int64_t offset,int64_t bytes, -BlockCopyMethod *method, -bool *error_is_read) +static int coroutine_fn GRAPH_RDLOCK +block_copy_do_copy (BlockCopyState *s,int64_t offset,int64_t bytes, +BlockCopyMethod *method,bool *error_is_read) {int ret;int64_t nbytes =MIN (offset + bytes, s->len) - offset;
@@ -558,8 +557,10 @@ static coroutine_fn int block_copy_task_entry(AioTask *task)BlockCopyMethod method = t->method;int ret; - ret =block_copy_do_copy (s, t->req.offset, t->req.bytes, &method, - &error_is_read); + WITH_GRAPH_RDLOCK_GUARD() { + ret =block_copy_do_copy (s, t->req.offset, t->req.bytes, &method, + &error_is_read); + } WITH_QEMU_LOCK_GUARD(&s->lock) {if (s->method == t->method) {
block/copy-before-write.c +3 -2
@@ -160,8 +160,9 @@ cbw_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes)return bdrv_co_pdiscard (bs->file, offset, bytes); } -static int coroutine_fn cbw_co_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags) {int ret =cbw_do_copy_before_write (bs, offset, bytes, flags);if (ret <0 ) {
block/copy-on-read.c +3 -3
@@ -192,9 +192,9 @@ static int coroutine_fn cor_co_pwritev_part(BlockDriverState *bs, } -static int coroutine_fn cor_co_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags) {return bdrv_co_pwrite_zeroes (bs->file, offset, bytes, flags); }
block/filter-compress.c +3 -3
@@ -84,9 +84,9 @@ static int coroutine_fn compress_co_pwritev_part(BlockDriverState *bs, } -static int coroutine_fn compress_co_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +compress_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags) {return bdrv_co_pwrite_zeroes (bs->file, offset, bytes, flags); }
block/io.c +9 -3
@@ -1172,6 +1172,8 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,int64_t progress =0 ;bool skip_write; +assume_graph_lock ();/* FIXME */ +bdrv_check_qiov_request (offset, bytes, qiov, qiov_offset, &error_abort);if (!drv) {
@@ -1692,6 +1694,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, bs->bl.request_alignment);int max_transfer =MIN_NON_ZERO (bs->bl.max_transfer,MAX_BOUNCE_BUFFER ); +assert_bdrv_graph_readable ();bdrv_check_request (offset, bytes, &error_abort);if (!drv) {
@@ -1907,6 +1910,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child,int64_t bytes_remaining = bytes;int max_transfer; +assume_graph_lock ();/* FIXME */ +bdrv_check_qiov_request (offset, bytes, qiov, qiov_offset, &error_abort);if (!drv) {
@@ -2156,6 +2161,7 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, {IO_CODE ();trace_bdrv_co_pwrite_zeroes (child->bs, offset, bytes, flags); +assert_bdrv_graph_readable ();if (!(child->bs->open_flags &BDRV_O_UNMAP )) { flags &= ~BDRV_REQ_MAY_UNMAP ;
@@ -2599,8 +2605,6 @@ int coroutine_fn bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset,int64_t pnum = bytes;IO_CODE (); -assume_graph_lock ();/* FIXME */ -if (!bytes) {return 1 ; }
@@ -3238,7 +3242,7 @@ void bdrv_unregister_buf(BlockDriverState *bs, void *host, size_t size) } } -static int coroutine_fn bdrv_co_copy_range_internal( +static int coroutine_fn GRAPH_RDLOCK bdrv_co_copy_range_internal( BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset, int64_t bytes, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags,
@@ -3327,6 +3331,7 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *src, int64_t src_offset, BdrvRequestFlags write_flags) {IO_CODE (); +assume_graph_lock ();/* FIXME */ trace_bdrv_co_copy_range_from (src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset,
@@ -3344,6 +3349,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset, BdrvRequestFlags write_flags) {IO_CODE (); +assume_graph_lock ();/* FIXME */ trace_bdrv_co_copy_range_to (src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset,
block/mirror.c +3 -3
@@ -1547,10 +1547,10 @@ static int coroutine_fn GRAPH_RDLOCK bdrv_mirror_top_flush(BlockDriverState *bs)return bdrv_co_flush (bs->backing->bs); } -static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_pwrite_zeroes (BlockDriverState *bs,int64_t offset, +int64_t bytes,BdrvRequestFlags flags) { -assume_graph_lock ();/* FIXME */ return bdrv_mirror_top_do_write (bs,MIRROR_METHOD_ZERO , offset, bytes,NULL , flags); }
block/preallocate.c +7 -4
@@ -269,8 +269,9 @@ static bool has_prealloc_perms(BlockDriverState *bs)* want_merge_zero is used to merge write-zero request with preallocation in * one bdrv_co_pwrite_zeroes() call. */ -static bool coroutine_fn handle_write(BlockDriverState *bs, int64_t offset, -int64_t bytes,bool want_merge_zero) +static bool coroutine_fn GRAPH_RDLOCK +handle_write (BlockDriverState *bs,int64_t offset,int64_t bytes, +bool want_merge_zero) {BDRVPreallocateState *s = bs->opaque;int64_t end = offset + bytes;
@@ -345,8 +346,9 @@ static bool coroutine_fn handle_write(BlockDriverState *bs, int64_t offset,return want_merge_zero; } -static int coroutine_fn preallocate_co_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset, +int64_t bytes,BdrvRequestFlags flags) {bool want_merge_zero = !(flags & ~(BDRV_REQ_ZERO_WRITE |BDRV_REQ_NO_FALLBACK ));
@@ -364,6 +366,7 @@ static coroutine_fn int preallocate_co_pwritev_part(BlockDriverState *bs,size_t qiov_offset, BdrvRequestFlags flags) { +assume_graph_lock ();/* FIXME */ handle_write (bs, offset, bytes, false); return bdrv_co_pwritev_part(bs->file, offset, bytes, qiov, qiov_offset,
block/qcow2.c +18 -12
@@ -2450,7 +2450,8 @@ static bool merge_cow(uint64_t offset, unsigned bytes,* Return 1 if the COW regions read as zeroes, 0 if not, < 0 on error. * Note that returning 0 does not guarantee non-zero data. */ -static int coroutine_fn is_zero_cow(BlockDriverState *bs, QCowL2Meta *m) +static int coroutine_fn GRAPH_RDLOCK +is_zero_cow (BlockDriverState *bs,QCowL2Meta *m) {/* * This check is designed for optimization shortcut so it must be
@@ -2468,8 +2469,8 @@ static int coroutine_fn is_zero_cow(BlockDriverState *bs, QCowL2Meta *m) m->cow_end.nb_bytes); } -static int coroutine_fn handle_alloc_space(BlockDriverState *bs, -QCowL2Meta *l2meta) +static int coroutine_fn GRAPH_RDLOCK +handle_alloc_space (BlockDriverState *bs,QCowL2Meta *l2meta) {BDRVQcow2State *s = bs->opaque;QCowL2Meta *m;
@@ -2532,12 +2533,10 @@ static int coroutine_fn handle_alloc_space(BlockDriverState *bs,* l2meta - if not NULL, qcow2_co_pwritev_task() will consume it. Caller must * not use it somehow after qcow2_co_pwritev_task() call */ -static coroutine_fn int qcow2_co_pwritev_task(BlockDriverState *bs, -uint64_t host_offset, -uint64_t offset,uint64_t bytes, -QEMUIOVector *qiov, -uint64_t qiov_offset, -QCowL2Meta *l2meta) +static coroutine_fn GRAPH_RDLOCK +int qcow2_co_pwritev_task (BlockDriverState *bs,uint64_t host_offset, +uint64_t offset,uint64_t bytes,QEMUIOVector *qiov, +uint64_t qiov_offset,QCowL2Meta *l2meta) {int ret;BDRVQcow2State *s = bs->opaque;
@@ -2603,7 +2602,11 @@ out_locked:return ret; } -static coroutine_fn int qcow2_co_pwritev_task_entry(AioTask *task) +/* +* This function can count as GRAPH_RDLOCK because qcow2_co_pwritev_part() holds +* the graph lock and keeps it until this coroutine has terminated. +*/ +static coroutine_fn GRAPH_RDLOCK int qcow2_co_pwritev_task_entry(AioTask *task) {Qcow2AioTask *t =container_of (task, Qcow2AioTask, task);
@@ -2626,6 +2629,8 @@ static coroutine_fn int qcow2_co_pwritev_part(QCowL2Meta *l2meta =NULL ;AioTaskPool *aio =NULL ; +assume_graph_lock ();/* FIXME */ +trace_qcow2_writev_start_req (qemu_coroutine_self (), offset, bytes);while (bytes !=0 &&aio_task_pool_status (aio) ==0 ) {
@@ -3974,8 +3979,9 @@ static bool is_zero(BlockDriverState *bs, int64_t offset, int64_t bytes)return res >=0 && (res &BDRV_BLOCK_ZERO ) && bytes ==0 ; } -static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags) {int ret;BDRVQcow2State *s = bs->opaque;
block/qed.c +3 -6
@@ -1420,15 +1420,12 @@ static int coroutine_fn bdrv_qed_co_writev(BlockDriverState *bs,return qed_co_request (bs, sector_num, qiov, nb_sectors,QED_AIOCB_WRITE ); } -static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, -int64_t offset, -int64_t bytes, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags) {BDRVQEDState *s = bs->opaque; -assume_graph_lock ();/* FIXME */ -/* * Zero writes start without an I/O buffer. If a buffer becomes necessary * then it will be allocated during request processing.
block/quorum.c +10 -5
@@ -683,7 +683,11 @@ static int coroutine_fn quorum_co_preadv(BlockDriverState *bs,return ret; } -static void coroutine_fn write_quorum_entry(void *opaque) +/* +* This function can count as GRAPH_RDLOCK because quorum_co_pwritev() holds the +* graph lock and keeps it until this coroutine has terminated. +*/ +static void coroutine_fn GRAPH_RDLOCK write_quorum_entry(void *opaque) {QuorumCo *co = opaque;QuorumAIOCB *acb = co->acb;
@@ -722,6 +726,8 @@ static int coroutine_fn quorum_co_pwritev(BlockDriverState *bs, int64_t offset,QuorumAIOCB *acb =quorum_aio_get (bs, qiov, offset, bytes, flags);int i, ret; +assume_graph_lock ();/* FIXME */ +for (i =0 ; i < s->num_children; i++) {Coroutine *co;QuorumCo data = {
@@ -745,10 +751,9 @@ static int coroutine_fn quorum_co_pwritev(BlockDriverState *bs, int64_t offset,return ret; } -static int coroutine_fn quorum_co_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes, -BdrvRequestFlags flags) - +static int coroutine_fn GRAPH_RDLOCK +quorum_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags) {return quorum_co_pwritev (bs, offset, bytes,NULL , flags |BDRV_REQ_ZERO_WRITE );
block/raw-format.c +3 -3
@@ -292,9 +292,9 @@ static int coroutine_fn raw_co_block_status(BlockDriverState *bs,return BDRV_BLOCK_RAW |BDRV_BLOCK_OFFSET_VALID ; } -static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags) {int ret;
block/throttle.c +3 -3
@@ -134,9 +134,9 @@ static int coroutine_fn throttle_co_pwritev(BlockDriverState *bs,return bdrv_co_pwritev (bs->file, offset, bytes, qiov, flags); } -static int coroutine_fn throttle_co_pwrite_zeroes(BlockDriverState *bs, -int64_t offset,int64_t bytes, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int64_t bytes, +BdrvRequestFlags flags) {ThrottleGroupMember *tgm = bs->opaque;throttle_group_co_io_limits_intercept (tgm, bytes, true);
Signature · 1 line
2.38.1
PATCH 5/23 block: Mark bdrv_co_ioctl() and callers GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_ioctl() need to hold a reader lock for the graph.
--- include/block/block-io.h | 3 ++- include/block/block_int-common.h | 9 +++++---- block/block-backend.c | 1 + block/io.c | 1 + block/raw-format.c | 4 ++-- 5 files changed, 11 insertions(+), 7 deletions(-)
include/block/block-io.h +2 -1
@@ -97,7 +97,8 @@ void bdrv_aio_cancel(BlockAIOCB *acb);void bdrv_aio_cancel_async (BlockAIOCB *acb);/* sg packet commands */ -int coroutine_fn bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_ioctl (BlockDriverState *bs,int req,void *buf);/* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
include/block/block_int-common.h +5 -4
@@ -714,11 +714,12 @@ struct BlockDriver { void coroutine_fn (*bdrv_co_lock_medium)(BlockDriverState *bs, bool locked);/* to control generic scsi devices */ -BlockAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs, -unsigned long int req,void *buf, + BlockAIOCB *coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_aio_ioctl)( +BlockDriverState *bs,unsigned long int req,void *buf,BlockCompletionFunc *cb,void *opaque); - int coroutine_fn (*bdrv_co_ioctl)(BlockDriverState *bs, -unsigned long int req,void *buf); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_ioctl)( +BlockDriverState *bs,unsigned long int req,void *buf);/* * Returns 0 for completed check, -errno for internal errors.
block/block-backend.c +1 -0
@@ -1672,6 +1672,7 @@ blk_co_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf)IO_CODE ();blk_wait_while_drained (blk); +GRAPH_RDLOCK_GUARD ();if (!blk_is_available (blk)) {return -ENOMEDIUM ;
block/io.c +1 -0
@@ -3080,6 +3080,7 @@ int coroutine_fn bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf) };BlockAIOCB *acb;IO_CODE (); +assert_bdrv_graph_readable ();bdrv_inc_in_flight (bs);if (!drv || (!drv->bdrv_aio_ioctl && !drv->bdrv_co_ioctl)) {
block/raw-format.c +2 -2
@@ -415,8 +415,8 @@ static void coroutine_fn raw_co_lock_medium(BlockDriverState *bs, bool locked)bdrv_co_lock_medium (bs->file->bs, locked); } -static int coroutine_fn raw_co_ioctl(BlockDriverState *bs, -unsigned long int req,void *buf) +static int coroutine_fn GRAPH_RDLOCK +raw_co_ioctl (BlockDriverState *bs,unsigned long int req,void *buf) {BDRVRawState *s = bs->opaque;if (s->offset || s->has_size) {
Signature · 1 line
2.38.1
PATCH 10/23 block: Mark read/write in block/io.c GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_driver_*() need to hold a reader lock for the graph. It doesn't add the annotation to public functions yet.
For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated.
--- block/qcow2.h | 5 ++- include/block/block_int-common.h | 40 ++++++++++--------- block/io.c | 66 +++++++++++++++----------------- block/parallels.c | 8 ++-- block/qcow.c | 20 ++++------ block/qcow2-cluster.c | 10 ++--- block/qcow2.c | 37 ++++++++++-------- block/qed.c | 14 +++---- block/quorum.c | 8 ++-- block/vmdk.c | 4 +- 10 files changed, 101 insertions(+), 111 deletions(-)
block/qcow2.h +3 -2
@@ -921,8 +921,9 @@ int coroutine_fn qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,void qcow2_parse_compressed_l2_entry (BlockDriverState *bs,uint64_t l2_entry,uint64_t *coffset,int *csize); -int coroutine_fn qcow2_alloc_cluster_link_l2(BlockDriverState *bs, - QCowL2Meta *m); +int coroutine_fn GRAPH_RDLOCK +qcow2_alloc_cluster_link_l2 (BlockDriverState *bs,QCowL2Meta *m); +void qcow2_alloc_cluster_abort (BlockDriverState *bs,QCowL2Meta *m); int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset, uint64_t bytes, enum qcow2_discard_type type,
include/block/block_int-common.h +22 -18
@@ -471,12 +471,14 @@ struct BlockDriver { Error **errp);/* aio */ -BlockAIOCB *(*bdrv_aio_preadv)(BlockDriverState *bs, + BlockAIOCB *GRAPH_RDLOCK_PTR (*bdrv_aio_preadv)(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); -BlockAIOCB *(*bdrv_aio_pwritev)(BlockDriverState *bs, + + BlockAIOCB *GRAPH_RDLOCK_PTR (*bdrv_aio_pwritev)(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); + BlockAIOCB *GRAPH_RDLOCK_PTR (*bdrv_aio_flush)( BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque);
@@ -484,7 +486,7 @@ struct BlockDriver { BlockDriverState *bs, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); - int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_readv)(BlockDriverState *bs,int64_t sector_num,int nb_sectors,QEMUIOVector *qiov);/**
@@ -502,16 +504,16 @@ struct BlockDriver {* * The buffer in @qiov may point directly to guest memory. */ - int coroutine_fn (*bdrv_co_preadv)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_preadv)(BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags); - int coroutine_fn (*bdrv_co_preadv_part)(BlockDriverState *bs, -int64_t offset,int64_t bytes, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_preadv_part)( +BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,size_t qiov_offset,BdrvRequestFlags flags); - int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_writev)(BlockDriverState *bs,int64_t sector_num,int nb_sectors,QEMUIOVector *qiov,int flags);/**
@@ -529,12 +531,12 @@ struct BlockDriver {* * The buffer in @qiov may point directly to guest memory. */ - int coroutine_fn (*bdrv_co_pwritev)(BlockDriverState *bs, -int64_t offset,int64_t bytes,QEMUIOVector *qiov, -BdrvRequestFlags flags); - int coroutine_fn (*bdrv_co_pwritev_part)(BlockDriverState *bs, -int64_t offset,int64_t bytes,QEMUIOVector *qiov,size_t qiov_offset, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev)( +BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev_part)( +BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov, +size_t qiov_offset,BdrvRequestFlags flags);/* * Efficiently zero a region of the disk image. Typically an image format
@@ -695,11 +697,13 @@ struct BlockDriver { BlockMeasureInfo *(*bdrv_measure)(QemuOpts *opts, BlockDriverState *in_bs, Error **errp); - int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs, -int64_t offset,int64_t bytes,QEMUIOVector *qiov); - int coroutine_fn (*bdrv_co_pwritev_compressed_part)(BlockDriverState *bs, -int64_t offset,int64_t bytes,QEMUIOVector *qiov, -size_t qiov_offset); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev_compressed)( +BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev_compressed_part)( +BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,size_t qiov_offset); int coroutine_fn (*bdrv_co_get_info)(BlockDriverState *bs,BlockDriverInfo *bdi);
@@ -764,7 +768,7 @@ struct BlockDriver { BlockDriverState *bs, const char *name, Error **errp); }; -static inline bool block_driver_can_compress (BlockDriver *drv) +static inline bool TSA_NO_TSA block_driver_can_compress(BlockDriver *drv) {return drv->bdrv_co_pwritev_compressed || drv->bdrv_co_pwritev_compressed_part;
block/io.c +31 -35
150 lines not on this page · raw message
block/parallels.c +3 -5
@@ -320,17 +320,15 @@ static int coroutine_fn parallels_co_block_status(BlockDriverState *bs,return BDRV_BLOCK_DATA |BDRV_BLOCK_OFFSET_VALID ; } -static coroutine_fn int parallels_co_writev(BlockDriverState *bs, -int64_t sector_num,int nb_sectors, -QEMUIOVector *qiov,int flags) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_writev (BlockDriverState *bs,int64_t sector_num,int nb_sectors, +QEMUIOVector *qiov,int flags) {BDRVParallelsState *s = bs->opaque;uint64_t bytes_done =0 ;QEMUIOVector hd_qiov;int ret =0 ; -assume_graph_lock ();/* FIXME */ -qemu_iovec_init (&hd_qiov, qiov->niov);while (nb_sectors >0 ) {
block/qcow.c +7 -13
@@ -617,9 +617,9 @@ static void qcow_refresh_limits(BlockDriverState *bs, Error **errp) bs->bl.request_alignment =BDRV_SECTOR_SIZE ; } -static coroutine_fn int qcow_co_preadv(BlockDriverState *bs, int64_t offset, -int64_t bytes,QEMUIOVector *qiov, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {BDRVQcowState *s = bs->opaque;int offset_in_cluster;
@@ -628,8 +628,6 @@ static coroutine_fn int qcow_co_preadv(BlockDriverState *bs, int64_t offset,uint8_t *buf;void *orig_buf; -assume_graph_lock ();/* FIXME */ -if (qiov->niov >1 ) { buf = orig_buf =qemu_try_blockalign (bs, qiov->size);if (buf ==NULL ) {
@@ -715,9 +713,9 @@ static coroutine_fn int qcow_co_preadv(BlockDriverState *bs, int64_t offset,return ret; } -static coroutine_fn int qcow_co_pwritev(BlockDriverState *bs, int64_t offset, -int64_t bytes,QEMUIOVector *qiov, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {BDRVQcowState *s = bs->opaque;int offset_in_cluster;
@@ -726,8 +724,6 @@ static coroutine_fn int qcow_co_pwritev(BlockDriverState *bs, int64_t offset,uint8_t *buf;void *orig_buf; -assume_graph_lock ();/* FIXME */ - s->cluster_cache_offset =-1 ;/* disable compressed cache */ /* We must always copy the iov when encrypting, so we
@@ -1048,7 +1044,7 @@ static int qcow_make_empty(BlockDriverState *bs)/* XXX: put compressed sectors first, then all the cluster aligned tables to avoid losing bytes in alignment */ -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCKqcow_co_pwritev_compressed (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov) {
@@ -1058,8 +1054,6 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes,uint8_t *buf, *out_buf;uint64_t cluster_offset; -assume_graph_lock ();/* FIXME */ - buf =qemu_blockalign (bs, s->cluster_size);if (bytes != s->cluster_size) { if (bytes > s->cluster_size ||
block/qcow2-cluster.c +5 -5
@@ -491,10 +491,9 @@ static int count_contiguous_subclusters(BlockDriverState *bs, int nb_clusters,return count; } -static int coroutine_fn do_perform_cow_read(BlockDriverState *bs, -uint64_t src_cluster_offset, -unsigned offset_in_cluster, -QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +do_perform_cow_read (BlockDriverState *bs,uint64_t src_cluster_offset, +unsigned offset_in_cluster,QEMUIOVector *qiov) {int ret;
@@ -886,7 +885,8 @@ int coroutine_fn qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,return 0 ; } -static int coroutine_fn perform_cow(BlockDriverState *bs, QCowL2Meta *m) +static int coroutine_fn GRAPH_RDLOCK +perform_cow (BlockDriverState *bs,QCowL2Meta *m) {BDRVQcow2State *s = bs->opaque;Qcow2COWRegion *start = &m->cow_start;
block/qcow2.c +20 -17
@@ -2137,9 +2137,8 @@ static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs,return status; } -static coroutine_fn int qcow2_handle_l2meta(BlockDriverState *bs, -QCowL2Meta **pl2meta, -bool link_l2) +static int coroutine_fn GRAPH_RDLOCK +qcow2_handle_l2meta (BlockDriverState *bs,QCowL2Meta **pl2meta,bool link_l2) {int ret =0 ;QCowL2Meta *l2meta = *pl2meta;
@@ -2617,9 +2616,10 @@ static coroutine_fn GRAPH_RDLOCK int qcow2_co_pwritev_task_entry(AioTask *task) t->l2meta); } -static coroutine_fn int qcow2_co_pwritev_part( -BlockDriverState *bs,int64_t offset,int64_t bytes, -QEMUIOVector *qiov,size_t qiov_offset,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_pwritev_part (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,size_t qiov_offset, +BdrvRequestFlags flags) {BDRVQcow2State *s = bs->opaque;int offset_in_cluster;
@@ -2629,8 +2629,6 @@ static coroutine_fn int qcow2_co_pwritev_part(QCowL2Meta *l2meta =NULL ;AioTaskPool *aio =NULL ; -assume_graph_lock ();/* FIXME */ -trace_qcow2_writev_start_req (qemu_coroutine_self (), offset, bytes);while (bytes !=0 &&aio_task_pool_status (aio) ==0 ) {
@@ -4160,6 +4158,7 @@ qcow2_co_copy_range_to(BlockDriverState *bs,uint64_t host_offset;QCowL2Meta *l2meta =NULL ; +assume_graph_lock ();/* FIXME */ assert (!bs->encrypted);qemu_co_mutex_lock (&s->lock);
@@ -4591,7 +4590,7 @@ fail:return ret; } -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCKqcow2_co_pwritev_compressed_task (BlockDriverState *bs,uint64_t offset,uint64_t bytes,QEMUIOVector *qiov,size_t qiov_offset)
@@ -4655,7 +4654,13 @@ fail:return ret; } -static coroutine_fn int qcow2_co_pwritev_compressed_task_entry(AioTask *task) +/* +* This function can count as GRAPH_RDLOCK because +* qcow2_co_pwritev_compressed_part() holds the graph lock and keeps it until +* this coroutine has terminated. +*/ +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_pwritev_compressed_task_entry (AioTask *task) {Qcow2AioTask *t =container_of (task, Qcow2AioTask, task);
@@ -4669,7 +4674,7 @@ static coroutine_fn int qcow2_co_pwritev_compressed_task_entry(AioTask *task)* XXX: put compressed sectors first, then all the cluster aligned * tables to avoid losing bytes in alignment */ -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCKqcow2_co_pwritev_compressed_part (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,size_t qiov_offset)
@@ -4678,8 +4683,6 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs,AioTaskPool *aio =NULL ;int ret =0 ; -assume_graph_lock ();/* FIXME */ -if (has_data_file (bs)) {return -ENOTSUP ; }
@@ -5296,8 +5299,8 @@ static int64_t qcow2_check_vmstate_request(BlockDriverState *bs,return pos; } -static coroutine_fn int qcow2_co_save_vmstate(BlockDriverState *bs, -QEMUIOVector *qiov,int64_t pos) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_save_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos) {int64_t offset =qcow2_check_vmstate_request (bs, qiov, pos);if (offset <0 ) {
@@ -5308,8 +5311,8 @@ static coroutine_fn int qcow2_co_save_vmstate(BlockDriverState *bs,return bs->drv->bdrv_co_pwritev_part (bs, offset, qiov->size, qiov,0 ,0 ); } -static coroutine_fn int qcow2_co_load_vmstate(BlockDriverState *bs, -QEMUIOVector *qiov,int64_t pos) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_load_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos) {int64_t offset =qcow2_check_vmstate_request (bs, qiov, pos);if (offset <0 ) {
block/qed.c +6 -8
@@ -1404,19 +1404,17 @@ qed_co_request(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov,return qed_aio_next_io (&acb); } -static int coroutine_fn bdrv_qed_co_readv(BlockDriverState *bs, -int64_t sector_num,int nb_sectors, -QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_readv (BlockDriverState *bs,int64_t sector_num,int nb_sectors, +QEMUIOVector *qiov) { -assume_graph_lock ();/* FIXME */ return qed_co_request (bs, sector_num, qiov, nb_sectors,0 ); } -static int coroutine_fn bdrv_qed_co_writev(BlockDriverState *bs, -int64_t sector_num,int nb_sectors, -QEMUIOVector *qiov,int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_writev (BlockDriverState *bs,int64_t sector_num,int nb_sectors, +QEMUIOVector *qiov,int flags) { -assume_graph_lock ();/* FIXME */ return qed_co_request (bs, sector_num, qiov, nb_sectors,QED_AIOCB_WRITE ); }
block/quorum.c +3 -5
@@ -718,16 +718,14 @@ static void coroutine_fn GRAPH_RDLOCK write_quorum_entry(void *opaque) } } -static int coroutine_fn quorum_co_pwritev(BlockDriverState *bs, int64_t offset, -int64_t bytes,QEMUIOVector *qiov, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +quorum_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {BDRVQuorumState *s = bs->opaque;QuorumAIOCB *acb =quorum_aio_get (bs, qiov, offset, bytes, flags);int i, ret; -assume_graph_lock ();/* FIXME */ -for (i =0 ; i < s->num_children; i++) {Coroutine *co; QuorumCo data = {
block/vmdk.c +1 -3
@@ -2128,12 +2128,10 @@ vmdk_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,return ret; } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKvmdk_co_pwritev_compressed (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov) { -assume_graph_lock ();/* FIXME */ -if (bytes ==0 ) {/* The caller will write bytes 0 to signal EOF. * When receive it, we align EOF to a sector boundary. */
Signature · 1 line
2.38.1
PATCH 11/23 block: Mark public read/write functions GRAPH_RDLOCK
In reply to Kevin WolfThis adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pread*/pwrite*() need to hold a reader lock for the graph.
For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated.
--- block/qcow2.h | 9 ++--- block/qed.h | 18 +++++----- include/block/block_int-io.h | 14 ++++---- block/blkdebug.c | 4 +-- block/blklogwrites.c | 7 ++-- block/blkreplay.c | 10 +++--- block/block-backend.c | 2 ++ block/bochs.c | 2 +- block/commit.c | 5 +-- block/copy-before-write.c | 16 ++++----- block/copy-on-read.c | 26 ++++++--------- block/crypto.c | 4 +-- block/filter-compress.c | 19 +++++------ block/io.c | 7 ++-- block/mirror.c | 18 +++++----- block/parallels.c | 8 +++-- block/preallocate.c | 18 +++++----- block/qcow.c | 8 ++--- block/qcow2-cluster.c | 7 ++-- block/qcow2.c | 53 +++++++++++++++-------------- block/qed-table.c | 4 +-- block/qed.c | 31 +++++++++-------- block/quorum.c | 29 ++++++++++------ block/raw-format.c | 12 +++---- block/replication.c | 15 ++++----- block/throttle.c | 21 +++++------- block/vdi.c | 4 +-- block/vhdx.c | 11 +++--- block/vmdk.c | 65 +++++++++++++++--------------------- block/vpc.c | 4 +-- tests/unit/test-bdrv-drain.c | 20 ++++++----- 31 files changed, 233 insertions(+), 238 deletions(-)
block/qcow2.h +5 -4
@@ -846,7 +846,7 @@ int qcow2_validate_table(BlockDriverState *bs, uint64_t offset, Error **errp);/* qcow2-refcount.c functions */ -int coroutine_fn qcow2_refcount_init(BlockDriverState *bs); +int coroutine_fn GRAPH_RDLOCK qcow2_refcount_init(BlockDriverState *bs);void qcow2_refcount_close (BlockDriverState *bs); int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,
@@ -954,9 +954,10 @@ void qcow2_free_snapshots(BlockDriverState *bs);int qcow2_read_snapshots (BlockDriverState *bs,Error **errp);int qcow2_write_snapshots (BlockDriverState *bs); -int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs, -BdrvCheckResult *result, -BdrvCheckMode fix); +int coroutine_fn GRAPH_RDLOCK +qcow2_check_read_snapshot_table (BlockDriverState *bs,BdrvCheckResult *result, +BdrvCheckMode fix); + int coroutine_fn qcow2_check_fix_snapshot_table(BlockDriverState *bs,BdrvCheckResult *result,BdrvCheckMode fix);
block/qed.h +9 -9
@@ -200,7 +200,7 @@ void qed_commit_l2_cache_entry(L2TableCache *l2_cache, CachedL2Table *l2_table);/** * Table I/O functions */ -int coroutine_fn qed_read_l1_table_sync(BDRVQEDState *s); +int coroutine_fn GRAPH_RDLOCK qed_read_l1_table_sync(BDRVQEDState *s); int coroutine_fn GRAPH_RDLOCKqed_write_l1_table (BDRVQEDState *s,unsigned int index,unsigned int n);
@@ -208,10 +208,11 @@ qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n); int coroutine_fn GRAPH_RDLOCKqed_write_l1_table_sync (BDRVQEDState *s,unsigned int index,unsigned int n); -int coroutine_fn qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, -uint64_t offset); -int coroutine_fn qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, -uint64_t offset); +int coroutine_fn GRAPH_RDLOCK +qed_read_l2_table_sync (BDRVQEDState *s,QEDRequest *request,uint64_t offset); + +int coroutine_fn GRAPH_RDLOCK +qed_read_l2_table (BDRVQEDState *s,QEDRequest *request,uint64_t offset); int coroutine_fn GRAPH_RDLOCK qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, unsigned int index,
@@ -224,9 +225,9 @@ qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request,/** * Cluster functions */ -int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDRequest *request, -uint64_t pos,size_t *len, -uint64_t *img_offset); +int coroutine_fn GRAPH_RDLOCK +qed_find_cluster (BDRVQEDState *s,QEDRequest *request,uint64_t pos, +size_t *len,uint64_t *img_offset);/** * Consistency check
@@ -234,7 +235,6 @@ int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDRequest *request, int coroutine_fn GRAPH_RDLOCKqed_check (BDRVQEDState *s,BdrvCheckResult *result,bool fix); -QEDTable *qed_alloc_table (BDRVQEDState *s);/**
include/block/block_int-io.h +8 -6
@@ -44,33 +44,35 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes); -int coroutine_fn bdrv_co_preadv(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv(BdrvChild *child,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags); -int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv_part(BdrvChild *child,int64_t offset,int64_t bytes,QEMUIOVector *qiov,size_t qiov_offset,BdrvRequestFlags flags); -int coroutine_fn bdrv_co_pwritev(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_pwritev(BdrvChild *child,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags); -int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_pwritev_part(BdrvChild *child,int64_t offset,int64_t bytes,QEMUIOVector *qiov,size_t qiov_offset,BdrvRequestFlags flags); -static inline int coroutine_fn bdrv_co_pread(BdrvChild *child, +static inline int coroutine_fn GRAPH_RDLOCK bdrv_co_pread(BdrvChild *child,int64_t offset,int64_t bytes,void *buf,BdrvRequestFlags flags) {QEMUIOVector qiov =QEMU_IOVEC_INIT_BUF (qiov, buf, bytes);IO_CODE (); +assert_bdrv_graph_readable ();return bdrv_co_preadv (child, offset, bytes, &qiov, flags); } -static inline int coroutine_fn bdrv_co_pwrite(BdrvChild *child, +static inline int coroutine_fn GRAPH_RDLOCK bdrv_co_pwrite(BdrvChild *child,int64_t offset,int64_t bytes,const void *buf,BdrvRequestFlags flags) {QEMUIOVector qiov =QEMU_IOVEC_INIT_BUF (qiov, buf, bytes);IO_CODE (); +assert_bdrv_graph_readable ();return bdrv_co_pwritev (child, offset, bytes, &qiov, flags); }
block/blkdebug.c +2 -2
@@ -626,7 +626,7 @@ static int rule_check(BlockDriverState *bs, uint64_t offset, uint64_t bytes,return -error; } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblkdebug_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
@@ -647,7 +647,7 @@ blkdebug_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,return bdrv_co_preadv (bs->file, offset, bytes, qiov, flags); } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblkdebug_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
block/blklogwrites.c +3 -4
@@ -294,7 +294,7 @@ static void blk_log_writes_refresh_limits(BlockDriverState *bs, Error **errp) bs->bl.request_alignment = s->sectorsize; } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblk_log_writes_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
@@ -430,7 +430,7 @@ blk_log_writes_co_log(BlockDriverState *bs, uint64_t offset, uint64_t bytes,return fr.file_ret; } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblk_log_writes_co_do_file_pwritev (BlkLogWritesFileReq *fr) { return bdrv_co_pwritev(fr->bs->file, fr->offset, fr->bytes,
@@ -456,11 +456,10 @@ blk_log_writes_co_do_file_pdiscard(BlkLogWritesFileReq *fr)return bdrv_co_pdiscard (fr->bs->file, fr->offset, fr->bytes); } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKblk_log_writes_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) { -assume_graph_lock ();/* FIXME */ return blk_log_writes_co_log (bs, offset, bytes, qiov, flags, blk_log_writes_co_do_file_pwritev,0 , false); }
block/blkreplay.c +6 -4
@@ -69,8 +69,9 @@ static void block_request_create(uint64_t reqid, BlockDriverState *bs,replay_block_event (req->bh, reqid); } -static int coroutine_fn blkreplay_co_preadv(BlockDriverState *bs, -int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {uint64_t reqid =blkreplay_next_id ();int ret =bdrv_co_preadv (bs->file, offset, bytes, qiov, flags);
@@ -80,8 +81,9 @@ static int coroutine_fn blkreplay_co_preadv(BlockDriverState *bs,return ret; } -static int coroutine_fn blkreplay_co_pwritev(BlockDriverState *bs, -int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {uint64_t reqid =blkreplay_next_id ();int ret =bdrv_co_pwritev (bs->file, offset, bytes, qiov, flags);
block/block-backend.c +2 -0
@@ -1289,6 +1289,7 @@ blk_co_do_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes,IO_CODE ();blk_wait_while_drained (blk); +GRAPH_RDLOCK_GUARD ();/* Call blk_bs() only after waiting, the graph may have changed */ bs =blk_bs (blk);
@@ -1363,6 +1364,7 @@ blk_co_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes,IO_CODE ();blk_wait_while_drained (blk); +GRAPH_RDLOCK_GUARD ();/* Call blk_bs() only after waiting, the graph may have changed */ bs =blk_bs (blk);
block/bochs.c +1 -1
@@ -237,7 +237,7 @@ static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)return bitmap_offset + (512 * (s->bitmap_blocks + extent_offset)); } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKbochs_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
block/commit.c +3 -2
@@ -207,8 +207,9 @@ static const BlockJobDriver commit_job_driver = { }, }; -static int coroutine_fn bdrv_commit_top_preadv(BlockDriverState *bs, -int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_commit_top_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {return bdrv_co_preadv (bs->backing, offset, bytes, qiov, flags); }
block/copy-before-write.c +8 -8
@@ -78,9 +78,9 @@ typedef struct BDRVCopyBeforeWriteState {int snapshot_error; } BDRVCopyBeforeWriteState; -static coroutine_fn int cbw_co_preadv( -BlockDriverState *bs,int64_t offset,int64_t bytes, -QEMUIOVector *qiov,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {return bdrv_co_preadv (bs->file, offset, bytes, qiov, flags); }
@@ -172,11 +172,9 @@ cbw_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes,return bdrv_co_pwrite_zeroes (bs->file, offset, bytes, flags); } -static coroutine_fn int cbw_co_pwritev(BlockDriverState *bs, -int64_t offset, -int64_t bytes, -QEMUIOVector *qiov, -BdrvRequestFlags flags) +static coroutine_fn GRAPH_RDLOCK +int cbw_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {int ret =cbw_do_copy_before_write (bs, offset, bytes, flags);if (ret <0 ) {
@@ -266,6 +264,8 @@ cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes,BdrvChild *file;int ret; +assume_graph_lock ();/* FIXME */ +/* TODO: upgrade to async loop using AioTask */ while (bytes) {int64_t cur_bytes;
block/copy-on-read.c +11 -15
@@ -127,11 +127,10 @@ static int64_t coroutine_fn cor_co_getlength(BlockDriverState *bs) } -static int coroutine_fn cor_co_preadv_part(BlockDriverState *bs, -int64_t offset,int64_t bytes, -QEMUIOVector *qiov, -size_t qiov_offset, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cor_co_preadv_part (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,size_t qiov_offset, +BdrvRequestFlags flags) {int64_t n;int local_flags;
@@ -180,12 +179,10 @@ static int coroutine_fn cor_co_preadv_part(BlockDriverState *bs, } -static int coroutine_fn cor_co_pwritev_part(BlockDriverState *bs, -int64_t offset, -int64_t bytes, -QEMUIOVector *qiov, -size_t qiov_offset, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pwritev_part (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,size_t qiov_offset, +BdrvRequestFlags flags) {return bdrv_co_pwritev_part (bs->file, offset, bytes, qiov, qiov_offset, flags);
@@ -207,10 +204,9 @@ cor_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) } -static int coroutine_fn cor_co_pwritev_compressed(BlockDriverState *bs, -int64_t offset, -int64_t bytes, -QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pwritev_compressed (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov) {return bdrv_co_pwritev (bs->file, offset, bytes, qiov,BDRV_REQ_WRITE_COMPRESSED );
block/crypto.c +2 -2
@@ -398,7 +398,7 @@ static int block_crypto_reopen_prepare(BDRVReopenState *state,*/ #define BLOCK_CRYPTO_MAX_IO_SIZE (1024 * 1024) -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCKblock_crypto_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
@@ -460,7 +460,7 @@ block_crypto_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, } -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCKblock_crypto_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
block/filter-compress.c +8 -11
@@ -61,23 +61,20 @@ static int64_t coroutine_fn compress_co_getlength(BlockDriverState *bs) } -static int coroutine_fn compress_co_preadv_part(BlockDriverState *bs, -int64_t offset,int64_t bytes, -QEMUIOVector *qiov, -size_t qiov_offset, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +compress_co_preadv_part (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,size_t qiov_offset, +BdrvRequestFlags flags) {return bdrv_co_preadv_part (bs->file, offset, bytes, qiov, qiov_offset, flags); } -static int coroutine_fn compress_co_pwritev_part(BlockDriverState *bs, -int64_t offset, -int64_t bytes, -QEMUIOVector *qiov, -size_t qiov_offset, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +compress_co_pwritev_part (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,size_t qiov_offset, +BdrvRequestFlags flags) {return bdrv_co_pwritev_part (bs->file, offset, bytes, qiov, qiov_offset, flags |BDRV_REQ_WRITE_COMPRESSED );
block/io.c +3 -4
@@ -971,6 +971,7 @@ bdrv_driver_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,unsigned int nb_sectors;QEMUIOVector local_qiov;int ret; +assert_bdrv_graph_readable ();bdrv_check_qiov_request (offset, bytes, qiov, qiov_offset, &error_abort);assert (!(flags & ~bs->supported_read_flags));
@@ -1041,6 +1042,7 @@ bdrv_driver_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,unsigned int nb_sectors;QEMUIOVector local_qiov;int ret; +assert_bdrv_graph_readable ();bdrv_check_qiov_request (offset, bytes, qiov, qiov_offset, &error_abort);
@@ -1119,6 +1121,7 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, int64_t offset,BlockDriver *drv = bs->drv;QEMUIOVector local_qiov;int ret; +assert_bdrv_graph_readable ();bdrv_check_qiov_request (offset, bytes, qiov, qiov_offset, &error_abort);
@@ -1621,8 +1624,6 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child,int ret;IO_CODE (); -assume_graph_lock ();/* FIXME */ -trace_bdrv_co_preadv_part (bs, offset, bytes, flags);if (!bdrv_co_is_inserted (bs)) {
@@ -2070,8 +2071,6 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child,bool padded = false;IO_CODE (); -assume_graph_lock ();/* FIXME */ -trace_bdrv_co_pwritev_part (child->bs, offset, bytes, flags);if (!bdrv_co_is_inserted (bs)) {
block/mirror.c +10 -8
@@ -390,8 +390,10 @@ static void coroutine_fn mirror_co_read(void *opaque) op->is_in_flight = true;trace_mirror_one_iteration (s, op->offset, op->bytes); - ret =bdrv_co_preadv (s->mirror_top_bs->backing, op->offset, op->bytes, - &op->qiov,0 ); + WITH_GRAPH_RDLOCK_GUARD() { + ret =bdrv_co_preadv (s->mirror_top_bs->backing, op->offset, op->bytes, + &op->qiov,0 ); + }mirror_read_complete (op, ret); }
@@ -1437,8 +1439,9 @@ static void coroutine_fn active_write_settle(MirrorOp *op)g_free (op); } -static int coroutine_fn bdrv_mirror_top_preadv(BlockDriverState *bs, -int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {return bdrv_co_preadv (bs->backing, offset, bytes, qiov, flags); }
@@ -1495,8 +1498,9 @@ out:return ret; } -static int coroutine_fn bdrv_mirror_top_pwritev(BlockDriverState *bs, -int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {MirrorBDSOpaque *s = bs->opaque;QEMUIOVector bounce_qiov;
@@ -1504,8 +1508,6 @@ static int coroutine_fn bdrv_mirror_top_pwritev(BlockDriverState *bs,int ret =0 ;bool copy_to_target = false; -assume_graph_lock ();/* FIXME */ -if (s->job) { copy_to_target = s->job->ret >=0 && !job_is_cancelled(&s->job->common.job) &&
block/parallels.c +5 -3
@@ -261,7 +261,8 @@ allocate_clusters(BlockDriverState *bs, int64_t sector_num, } -static coroutine_fn int parallels_co_flush_to_os(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_flush_to_os (BlockDriverState *bs) {BDRVParallelsState *s = bs->opaque;unsigned long size =DIV_ROUND_UP (s->header_size, s->bat_dirty_block);
@@ -363,8 +364,9 @@ parallels_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors,return ret; } -static coroutine_fn int parallels_co_readv(BlockDriverState *bs, -int64_t sector_num,int nb_sectors,QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_readv (BlockDriverState *bs,int64_t sector_num,int nb_sectors, +QEMUIOVector *qiov) {BDRVParallelsState *s = bs->opaque;uint64_t bytes_done =0 ;
block/preallocate.c +8 -10
@@ -226,9 +226,10 @@ static void preallocate_reopen_abort(BDRVReopenState *state) state->opaque =NULL ; } -static coroutine_fn int preallocate_co_preadv_part( -BlockDriverState *bs,int64_t offset,int64_t bytes, -QEMUIOVector *qiov,size_t qiov_offset,BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_preadv_part (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,size_t qiov_offset, +BdrvRequestFlags flags) {return bdrv_co_preadv_part (bs->file, offset, bytes, qiov, qiov_offset, flags);
@@ -359,14 +360,11 @@ preallocate_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,return bdrv_co_pwrite_zeroes (bs->file, offset, bytes, flags); } -static coroutine_fn int preallocate_co_pwritev_part(BlockDriverState *bs, -int64_t offset, -int64_t bytes, -QEMUIOVector *qiov, -size_t qiov_offset, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_pwritev_part (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,size_t qiov_offset, +BdrvRequestFlags flags) { -assume_graph_lock ();/* FIXME */ handle_write (bs, offset, bytes, false); return bdrv_co_pwritev_part(bs->file, offset, bytes, qiov, qiov_offset,
block/qcow.c +4 -4
@@ -92,8 +92,8 @@ typedef struct BDRVQcowState {static QemuOptsList qcow_create_opts; -static int coroutine_fn decompress_cluster(BlockDriverState *bs, -uint64_t cluster_offset); +static int coroutine_fn GRAPH_RDLOCK +decompress_cluster (BlockDriverState *bs,uint64_t cluster_offset);static int qcow_probe (const uint8_t *buf,int buf_size,const char *filename) {
@@ -584,8 +584,8 @@ static int decompress_buffer(uint8_t *out_buf, int out_buf_size,return 0 ; } -static int coroutine_fn decompress_cluster(BlockDriverState *bs, -uint64_t cluster_offset) +static int coroutine_fn GRAPH_RDLOCK +decompress_cluster (BlockDriverState *bs,uint64_t cluster_offset) {BDRVQcowState *s = bs->opaque;int ret, csize;
block/qcow2-cluster.c +3 -4
@@ -534,10 +534,9 @@ do_perform_cow_read(BlockDriverState *bs, uint64_t src_cluster_offset,return 0 ; } -static int coroutine_fn do_perform_cow_write(BlockDriverState *bs, -uint64_t cluster_offset, -unsigned offset_in_cluster, -QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +do_perform_cow_write (BlockDriverState *bs,uint64_t cluster_offset, +unsigned offset_in_cluster,QEMUIOVector *qiov) {BDRVQcow2State *s = bs->opaque;int ret;
block/qcow2.c +28 -25
113 lines not on this page · raw message
block/qed-table.c +2 -2
@@ -21,8 +21,8 @@#include "qemu/memalign.h" /* Called with table_lock held. */ -static int coroutine_fn qed_read_table(BDRVQEDState *s, uint64_t offset, -QEDTable *table) +static int coroutine_fn GRAPH_RDLOCK +qed_read_table (BDRVQEDState *s,uint64_t offset,QEDTable *table) {unsigned int bytes = s->header.cluster_size * s->header.table_size;
block/qed.c +15 -16
@@ -100,7 +100,7 @@ int qed_write_header_sync(BDRVQEDState *s)* * No new allocating reqs can start while this function runs. */ -static int coroutine_fn qed_write_header(BDRVQEDState *s) +static int coroutine_fn GRAPH_RDLOCK qed_write_header(BDRVQEDState *s) {/* We must write full sectors for O_DIRECT but cannot necessarily generate * the data following the header if an unrecognized compat feature is
@@ -826,11 +826,10 @@ fail:return ret; } -static int coroutine_fn bdrv_qed_co_block_status(BlockDriverState *bs, -bool want_zero, -int64_t pos,int64_t bytes, -int64_t *pnum,int64_t *map, -BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_block_status (BlockDriverState *bs,bool want_zero,int64_t pos, +int64_t bytes,int64_t *pnum,int64_t *map, +BlockDriverState **file) {BDRVQEDState *s = bs->opaque;size_t len =MIN (bytes,SIZE_MAX );
@@ -883,8 +882,8 @@ static BDRVQEDState *acb_to_s(QEDAIOCB *acb)* This function reads qiov->size bytes starting at pos from the backing file. * If there is no backing file then zeroes are read. */ -static int coroutine_fn qed_read_backing_file(BDRVQEDState *s, uint64_t pos, -QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +qed_read_backing_file (BDRVQEDState *s,uint64_t pos,QEMUIOVector *qiov) {if (s->bs->backing) {BLKDBG_EVENT (s->bs->file,BLKDBG_READ_BACKING_AIO );
@@ -902,9 +901,9 @@ static int coroutine_fn qed_read_backing_file(BDRVQEDState *s, uint64_t pos,* @len: Number of bytes * @offset: Byte offset in image file */ -static int coroutine_fn qed_copy_from_backing_file(BDRVQEDState *s, -uint64_t pos,uint64_t len, -uint64_t offset) +static int coroutine_fn GRAPH_RDLOCK +qed_copy_from_backing_file (BDRVQEDState *s,uint64_t pos,uint64_t len, +uint64_t offset) {QEMUIOVector qiov;int ret;
@@ -1066,7 +1065,7 @@ qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t offset)* * Called with table_lock *not* held. */ -static int coroutine_fn qed_aio_write_main(QEDAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK qed_aio_write_main(QEDAIOCB *acb) {BDRVQEDState *s =acb_to_s (acb); uint64_t offset = acb->cur_cluster +
@@ -1226,8 +1225,8 @@ qed_aio_write_alloc(QEDAIOCB *acb, size_t len)* * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, -size_t len) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_write_inplace (QEDAIOCB *acb,uint64_t offset,size_t len) {BDRVQEDState *s =acb_to_s (acb);int r;
@@ -1302,8 +1301,8 @@ qed_aio_write_data(void *opaque, int ret, uint64_t offset, size_t len)* * Called with table_lock held. */ -static int coroutine_fn qed_aio_read_data(void *opaque, int ret, -uint64_t offset,size_t len) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_read_data (void *opaque,int ret,uint64_t offset,size_t len) {QEDAIOCB *acb = opaque;BDRVQEDState *s =acb_to_s (acb);
block/quorum.c +18 -11
@@ -270,7 +270,11 @@ static void quorum_report_bad_versions(BDRVQuorumState *s, } } -static void coroutine_fn quorum_rewrite_entry(void *opaque) +/* +* This function can count as GRAPH_RDLOCK because read_quorum_children() holds +* the graph lock and keeps it until this coroutine has terminated. +*/ +static void coroutine_fn GRAPH_RDLOCK quorum_rewrite_entry(void *opaque) {QuorumCo *co = opaque;QuorumAIOCB *acb = co->acb;
@@ -290,8 +294,8 @@ static void coroutine_fn quorum_rewrite_entry(void *opaque) } } -static bool quorum_rewrite_bad_versions (QuorumAIOCB *acb, -QuorumVoteValue *value) +static bool coroutine_fn GRAPH_RDLOCK +quorum_rewrite_bad_versions (QuorumAIOCB *acb,QuorumVoteValue *value) {QuorumVoteVersion *version;QuorumVoteItem *item;
@@ -491,7 +495,7 @@ static int quorum_vote_error(QuorumAIOCB *acb)return ret; } -static void quorum_vote (QuorumAIOCB *acb) +static void coroutine_fn GRAPH_RDLOCK quorum_vote(QuorumAIOCB *acb) {bool quorum = true;int i, j, ret;
@@ -571,7 +575,11 @@ free_exit:quorum_free_vote_list (&acb->votes); } -static void coroutine_fn read_quorum_children_entry(void *opaque) +/* +* This function can count as GRAPH_RDLOCK because read_quorum_children() holds +* the graph lock and keeps it until this coroutine has terminated. +*/ +static void coroutine_fn GRAPH_RDLOCK read_quorum_children_entry(void *opaque) {QuorumCo *co = opaque;QuorumAIOCB *acb = co->acb;
@@ -599,7 +607,7 @@ static void coroutine_fn read_quorum_children_entry(void *opaque) } } -static int coroutine_fn read_quorum_children(QuorumAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK read_quorum_children(QuorumAIOCB *acb) {BDRVQuorumState *s = acb->bs->opaque;int i;
@@ -640,7 +648,7 @@ static int coroutine_fn read_quorum_children(QuorumAIOCB *acb)return acb->vote_ret; } -static int coroutine_fn read_fifo_child(QuorumAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK read_fifo_child(QuorumAIOCB *acb) {BDRVQuorumState *s = acb->bs->opaque;int n, ret;
@@ -661,10 +669,9 @@ static int coroutine_fn read_fifo_child(QuorumAIOCB *acb)return ret; } -static int coroutine_fn quorum_co_preadv(BlockDriverState *bs, -int64_t offset,int64_t bytes, -QEMUIOVector *qiov, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +quorum_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {BDRVQuorumState *s = bs->opaque;QuorumAIOCB *acb =quorum_aio_get (bs, qiov, offset, bytes, flags);
block/raw-format.c +6 -6
@@ -203,9 +203,9 @@ static inline int raw_adjust_offset(BlockDriverState *bs, int64_t *offset,return 0 ; } -static int coroutine_fn raw_co_preadv(BlockDriverState *bs, int64_t offset, -int64_t bytes,QEMUIOVector *qiov, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {int ret;
@@ -218,9 +218,9 @@ static int coroutine_fn raw_co_preadv(BlockDriverState *bs, int64_t offset,return bdrv_co_preadv (bs->file, offset, bytes, qiov, flags); } -static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, int64_t offset, -int64_t bytes,QEMUIOVector *qiov, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {void *buf =NULL ;BlockDriver *drv;
block/replication.c +6 -9
@@ -220,10 +220,9 @@ static int replication_return_value(BDRVReplicationState *s, int ret)return ret; } -static coroutine_fn int replication_co_readv(BlockDriverState *bs, -int64_t sector_num, -int remaining_sectors, -QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +replication_co_readv (BlockDriverState *bs,int64_t sector_num, +int remaining_sectors,QEMUIOVector *qiov) {BDRVReplicationState *s = bs->opaque;int ret;
@@ -244,11 +243,9 @@ static coroutine_fn int replication_co_readv(BlockDriverState *bs,return replication_return_value (s, ret); } -static coroutine_fn int replication_co_writev(BlockDriverState *bs, -int64_t sector_num, -int remaining_sectors, -QEMUIOVector *qiov, -int flags) +static int coroutine_fn GRAPH_RDLOCK +replication_co_writev (BlockDriverState *bs,int64_t sector_num, +int remaining_sectors,QEMUIOVector *qiov,int flags) {BDRVReplicationState *s = bs->opaque;QEMUIOVector hd_qiov;
block/throttle.c +9 -12
@@ -111,10 +111,9 @@ static int64_t coroutine_fn throttle_co_getlength(BlockDriverState *bs)return bdrv_co_getlength (bs->file->bs); } -static int coroutine_fn throttle_co_preadv(BlockDriverState *bs, -int64_t offset,int64_t bytes, -QEMUIOVector *qiov, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {ThrottleGroupMember *tgm = bs->opaque;
@@ -123,10 +122,9 @@ static int coroutine_fn throttle_co_preadv(BlockDriverState *bs,return bdrv_co_preadv (bs->file, offset, bytes, qiov, flags); } -static int coroutine_fn throttle_co_pwritev(BlockDriverState *bs, -int64_t offset,int64_t bytes, -QEMUIOVector *qiov, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {ThrottleGroupMember *tgm = bs->opaque;throttle_group_co_io_limits_intercept (tgm, bytes, true);
@@ -153,10 +151,9 @@ throttle_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes)return bdrv_co_pdiscard (bs->file, offset, bytes); } -static int coroutine_fn throttle_co_pwritev_compressed(BlockDriverState *bs, -int64_t offset, -int64_t bytes, -QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pwritev_compressed (BlockDriverState *bs,int64_t offset, +int64_t bytes,QEMUIOVector *qiov) {return throttle_co_pwritev (bs, offset, bytes, qiov,BDRV_REQ_WRITE_COMPRESSED );
block/vdi.c +2 -2
@@ -544,7 +544,7 @@ static int coroutine_fn vdi_co_block_status(BlockDriverState *bs, (s->header.image_type ==VDI_TYPE_STATIC ?BDRV_BLOCK_RECURSE :0 ); } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKvdi_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
@@ -600,7 +600,7 @@ vdi_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,return ret; } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKvdi_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
block/vhdx.c +6 -5
@@ -1172,8 +1172,9 @@ vhdx_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) } -static coroutine_fn int vhdx_co_readv(BlockDriverState *bs, int64_t sector_num, -int nb_sectors,QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +vhdx_co_readv (BlockDriverState *bs,int64_t sector_num,int nb_sectors, +QEMUIOVector *qiov) {BDRVVHDXState *s = bs->opaque;int ret =0 ;
@@ -1324,9 +1325,9 @@ int vhdx_user_visible_write(BlockDriverState *bs, BDRVVHDXState *s)return ret; } -static coroutine_fn int vhdx_co_writev(BlockDriverState *bs, int64_t sector_num, -int nb_sectors,QEMUIOVector *qiov, -int flags) +static int coroutine_fn GRAPH_RDLOCK +vhdx_co_writev (BlockDriverState *bs,int64_t sector_num,int nb_sectors, +QEMUIOVector *qiov,int flags) {int ret = -ENOTSUP ;BDRVVHDXState *s = bs->opaque;
block/vmdk.c +27 -38
132 lines not on this page · raw message
block/vpc.c +2 -2
@@ -610,7 +610,7 @@ vpc_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)return 0 ; } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKvpc_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
@@ -660,7 +660,7 @@ fail:return ret; } -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCKvpc_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
tests/unit/test-bdrv-drain.c +11 -9
@@ -933,10 +933,9 @@ static void bdrv_test_top_close(BlockDriverState *bs) } } -static int coroutine_fn bdrv_test_top_co_preadv(BlockDriverState *bs, -int64_t offset,int64_t bytes, -QEMUIOVector *qiov, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_test_top_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {BDRVTestTopState *tts = bs->opaque;return bdrv_co_preadv (tts->wait_child, offset, bytes, qiov, flags);
@@ -967,6 +966,8 @@ static void coroutine_fn test_co_delete_by_drain(void *opaque)void *buffer =g_malloc (65536 );QEMUIOVector qiov =QEMU_IOVEC_INIT_BUF (qiov, buffer,65536 ); +GRAPH_RDLOCK_GUARD (); +/* Pretend some internal write operation from parent to child. * Important: We have to read from the child, not from the parent! * Draining works by first propagating it all up the tree to the
@@ -1698,11 +1699,9 @@ static void bdrv_replace_test_close(BlockDriverState *bs)* Otherwise: * Set .has_read to true and return success. */ -static int coroutine_fn bdrv_replace_test_co_preadv(BlockDriverState *bs, -int64_t offset, -int64_t bytes, -QEMUIOVector *qiov, -BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_replace_test_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags) {BDRVReplaceTestState *s = bs->opaque;
@@ -1778,7 +1777,10 @@ static void coroutine_fn bdrv_replace_test_read_entry(void *opaque)int ret;/* Queue a read request post-drain */ +bdrv_graph_co_rdlock (); ret =bdrv_replace_test_co_preadv (bs,0 ,1 , &qiov,0 ); +bdrv_graph_co_rdunlock (); +g_assert (ret >=0 );bdrv_dec_in_flight (bs); }
Signature · 1 line
2.38.1
Am 03/02/2023 um 16:21 schrieb Kevin Wolf:
Quoted 10 lines
After introducing the graph lock in a previous series, this series actually starts making widespread use of it.
Most of the BlockDriver callbacks access the children list in some way, so you need to hold the graph lock to call them. The patches in this series add the corresponding
GRAPH_RDLOCKannotations and take the lock in places where it doesn't happen yet - all of the bdrv_*()co_wrappersare already covered, but in particular BlockBackendcoroutine_fnsstill need it.
Quoted 7 lines
There is no particularly good reason why exactly these patches and not others are included in the series. I couldn't find a self-contained part that could reasonable be addressed in a single series. So these just happen to be patches that are somewhat related (centered around the BlockDriver callback theme), are ready and their number looks manageable. You will still see some FIXMEs at the end of the series that will only be addressed in future patches.
Quoted 82 lines
Emanuele Giuseppe Esposito (5):
block/qed: add missing graph rdlock inqed_need_check_timer_entry
block: Markbdrv_co_flush()and callersGRAPH_RDLOCK
block: Markbdrv_co_pdiscard()and callersGRAPH_RDLOCK
block: Markbdrv_co_copy_range()GRAPH_RDLOCK
block: Markbdrv_co_is_inserted()and callersGRAPH_RDLOCKKevin Wolf (18):
block: Makebdrv_can_set_read_only()static
mirror: Fix access of uninitialised fields during start
block: Markbdrv_co_truncate()and callersGRAPH_RDLOCK
block: Markbdrv_co_block_status()and callersGRAPH_RDLOCK
block: Markbdrv_co_ioctl()and callersGRAPH_RDLOCK
block: Markbdrv_co_pwrite_zeroes()and callersGRAPH_RDLOCK
block: Mark read/write inblock/io.cGRAPH_RDLOCK
block: Mark public read/write functionsGRAPH_RDLOCK
block: Markbdrv_co_pwrite_sync()and callersGRAPH_RDLOCK
block: Markbdrv_co_do_pwrite_zeroes()GRAPH_RDLOCK
block: Mark preadv_snapshot/snapshot_block_statusGRAPH_RDLOCK
block: Markbdrv_co_create()and callersGRAPH_RDLOCK
block: Mark bdrv_co_io_(un)plug() and callersGRAPH_RDLOCK
block: Mark bdrv_co_eject/lock_medium() and callersGRAPH_RDLOCK
block: Mark bdrv_(un)register_buf()GRAPH_RDLOCK
block: Markbdrv_co_delete_file()and callersGRAPH_RDLOCK
block: Mark bdrv_*_dirty_bitmap() and callersGRAPH_RDLOCK
block: Markbdrv_co_refresh_total_sectors()and callersGRAPH_RDLOCKblock/coroutines.h | 2 +- block/qcow2.h | 27 +++-- block/qed.h | 45 ++++---- include/block/block-copy.h | 6 +- include/block/block-global-state.h | 14 ++- include/block/block-io.h | 110 +++++++++--------- include/block/block_int-common.h | 173 ++++++++++++++++------------- include/block/block_int-io.h | 53 ++++----- include/block/dirty-bitmap.h | 12 +- include/sysemu/block-backend-io.h | 7 +- block.c | 12 +- block/backup.c | 3 + block/blkdebug.c | 19 ++-- block/blklogwrites.c | 35 +++--- block/blkreplay.c | 24 ++-- block/blkverify.c | 5 +- block/block-backend.c | 39 +++++-- block/block-copy.c | 32 +++--- block/bochs.c | 2 +- block/commit.c | 5 +- block/copy-before-write.c | 33 +++--- block/copy-on-read.c | 44 ++++---- block/create.c | 9 +- block/crypto.c | 16 +-- block/dirty-bitmap.c | 2 + block/file-posix.c | 27 ++--- block/file-win32.c | 7 +- block/filter-compress.c | 36 +++--- block/io.c | 108 +++++++++++------- block/iscsi.c | 28 ++--- block/mirror.c | 59 ++++++---- block/parallels.c | 33 +++--- block/preallocate.c | 38 ++++--- block/qcow.c | 46 ++++---- block/qcow2-cluster.c | 17 ++- block/qcow2.c | 136 ++++++++++++----------- block/qed-check.c | 3 +- block/qed-table.c | 10 +- block/qed.c | 101 +++++++++-------- block/quorum.c | 62 ++++++----- block/raw-format.c | 76 ++++++------- block/replication.c | 18 ++- block/snapshot-access.c | 8 +- block/stream.c | 40 ++++--- block/throttle.c | 36 +++--- block/vdi.c | 11 +- block/vhdx.c | 18 +-- block/vmdk.c | 132 ++++++++++------------ block/vpc.c | 11 +- qemu-img.c | 8 +- tests/unit/test-bdrv-drain.c | 20 ++-- tests/unit/test-block-iothread.c | 3 +- 52 files changed, 983 insertions(+), 838 deletions(-)
Quoted 10 lines · Kevin Wolf
After introducing the graph lock in a previous series, this series actually starts making widespread use of it.
Most of the BlockDriver callbacks access the children list in some way, so you need to hold the graph lock to call them. The patches in this series add the corresponding
GRAPH_RDLOCKannotations and take the lock in places where it doesn't happen yet - all of the bdrv_*()co_wrappersare already covered, but in particular BlockBackendcoroutine_fnsstill need it.
Quoted 7 lines
There is no particularly good reason why exactly these patches and not others are included in the series. I couldn't find a self-contained part that could reasonable be addressed in a single series. So these just happen to be patches that are somewhat related (centered around the BlockDriver callback theme), are ready and their number looks manageable. You will still see some FIXMEs at the end of the series that will only be addressed in future patches.
Two things occurred to me:
1. The graph lock is becoming the new AioContext lock in the sense that code using the block layer APIs needs to carefully acquire and release the lock around operations. Why is it necessary to explicitly take the rdlock in mirror_iteration()?
+ WITH_GRAPH_RDLOCK_GUARD() {
ret = bdrv_block_status_above(source, NULL, offset,
I guess because bdrv_*() APIs are unlocked? The equivalent blk_*() API would have taken the graph lock internally. Do we want to continue using bdrv APIs even though it spreads graph locking concerns into block jobs?
2. This series touches block drivers like qcow2. Luckily block drivers just need to annotate their BlockDriver functions to indicate they run under the rdlock, a lock that the block driver itself doesn't mess with. It makes me wonder whether there is any point in annotating the BlockDriver function pointers? It would be simpler if the block drivers were unaware of the graph lock.
Stefan
Re: [PATCH 01/23] block: Make bdrv_can_set_read_only() static
In reply to Kevin WolfQuoted 3 lines · Kevin Wolf
It is never called outside of
block.c.Signed-off-by Kevin Wolf<[email protected]>
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH 02/23] mirror: Fix access of uninitialised fields during start
In reply to Kevin WolfQuoted 9 lines · Kevin Wolf
bdrv_mirror_top_pwritev()accesses the job object when active mirroring is enabled. It disables this code during early initialisation whiles->jobisn't set yet.However,
s->jobis still set way too early when the job object isn't fully initialised. For example,&s->ops_in_flightisn't initialised yet and thein_flightbitmap doesn't exist yet. This causes crashes when a write request comes in too early.
Quoted 5 lines
Move the assignment of
s->jobto when the mirror job is actually fully initialised to make sure that themirror_topdriver doesn't access it too early.Signed-off-by Kevin Wolf <[email protected]>
Probably bitmap initialization and (maybe) some other things in mirror_run() should actually be done in mirror_start_job(). Still:
Signature · 2 lines
Best regards, Vladimir
Am 21.02.2023 um 23:13 hat Stefan Hajnoczi geschrieben:
Quoted 26 lines · Kevin Wolf
Quoted 10 lines
After introducing the graph lock in a previous series, this series actually starts making widespread use of it.
Most of the BlockDriver callbacks access the children list in some way, so you need to hold the graph lock to call them. The patches in this series add the corresponding
GRAPH_RDLOCKannotations and take the lock in places where it doesn't happen yet - all of the bdrv_*()co_wrappersare already covered, but in particular BlockBackendcoroutine_fnsstill need it.Quoted 7 lines
There is no particularly good reason why exactly these patches and not others are included in the series. I couldn't find a self-contained part that could reasonable be addressed in a single series. So these just happen to be patches that are somewhat related (centered around the BlockDriver callback theme), are ready and their number looks manageable. You will still see some FIXMEs at the end of the series that will only be addressed in future patches.
Two things occurred to me:
1. The graph lock is becoming the new AioContext lock in the sense that code using the block layer APIs needs to carefully acquire and release the lock around operations. Why is it necessary to explicitly take the rdlock in
mirror_iteration()?
Quoted 6 lines
+
WITH_GRAPH_RDLOCK_GUARD(){
ret = bdrv_block_status_above(source, NULL, offset,I guess because bdrv_*() APIs are unlocked? The equivalent blk_*() API would have taken the graph lock internally. Do we want to continue using bdrv APIs even though it spreads graph locking concerns into block jobs?
The thing that makes it a bit ugly is that block jobs mix bdrv_*() and blk_*() calls. If they only used blk_*() we wouldn't have to take care of locking (but that means that the job code itself must not have a problem with a changing graph!). If they only used bdrv_*(), the function could just take a lock at the start and only temporarily release it around pause points. Both ways would look nicer than what we have now.
Quoted 6 lines
2. This series touches block drivers like qcow2. Luckily block drivers just need to annotate their BlockDriver functions to indicate they run under the rdlock, a lock that the block driver itself doesn't mess with. It makes me wonder whether there is any point in annotating the BlockDriver function pointers? It would be simpler if the block drivers were unaware of the graph lock.
If you're unaware of the graph lock, how do you tell if you can call certain block layer functions that require the lock?
Especially since different BlockDriver callbacks have different rules (some have a reader lock, some have a writer lock, and some may stay unlocked even in the future), it would seem really hard to keep track of this when you don't make it explicit.
Kevin
Quoted 49 lines · Kevin Wolf
Am 21.02.2023 um 23:13 hat Stefan Hajnoczi geschrieben:
Quoted 26 lines · Kevin Wolf
Quoted 10 lines
After introducing the graph lock in a previous series, this series actually starts making widespread use of it.
Most of the BlockDriver callbacks access the children list in some way, so you need to hold the graph lock to call them. The patches in this series add the corresponding
GRAPH_RDLOCKannotations and take the lock in places where it doesn't happen yet - all of the bdrv_*()co_wrappersare already covered, but in particular BlockBackendcoroutine_fnsstill need it.Quoted 7 lines
There is no particularly good reason why exactly these patches and not others are included in the series. I couldn't find a self-contained part that could reasonable be addressed in a single series. So these just happen to be patches that are somewhat related (centered around the BlockDriver callback theme), are ready and their number looks manageable. You will still see some FIXMEs at the end of the series that will only be addressed in future patches.
Two things occurred to me:
1. The graph lock is becoming the new AioContext lock in the sense that code using the block layer APIs needs to carefully acquire and release the lock around operations. Why is it necessary to explicitly take the rdlock in
mirror_iteration()?Quoted 6 lines
+
WITH_GRAPH_RDLOCK_GUARD(){
ret = bdrv_block_status_above(source, NULL, offset,I guess because bdrv_*() APIs are unlocked? The equivalent blk_*() API would have taken the graph lock internally. Do we want to continue using bdrv APIs even though it spreads graph locking concerns into block jobs?
The thing that makes it a bit ugly is that block jobs mix bdrv_*() and blk_*() calls. If they only used blk_*() we wouldn't have to take care of locking (but that means that the job code itself must not have a problem with a changing graph!). If they only used bdrv_*(), the function could just take a lock at the start and only temporarily release it around pause points. Both ways would look nicer than what we have now.
Quoted 6 lines
2. This series touches block drivers like qcow2. Luckily block drivers just need to annotate their BlockDriver functions to indicate they run under the rdlock, a lock that the block driver itself doesn't mess with. It makes me wonder whether there is any point in annotating the BlockDriver function pointers? It would be simpler if the block drivers were unaware of the graph lock.
Quoted 7 lines
If you're unaware of the graph lock, how do you tell if you can call certain block layer functions that require the lock?
Especially since different BlockDriver callbacks have different rules (some have a reader lock, some have a writer lock, and some may stay unlocked even in the future), it would seem really hard to keep track of this when you don't make it explicit.
Hi Kevin,
Can you give an example of where it is necessary (not accidental complexity) to expose an unlocked API and put the responsibility of locking on the caller?
Thanks,
Stefan
Stefan Hajnoczi
Acked-byQuoted 49 lines · Kevin Wolf
Am 21.02.2023 um 23:13 hat Stefan Hajnoczi geschrieben:
Quoted 26 lines · Kevin Wolf
Quoted 10 lines
After introducing the graph lock in a previous series, this series actually starts making widespread use of it.
Most of the BlockDriver callbacks access the children list in some way, so you need to hold the graph lock to call them. The patches in this series add the corresponding
GRAPH_RDLOCKannotations and take the lock in places where it doesn't happen yet - all of the bdrv_*()co_wrappersare already covered, but in particular BlockBackendcoroutine_fnsstill need it.Quoted 7 lines
There is no particularly good reason why exactly these patches and not others are included in the series. I couldn't find a self-contained part that could reasonable be addressed in a single series. So these just happen to be patches that are somewhat related (centered around the BlockDriver callback theme), are ready and their number looks manageable. You will still see some FIXMEs at the end of the series that will only be addressed in future patches.
Two things occurred to me:
1. The graph lock is becoming the new AioContext lock in the sense that code using the block layer APIs needs to carefully acquire and release the lock around operations. Why is it necessary to explicitly take the rdlock in
mirror_iteration()?Quoted 6 lines
+
WITH_GRAPH_RDLOCK_GUARD(){
ret = bdrv_block_status_above(source, NULL, offset,I guess because bdrv_*() APIs are unlocked? The equivalent blk_*() API would have taken the graph lock internally. Do we want to continue using bdrv APIs even though it spreads graph locking concerns into block jobs?
The thing that makes it a bit ugly is that block jobs mix bdrv_*() and blk_*() calls. If they only used blk_*() we wouldn't have to take care of locking (but that means that the job code itself must not have a problem with a changing graph!). If they only used bdrv_*(), the function could just take a lock at the start and only temporarily release it around pause points. Both ways would look nicer than what we have now.
Quoted 6 lines
2. This series touches block drivers like qcow2. Luckily block drivers just need to annotate their BlockDriver functions to indicate they run under the rdlock, a lock that the block driver itself doesn't mess with. It makes me wonder whether there is any point in annotating the BlockDriver function pointers? It would be simpler if the block drivers were unaware of the graph lock.
Quoted 7 lines
If you're unaware of the graph lock, how do you tell if you can call certain block layer functions that require the lock?
Especially since different BlockDriver callbacks have different rules (some have a reader lock, some have a writer lock, and some may stay unlocked even in the future), it would seem really hard to keep track of this when you don't make it explicit.
I discussed this offline with Kevin some more today. While there might be opportunities to hide the lock (thereby making it easier), it's not easy to do because we don't want to give up TSA static checking. Let's put the graph lock in place first and worry about that later.