@@ -139,7 +139,10 @@ bool bdrv_is_read_only(BlockDriverState *bs);
bool bdrv_is_writable(BlockDriverState *bs);
bool bdrv_is_sg(BlockDriverState *bs);
int bdrv_get_flags(BlockDriverState *bs);
-bool bdrv_is_inserted(BlockDriverState *bs);
+
+bool coroutine_fn bdrv_co_is_inserted(BlockDriverState *bs);
+bool co_wrapper bdrv_is_inserted(BlockDriverState *bs);
+
void bdrv_lock_medium(BlockDriverState *bs, bool locked);
void bdrv_eject(BlockDriverState *bs, bool eject_flag);
const char *bdrv_get_format_name(BlockDriverState *bs);
@@ -710,7 +710,7 @@ struct BlockDriver {
BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
/* removable device specific */
- bool (*bdrv_is_inserted)(BlockDriverState *bs);
+ bool coroutine_fn (*bdrv_is_inserted)(BlockDriverState *bs);
void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag);
void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked);
@@ -53,7 +53,10 @@ 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 blk_is_inserted(BlockBackend *blk);
+
+bool coroutine_fn blk_co_is_inserted(BlockBackend *blk);
+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);
@@ -6797,7 +6797,7 @@ out:
/**
* Return TRUE if the media is present
*/
-bool bdrv_is_inserted(BlockDriverState *bs)
+bool coroutine_fn bdrv_co_is_inserted(BlockDriverState *bs)
{
BlockDriver *drv = bs->drv;
BdrvChild *child;
@@ -6810,7 +6810,7 @@ bool bdrv_is_inserted(BlockDriverState *bs)
return drv->bdrv_is_inserted(bs);
}
QLIST_FOREACH(child, &bs->children, next) {
- if (!bdrv_is_inserted(child->bs)) {
+ if (!bdrv_co_is_inserted(child->bs)) {
return false;
}
}
@@ -1985,12 +1985,12 @@ void blk_activate(BlockBackend *blk, Error **errp)
bdrv_activate(bs, errp);
}
-bool blk_is_inserted(BlockBackend *blk)
+bool coroutine_fn blk_co_is_inserted(BlockBackend *blk)
{
BlockDriverState *bs = blk_bs(blk);
IO_CODE();
- return bs && bdrv_is_inserted(bs);
+ return bs && bdrv_co_is_inserted(bs);
}
bool blk_is_available(BlockBackend *blk)
@@ -1612,7 +1612,7 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child,
trace_bdrv_co_preadv_part(bs, offset, bytes, flags);
- if (!bdrv_is_inserted(bs)) {
+ if (!bdrv_co_is_inserted(bs)) {
return -ENOMEDIUM;
}
@@ -2057,7 +2057,7 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child,
trace_bdrv_co_pwritev_part(child->bs, offset, bytes, flags);
- if (!bdrv_is_inserted(bs)) {
+ if (!bdrv_co_is_inserted(bs)) {
return -ENOMEDIUM;
}
@@ -2825,7 +2825,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
bdrv_inc_in_flight(bs);
- if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs) ||
+ if (!bdrv_co_is_inserted(bs) || bdrv_is_read_only(bs) ||
bdrv_is_sg(bs)) {
goto early_exit;
}
@@ -2949,7 +2949,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset,
BlockDriverState *bs = child->bs;
IO_CODE();
- if (!bs || !bs->drv || !bdrv_is_inserted(bs)) {
+ if (!bs || !bs->drv || !bdrv_co_is_inserted(bs)) {
return -ENOMEDIUM;
}
@@ -3231,7 +3231,7 @@ static int coroutine_fn bdrv_co_copy_range_internal(
assert(!(read_flags & BDRV_REQ_NO_WAIT));
assert(!(write_flags & BDRV_REQ_NO_WAIT));
- if (!dst || !dst->bs || !bdrv_is_inserted(dst->bs)) {
+ if (!dst || !dst->bs || !bdrv_co_is_inserted(dst->bs)) {
return -ENOMEDIUM;
}
ret = bdrv_check_request32(dst_offset, bytes, NULL, 0);
@@ -3242,7 +3242,7 @@ static int coroutine_fn bdrv_co_copy_range_internal(
return bdrv_co_pwrite_zeroes(dst, dst_offset, bytes, write_flags);
}
- if (!src || !src->bs || !bdrv_is_inserted(src->bs)) {
+ if (!src || !src->bs || !bdrv_co_is_inserted(src->bs)) {
return -ENOMEDIUM;
}
ret = bdrv_check_request32(src_offset, bytes, NULL, 0);
@@ -1023,6 +1023,7 @@ fail:
static BlockDriverState *qmp_get_root_bs(const char *name, Error **errp)
{
BlockDriverState *bs;
+ AioContext *aio_context;
bs = bdrv_lookup_bs(name, name, errp);
if (bs == NULL) {
@@ -1034,11 +1035,16 @@ static BlockDriverState *qmp_get_root_bs(const char *name, Error **errp)
return NULL;
}
+ aio_context = bdrv_get_aio_context(bs);
+ aio_context_acquire(aio_context);
+
if (!bdrv_is_inserted(bs)) {
error_setg(errp, "Device has no medium");
- return NULL;
+ bs = NULL;
}
+ aio_context_release(aio_context);
+
return bs;
}