aboutsummaryrefslogtreecommitdiffstats
path: root/hw
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-07-31 12:25:41 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-08-10 13:05:28 -0500
commitd176c495b6664b72dc1e595f6e89dc5648aa248b (patch)
tree8007516b5e4a7bc56cd806e92b0be7028ce643bb /hw
parent14b41872fd4ccdb750d539f1f317ae0e070f73a4 (diff)
qdev-ify virtio-blk.
First user of the new drive property. With this patch applied host and guest config can be specified separately, like this: -drive if=none,id=disk1,file=/path/to/disk.img -device virtio-blk-pci,drive=disk1 You can set any property for virtio-blk-pci now. You can set the pci address via addr=. You can switch the device into 0.10 compat mode using class=0x0180. As this is per device you can have one 0.10 and one 0.11 virtio block device in a single virtual machine. Old syntax continues to work. Internally it does the same as the two lines above though. One side effect this has is a different initialization order, which might result in a different pci address being assigned by default. Long term plan here is to have this working for all block devices, i.e. once all scsi is properly qdev-ified you will be able to do something like this: -drive if=none,id=sda,file=/path/to/disk.img -device lsi,id=lsi,addr=<pciaddr> -device scsi-disk,drive=sda,bus=lsi.0,lun=<n> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Message-Id:
Diffstat (limited to 'hw')
-rw-r--r--hw/pc.c12
-rw-r--r--hw/pci-hotplug.c1
-rw-r--r--hw/ppc440_bamboo.c11
-rw-r--r--hw/ppce500_mpc8544ds.c11
-rw-r--r--hw/virtio-blk.c10
-rw-r--r--hw/virtio-pci.c12
-rw-r--r--hw/virtio.h3
7 files changed, 17 insertions, 43 deletions
diff --git a/hw/pc.c b/hw/pc.c
index bc9e64609..6e5669ce0 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -1409,18 +1409,6 @@ static void pc_init1(ram_addr_t ram_size,
}
}
- /* Add virtio block devices */
- if (pci_enabled) {
- int unit_id = 0;
-
- while ((dinfo = drive_get(IF_VIRTIO, 0, unit_id)) != NULL) {
- pci_dev = pci_create("virtio-blk-pci",
- dinfo->devaddr);
- qdev_init(&pci_dev->qdev);
- unit_id++;
- }
- }
-
/* Add virtio balloon device */
if (pci_enabled && virtio_balloon) {
pci_dev = pci_create("virtio-balloon-pci", virtio_balloon_devaddr);
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index 43675e265..4da916cca 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -136,6 +136,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
break;
case IF_VIRTIO:
dev = pci_create("virtio-blk-pci", devaddr);
+ qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
break;
default:
dev = NULL;
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index 5011679cc..3c59f3309 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -90,7 +90,6 @@ static void bamboo_init(ram_addr_t ram_size,
{
unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
PCIBus *pcibus;
- PCIDevice *pci_dev;
CPUState *env;
uint64_t elf_entry;
uint64_t elf_lowaddr;
@@ -102,21 +101,11 @@ static void bamboo_init(ram_addr_t ram_size,
target_ulong dt_base = 0;
void *fdt;
int i;
- DriveInfo *dinfo;
/* Setup CPU. */
env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);
if (pcibus) {
- int unit_id = 0;
-
- /* Add virtio block devices. */
- while ((dinfo = drive_get(IF_VIRTIO, 0, unit_id)) != NULL) {
- pci_dev = pci_create("virtio-blk-pci", dinfo->devaddr);
- qdev_init(&pci_dev->qdev);
- unit_id++;
- }
-
/* Add virtio console devices */
for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
if (virtcon_hds[i]) {
diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
index d154c7fd7..51208215f 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -157,7 +157,6 @@ static void mpc8544ds_init(ram_addr_t ram_size,
const char *cpu_model)
{
PCIBus *pci_bus;
- PCIDevice *pci_dev;
CPUState *env;
uint64_t elf_entry;
uint64_t elf_lowaddr;
@@ -172,7 +171,6 @@ static void mpc8544ds_init(ram_addr_t ram_size,
unsigned int pci_irq_nrs[4] = {1, 2, 3, 4};
qemu_irq *irqs, *mpic, *pci_irqs;
SerialState * serial[2];
- DriveInfo *dinfo;
/* Setup CPU */
env = cpu_ppc_init("e500v2_v30");
@@ -217,15 +215,6 @@ static void mpc8544ds_init(ram_addr_t ram_size,
isa_mmio_init(MPC8544_PCI_IO, MPC8544_PCI_IOLEN);
if (pci_bus) {
- int unit_id = 0;
-
- /* Add virtio block devices. */
- while ((dinfo = drive_get(IF_VIRTIO, 0, unit_id)) != NULL) {
- pci_dev = pci_create("virtio-blk-pci", dinfo->devaddr);
- qdev_init(&pci_dev->qdev);
- unit_id++;
- }
-
/* Register network interfaces. */
for (i = 0; i < nb_nics; i++) {
pci_nic_init(&nd_table[i], "virtio", NULL);
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 5036b5b02..c278d2ef0 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -414,29 +414,27 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
return 0;
}
-VirtIODevice *virtio_blk_init(DeviceState *dev)
+VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo)
{
VirtIOBlock *s;
int cylinders, heads, secs;
static int virtio_blk_id;
- BlockDriverState *bs;
char *ps;
s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
sizeof(struct virtio_blk_config),
sizeof(VirtIOBlock));
- bs = qdev_init_bdrv(dev, IF_VIRTIO);
s->vdev.get_config = virtio_blk_update_config;
s->vdev.get_features = virtio_blk_get_features;
s->vdev.reset = virtio_blk_reset;
- s->bs = bs;
+ s->bs = dinfo->bdrv;
s->rq = NULL;
- if (strlen(ps = (char *)drive_get_serial(bs)))
+ if (strlen(ps = (char *)drive_get_serial(s->bs)))
strncpy(s->serial_str, ps, sizeof(s->serial_str));
else
snprintf(s->serial_str, sizeof(s->serial_str), "0");
- bs->private = dev;
+ s->bs->private = dev;
bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
bdrv_set_geometry_hint(s->bs, cylinders, heads, secs);
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 703f4fe53..8cf4b57a3 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -17,7 +17,7 @@
#include "virtio.h"
#include "pci.h"
-//#include "sysemu.h"
+#include "sysemu.h"
#include "msix.h"
#include "net.h"
@@ -89,6 +89,7 @@ typedef struct {
uint32_t addr;
uint32_t class_code;
uint32_t nvectors;
+ DriveInfo *dinfo;
} VirtIOPCIProxy;
/* virtio device */
@@ -432,7 +433,10 @@ static void virtio_blk_init_pci(PCIDevice *pci_dev)
proxy->class_code != PCI_CLASS_STORAGE_OTHER)
proxy->class_code = PCI_CLASS_STORAGE_SCSI;
- vdev = virtio_blk_init(&pci_dev->qdev);
+ if (!proxy->dinfo) {
+ fprintf(stderr, "drive property not set\n");
+ }
+ vdev = virtio_blk_init(&pci_dev->qdev, proxy->dinfo);
virtio_init_pci(proxy, vdev,
PCI_VENDOR_ID_REDHAT_QUMRANET,
PCI_DEVICE_ID_VIRTIO_BLOCK,
@@ -502,6 +506,10 @@ static PCIDeviceInfo virtio_info[] = {
.name = "class",
.info = &qdev_prop_hex32,
.offset = offsetof(VirtIOPCIProxy, class_code),
+ },{
+ .name = "drive",
+ .info = &qdev_prop_drive,
+ .offset = offsetof(VirtIOPCIProxy, dinfo),
},
{/* end of list */}
},
diff --git a/hw/virtio.h b/hw/virtio.h
index aa556778e..c441a93e5 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -16,6 +16,7 @@
#include "hw.h"
#include "qdev.h"
+#include "sysemu.h"
/* from Linux's linux/virtio_config.h */
@@ -161,7 +162,7 @@ void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
void *opaque);
/* Base devices. */
-VirtIODevice *virtio_blk_init(DeviceState *dev);
+VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo);
VirtIODevice *virtio_net_init(DeviceState *dev);
VirtIODevice *virtio_console_init(DeviceState *dev);
VirtIODevice *virtio_balloon_init(DeviceState *dev);