[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 21/30] virtio: Start converting VirtioDevice to QOM r
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 21/30] virtio: Start converting VirtioDevice to QOM realize |
Date: |
Mon, 9 Dec 2013 21:48:23 +0100 |
From: Andreas Färber <address@hidden>
Temporarily allow either VirtioDeviceClass::init or
VirtioDeviceClass::realize.
Introduce VirtioDeviceClass::unrealize for symmetry.
Signed-off-by: Andreas Färber <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/virtio/virtio.c | 42 +++++++++++++++++++++++++++---------------
include/hw/virtio/virtio.h | 4 +++-
2 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 965b2c0..4070b37 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1150,40 +1150,52 @@ void virtio_device_set_child_bus_name(VirtIODevice
*vdev, char *bus_name)
}
}
-static int virtio_device_init(DeviceState *qdev)
-{
- VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
- VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
- assert(k->init != NULL);
- if (k->init(vdev) < 0) {
- return -1;
+static void virtio_device_realize(DeviceState *dev, Error **errp)
+{
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+ VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
+ Error *err = NULL;
+
+ assert(vdc->init != NULL || vdc->realize != NULL);
+ if (vdc->realize != NULL) {
+ vdc->realize(dev, &err);
+ if (err != NULL) {
+ error_propagate(errp, err);
+ return;
+ }
+ } else {
+ if (vdc->init(vdev) < 0) {
+ error_setg(errp, "Device initialization failed.");
+ return;
+ }
}
virtio_bus_device_plugged(vdev);
- return 0;
}
-static int virtio_device_exit(DeviceState *qdev)
+static void virtio_device_unrealize(DeviceState *dev, Error **errp)
{
- VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
- VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(dev);
virtio_bus_device_unplugged(vdev);
- if (k->exit) {
+
+ if (k->exit != NULL) {
k->exit(vdev);
}
+
if (vdev->bus_name) {
g_free(vdev->bus_name);
vdev->bus_name = NULL;
}
- return 0;
}
static void virtio_device_class_init(ObjectClass *klass, void *data)
{
/* Set the default value here. */
DeviceClass *dc = DEVICE_CLASS(klass);
- dc->init = virtio_device_init;
- dc->exit = virtio_device_exit;
+
+ dc->realize = virtio_device_realize;
+ dc->unrealize = virtio_device_unrealize;
dc->bus_type = TYPE_VIRTIO_BUS;
}
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 59756c2..54c5efe 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -124,10 +124,12 @@ struct VirtIODevice
};
typedef struct VirtioDeviceClass {
- /* This is what a VirtioDevice must implement */
DeviceClass parent;
+
+ /* This is what a VirtioDevice must implement */
int (*init)(VirtIODevice *vdev);
void (*exit)(VirtIODevice *vdev);
+ DeviceRealize realize;
uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
uint32_t (*bad_features)(VirtIODevice *vdev);
void (*set_features)(VirtIODevice *vdev, uint32_t val);
--
1.8.4.2
- [Qemu-devel] [PULL 11/30] virtio-rng: switch exit callback to VirtioDeviceClass, (continued)
- [Qemu-devel] [PULL 11/30] virtio-rng: switch exit callback to VirtioDeviceClass, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 12/30] virtio-pci: add device_unplugged callback, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 13/30] virtio-blk-dataplane: Improve error reporting, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 14/30] virtio-9p: QOM realize preparations, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 15/30] virtio-blk: QOM realize preparations, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 16/30] virtio-serial: QOM realize preparations, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 17/30] virtio-net: QOM realize preparations, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 18/30] virtio-balloon: QOM realize preparations, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 19/30] virtio-rng: QOM realize preparations, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 20/30] virtio-scsi: QOM realize preparations, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 21/30] virtio: Start converting VirtioDevice to QOM realize,
Paolo Bonzini <=
- [Qemu-devel] [PULL 22/30] virtio-9p: Convert to QOM realize, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 23/30] virtio-blk: Convert to QOM realize, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 24/30] virtio-serial: Convert to QOM realize, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 25/30] virtio-net: Convert to QOM realize, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 26/30] virtio-balloon: Convert to QOM realize, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 27/30] virtio-rng: Convert to QOM realize, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 28/30] virtio-scsi: Convert to QOM realize, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 29/30] virtio: Complete converting VirtioDevice to QOM realize, Paolo Bonzini, 2013/12/09
- [Qemu-devel] [PULL 30/30] virtio: Convert exit to unrealize, Paolo Bonzini, 2013/12/09