From 07e3af9ac31008a1d7eaaf44d62a13545f01c579 Mon Sep 17 00:00:00 2001 From: Paul Brook Date: Thu, 14 May 2009 22:35:08 +0100 Subject: [PATCH] Virtio-blk qdev conversion Signed-off-by: Paul Brook --- hw/pc.c | 3 +-- hw/pci-hotplug.c | 3 ++- hw/ppc440_bamboo.c | 3 +-- hw/ppce500_mpc8544ds.c | 3 +-- hw/virtio-blk.c | 19 ++++++++++--------- hw/virtio-blk.h | 2 -- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index d1ba79b..12065ba 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -33,7 +33,6 @@ #include "boards.h" #include "monitor.h" #include "fw_cfg.h" -#include "virtio-blk.h" #include "virtio-balloon.h" #include "virtio-console.h" #include "hpet_emul.h" @@ -1136,7 +1135,7 @@ static void pc_init1(ram_addr_t ram_size, int unit_id = 0; while ((index = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) { - virtio_blk_init(pci_bus, drives_table[index].bdrv); + pci_create_simple(pci_bus, -1, "virtio-blk"); unit_id++; } } diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index 294fdd1..acda2bb 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -120,7 +120,8 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, PCIBus *pci_bus, opaque = pci_create_simple(pci_bus, -1, "lsi53c895a"); break; case IF_VIRTIO: - opaque = virtio_blk_init (pci_bus, drives_table[drive_idx].bdrv); + opaque = pci_create_simple(pci_bus, -1, "virtio-blk"); + qdev_init(opaque); break; } diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c index e396ac3..a58f6ea 100644 --- a/hw/ppc440_bamboo.c +++ b/hw/ppc440_bamboo.c @@ -16,7 +16,6 @@ #include "net.h" #include "hw.h" #include "pci.h" -#include "virtio-blk.h" #include "virtio-console.h" #include "boards.h" #include "sysemu.h" @@ -113,7 +112,7 @@ static void bamboo_init(ram_addr_t ram_size, /* Add virtio block devices. */ while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) { - virtio_blk_init(pcibus, drives_table[i].bdrv); + pci_create_simple(pcibus, -1, "virtio-blk"); unit_id++; } diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c index 94a83d7..a5de61c 100644 --- a/hw/ppce500_mpc8544ds.c +++ b/hw/ppce500_mpc8544ds.c @@ -22,7 +22,6 @@ #include "hw.h" #include "pc.h" #include "pci.h" -#include "virtio-blk.h" #include "boards.h" #include "sysemu.h" #include "kvm.h" @@ -221,7 +220,7 @@ static void mpc8544ds_init(ram_addr_t ram_size, /* Add virtio block devices. */ while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) { - virtio_blk_init(pci_bus, drives_table[i].bdrv); + pci_create_simple(pci_bus, -1, "virtio-blk"); unit_id++; } diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index b80302b..ef09113 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -348,19 +348,14 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id) return 0; } -void *virtio_blk_init(PCIBus *bus, BlockDriverState *bs) +static void virtio_blk_init(PCIDevice *pci_dev) { VirtIOBlock *s; int cylinders, heads, secs; static int virtio_blk_id; - PCIDevice *d; - - d = pci_register_device(bus, "virtio-blk", sizeof(VirtIOBlock), - -1, NULL, NULL); - if (!d) - return NULL; + BlockDriverState *bs; - s = (VirtIOBlock *)virtio_init_pci(d, "virtio-blk", + s = (VirtIOBlock *)virtio_init_pci(pci_dev, "virtio-blk", PCI_VENDOR_ID_REDHAT_QUMRANET, PCI_DEVICE_ID_VIRTIO_BLOCK, PCI_VENDOR_ID_REDHAT_QUMRANET, @@ -368,6 +363,7 @@ void *virtio_blk_init(PCIBus *bus, BlockDriverState *bs) PCI_CLASS_STORAGE_OTHER, 0x00, sizeof(struct virtio_blk_config)); + bs = qdev_init_bdrv(&pci_dev->qdev, IF_VIRTIO); s->vdev.get_config = virtio_blk_update_config; s->vdev.get_features = virtio_blk_get_features; s->vdev.reset = virtio_blk_reset; @@ -382,6 +378,11 @@ void *virtio_blk_init(PCIBus *bus, BlockDriverState *bs) qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s); register_savevm("virtio-blk", virtio_blk_id++, 2, virtio_blk_save, virtio_blk_load, s); +} - return s; +static void virtio_blk_register_devices(void) +{ + pci_qdev_register("virtio-blk", sizeof(VirtIOBlock), virtio_blk_init); } + +device_init(virtio_blk_register_devices) diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h index 5ef6c36..e368608 100644 --- a/hw/virtio-blk.h +++ b/hw/virtio-blk.h @@ -82,6 +82,4 @@ struct virtio_scsi_inhdr uint32_t residual; }; -void *virtio_blk_init(PCIBus *bus, BlockDriverState *bs); - #endif -- 1.7.9.5