From: KONRAD Frederic <fred.kon...@greensocs.com> Signed-off-by: KONRAD Frederic <fred.kon...@greensocs.com> --- hw/s390x/virtio-ccw.c | 38 ++++++++++++++++++++++++-------------- hw/s390x/virtio-ccw.h | 14 +++++++++++++- 2 files changed, 37 insertions(+), 15 deletions(-)
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index d92e427..271f770 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -570,23 +570,32 @@ static int virtio_ccw_net_exit(VirtioCcwDevice *dev) return virtio_ccw_exit(dev); } -static int virtio_ccw_blk_init(VirtioCcwDevice *dev) +static int virtio_ccw_blk_init(VirtioCcwDevice *ccw_dev) { - VirtIODevice *vdev; - - vdev = virtio_blk_init((DeviceState *)dev, &dev->blk); - if (!vdev) { + VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(ccw_dev); + DeviceState *vdev = DEVICE(&dev->vdev); + virtio_blk_set_conf(vdev, &(dev->blk)); + qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); + if (qdev_init(vdev) < 0) { return -1; } - return virtio_ccw_device_init(dev, vdev); + return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev)); } -static int virtio_ccw_blk_exit(VirtioCcwDevice *dev) +static int virtio_ccw_blk_exit(VirtioCcwDevice *ccw_dev) { - virtio_blk_exit(dev->vdev); + VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(ccw_dev); blockdev_mark_auto_del(dev->blk.conf.bs); - return virtio_ccw_exit(dev); + virtio_bus_destroy_device(&ccw_dev->bus); + return virtio_ccw_exit(ccw_dev); +} + +static void virtio_ccw_blk_instance_init(Object *obj) +{ + VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(obj); + object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_BLK); + object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL); } static int virtio_ccw_serial_init(VirtioCcwDevice *dev) @@ -731,10 +740,10 @@ static const TypeInfo virtio_ccw_net = { static Property virtio_ccw_blk_properties[] = { DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id), - DEFINE_BLOCK_PROPERTIES(VirtioCcwDevice, blk.conf), - DEFINE_PROP_STRING("serial", VirtioCcwDevice, blk.serial), + DEFINE_BLOCK_PROPERTIES(VirtIOBlkCcw, blk.conf), + DEFINE_PROP_STRING("serial", VirtIOBlkCcw, blk.serial), #ifdef __linux__ - DEFINE_PROP_BIT("scsi", VirtioCcwDevice, blk.scsi, 0, true), + DEFINE_PROP_BIT("scsi", VirtIOBlkCcw, blk.scsi, 0, true), #endif DEFINE_VIRTIO_BLK_FEATURES(VirtioCcwDevice, host_features[0]), DEFINE_PROP_END_OF_LIST(), @@ -752,9 +761,10 @@ static void virtio_ccw_blk_class_init(ObjectClass *klass, void *data) } static const TypeInfo virtio_ccw_blk = { - .name = "virtio-blk-ccw", + .name = TYPE_VIRTIO_BLK_CCW, .parent = TYPE_VIRTIO_CCW_DEVICE, - .instance_size = sizeof(VirtioCcwDevice), + .instance_size = sizeof(VirtIOBlkCcw), + .instance_init = virtio_ccw_blk_instance_init, .class_init = virtio_ccw_blk_class_init, }; diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h index 48474b3..9ab0b0d 100644 --- a/hw/s390x/virtio-ccw.h +++ b/hw/s390x/virtio-ccw.h @@ -71,7 +71,6 @@ struct VirtioCcwDevice { SubchDev *sch; VirtIODevice *vdev; char *bus_id; - VirtIOBlkConf blk; NICConf nic; uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE]; virtio_serial_conf serial; @@ -92,6 +91,19 @@ typedef struct VirtualCssBus { #define VIRTUAL_CSS_BUS(obj) \ OBJECT_CHECK(VirtualCssBus, (obj), TYPE_VIRTUAL_CSS_BUS) +/* virtio-blk-ccw */ + +#define TYPE_VIRTIO_BLK_CCW "virtio-blk-ccw" +#define VIRTIO_BLK_CCW(obj) \ + OBJECT_CHECK(VirtIOBlkCcw, (obj), TYPE_VIRTIO_BLK_CCW) + +typedef struct VirtIOBlkCcw { + VirtioCcwDevice parent_obj; + VirtIOBlock vdev; + VirtIOBlkConf blk; +} VirtIOBlkCcw; + + VirtualCssBus *virtual_css_bus_init(void); void virtio_ccw_device_update_status(SubchDev *sch); VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch); -- 1.7.11.7