aboutsummaryrefslogtreecommitdiff
path: root/hw
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 /hw
parent648fb0ea5e9d7f32c80ec23c3ece4321403dfecd (diff)
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 'hw')
-rw-r--r--hw/ide/core.c1
-rw-r--r--hw/ide/piix.c4
-rw-r--r--hw/pflash_cfi01.c1
-rw-r--r--hw/pflash_cfi02.c1
-rw-r--r--hw/qdev-properties.c6
-rw-r--r--hw/sd.c1
-rw-r--r--hw/usb-msd.c2
-rw-r--r--hw/xen_disk.c1
8 files changed, 11 insertions, 6 deletions
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 40abc1edd2..428f033876 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1890,6 +1890,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
error_report("Can't set up IDE drive %s", dinfo->id);
exit(1);
}
+ bdrv_attach_dev_nofail(dinfo->bdrv, &bus->ifs[i]);
} else {
ide_reset(&bus->ifs[i]);
}
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 8525336075..b9cdcd6b75 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -177,9 +177,9 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
for (; i < 3; i++) {
di = drive_get_by_index(IF_IDE, i);
if (di != NULL && di->bdrv != NULL && !di->bdrv->removable) {
- DeviceState *ds = bdrv_get_attached(di->bdrv);
+ DeviceState *ds = bdrv_get_attached_dev(di->bdrv);
if (ds) {
- bdrv_detach(di->bdrv, ds);
+ bdrv_detach_dev(di->bdrv, ds);
}
bdrv_close(di->bdrv);
pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
diff --git a/hw/pflash_cfi01.c b/hw/pflash_cfi01.c
index 90e1301c5e..a2d94022b6 100644
--- a/hw/pflash_cfi01.c
+++ b/hw/pflash_cfi01.c
@@ -620,6 +620,7 @@ pflash_t *pflash_cfi01_register(target_phys_addr_t base, ram_addr_t off,
g_free(pfl);
return NULL;
}
+ bdrv_attach_dev_nofail(pfl->bs, pfl);
}
#if 0 /* XXX: there should be a bit to set up read-only,
* the same way the hardware does (with WP pin).
diff --git a/hw/pflash_cfi02.c b/hw/pflash_cfi02.c
index ac5115e4c8..919cfc466f 100644
--- a/hw/pflash_cfi02.c
+++ b/hw/pflash_cfi02.c
@@ -643,6 +643,7 @@ pflash_t *pflash_cfi02_register(target_phys_addr_t base, ram_addr_t off,
g_free(pfl);
return NULL;
}
+ bdrv_attach_dev_nofail(pfl->bs, pfl);
}
#if 0 /* XXX: there should be a bit to set up read-only,
* the same way the hardware does (with WP pin).
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 0c0c29212d..7ce95b679c 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -312,7 +312,7 @@ static int parse_drive(DeviceState *dev, Property *prop, const char *str)
bs = bdrv_find(str);
if (bs == NULL)
return -ENOENT;
- if (bdrv_attach(bs, dev) < 0)
+ if (bdrv_attach_dev(bs, dev) < 0)
return -EEXIST;
*ptr = bs;
return 0;
@@ -323,7 +323,7 @@ static void free_drive(DeviceState *dev, Property *prop)
BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
if (*ptr) {
- bdrv_detach(*ptr, dev);
+ bdrv_detach_dev(*ptr, dev);
blockdev_auto_del(*ptr);
}
}
@@ -678,7 +678,7 @@ int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *va
{
int res;
- res = bdrv_attach(value, dev);
+ res = bdrv_attach_dev(value, dev);
if (res < 0) {
error_report("Can't attach drive %s to %s.%s: %s",
bdrv_get_device_name(value),
diff --git a/hw/sd.c b/hw/sd.c
index bb8c2ff677..ab52634ec3 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -449,6 +449,7 @@ SDState *sd_init(BlockDriverState *bs, int is_spi)
sd->enable = 1;
sd_reset(sd, bs);
if (sd->bdrv) {
+ bdrv_attach_dev_nofail(sd->bdrv, sd);
bdrv_set_change_cb(sd->bdrv, sd_cardchange, sd);
}
return sd;
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 4072efd4b7..e92434cc94 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -518,7 +518,7 @@ static int usb_msd_initfn(USBDevice *dev)
*
* The hack is probably a bad idea.
*/
- bdrv_detach(bs, &s->dev.qdev);
+ bdrv_detach_dev(bs, &s->dev.qdev);
s->conf.bs = NULL;
if (!s->serial) {
diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index bd5c66916b..da531a67dd 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -697,6 +697,7 @@ static int blk_init(struct XenDevice *xendev)
xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");
blkdev->bs = blkdev->dinfo->bdrv;
}
+ bdrv_attach_dev_nofail(blkdev->bs, blkdev);
blkdev->file_blk = BLOCK_SIZE;
blkdev->file_size = bdrv_getlength(blkdev->bs);
if (blkdev->file_size < 0) {