@@ -6817,10 +6817,11 @@ void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag)
* Lock or unlock the media (if it is locked, the user won't be able
* to eject it manually).
*/
-void bdrv_lock_medium(BlockDriverState *bs, bool locked)
+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_lock_medium) {
@@ -2009,13 +2009,14 @@ bool blk_is_available(BlockBackend *blk)
return blk_is_inserted(blk) && !blk_dev_is_tray_open(blk);
}
-void blk_lock_medium(BlockBackend *blk, bool locked)
+void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked)
{
BlockDriverState *bs = blk_bs(blk);
IO_CODE();
+ assert_bdrv_graph_readable();
if (bs) {
- bdrv_lock_medium(bs, locked);
+ bdrv_co_lock_medium(bs, locked);
}
}
@@ -224,7 +224,7 @@ static void cor_eject(BlockDriverState *bs, bool eject_flag)
static void cor_lock_medium(BlockDriverState *bs, bool locked)
{
- bdrv_lock_medium(bs->file->bs, locked);
+ bdrv_co_lock_medium(bs->file->bs, locked);
}
@@ -124,7 +124,7 @@ static void compress_eject(BlockDriverState *bs, bool eject_flag)
static void compress_lock_medium(BlockDriverState *bs, bool locked)
{
- bdrv_lock_medium(bs->file->bs, locked);
+ bdrv_co_lock_medium(bs->file->bs, locked);
}
@@ -410,7 +410,7 @@ static void raw_eject(BlockDriverState *bs, bool eject_flag)
static void raw_lock_medium(BlockDriverState *bs, bool locked)
{
- bdrv_lock_medium(bs->file->bs, locked);
+ bdrv_co_lock_medium(bs->file->bs, locked);
}
static int coroutine_fn raw_co_ioctl(BlockDriverState *bs,
@@ -124,7 +124,7 @@ int bdrv_get_flags(BlockDriverState *bs);
bool coroutine_fn bdrv_co_is_inserted(BlockDriverState *bs);
bool generated_co_wrapper_simple bdrv_is_inserted(BlockDriverState *bs);
-void bdrv_lock_medium(BlockDriverState *bs, bool locked);
+void coroutine_fn bdrv_co_lock_medium(BlockDriverState *bs, bool locked);
void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag);
const char *bdrv_get_format_name(BlockDriverState *bs);
@@ -762,7 +762,7 @@ struct BlockDriver {
/* removable device specific. Called with graph rdlock held. */
bool coroutine_fn (*bdrv_is_inserted)(BlockDriverState *bs);
void coroutine_fn (*bdrv_eject)(BlockDriverState *bs, bool eject_flag);
- void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked);
+ void coroutine_fn (*bdrv_lock_medium)(BlockDriverState *bs, bool locked);
/* to control generic scsi devices. Called with graph rdlock taken. */
BlockAIOCB *coroutine_fn (*bdrv_aio_ioctl)(BlockDriverState *bs,
@@ -58,7 +58,10 @@ bool coroutine_fn blk_co_is_inserted(BlockBackend *blk);
bool generated_co_wrapper blk_is_inserted(BlockBackend *blk);
bool blk_is_available(BlockBackend *blk);
-void blk_lock_medium(BlockBackend *blk, bool locked);
+
+void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked);
+void generated_co_wrapper_simple blk_lock_medium(BlockBackend *blk,
+ bool locked);
void coroutine_fn blk_co_eject(BlockBackend *blk, bool eject_flag);
void generated_co_wrapper_simple blk_eject(BlockBackend *blk, bool eject_flag);
BlockDriver->bdrv_lock_medium is categorized as IO callback, and it currently doesn't run in a coroutine. This makes very difficult to add the graph rdlock, since the callback traverses the block nodes graph. The only caller of this function is blk_lock_medium, therefore make blk_lock_medium a generated_co_wrapper_simple, so that it always creates a new coroutine, and then make bdrv_lock_medium coroutine_fn. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> --- block.c | 3 ++- block/block-backend.c | 5 +++-- block/copy-on-read.c | 2 +- block/filter-compress.c | 2 +- block/raw-format.c | 2 +- include/block/block-io.h | 2 +- include/block/block_int-common.h | 2 +- include/sysemu/block-backend-io.h | 5 ++++- 8 files changed, 14 insertions(+), 9 deletions(-)