mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-30 21:42:06 -06:00
block-backend: Remember if attached device is non-qdev
Almost all block devices are qdevified by now. This allows us to go back from the BlockBackend to the DeviceState. xen_disk is the last device that is missing. We'll remember in the BlockBackend if a xen_disk is attached and can then disable any features that require going from a BB to the DeviceState. While at it, clearly mark the function used by xen_disk as legacy even in its name, not just in TODO comments. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
2bf7e10f78
commit
bbc8ea98bc
3 changed files with 23 additions and 11 deletions
|
@ -38,6 +38,7 @@ struct BlockBackend {
|
||||||
BlockBackendPublic public;
|
BlockBackendPublic public;
|
||||||
|
|
||||||
void *dev; /* attached device model, if any */
|
void *dev; /* attached device model, if any */
|
||||||
|
bool legacy_dev; /* true if dev is not a DeviceState */
|
||||||
/* TODO change to DeviceState when all users are qdevified */
|
/* TODO change to DeviceState when all users are qdevified */
|
||||||
const BlockDevOps *dev_ops;
|
const BlockDevOps *dev_ops;
|
||||||
void *dev_opaque;
|
void *dev_opaque;
|
||||||
|
@ -506,32 +507,38 @@ void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static int blk_do_attach_dev(BlockBackend *blk, void *dev)
|
||||||
* Attach device model @dev to @blk.
|
|
||||||
* Return 0 on success, -EBUSY when a device model is attached already.
|
|
||||||
*/
|
|
||||||
int blk_attach_dev(BlockBackend *blk, void *dev)
|
|
||||||
/* TODO change to DeviceState *dev when all users are qdevified */
|
|
||||||
{
|
{
|
||||||
if (blk->dev) {
|
if (blk->dev) {
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
blk_ref(blk);
|
blk_ref(blk);
|
||||||
blk->dev = dev;
|
blk->dev = dev;
|
||||||
|
blk->legacy_dev = false;
|
||||||
blk_iostatus_reset(blk);
|
blk_iostatus_reset(blk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Attach device model @dev to @blk.
|
||||||
|
* Return 0 on success, -EBUSY when a device model is attached already.
|
||||||
|
*/
|
||||||
|
int blk_attach_dev(BlockBackend *blk, DeviceState *dev)
|
||||||
|
{
|
||||||
|
return blk_do_attach_dev(blk, dev);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attach device model @dev to @blk.
|
* Attach device model @dev to @blk.
|
||||||
* @blk must not have a device model attached already.
|
* @blk must not have a device model attached already.
|
||||||
* TODO qdevified devices don't use this, remove when devices are qdevified
|
* TODO qdevified devices don't use this, remove when devices are qdevified
|
||||||
*/
|
*/
|
||||||
void blk_attach_dev_nofail(BlockBackend *blk, void *dev)
|
void blk_attach_dev_legacy(BlockBackend *blk, void *dev)
|
||||||
{
|
{
|
||||||
if (blk_attach_dev(blk, dev) < 0) {
|
if (blk_do_attach_dev(blk, dev) < 0) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
blk->legacy_dev = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -585,6 +592,11 @@ BlockBackend *blk_by_dev(void *dev)
|
||||||
void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops,
|
void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
|
/* All drivers that use blk_set_dev_ops() are qdevified and we want to keep
|
||||||
|
* it that way, so we can assume blk->dev is a DeviceState if blk->dev_ops
|
||||||
|
* is set. */
|
||||||
|
assert(!blk->legacy_dev);
|
||||||
|
|
||||||
blk->dev_ops = ops;
|
blk->dev_ops = ops;
|
||||||
blk->dev_opaque = opaque;
|
blk->dev_opaque = opaque;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1079,7 +1079,7 @@ static int blk_connect(struct XenDevice *xendev)
|
||||||
* so we can blk_unref() unconditionally */
|
* so we can blk_unref() unconditionally */
|
||||||
blk_ref(blkdev->blk);
|
blk_ref(blkdev->blk);
|
||||||
}
|
}
|
||||||
blk_attach_dev_nofail(blkdev->blk, blkdev);
|
blk_attach_dev_legacy(blkdev->blk, blkdev);
|
||||||
blkdev->file_size = blk_getlength(blkdev->blk);
|
blkdev->file_size = blk_getlength(blkdev->blk);
|
||||||
if (blkdev->file_size < 0) {
|
if (blkdev->file_size < 0) {
|
||||||
BlockDriverState *bs = blk_bs(blkdev->blk);
|
BlockDriverState *bs = blk_bs(blkdev->blk);
|
||||||
|
|
|
@ -107,8 +107,8 @@ BlockDeviceIoStatus blk_iostatus(const BlockBackend *blk);
|
||||||
void blk_iostatus_disable(BlockBackend *blk);
|
void blk_iostatus_disable(BlockBackend *blk);
|
||||||
void blk_iostatus_reset(BlockBackend *blk);
|
void blk_iostatus_reset(BlockBackend *blk);
|
||||||
void blk_iostatus_set_err(BlockBackend *blk, int error);
|
void blk_iostatus_set_err(BlockBackend *blk, int error);
|
||||||
int blk_attach_dev(BlockBackend *blk, void *dev);
|
int blk_attach_dev(BlockBackend *blk, DeviceState *dev);
|
||||||
void blk_attach_dev_nofail(BlockBackend *blk, void *dev);
|
void blk_attach_dev_legacy(BlockBackend *blk, void *dev);
|
||||||
void blk_detach_dev(BlockBackend *blk, void *dev);
|
void blk_detach_dev(BlockBackend *blk, void *dev);
|
||||||
void *blk_get_attached_dev(BlockBackend *blk);
|
void *blk_get_attached_dev(BlockBackend *blk);
|
||||||
BlockBackend *blk_by_dev(void *dev);
|
BlockBackend *blk_by_dev(void *dev);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue