qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring.
@ 2013-04-14 13:01 fred.konrad
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 1/8] virtio-rng: don't use pointer for configuration fred.konrad
                   ` (9 more replies)
  0 siblings, 10 replies; 14+ messages in thread
From: fred.konrad @ 2013-04-14 13:01 UTC (permalink / raw)
  To: qemu-devel, aliguori, amit.shah
  Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This is the last backend of the refactoring.

Basically it creates virtio-rng-device which extends virtio-device.
Then a virtio-rng-device can be connected on a virtio-bus.
virtio-rng-pci, virtio-rng-s390, virtio-rng-ccw are created too, they extend
respectively virtio-pci, virtio-s390-device, virtio-ccw-device and have a
virtio-rng-device.

When rng option is NULL, a default rng backend is created as before. But after
this refactoring, this default-backend will be the child of virtio-rng-device
instead of virtio-rng-*.

You can checkout my branch here:

git://project.greensocs.com/qemu-virtio.git virtio-rng-v3

Note that it is nearly the same series as virtio-blk and virtio-scsi
refactoring, and is rebased on top of virtio-net-v3 I posted before.

I made basic tests (with linux guests) on:
 * qemu-system-i386

Changes v2 -> v3:
    * Added CCW device.
    * Changes name: "virtio-rng" => "virtio-rng-device".
    * Rebased.

Thanks,

Fred

KONRAD Frederic (8):
  virtio-rng: don't use pointer for configuration.
  virtio-rng: add virtio-rng device.
  virtio-rng-pci: switch to the new API.
  virtio-rng-s390: switch to the new API.
  virtio-rng-ccw: switch to the new API.
  virtio-rng: cleanup: init and exit functions.
  virtio-rng: cleanup: remove qdev field.
  virtio-rng: cleanup: use QOM casts.

 hw/s390x/s390-virtio-bus.c     |  38 +++++-----
 hw/s390x/s390-virtio-bus.h     |  12 +++-
 hw/s390x/virtio-ccw.c          |  49 ++++++-------
 hw/s390x/virtio-ccw.h          |  12 +++-
 hw/virtio/virtio-pci.c         | 156 ++++++++++++++++-------------------------
 hw/virtio/virtio-pci.h         |  14 +++-
 hw/virtio/virtio-rng.c         | 120 ++++++++++++++++++++++---------
 include/hw/virtio/virtio-rng.h |  20 ++++--
 include/hw/virtio/virtio.h     |   2 -
 9 files changed, 240 insertions(+), 183 deletions(-)

-- 
1.7.11.7

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH v3 1/8] virtio-rng: don't use pointer for configuration.
  2013-04-14 13:01 [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring fred.konrad
@ 2013-04-14 13:01 ` fred.konrad
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 2/8] virtio-rng: add virtio-rng device fred.konrad
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: fred.konrad @ 2013-04-14 13:01 UTC (permalink / raw)
  To: qemu-devel, aliguori, amit.shah
  Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

The configuration field must not be a pointer as it will be used for
virtio-rng properties. So *conf is replaced by conf.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio/virtio-rng.c         | 12 ++++++------
 include/hw/virtio/virtio-rng.h |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 6079b2a..5a5e049 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -124,10 +124,10 @@ static void check_rate_limit(void *opaque)
 {
     VirtIORNG *s = opaque;
 
-    s->quota_remaining = s->conf->max_bytes;
+    s->quota_remaining = s->conf.max_bytes;
     virtio_rng_process(s);
     qemu_mod_timer(s->rate_limit_timer,
-                   qemu_get_clock_ms(vm_clock) + s->conf->period_ms);
+                   qemu_get_clock_ms(vm_clock) + s->conf.period_ms);
 }
 
 
@@ -159,16 +159,16 @@ VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
     vrng->vdev.get_features = get_features;
 
     vrng->qdev = dev;
-    vrng->conf = conf;
+    memcpy(&(vrng->conf), conf, sizeof(struct VirtIORNGConf));
 
-    assert(vrng->conf->max_bytes <= INT64_MAX);
-    vrng->quota_remaining = vrng->conf->max_bytes;
+    assert(vrng->conf.max_bytes <= INT64_MAX);
+    vrng->quota_remaining = vrng->conf.max_bytes;
 
     vrng->rate_limit_timer = qemu_new_timer_ms(vm_clock,
                                                check_rate_limit, vrng);
 
     qemu_mod_timer(vrng->rate_limit_timer,
-                   qemu_get_clock_ms(vm_clock) + vrng->conf->period_ms);
+                   qemu_get_clock_ms(vm_clock) + vrng->conf.period_ms);
 
     register_savevm(dev, "virtio-rng", -1, 1, virtio_rng_save,
                     virtio_rng_load, vrng);
diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h
index 3711c97..3deb283 100644
--- a/include/hw/virtio/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
@@ -33,7 +33,7 @@ typedef struct VirtIORNG {
     /* Only one vq - guest puts buffer(s) on it when it needs entropy */
     VirtQueue *vq;
 
-    VirtIORNGConf *conf;
+    VirtIORNGConf conf;
 
     RngBackend *rng;
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH v3 2/8] virtio-rng: add virtio-rng device.
  2013-04-14 13:01 [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring fred.konrad
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 1/8] virtio-rng: don't use pointer for configuration fred.konrad
@ 2013-04-14 13:01 ` fred.konrad
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 3/8] virtio-rng-pci: switch to the new API fred.konrad
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: fred.konrad @ 2013-04-14 13:01 UTC (permalink / raw)
  To: qemu-devel, aliguori, amit.shah
  Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Create virtio-rng-device which extends virtio-device, so it can be connected on
virtio-bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390x/virtio-ccw.c          |   3 +-
 hw/virtio/virtio-pci.c         |   8 +--
 hw/virtio/virtio-rng.c         | 108 ++++++++++++++++++++++++++++++++++++++---
 include/hw/virtio/virtio-rng.h |  14 ++++++
 4 files changed, 117 insertions(+), 16 deletions(-)

diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index d624346..804b8b0 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -874,8 +874,7 @@ static void virtio_ccw_rng_initfn(Object *obj)
 static Property virtio_ccw_rng_properties[] = {
     DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
     DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
-    DEFINE_PROP_UINT64("max-bytes", VirtioCcwDevice, rng.max_bytes, INT64_MAX),
-    DEFINE_PROP_UINT32("period", VirtioCcwDevice, rng.period_ms, 1 << 16),
+    DEFINE_VIRTIO_RNG_PROPERTIES(VirtioCcwDevice, rng),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 6ac90f4..8ea130a 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -988,13 +988,7 @@ static void virtio_rng_initfn(Object *obj)
 
 static Property virtio_rng_properties[] = {
     DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-    /* Set a default rate limit of 2^47 bytes per minute or roughly 2TB/s.  If
-       you have an entropy source capable of generating more entropy than this
-       and you can pass it through via virtio-rng, then hats off to you.  Until
-       then, this is unlimited for all practical purposes.
-    */
-    DEFINE_PROP_UINT64("max-bytes", VirtIOPCIProxy, rng.max_bytes, INT64_MAX),
-    DEFINE_PROP_UINT32("period", VirtIOPCIProxy, rng.period_ms, 1 << 16),
+    DEFINE_VIRTIO_RNG_PROPERTIES(VirtIOPCIProxy, rng),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 5a5e049..cbf9ae6 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -130,17 +130,27 @@ static void check_rate_limit(void *opaque)
                    qemu_get_clock_ms(vm_clock) + s->conf.period_ms);
 }
 
-
-VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
+static VirtIODevice *virtio_rng_common_init(DeviceState *dev,
+                                            VirtIORNGConf *conf,
+                                            VirtIORNG **pvrng)
 {
-    VirtIORNG *vrng;
+    VirtIORNG *vrng = *pvrng;
     VirtIODevice *vdev;
     Error *local_err = NULL;
 
-    vdev = virtio_common_init("virtio-rng", VIRTIO_ID_RNG, 0,
-                              sizeof(VirtIORNG));
-
-    vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
+    /*
+     * 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);
+    }
 
     vrng->rng = conf->rng;
     if (vrng->rng == NULL) {
@@ -156,6 +166,7 @@ VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
     }
 
     vrng->vq = virtio_add_queue(vdev, 8, handle_input);
+
     vrng->vdev.get_features = get_features;
 
     vrng->qdev = dev;
@@ -176,6 +187,15 @@ VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
     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);
@@ -185,3 +205,77 @@ void virtio_rng_exit(VirtIODevice *vdev)
     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;
+}
+
+static int virtio_rng_device_exit(DeviceState *qdev)
+{
+    VirtIORNG *vrng = VIRTIO_RNG(qdev);
+    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+
+    qemu_del_timer(vrng->rate_limit_timer);
+    qemu_free_timer(vrng->rate_limit_timer);
+    unregister_savevm(qdev, "virtio-rng", vrng);
+    virtio_common_cleanup(vdev);
+    return 0;
+}
+
+static Property virtio_rng_properties[] = {
+    DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORNG, conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_rng_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->exit = virtio_rng_device_exit;
+    dc->props = virtio_rng_properties;
+    vdc->init = virtio_rng_device_init;
+    vdc->get_features = get_features;
+}
+
+static void virtio_rng_initfn(Object *obj)
+{
+    VirtIORNG *vrng = VIRTIO_RNG(obj);
+
+    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
+                             (Object **)&vrng->conf.rng, NULL);
+}
+
+static const TypeInfo virtio_rng_info = {
+    .name = TYPE_VIRTIO_RNG,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIORNG),
+    .instance_init = virtio_rng_initfn,
+    .class_init = virtio_rng_class_init,
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_rng_info);
+}
+
+type_init(virtio_register_types)
diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h
index 3deb283..8b94c27 100644
--- a/include/hw/virtio/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
@@ -15,6 +15,10 @@
 #include "qemu/rng.h"
 #include "qemu/rng-random.h"
 
+#define TYPE_VIRTIO_RNG "virtio-rng-device"
+#define VIRTIO_RNG(obj) \
+        OBJECT_CHECK(VirtIORNG, (obj), TYPE_VIRTIO_RNG)
+
 /* The Virtio ID for the virtio rng device */
 #define VIRTIO_ID_RNG    4
 
@@ -44,4 +48,14 @@ typedef struct VirtIORNG {
     int64_t quota_remaining;
 } VirtIORNG;
 
+/* Set a default rate limit of 2^47 bytes per minute or roughly 2TB/s.  If
+   you have an entropy source capable of generating more entropy than this
+   and you can pass it through via virtio-rng, then hats off to you.  Until
+   then, this is unlimited for all practical purposes.
+*/
+#define DEFINE_VIRTIO_RNG_PROPERTIES(_state, _conf_field)                    \
+        DEFINE_PROP_UINT64("max-bytes", _state, _conf_field.max_bytes,       \
+                           INT64_MAX),                                       \
+        DEFINE_PROP_UINT32("period", _state, _conf_field.period_ms, 1 << 16)
+
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH v3 3/8] virtio-rng-pci: switch to the new API.
  2013-04-14 13:01 [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring fred.konrad
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 1/8] virtio-rng: don't use pointer for configuration fred.konrad
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 2/8] virtio-rng: add virtio-rng device fred.konrad
@ 2013-04-14 13:01 ` fred.konrad
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 4/8] virtio-rng-s390: " fred.konrad
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: fred.konrad @ 2013-04-14 13:01 UTC (permalink / raw)
  To: qemu-devel, aliguori, amit.shah
  Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-rng-pci is modified for the new API. The device
virtio-rng-pci extends virtio-pci. It creates and connects a virtio-rng-device
during the init. The properties are not changed.

The virtio_pci_reset function, is removed as no longer used.
The virtio_pci_rst function, is renamed virtio_pci_reset.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio/virtio-pci.c | 150 ++++++++++++++++++++-----------------------------
 hw/virtio/virtio-pci.h |  14 ++++-
 2 files changed, 74 insertions(+), 90 deletions(-)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 8ea130a..2929971 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -256,15 +256,6 @@ static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
     proxy->ioeventfd_started = false;
 }
 
-static void virtio_pci_reset(DeviceState *d)
-{
-    VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
-    virtio_pci_stop_ioeventfd(proxy);
-    virtio_reset(proxy->vdev);
-    msix_unuse_all_vectors(&proxy->pci_dev);
-    proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
-}
-
 static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 {
     VirtIOPCIProxy *proxy = opaque;
@@ -942,79 +933,6 @@ static void virtio_exit_pci(PCIDevice *pci_dev)
     msix_uninit_exclusive_bar(pci_dev);
 }
 
-static int virtio_rng_init_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-    VirtIODevice *vdev;
-
-    if (proxy->rng.rng == NULL) {
-        proxy->rng.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
-
-        object_property_add_child(OBJECT(pci_dev),
-                                  "default-backend",
-                                  OBJECT(proxy->rng.default_backend),
-                                  NULL);
-
-        object_property_set_link(OBJECT(pci_dev),
-                                 OBJECT(proxy->rng.default_backend),
-                                 "rng", NULL);
-    }
-
-    vdev = virtio_rng_init(&pci_dev->qdev, &proxy->rng);
-    if (!vdev) {
-        return -1;
-    }
-    virtio_init_pci(proxy, vdev);
-    return 0;
-}
-
-static void virtio_rng_exit_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-    virtio_pci_stop_ioeventfd(proxy);
-    virtio_rng_exit(proxy->vdev);
-    virtio_exit_pci(pci_dev);
-}
-
-static void virtio_rng_initfn(Object *obj)
-{
-    PCIDevice *pci_dev = PCI_DEVICE(obj);
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&proxy->rng.rng, NULL);
-}
-
-static Property virtio_rng_properties[] = {
-    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_VIRTIO_RNG_PROPERTIES(VirtIOPCIProxy, rng),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_rng_class_init(ObjectClass *klass, void *data)
-{
-    DeviceClass *dc = DEVICE_CLASS(klass);
-    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
-    k->init = virtio_rng_init_pci;
-    k->exit = virtio_rng_exit_pci;
-    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    k->device_id = PCI_DEVICE_ID_VIRTIO_RNG;
-    k->revision = VIRTIO_PCI_ABI_VERSION;
-    k->class_id = PCI_CLASS_OTHERS;
-    dc->reset = virtio_pci_reset;
-    dc->props = virtio_rng_properties;
-}
-
-static const TypeInfo virtio_rng_info = {
-    .name          = "virtio-rng-pci",
-    .parent        = TYPE_PCI_DEVICE,
-    .instance_size = sizeof(VirtIOPCIProxy),
-    .instance_init = virtio_rng_initfn,
-    .class_init    = virtio_rng_class_init,
-};
-
 #ifdef CONFIG_VIRTFS
 static int virtio_9p_init_pci(VirtIOPCIProxy *vpci_dev)
 {
@@ -1136,11 +1054,7 @@ static void virtio_pci_exit(PCIDevice *pci_dev)
     virtio_exit_pci(pci_dev);
 }
 
-/*
- * This will be renamed virtio_pci_reset at the end of the series.
- * virtio_pci_reset is still in use at this moment.
- */
-static void virtio_pci_rst(DeviceState *qdev)
+static void virtio_pci_reset(DeviceState *qdev)
 {
     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
     VirtioBusState *bus = VIRTIO_BUS(&proxy->bus);
@@ -1160,7 +1074,7 @@ static void virtio_pci_class_init(ObjectClass *klass, void *data)
     k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = PCI_CLASS_OTHERS;
-    dc->reset = virtio_pci_rst;
+    dc->reset = virtio_pci_reset;
 }
 
 static const TypeInfo virtio_pci_info = {
@@ -1456,6 +1370,64 @@ static const TypeInfo virtio_net_pci_info = {
     .class_init    = virtio_net_pci_class_init,
 };
 
+/* virtio-rng-pci */
+
+static Property virtio_rng_pci_properties[] = {
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+    DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORngPCI, vdev.conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static int virtio_rng_pci_init(VirtIOPCIProxy *vpci_dev)
+{
+    VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev);
+    DeviceState *vdev = DEVICE(&vrng->vdev);
+
+    qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
+    if (qdev_init(vdev) < 0) {
+        return -1;
+    }
+
+    object_property_set_link(OBJECT(vrng),
+                             OBJECT(vrng->vdev.conf.default_backend), "rng",
+                             NULL);
+
+    return 0;
+}
+
+static void virtio_rng_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+    PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+
+    k->init = virtio_rng_pci_init;
+    dc->props = virtio_rng_pci_properties;
+
+    pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+    pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_RNG;
+    pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
+    pcidev_k->class_id = PCI_CLASS_OTHERS;
+}
+
+static void virtio_rng_initfn(Object *obj)
+{
+    VirtIORngPCI *dev = VIRTIO_RNG_PCI(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_RNG);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
+                             (Object **)&dev->vdev.conf.rng, NULL);
+
+}
+
+static const TypeInfo virtio_rng_pci_info = {
+    .name          = TYPE_VIRTIO_RNG_PCI,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(VirtIORngPCI),
+    .instance_init = virtio_rng_initfn,
+    .class_init    = virtio_rng_pci_class_init,
+};
+
 /* virtio-pci-bus */
 
 void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev)
@@ -1494,7 +1466,7 @@ static const TypeInfo virtio_pci_bus_info = {
 
 static void virtio_pci_register_types(void)
 {
-    type_register_static(&virtio_rng_info);
+    type_register_static(&virtio_rng_pci_info);
     type_register_static(&virtio_pci_bus_info);
     type_register_static(&virtio_pci_info);
 #ifdef CONFIG_VIRTFS
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 6f7116e..44f2fb3 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -34,6 +34,7 @@ typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
 typedef struct VirtIOSerialPCI VirtIOSerialPCI;
 typedef struct VirtIONetPCI VirtIONetPCI;
+typedef struct VirtIORngPCI VirtIORngPCI;
 
 /* virtio-pci-bus */
 
@@ -83,7 +84,6 @@ struct VirtIOPCIProxy {
     uint32_t class_code;
     uint32_t nvectors;
     uint32_t host_features;
-    VirtIORNGConf rng;
     bool ioeventfd_disabled;
     bool ioeventfd_started;
     VirtIOIRQFD *vector_irqfd;
@@ -170,6 +170,18 @@ struct VirtIONetPCI {
     VirtIONet vdev;
 };
 
+/*
+ * virtio-rng-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
+#define VIRTIO_RNG_PCI(obj) \
+        OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
+
+struct VirtIORngPCI {
+    VirtIOPCIProxy parent_obj;
+    VirtIORNG vdev;
+};
+
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev);
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH v3 4/8] virtio-rng-s390: switch to the new API.
  2013-04-14 13:01 [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring fred.konrad
                   ` (2 preceding siblings ...)
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 3/8] virtio-rng-pci: switch to the new API fred.konrad
@ 2013-04-14 13:01 ` fred.konrad
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 5/8] virtio-rng-ccw: " fred.konrad
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: fred.konrad @ 2013-04-14 13:01 UTC (permalink / raw)
  To: qemu-devel, aliguori, amit.shah
  Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-rng-s390 is modified for the new API. The device
virtio-rng-s390 extends virtio-s390-device as before. It creates and
connects a virtio-rng during the init. The properties are not modified.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390x/s390-virtio-bus.c | 38 ++++++++++++++++++++++----------------
 hw/s390x/s390-virtio-bus.h | 12 +++++++++++-
 2 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index ca0e301..4d9f2ec 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -239,16 +239,30 @@ static void s390_virtio_scsi_instance_init(Object *obj)
     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
 }
 
-static int s390_virtio_rng_init(VirtIOS390Device *dev)
+static int s390_virtio_rng_init(VirtIOS390Device *s390_dev)
 {
-    VirtIODevice *vdev;
+    VirtIORNGS390 *dev = VIRTIO_RNG_S390(s390_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
 
-    vdev = virtio_rng_init((DeviceState *)dev, &dev->rng);
-    if (!vdev) {
+    qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
+    if (qdev_init(vdev) < 0) {
         return -1;
     }
 
-    return s390_virtio_device_init(dev, vdev);
+    object_property_set_link(OBJECT(dev),
+                             OBJECT(dev->vdev.conf.default_backend), "rng",
+                             NULL);
+
+    return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
+}
+
+static void s390_virtio_rng_instance_init(Object *obj)
+{
+    VirtIORNGS390 *dev = VIRTIO_RNG_S390(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_RNG);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
+                             (Object **)&dev->vdev.conf.rng, NULL);
 }
 
 static uint64_t s390_virtio_device_vq_token(VirtIOS390Device *dev, int vq)
@@ -500,14 +514,6 @@ static const TypeInfo s390_virtio_serial = {
     .class_init    = s390_virtio_serial_class_init,
 };
 
-static void s390_virtio_rng_initfn(Object *obj)
-{
-    VirtIOS390Device *dev = VIRTIO_S390_DEVICE(obj);
-
-    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&dev->rng.rng, NULL);
-}
-
 static void s390_virtio_rng_class_init(ObjectClass *klass, void *data)
 {
     VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
@@ -516,10 +522,10 @@ static void s390_virtio_rng_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo s390_virtio_rng = {
-    .name          = "virtio-rng-s390",
+    .name          = TYPE_VIRTIO_RNG_S390,
     .parent        = TYPE_VIRTIO_S390_DEVICE,
-    .instance_size = sizeof(VirtIOS390Device),
-    .instance_init = s390_virtio_rng_initfn,
+    .instance_size = sizeof(VirtIORNGS390),
+    .instance_init = s390_virtio_rng_instance_init,
     .class_init    = s390_virtio_rng_class_init,
 };
 
diff --git a/hw/s390x/s390-virtio-bus.h b/hw/s390x/s390-virtio-bus.h
index 925ed2b..ba1fb85 100644
--- a/hw/s390x/s390-virtio-bus.h
+++ b/hw/s390x/s390-virtio-bus.h
@@ -90,7 +90,6 @@ struct VirtIOS390Device {
     uint8_t feat_len;
     VirtIODevice *vdev;
     uint32_t host_features;
-    VirtIORNGConf rng;
     VirtioBusState bus;
 };
 
@@ -160,4 +159,15 @@ typedef struct VirtIONetS390 {
     VirtIONet vdev;
 } VirtIONetS390;
 
+/* virtio-rng-s390 */
+
+#define TYPE_VIRTIO_RNG_S390 "virtio-rng-s390"
+#define VIRTIO_RNG_S390(obj) \
+        OBJECT_CHECK(VirtIORNGS390, (obj), TYPE_VIRTIO_RNG_S390)
+
+typedef struct VirtIORNGS390 {
+    VirtIOS390Device parent_obj;
+    VirtIORNG vdev;
+} VirtIORNGS390;
+
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH v3 5/8] virtio-rng-ccw: switch to the new API.
  2013-04-14 13:01 [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring fred.konrad
                   ` (3 preceding siblings ...)
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 4/8] virtio-rng-s390: " fred.konrad
@ 2013-04-14 13:01 ` fred.konrad
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 6/8] virtio-rng: cleanup: init and exit functions fred.konrad
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: fred.konrad @ 2013-04-14 13:01 UTC (permalink / raw)
  To: qemu-devel, aliguori, amit.shah
  Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-rng-ccw is modified for the new API. The device
virtio-rng-pci extends virtio-pci. It creates and connects a virtio-rng-device
during the init. The properties are not changed.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390x/virtio-ccw.c | 48 +++++++++++++++++++++---------------------------
 hw/s390x/virtio-ccw.h | 12 +++++++++++-
 2 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 804b8b0..93a0c9c 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -653,28 +653,21 @@ static void virtio_ccw_scsi_instance_init(Object *obj)
     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
 }
 
-static int virtio_ccw_rng_init(VirtioCcwDevice *dev)
+static int virtio_ccw_rng_init(VirtioCcwDevice *ccw_dev)
 {
-    VirtIODevice *vdev;
-
-    if (dev->rng.rng == NULL) {
-        dev->rng.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
-        object_property_add_child(OBJECT(dev), "default-backend",
-                                  OBJECT(dev->rng.default_backend), NULL);
-        object_property_set_link(OBJECT(dev), OBJECT(dev->rng.default_backend),
-                                 "rng", NULL);
-    }
-    vdev = virtio_rng_init((DeviceState *)dev, &dev->rng);
-    if (!vdev) {
+    VirtIORNGCcw *dev = VIRTIO_RNG_CCW(ccw_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+
+    qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
+    if (qdev_init(vdev) < 0) {
         return -1;
     }
-    return virtio_ccw_device_init(dev, vdev);
-}
 
-static int virtio_ccw_rng_exit(VirtioCcwDevice *dev)
-{
-    virtio_rng_exit(dev->vdev);
-    return virtio_ccw_exit(dev);
+    object_property_set_link(OBJECT(dev),
+                             OBJECT(dev->vdev.conf.default_backend), "rng",
+                             NULL);
+
+    return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
 }
 
 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
@@ -863,18 +856,19 @@ static const TypeInfo virtio_ccw_scsi = {
     .class_init    = virtio_ccw_scsi_class_init,
 };
 
-static void virtio_ccw_rng_initfn(Object *obj)
+static void virtio_ccw_rng_instance_init(Object *obj)
 {
-    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(obj);
-
+    VirtIORNGCcw *dev = VIRTIO_RNG_CCW(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_RNG);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
     object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&dev->rng.rng, NULL);
+                             (Object **)&dev->vdev.conf.rng, NULL);
 }
 
 static Property virtio_ccw_rng_properties[] = {
     DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
     DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
-    DEFINE_VIRTIO_RNG_PROPERTIES(VirtioCcwDevice, rng),
+    DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORNGCcw, vdev.conf),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -884,16 +878,16 @@ static void virtio_ccw_rng_class_init(ObjectClass *klass, void *data)
     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
 
     k->init = virtio_ccw_rng_init;
-    k->exit = virtio_ccw_rng_exit;
+    k->exit = virtio_ccw_exit;
     dc->reset = virtio_ccw_reset;
     dc->props = virtio_ccw_rng_properties;
 }
 
 static const TypeInfo virtio_ccw_rng = {
-    .name          = "virtio-rng-ccw",
+    .name          = TYPE_VIRTIO_RNG_CCW,
     .parent        = TYPE_VIRTIO_CCW_DEVICE,
-    .instance_size = sizeof(VirtioCcwDevice),
-    .instance_init = virtio_ccw_rng_initfn,
+    .instance_size = sizeof(VirtIORNGCcw),
+    .instance_init = virtio_ccw_rng_instance_init,
     .class_init    = virtio_ccw_rng_class_init,
 };
 
diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h
index 35ab1a5..fea9208 100644
--- a/hw/s390x/virtio-ccw.h
+++ b/hw/s390x/virtio-ccw.h
@@ -74,7 +74,6 @@ struct VirtioCcwDevice {
     VirtIODevice *vdev;
     char *bus_id;
     uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE];
-    VirtIORNGConf rng;
     VirtioBusState bus;
     /* Guest provided values: */
     hwaddr indicators;
@@ -146,6 +145,17 @@ typedef struct VirtIONetCcw {
     VirtIONet vdev;
 } VirtIONetCcw;
 
+/* virtio-rng-ccw */
+
+#define TYPE_VIRTIO_RNG_CCW "virtio-rng-ccw"
+#define VIRTIO_RNG_CCW(obj) \
+        OBJECT_CHECK(VirtIORNGCcw, (obj), TYPE_VIRTIO_RNG_CCW)
+
+typedef struct VirtIORNGCcw {
+    VirtioCcwDevice parent_obj;
+    VirtIORNG vdev;
+} VirtIORNGCcw;
+
 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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH v3 6/8] virtio-rng: cleanup: init and exit functions.
  2013-04-14 13:01 [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring fred.konrad
                   ` (4 preceding siblings ...)
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 5/8] virtio-rng-ccw: " fred.konrad
@ 2013-04-14 13:01 ` fred.konrad
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 7/8] virtio-rng: cleanup: remove qdev field fred.konrad
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: fred.konrad @ 2013-04-14 13:01 UTC (permalink / raw)
  To: qemu-devel, aliguori, amit.shah
  Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove old init and exit function as they are no longer needed.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio/virtio-rng.c     | 87 +++++++++++-----------------------------------
 include/hw/virtio/virtio.h |  2 --
 2 files changed, 21 insertions(+), 68 deletions(-)

diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index cbf9ae6..1832996 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -130,47 +130,45 @@ static void check_rate_limit(void *opaque)
                    qemu_get_clock_ms(vm_clock) + s->conf.period_ms);
 }
 
-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);
 
     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;
@@ -181,52 +179,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;
 }
 
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index b21e5c2..c94ee34 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -262,7 +262,6 @@ VirtIODevice *virtio_balloon_init(DeviceState *dev);
 typedef struct VirtIOSCSIConf VirtIOSCSIConf;
 VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *conf);
 typedef struct VirtIORNGConf VirtIORNGConf;
-VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf);
 #ifdef CONFIG_VIRTFS
 VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf);
 #endif
@@ -272,7 +271,6 @@ void virtio_net_exit(VirtIODevice *vdev);
 void virtio_serial_exit(VirtIODevice *vdev);
 void virtio_balloon_exit(VirtIODevice *vdev);
 void virtio_scsi_exit(VirtIODevice *vdev);
-void virtio_rng_exit(VirtIODevice *vdev);
 
 #define DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) \
 	DEFINE_PROP_BIT("indirect_desc", _state, _field, \
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH v3 7/8] virtio-rng: cleanup: remove qdev field.
  2013-04-14 13:01 [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring fred.konrad
                   ` (5 preceding siblings ...)
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 6/8] virtio-rng: cleanup: init and exit functions fred.konrad
@ 2013-04-14 13:01 ` fred.konrad
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 8/8] virtio-rng: cleanup: use QOM casts fred.konrad
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: fred.konrad @ 2013-04-14 13:01 UTC (permalink / raw)
  To: qemu-devel, aliguori, amit.shah
  Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

The qdev field is no longer needed, just drop it.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio/virtio-rng.c         | 2 --
 include/hw/virtio/virtio-rng.h | 2 --
 2 files changed, 4 deletions(-)

diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 1832996..088f8fe 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -168,8 +168,6 @@ static int virtio_rng_device_init(VirtIODevice *vdev)
 
     vrng->vdev.get_features = get_features;
 
-    vrng->qdev = qdev;
-
     assert(vrng->conf.max_bytes <= INT64_MAX);
     vrng->quota_remaining = vrng->conf.max_bytes;
 
diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h
index 8b94c27..ac04ad5 100644
--- a/include/hw/virtio/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
@@ -32,8 +32,6 @@ struct VirtIORNGConf {
 typedef struct VirtIORNG {
     VirtIODevice vdev;
 
-    DeviceState *qdev;
-
     /* Only one vq - guest puts buffer(s) on it when it needs entropy */
     VirtQueue *vq;
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH v3 8/8] virtio-rng: cleanup: use QOM casts.
  2013-04-14 13:01 [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring fred.konrad
                   ` (6 preceding siblings ...)
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 7/8] virtio-rng: cleanup: remove qdev field fred.konrad
@ 2013-04-14 13:01 ` fred.konrad
  2013-04-15 13:34   ` Andreas Färber
  2013-04-15 13:12 ` [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring Cornelia Huck
  2013-04-16  9:51 ` Amit Shah
  9 siblings, 1 reply; 14+ messages in thread
From: fred.konrad @ 2013-04-14 13:01 UTC (permalink / raw)
  To: qemu-devel, aliguori, amit.shah
  Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As the virtio-rng-pci and virtio-rng-s390 are switched to the new API,
we can use QOM casts.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio/virtio-rng.c         | 31 +++++++++++++++++--------------
 include/hw/virtio/virtio-rng.h |  2 +-
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 088f8fe..1acbe18 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -18,8 +18,9 @@
 
 static bool is_guest_ready(VirtIORNG *vrng)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(vrng);
     if (virtio_queue_ready(vrng->vq)
-        && (vrng->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+        && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
         return true;
     }
     return false;
@@ -38,7 +39,8 @@ static void virtio_rng_process(VirtIORNG *vrng);
 /* Send data from a char device over to the guest */
 static void chr_read(void *opaque, const void *buf, size_t size)
 {
-    VirtIORNG *vrng = opaque;
+    VirtIORNG *vrng = VIRTIO_RNG(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
     VirtQueueElement elem;
     size_t len;
     int offset;
@@ -60,7 +62,7 @@ static void chr_read(void *opaque, const void *buf, size_t size)
 
         virtqueue_push(vrng->vq, &elem, len);
     }
-    virtio_notify(&vrng->vdev, vrng->vq);
+    virtio_notify(vdev, vrng->vq);
 }
 
 static void virtio_rng_process(VirtIORNG *vrng)
@@ -86,7 +88,7 @@ static void virtio_rng_process(VirtIORNG *vrng)
 
 static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIORNG *vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
+    VirtIORNG *vrng = VIRTIO_RNG(vdev);
     virtio_rng_process(vrng);
 }
 
@@ -97,19 +99,20 @@ static uint32_t get_features(VirtIODevice *vdev, uint32_t f)
 
 static void virtio_rng_save(QEMUFile *f, void *opaque)
 {
-    VirtIORNG *vrng = opaque;
+    VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
 
-    virtio_save(&vrng->vdev, f);
+    virtio_save(vdev, f);
 }
 
 static int virtio_rng_load(QEMUFile *f, void *opaque, int version_id)
 {
-    VirtIORNG *vrng = opaque;
+    VirtIORNG *vrng = VIRTIO_RNG(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(vrng);
 
     if (version_id != 1) {
         return -EINVAL;
     }
-    virtio_load(&vrng->vdev, f);
+    virtio_load(vdev, f);
 
     /* We may have an element ready but couldn't process it due to a quota
      * limit.  Make sure to try again after live migration when the quota may
@@ -122,12 +125,12 @@ static int virtio_rng_load(QEMUFile *f, void *opaque, int version_id)
 
 static void check_rate_limit(void *opaque)
 {
-    VirtIORNG *s = opaque;
+    VirtIORNG *vrng = VIRTIO_RNG(opaque);
 
-    s->quota_remaining = s->conf.max_bytes;
-    virtio_rng_process(s);
-    qemu_mod_timer(s->rate_limit_timer,
-                   qemu_get_clock_ms(vm_clock) + s->conf.period_ms);
+    vrng->quota_remaining = vrng->conf.max_bytes;
+    virtio_rng_process(vrng);
+    qemu_mod_timer(vrng->rate_limit_timer,
+                   qemu_get_clock_ms(vm_clock) + vrng->conf.period_ms);
 }
 
 static int virtio_rng_device_init(VirtIODevice *vdev)
@@ -166,7 +169,7 @@ static int virtio_rng_device_init(VirtIODevice *vdev)
 
     vrng->vq = virtio_add_queue(vdev, 8, handle_input);
 
-    vrng->vdev.get_features = get_features;
+    vdev->get_features = get_features;
 
     assert(vrng->conf.max_bytes <= INT64_MAX);
     vrng->quota_remaining = vrng->conf.max_bytes;
diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h
index ac04ad5..5e007c6 100644
--- a/include/hw/virtio/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
@@ -30,7 +30,7 @@ struct VirtIORNGConf {
 };
 
 typedef struct VirtIORNG {
-    VirtIODevice vdev;
+    VirtIODevice parent_obj;
 
     /* Only one vq - guest puts buffer(s) on it when it needs entropy */
     VirtQueue *vq;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring.
  2013-04-14 13:01 [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring fred.konrad
                   ` (7 preceding siblings ...)
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 8/8] virtio-rng: cleanup: use QOM casts fred.konrad
@ 2013-04-15 13:12 ` Cornelia Huck
  2013-04-16  9:51 ` Amit Shah
  9 siblings, 0 replies; 14+ messages in thread
From: Cornelia Huck @ 2013-04-15 13:12 UTC (permalink / raw)
  To: fred.konrad; +Cc: amit.shah, peter.maydell, aliguori, mark.burton, qemu-devel

On Sun, 14 Apr 2013 15:01:02 +0200
fred.konrad@greensocs.com wrote:

> From: KONRAD Frederic <fred.konrad@greensocs.com>
> 
> This is the last backend of the refactoring.
> 
> Basically it creates virtio-rng-device which extends virtio-device.
> Then a virtio-rng-device can be connected on a virtio-bus.
> virtio-rng-pci, virtio-rng-s390, virtio-rng-ccw are created too, they extend
> respectively virtio-pci, virtio-s390-device, virtio-ccw-device and have a
> virtio-rng-device.
> 
> When rng option is NULL, a default rng backend is created as before. But after
> this refactoring, this default-backend will be the child of virtio-rng-device
> instead of virtio-rng-*.
> 
> You can checkout my branch here:
> 
> git://project.greensocs.com/qemu-virtio.git virtio-rng-v3
> 
> Note that it is nearly the same series as virtio-blk and virtio-scsi
> refactoring, and is rebased on top of virtio-net-v3 I posted before.
> 
> I made basic tests (with linux guests) on:
>  * qemu-system-i386

On s390, with virtio-ccw and s390-virtio:

Tested-by: Cornelia Huck <cornelia.huck@de.ibm.com>

> 
> Changes v2 -> v3:
>     * Added CCW device.
>     * Changes name: "virtio-rng" => "virtio-rng-device".
>     * Rebased.
> 
> Thanks,
> 
> Fred
> 
> KONRAD Frederic (8):
>   virtio-rng: don't use pointer for configuration.
>   virtio-rng: add virtio-rng device.
>   virtio-rng-pci: switch to the new API.
>   virtio-rng-s390: switch to the new API.
>   virtio-rng-ccw: switch to the new API.
>   virtio-rng: cleanup: init and exit functions.
>   virtio-rng: cleanup: remove qdev field.
>   virtio-rng: cleanup: use QOM casts.
> 
>  hw/s390x/s390-virtio-bus.c     |  38 +++++-----
>  hw/s390x/s390-virtio-bus.h     |  12 +++-
>  hw/s390x/virtio-ccw.c          |  49 ++++++-------
>  hw/s390x/virtio-ccw.h          |  12 +++-
>  hw/virtio/virtio-pci.c         | 156 ++++++++++++++++-------------------------
>  hw/virtio/virtio-pci.h         |  14 +++-
>  hw/virtio/virtio-rng.c         | 120 ++++++++++++++++++++++---------
>  include/hw/virtio/virtio-rng.h |  20 ++++--
>  include/hw/virtio/virtio.h     |   2 -
>  9 files changed, 240 insertions(+), 183 deletions(-)
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH v3 8/8] virtio-rng: cleanup: use QOM casts.
  2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 8/8] virtio-rng: cleanup: use QOM casts fred.konrad
@ 2013-04-15 13:34   ` Andreas Färber
  2013-04-15 14:33     ` KONRAD Frédéric
  0 siblings, 1 reply; 14+ messages in thread
From: Andreas Färber @ 2013-04-15 13:34 UTC (permalink / raw)
  To: fred.konrad
  Cc: peter.maydell, aliguori, mark.burton, qemu-devel, cornelia.huck,
	amit.shah

Am 14.04.2013 15:01, schrieb fred.konrad@greensocs.com:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
> 
> As the virtio-rng-pci and virtio-rng-s390 are switched to the new API,

and virtio-rng-ccw ;)

> we can use QOM casts.
> 
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
>  hw/virtio/virtio-rng.c         | 31 +++++++++++++++++--------------
>  include/hw/virtio/virtio-rng.h |  2 +-
>  2 files changed, 18 insertions(+), 15 deletions(-)

Thanks,

Reviewed-by: Andreas Färber <afaerber@suse.de>

I was surprised to see FOO(opaque) since we usually try to avoid it for
performance reasons, but it's not forbidden either.
Also, leaving the variable name as "s" would've spared a few lines but
so what. :)

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH v3 8/8] virtio-rng: cleanup: use QOM casts.
  2013-04-15 13:34   ` Andreas Färber
@ 2013-04-15 14:33     ` KONRAD Frédéric
  2013-04-15 17:06       ` Andreas Färber
  0 siblings, 1 reply; 14+ messages in thread
From: KONRAD Frédéric @ 2013-04-15 14:33 UTC (permalink / raw)
  To: Andreas Färber
  Cc: peter.maydell, aliguori, mark.burton, qemu-devel, cornelia.huck,
	amit.shah

On 15/04/2013 15:34, Andreas Färber wrote:
> Am 14.04.2013 15:01, schrieb fred.konrad@greensocs.com:
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> As the virtio-rng-pci and virtio-rng-s390 are switched to the new API,
> and virtio-rng-ccw ;)
>
>> we can use QOM casts.
>>
>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>> ---
>>   hw/virtio/virtio-rng.c         | 31 +++++++++++++++++--------------
>>   include/hw/virtio/virtio-rng.h |  2 +-
>>   2 files changed, 18 insertions(+), 15 deletions(-)
> Thanks,
>
> Reviewed-by: Andreas Färber <afaerber@suse.de>
>
> I was surprised to see FOO(opaque) since we usually try to avoid it for
> performance reasons, but it's not forbidden either.
True, I had taken that in account but forget this series :/.

Is it better to change that?

Thanks,
Fred
> Also, leaving the variable name as "s" would've spared a few lines but
> so what. :)
>
> Regards,
> Andreas
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH v3 8/8] virtio-rng: cleanup: use QOM casts.
  2013-04-15 14:33     ` KONRAD Frédéric
@ 2013-04-15 17:06       ` Andreas Färber
  0 siblings, 0 replies; 14+ messages in thread
From: Andreas Färber @ 2013-04-15 17:06 UTC (permalink / raw)
  To: KONRAD Frédéric
  Cc: peter.maydell, aliguori, mark.burton, qemu-devel, cornelia.huck,
	amit.shah

Am 15.04.2013 16:33, schrieb KONRAD Frédéric:
> On 15/04/2013 15:34, Andreas Färber wrote:
>> Am 14.04.2013 15:01, schrieb fred.konrad@greensocs.com:
>>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>>
>>> As the virtio-rng-pci and virtio-rng-s390 are switched to the new API,
>> and virtio-rng-ccw ;)
>>
>>> we can use QOM casts.
>>>
>>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>>> ---
>>>   hw/virtio/virtio-rng.c         | 31 +++++++++++++++++--------------
>>>   include/hw/virtio/virtio-rng.h |  2 +-
>>>   2 files changed, 18 insertions(+), 15 deletions(-)
>> Thanks,
>>
>> Reviewed-by: Andreas Färber <afaerber@suse.de>
>>
>> I was surprised to see FOO(opaque) since we usually try to avoid it for
>> performance reasons, but it's not forbidden either.
> True, I had taken that in account but forget this series :/.
> 
> Is it better to change that?

I didn't spot an obvious issue, but you know the code better than me and
should take a second look: load/save hooks should be no problem, but
there were some opaques I didn't know where they are coming from.

Andreas

> 
> Thanks,
> Fred
>> Also, leaving the variable name as "s" would've spared a few lines but
>> so what. :)
>>
>> Regards,
>> Andreas
>>
> 


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring.
  2013-04-14 13:01 [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring fred.konrad
                   ` (8 preceding siblings ...)
  2013-04-15 13:12 ` [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring Cornelia Huck
@ 2013-04-16  9:51 ` Amit Shah
  9 siblings, 0 replies; 14+ messages in thread
From: Amit Shah @ 2013-04-16  9:51 UTC (permalink / raw)
  To: fred.konrad
  Cc: cornelia.huck, peter.maydell, aliguori, mark.burton, qemu-devel

On (Sun) 14 Apr 2013 [15:01:02], fred.konrad@greensocs.com wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
> 
> This is the last backend of the refactoring.
> 
> Basically it creates virtio-rng-device which extends virtio-device.
> Then a virtio-rng-device can be connected on a virtio-bus.
> virtio-rng-pci, virtio-rng-s390, virtio-rng-ccw are created too, they extend
> respectively virtio-pci, virtio-s390-device, virtio-ccw-device and have a
> virtio-rng-device.
> 
> When rng option is NULL, a default rng backend is created as before. But after
> this refactoring, this default-backend will be the child of virtio-rng-device
> instead of virtio-rng-*.
> 
> You can checkout my branch here:
> 
> git://project.greensocs.com/qemu-virtio.git virtio-rng-v3
> 
> Note that it is nearly the same series as virtio-blk and virtio-scsi
> refactoring, and is rebased on top of virtio-net-v3 I posted before.
> 
> I made basic tests (with linux guests) on:
>  * qemu-system-i386

Looks OK.

Acked-by: Amit Shah <amit.shah@redhat.com>

Thanks,

		Amit

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-04-16  9:51 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-14 13:01 [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring fred.konrad
2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 1/8] virtio-rng: don't use pointer for configuration fred.konrad
2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 2/8] virtio-rng: add virtio-rng device fred.konrad
2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 3/8] virtio-rng-pci: switch to the new API fred.konrad
2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 4/8] virtio-rng-s390: " fred.konrad
2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 5/8] virtio-rng-ccw: " fred.konrad
2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 6/8] virtio-rng: cleanup: init and exit functions fred.konrad
2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 7/8] virtio-rng: cleanup: remove qdev field fred.konrad
2013-04-14 13:01 ` [Qemu-devel] [PATCH v3 8/8] virtio-rng: cleanup: use QOM casts fred.konrad
2013-04-15 13:34   ` Andreas Färber
2013-04-15 14:33     ` KONRAD Frédéric
2013-04-15 17:06       ` Andreas Färber
2013-04-15 13:12 ` [Qemu-devel] [PATCH v3 0/8] virtio-rng refactoring Cornelia Huck
2013-04-16  9:51 ` Amit Shah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).