mirror of https://gitlab.com/qemu-project/qemu
virtio: Start converting VirtioDevice to QOM realize
Temporarily allow either VirtioDeviceClass::init or VirtioDeviceClass::realize. Introduce VirtioDeviceClass::unrealize for symmetry. Signed-off-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
7598f0f30e
commit
1d244b42d2
|
@ -1150,40 +1150,52 @@ void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int virtio_device_init(DeviceState *qdev)
|
static void virtio_device_realize(DeviceState *dev, Error **errp)
|
||||||
{
|
{
|
||||||
VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
|
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
||||||
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
|
VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
|
||||||
assert(k->init != NULL);
|
Error *err = NULL;
|
||||||
if (k->init(vdev) < 0) {
|
|
||||||
return -1;
|
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);
|
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);
|
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
||||||
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
|
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(dev);
|
||||||
|
|
||||||
virtio_bus_device_unplugged(vdev);
|
virtio_bus_device_unplugged(vdev);
|
||||||
if (k->exit) {
|
|
||||||
|
if (k->exit != NULL) {
|
||||||
k->exit(vdev);
|
k->exit(vdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vdev->bus_name) {
|
if (vdev->bus_name) {
|
||||||
g_free(vdev->bus_name);
|
g_free(vdev->bus_name);
|
||||||
vdev->bus_name = NULL;
|
vdev->bus_name = NULL;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void virtio_device_class_init(ObjectClass *klass, void *data)
|
static void virtio_device_class_init(ObjectClass *klass, void *data)
|
||||||
{
|
{
|
||||||
/* Set the default value here. */
|
/* Set the default value here. */
|
||||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
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;
|
dc->bus_type = TYPE_VIRTIO_BUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,10 +124,12 @@ struct VirtIODevice
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct VirtioDeviceClass {
|
typedef struct VirtioDeviceClass {
|
||||||
/* This is what a VirtioDevice must implement */
|
|
||||||
DeviceClass parent;
|
DeviceClass parent;
|
||||||
|
|
||||||
|
/* This is what a VirtioDevice must implement */
|
||||||
int (*init)(VirtIODevice *vdev);
|
int (*init)(VirtIODevice *vdev);
|
||||||
void (*exit)(VirtIODevice *vdev);
|
void (*exit)(VirtIODevice *vdev);
|
||||||
|
DeviceRealize realize;
|
||||||
uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
|
uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
|
||||||
uint32_t (*bad_features)(VirtIODevice *vdev);
|
uint32_t (*bad_features)(VirtIODevice *vdev);
|
||||||
void (*set_features)(VirtIODevice *vdev, uint32_t val);
|
void (*set_features)(VirtIODevice *vdev, uint32_t val);
|
||||||
|
|
Loading…
Reference in New Issue