mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-17 21:26:13 -07:00
block: Convert bdrv_refresh_total_sectors() to co_wrapper_mixed
BlockDriver->bdrv_getlength is categorized as IO callback, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since the callback traverses the block nodes graph, which however is only possible in a coroutine. Therefore turn it into a co_wrapper to move the actual function into a coroutine where the lock can be taken. Because now this function creates a new coroutine and polls, we need to take the AioContext lock where it is missing, for the only reason that internally co_wrapper calls AIO_WAIT_WHILE and it expects to release the AioContext lock. This is especially messy when a co_wrapper creates a coroutine and polls in bdrv_open_driver, because this function has so many callers in so many context that it can easily lead to deadlocks. Therefore the new rule for bdrv_open_driver is that the caller must always hold the AioContext lock of the given bs (except if it is a coroutine), because the function calls bdrv_refresh_total_sectors() which is now a co_wrapper. Once the rwlock is ultimated and placed in every place it needs to be, we will poll using AIO_WAIT_WHILE_UNLOCKED and remove the AioContext lock. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20230113204212.359076-7-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
c057960c4e
commit
c86422c554
35 changed files with 161 additions and 121 deletions
|
|
@ -76,8 +76,12 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
|
|||
PreallocMode prealloc, BdrvRequestFlags flags,
|
||||
Error **errp);
|
||||
|
||||
int64_t bdrv_nb_sectors(BlockDriverState *bs);
|
||||
int64_t bdrv_getlength(BlockDriverState *bs);
|
||||
int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs);
|
||||
int64_t co_wrapper_mixed 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 bdrv_get_allocated_file_size(BlockDriverState *bs);
|
||||
BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts,
|
||||
BlockDriverState *in_bs, Error **errp);
|
||||
|
|
|
|||
|
|
@ -680,7 +680,7 @@ struct BlockDriver {
|
|||
int coroutine_fn (*bdrv_co_truncate)(BlockDriverState *bs, int64_t offset,
|
||||
bool exact, PreallocMode prealloc,
|
||||
BdrvRequestFlags flags, Error **errp);
|
||||
int64_t (*bdrv_getlength)(BlockDriverState *bs);
|
||||
int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs);
|
||||
int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs);
|
||||
BlockMeasureInfo *(*bdrv_measure)(QemuOpts *opts, BlockDriverState *in_bs,
|
||||
Error **errp);
|
||||
|
|
|
|||
|
|
@ -122,7 +122,10 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset,
|
|||
BdrvRequestFlags read_flags,
|
||||
BdrvRequestFlags write_flags);
|
||||
|
||||
int bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint);
|
||||
int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs,
|
||||
int64_t hint);
|
||||
int co_wrapper_mixed
|
||||
bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint);
|
||||
|
||||
BdrvChild *bdrv_cow_child(BlockDriverState *bs);
|
||||
BdrvChild *bdrv_filter_child(BlockDriverState *bs);
|
||||
|
|
|
|||
|
|
@ -61,9 +61,15 @@ bool co_wrapper_mixed blk_is_inserted(BlockBackend *blk);
|
|||
bool blk_is_available(BlockBackend *blk);
|
||||
void blk_lock_medium(BlockBackend *blk, bool locked);
|
||||
void blk_eject(BlockBackend *blk, bool eject_flag);
|
||||
int64_t blk_getlength(BlockBackend *blk);
|
||||
|
||||
int64_t coroutine_fn blk_co_getlength(BlockBackend *blk);
|
||||
int64_t co_wrapper_mixed blk_getlength(BlockBackend *blk);
|
||||
|
||||
void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr);
|
||||
int64_t blk_nb_sectors(BlockBackend *blk);
|
||||
|
||||
int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk);
|
||||
int64_t co_wrapper_mixed blk_nb_sectors(BlockBackend *blk);
|
||||
|
||||
void *blk_try_blockalign(BlockBackend *blk, size_t size);
|
||||
void *blk_blockalign(BlockBackend *blk, size_t size);
|
||||
bool blk_is_writable(BlockBackend *blk);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue