[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Poking around bdrv_is_inserted()
From: |
Markus Armbruster |
Subject: |
Poking around bdrv_is_inserted() |
Date: |
Tue, 09 Nov 2021 07:34:33 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
bdrv_is_inserted() returns false when:
/**
* Return TRUE if the media is present
*/
bool bdrv_is_inserted(BlockDriverState *bs)
{
BlockDriver *drv = bs->drv;
BdrvChild *child;
if (!drv) {
return false;
1. @bs has no driver (this is how we represent "no medium").
}
if (drv->bdrv_is_inserted) {
return drv->bdrv_is_inserted(bs);
2. Its driver's ->bdrv_is_inserted() returns false. This is how
passthrough block backends signal "host device has no medium". Right
now, the only user is "host_cdrom".
}
QLIST_FOREACH(child, &bs->children, next) {
if (!bdrv_is_inserted(child->bs)) {
return false;
3. Any of its children has no medium. Common use looking through
filters, which have a single child.
}
}
return true;
}
Makes sense.
Now look at the uses of QERR_DEVICE_HAS_NO_MEDIUM.
* external_snapshot_prepare() in blockdev.c:
if (!bdrv_is_inserted(state->old_bs)) {
error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
goto out;
}
where @device is the device name, i.e. BlockdevSnapshot member @node
or BlockdevSnapshotSync member @device. Uh-oh: the latter can be
null. If we can reach the error_setg() then, we crash on some
systems.
* bdrv_snapshot_delete() and bdrv_snapshot_load_tmp() in
block/snaphot.c:
if (!drv) {
error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, bdrv_get_device_name(bs));
return -ENOMEDIUM;
}
where @drv is bs->drv.
Why do we check only for 1. here instead of calling
bdrv_is_inserted()?
- Poking around bdrv_is_inserted(),
Markus Armbruster <=