Patchwork [43/61] virtio-rng.c : cleanup : init and exit functions.

login
register
mail settings
Submitter fred.konrad@greensocs.com
Date Jan. 7, 2013, 6:40 p.m.
Message ID <1357584074-10852-44-git-send-email-fred.konrad@greensocs.com>
Download mbox | patch
Permalink /patch/210068/
State New
Headers show

Comments

fred.konrad@greensocs.com - Jan. 7, 2013, 6:40 p.m.
From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove old init and exit function as they are no longer needed.
This shouldn't been applyied before virtio-rng-pci and virtio-rng-s390
refactoring.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-rng.c | 88 ++++++++++++++-------------------------------------------
 1 file changed, 21 insertions(+), 67 deletions(-)

Patch

diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c
index 98adef1..646bcf3 100644
--- a/hw/virtio-rng.c
+++ b/hw/virtio-rng.c
@@ -135,39 +135,38 @@  void virtio_rng_set_conf(DeviceState *dev, VirtIORNGConf *conf)
     memcpy(&(vrng->conf), conf, sizeof(struct VirtIORNGConf));
 }
 
-static VirtIODevice *virtio_rng_common_init(DeviceState *dev,
-                                            VirtIORNGConf *conf,
-                                            VirtIORNG **pvrng)
+static int virtio_rng_device_init(VirtIODevice *vdev)
 {
-    VirtIORNG *vrng = *pvrng;
-    VirtIODevice *vdev;
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIORNG *vrng = VIRTIO_RNG(vdev);
     Error *local_err = NULL;
 
-    /*
-     * We have two cases here : the old virtio-rng-x device, and the
-     * refactored virtio-rng.
-     * This will disappear later in the serie.
-     */
-    if (vrng == NULL) {
-        vdev = virtio_common_init("virtio-rng", VIRTIO_ID_RNG, 0,
-                                  sizeof(VirtIORNG));
-        vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
-    } else {
-        vdev = VIRTIO_DEVICE(vrng);
-        virtio_init(vdev, "virtio-rng", VIRTIO_ID_RNG, 0);
+    if (vrng->conf.rng == NULL) {
+        vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
+
+        object_property_add_child(OBJECT(qdev),
+                                  "default-backend",
+                                  OBJECT(vrng->conf.default_backend),
+                                  NULL);
+
+        object_property_set_link(OBJECT(qdev),
+                                 OBJECT(vrng->conf.default_backend),
+                                 "rng", NULL);
     }
 
-    vrng->rng = conf->rng;
+    virtio_init(vdev, "virtio-rng", VIRTIO_ID_RNG, 0);
+
+    vrng->rng = vrng->conf.rng;
     if (vrng->rng == NULL) {
         qerror_report(QERR_INVALID_PARAMETER_VALUE, "rng", "a valid object");
-        return NULL;
+        return -1;
     }
 
     rng_backend_open(vrng->rng, &local_err);
     if (local_err) {
         qerror_report_err(local_err);
         error_free(local_err);
-        return NULL;
+        return -1;
     }
 
     vrng->vq = virtio_add_queue(vdev, 8, handle_input);
@@ -177,8 +176,7 @@  static VirtIODevice *virtio_rng_common_init(DeviceState *dev,
      */
     vrng->vdev.get_features = get_features;
     /**/
-    vrng->qdev = dev;
-    memcpy(&(vrng->conf), conf, sizeof(struct VirtIORNGConf));
+    vrng->qdev = qdev;
 
     assert(vrng->conf.max_bytes <= INT64_MAX);
     vrng->quota_remaining = vrng->conf.max_bytes;
@@ -189,53 +187,9 @@  static VirtIODevice *virtio_rng_common_init(DeviceState *dev,
     qemu_mod_timer(vrng->rate_limit_timer,
                    qemu_get_clock_ms(vm_clock) + vrng->conf.period_ms);
 
-    register_savevm(dev, "virtio-rng", -1, 1, virtio_rng_save,
+    register_savevm(qdev, "virtio-rng", -1, 1, virtio_rng_save,
                     virtio_rng_load, vrng);
 
-    return vdev;
-}
-
-/*
- * This two functions will be removed later in the serie.
- */
-VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
-{
-    VirtIORNG *vdev = NULL;
-    return virtio_rng_common_init(dev, conf, &vdev);
-}
-
-void virtio_rng_exit(VirtIODevice *vdev)
-{
-    VirtIORNG *vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
-
-    qemu_del_timer(vrng->rate_limit_timer);
-    qemu_free_timer(vrng->rate_limit_timer);
-    unregister_savevm(vrng->qdev, "virtio-rng", vrng);
-    virtio_cleanup(vdev);
-}
-/**/
-
-static int virtio_rng_device_init(VirtIODevice *vdev)
-{
-    DeviceState *qdev = DEVICE(vdev);
-    VirtIORNG *vrng = VIRTIO_RNG(vdev);
-
-    if (vrng->conf.rng == NULL) {
-        vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
-
-        object_property_add_child(OBJECT(qdev),
-                                  "default-backend",
-                                  OBJECT(vrng->conf.default_backend),
-                                  NULL);
-
-        object_property_set_link(OBJECT(qdev),
-                                 OBJECT(vrng->conf.default_backend),
-                                 "rng", NULL);
-    }
-
-    if (virtio_rng_common_init(qdev, &(vrng->conf), &vrng) == NULL) {
-        return -1;
-    }
     return 0;
 }