aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2011-08-03 15:07:40 +0200
committerKevin Wolf <kwolf@redhat.com>2011-09-06 11:23:51 +0200
commitfa879d62eb51253d00b6920ce1d1d9d261370a49 (patch)
treef83542a0ae74fe8ef0078f90098ae6aa7e02a7d6 /block.c
parent648fb0ea5e9d7f32c80ec23c3ece4321403dfecd (diff)
downloadqemu-fa879d62eb51253d00b6920ce1d1d9d261370a49.zip
qemu-fa879d62eb51253d00b6920ce1d1d9d261370a49.tar.gz
qemu-fa879d62eb51253d00b6920ce1d1d9d261370a49.tar.bz2
block: Attach non-qdev devices as well
For now, this just protects against programming errors like having the same drive back multiple non-qdev devices, or untimely bdrv_delete(). Later commits will add other interesting uses. While there, rename BlockDriverState member peer to dev, bdrv_attach() to bdrv_attach_dev(), bdrv_detach() to bdrv_detach_dev(), and bdrv_get_attached() to bdrv_get_attached_dev(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/block.c b/block.c
index 43742b7..fb9341c 100644
--- a/block.c
+++ b/block.c
@@ -755,7 +755,7 @@ void bdrv_make_anon(BlockDriverState *bs)
void bdrv_delete(BlockDriverState *bs)
{
- assert(!bs->peer);
+ assert(!bs->dev);
/* remove from list, if necessary */
bdrv_make_anon(bs);
@@ -769,26 +769,37 @@ void bdrv_delete(BlockDriverState *bs)
g_free(bs);
}
-int bdrv_attach(BlockDriverState *bs, DeviceState *qdev)
+int bdrv_attach_dev(BlockDriverState *bs, void *dev)
+/* TODO change to DeviceState *dev when all users are qdevified */
{
- if (bs->peer) {
+ if (bs->dev) {
return -EBUSY;
}
- bs->peer = qdev;
+ bs->dev = dev;
return 0;
}
-void bdrv_detach(BlockDriverState *bs, DeviceState *qdev)
+/* TODO qdevified devices don't use this, remove when devices are qdevified */
+void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev)
{
- assert(bs->peer == qdev);
- bs->peer = NULL;
+ if (bdrv_attach_dev(bs, dev) < 0) {
+ abort();
+ }
+}
+
+void bdrv_detach_dev(BlockDriverState *bs, void *dev)
+/* TODO change to DeviceState *dev when all users are qdevified */
+{
+ assert(bs->dev == dev);
+ bs->dev = NULL;
bs->change_cb = NULL;
bs->change_opaque = NULL;
}
-DeviceState *bdrv_get_attached(BlockDriverState *bs)
+/* TODO change to return DeviceState * when all users are qdevified */
+void *bdrv_get_attached_dev(BlockDriverState *bs)
{
- return bs->peer;
+ return bs->dev;
}
/*