Patchwork [RFC,for-next,v2,22/22] virtio-scsi: Convert virtio_scsi_common_[un]realize to QOM realize

login
register
mail settings
Submitter Andreas Färber
Date Aug. 1, 2013, 2:17 a.m.
Message ID <1375323463-32747-23-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/263875/
State New
Headers show

Comments

Andreas Färber - Aug. 1, 2013, 2:17 a.m.
VirtIOSCSI and VHostSCSI now perform some initializations after
VirtIOSCSICommon's realize calls virtio_bus_plug_device(), namely
creating the SCSIBus and initializing /dev/vhost-scsi respectively.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/scsi/vhost-scsi.c            |  6 +-----
 hw/scsi/virtio-scsi.c           | 20 +++++++++++++-------
 include/hw/virtio/virtio-scsi.h |  5 ++---
 3 files changed, 16 insertions(+), 15 deletions(-)

Patch

diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
index ad7cc9b..f4546da 100644
--- a/hw/scsi/vhost-scsi.c
+++ b/hw/scsi/vhost-scsi.c
@@ -219,7 +219,7 @@  static void vhost_scsi_realize(DeviceState *dev, Error **errp)
         }
     }
 
-    virtio_scsi_common_realize(dev, &err);
+    parent_dc->realize(dev, &err);
     if (err != NULL) {
         error_propagate(errp, err);
         return;
@@ -240,8 +240,6 @@  static void vhost_scsi_realize(DeviceState *dev, Error **errp)
     error_setg(&s->migration_blocker,
             "vhost-scsi does not support migration");
     migrate_add_blocker(s->migration_blocker);
-
-    parent_dc->realize(dev, errp);
 }
 
 static void vhost_scsi_unrealize(DeviceState *dev, Error **errp)
@@ -259,8 +257,6 @@  static void vhost_scsi_unrealize(DeviceState *dev, Error **errp)
 
     g_free(s->dev.vqs);
 
-    virtio_scsi_common_unrealize(dev, errp);
-
     parent_dc->unrealize(dev, errp);
 }
 
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index ac0ecdf..3a4ec97 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -589,10 +589,12 @@  static struct SCSIBusInfo virtio_scsi_scsi_info = {
     .load_request = virtio_scsi_load_request,
 };
 
-void virtio_scsi_common_realize(DeviceState *dev, Error **errp)
+static void virtio_scsi_common_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(dev);
+    ObjectClass *parent_oc = VIRTIO_SCSI_COMMON_GET_PARENT_CLASS(dev);
+    DeviceClass *parent_dc = DEVICE_CLASS(parent_oc);
     int i;
 
     virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI,
@@ -610,6 +612,8 @@  void virtio_scsi_common_realize(DeviceState *dev, Error **errp)
         s->cmd_vqs[i] = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
                                          virtio_scsi_handle_cmd);
     }
+
+    parent_dc->realize(dev, errp);
 }
 
 static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
@@ -621,7 +625,7 @@  static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
     static int virtio_scsi_id;
     Error *err = NULL;
 
-    virtio_scsi_common_realize(dev, &err);
+    parent_dc->realize(dev, &err);
     if (err != NULL) {
         error_propagate(errp, err);
         return;
@@ -639,17 +643,19 @@  static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
 
     register_savevm(dev, "virtio-scsi", virtio_scsi_id++, 1,
                     virtio_scsi_save, virtio_scsi_load, s);
-
-    parent_dc->realize(dev, errp);
 }
 
-void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp)
+static void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
+    ObjectClass *parent_oc = VIRTIO_SCSI_COMMON_GET_PARENT_CLASS(dev);
+    DeviceClass *parent_dc = DEVICE_CLASS(parent_oc);
 
     g_free(vs->cmd_vqs);
     virtio_cleanup(vdev);
+
+    parent_dc->unrealize(dev, errp);
 }
 
 static void virtio_scsi_device_unrealize(DeviceState *dev, Error **errp)
@@ -660,8 +666,6 @@  static void virtio_scsi_device_unrealize(DeviceState *dev, Error **errp)
 
     unregister_savevm(dev, "virtio-scsi", s);
 
-    virtio_scsi_common_unrealize(dev, errp);
-
     parent_dc->unrealize(dev, errp);
 }
 
@@ -675,6 +679,8 @@  static void virtio_scsi_common_class_init(ObjectClass *klass, void *data)
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
+    dc->realize = virtio_scsi_common_realize;
+    dc->unrealize = virtio_scsi_common_unrealize;
     vdc->get_config = virtio_scsi_get_config;
     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
 }
diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
index c56292b..a9fac74 100644
--- a/include/hw/virtio/virtio-scsi.h
+++ b/include/hw/virtio/virtio-scsi.h
@@ -21,6 +21,8 @@ 
 #define TYPE_VIRTIO_SCSI_COMMON "virtio-scsi-common"
 #define VIRTIO_SCSI_COMMON(obj) \
         OBJECT_CHECK(VirtIOSCSICommon, (obj), TYPE_VIRTIO_SCSI_COMMON)
+#define VIRTIO_SCSI_COMMON_GET_PARENT_CLASS(obj) \
+        OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_SCSI_COMMON)
 
 #define TYPE_VIRTIO_SCSI "virtio-scsi-device"
 #define VIRTIO_SCSI(obj) \
@@ -188,7 +190,4 @@  typedef struct {
     DEFINE_PROP_BIT("param_change", _state, _feature_field,                    \
                                             VIRTIO_SCSI_F_CHANGE, true)
 
-void virtio_scsi_common_realize(DeviceState *dev, Error **errp);
-void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp);
-
 #endif /* _QEMU_VIRTIO_SCSI_H */