* [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring.
@ 2013-04-24 8:07 fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 1/8] virtio-rng: don't use pointer for configuration fred.konrad
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: fred.konrad @ 2013-04-24 8:07 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Tested-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Acked-by: Amit Shah <amit.shah@redhat.com>
There are no modifications, just rebased.
This is the last backend of the refactoring (*and must be applied at last,
because it would break virtio-9p*).
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-v4
Note that it is nearly the same series as virtio-blk and virtio-scsi
refactoring, and is rebased on top of virtio-9p-v4 I posted before.
I made basic tests (with linux guests) on:
* qemu-system-i386
Cornelia tested it on s390 and ccw.
Changes v3 -> v4:
* Remove some QOM casts on opaque.
* Fix the commit message of the last patch.
* Rebased.
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 | 39 ++++++-----
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 | 116 +++++++++++++++++++++---------
include/hw/virtio/virtio-rng.h | 20 ++++--
include/hw/virtio/virtio.h | 2 -
9 files changed, 239 insertions(+), 181 deletions(-)
--
1.7.11.7
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH RESEND v4 1/8] virtio-rng: don't use pointer for configuration.
2013-04-24 8:07 [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring fred.konrad
@ 2013-04-24 8:07 ` fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 2/8] virtio-rng: add virtio-rng device fred.konrad
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-04-24 8:07 UTC (permalink / raw)
To: qemu-devel, aliguori
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 fcc223a..05b4d57 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 c9cadc2..c578c00 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] 10+ messages in thread
* [Qemu-devel] [PATCH RESEND v4 2/8] virtio-rng: add virtio-rng device.
2013-04-24 8:07 [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 1/8] virtio-rng: don't use pointer for configuration fred.konrad
@ 2013-04-24 8:07 ` fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 3/8] virtio-rng-pci: switch to the new API fred.konrad
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-04-24 8:07 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: peter.maydell, mark.burton, Alexander Graf, cornelia.huck,
fred.konrad, Richard Henderson
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 56539d3..7fdc8c3 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -958,8 +958,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 a1f15a8..4860db1 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -989,13 +989,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 05b4d57..b70975b 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 c578c00..973d809 100644
--- a/include/hw/virtio/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
@@ -15,6 +15,10 @@
#include "sysemu/rng.h"
#include "sysemu/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] 10+ messages in thread
* [Qemu-devel] [PATCH RESEND v4 3/8] virtio-rng-pci: switch to the new API.
2013-04-24 8:07 [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 1/8] virtio-rng: don't use pointer for configuration fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 2/8] virtio-rng: add virtio-rng device fred.konrad
@ 2013-04-24 8:07 ` fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 4/8] virtio-rng-s390: " fred.konrad
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-04-24 8:07 UTC (permalink / raw)
To: qemu-devel, aliguori
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 4860db1..1269a22 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -257,15 +257,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;
@@ -943,79 +934,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)
{
@@ -1137,11 +1055,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);
@@ -1161,7 +1075,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 = {
@@ -1550,6 +1464,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)
@@ -1588,7 +1560,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 db0185c..ac71824 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -38,6 +38,7 @@ typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
typedef struct VirtIOSerialPCI VirtIOSerialPCI;
typedef struct VirtIONetPCI VirtIONetPCI;
typedef struct VHostSCSIPCI VHostSCSIPCI;
+typedef struct VirtIORngPCI VirtIORngPCI;
/* virtio-pci-bus */
@@ -87,7 +88,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;
@@ -188,6 +188,18 @@ typedef struct V9fsPCIState {
#endif
+/*
+ * 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] 10+ messages in thread
* [Qemu-devel] [PATCH RESEND v4 4/8] virtio-rng-s390: switch to the new API.
2013-04-24 8:07 [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring fred.konrad
` (2 preceding siblings ...)
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 3/8] virtio-rng-pci: switch to the new API fred.konrad
@ 2013-04-24 8:07 ` fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 5/8] virtio-rng-ccw: " fred.konrad
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-04-24 8:07 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: peter.maydell, mark.burton, Alexander Graf, cornelia.huck,
fred.konrad, Richard Henderson
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 | 39 +++++++++++++++++++++++----------------
hw/s390x/s390-virtio-bus.h | 12 +++++++++++-
2 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index dabbc2e..95c9275 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -262,16 +262,31 @@ static void s390_vhost_scsi_instance_init(Object *obj)
}
#endif
-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)
@@ -523,14 +538,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);
@@ -539,10 +546,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 d7c47db..991f9e2 100644
--- a/hw/s390x/s390-virtio-bus.h
+++ b/hw/s390x/s390-virtio-bus.h
@@ -93,7 +93,6 @@ struct VirtIOS390Device {
uint8_t feat_len;
VirtIODevice *vdev;
uint32_t host_features;
- VirtIORNGConf rng;
VirtioBusState bus;
};
@@ -176,4 +175,15 @@ typedef struct VHostSCSIS390 {
} VHostSCSIS390;
#endif
+/* 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] 10+ messages in thread
* [Qemu-devel] [PATCH RESEND v4 5/8] virtio-rng-ccw: switch to the new API.
2013-04-24 8:07 [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring fred.konrad
` (3 preceding siblings ...)
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 4/8] virtio-rng-s390: " fred.konrad
@ 2013-04-24 8:07 ` fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 6/8] virtio-rng: cleanup: init and exit functions fred.konrad
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-04-24 8:07 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: peter.maydell, mark.burton, Alexander Graf, cornelia.huck,
fred.konrad, Richard Henderson
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 7fdc8c3..930531b 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -709,28 +709,21 @@ static void vhost_ccw_scsi_instance_init(Object *obj)
}
#endif
-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,
@@ -947,18 +940,19 @@ static const TypeInfo vhost_ccw_scsi = {
};
#endif
-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(),
};
@@ -968,16 +962,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 84055e7..8599248 100644
--- a/hw/s390x/virtio-ccw.h
+++ b/hw/s390x/virtio-ccw.h
@@ -77,7 +77,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;
@@ -160,6 +159,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] 10+ messages in thread
* [Qemu-devel] [PATCH RESEND v4 6/8] virtio-rng: cleanup: init and exit functions.
2013-04-24 8:07 [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring fred.konrad
` (4 preceding siblings ...)
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 5/8] virtio-rng-ccw: " fred.konrad
@ 2013-04-24 8:07 ` fred.konrad
2013-04-24 8:08 ` [Qemu-devel] [PATCH RESEND v4 7/8] virtio-rng: cleanup: remove qdev field fred.konrad
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-04-24 8:07 UTC (permalink / raw)
To: qemu-devel, aliguori
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 b70975b..805dd18 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 d3f1436..efd29b1 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -261,7 +261,6 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *serial);
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
@@ -270,7 +269,6 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf);
void virtio_net_exit(VirtIODevice *vdev);
void virtio_serial_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] 10+ messages in thread
* [Qemu-devel] [PATCH RESEND v4 7/8] virtio-rng: cleanup: remove qdev field.
2013-04-24 8:07 [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring fred.konrad
` (5 preceding siblings ...)
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 6/8] virtio-rng: cleanup: init and exit functions fred.konrad
@ 2013-04-24 8:08 ` fred.konrad
2013-04-24 8:08 ` [Qemu-devel] [PATCH RESEND v4 8/8] virtio-rng: cleanup: use QOM casts fred.konrad
2013-04-24 18:24 ` [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring Anthony Liguori
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-04-24 8:08 UTC (permalink / raw)
To: qemu-devel, aliguori
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 805dd18..a1dbd1e 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 973d809..4347818 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] 10+ messages in thread
* [Qemu-devel] [PATCH RESEND v4 8/8] virtio-rng: cleanup: use QOM casts.
2013-04-24 8:07 [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring fred.konrad
` (6 preceding siblings ...)
2013-04-24 8:08 ` [Qemu-devel] [PATCH RESEND v4 7/8] virtio-rng: cleanup: remove qdev field fred.konrad
@ 2013-04-24 8:08 ` fred.konrad
2013-04-24 18:24 ` [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring Anthony Liguori
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-04-24 8:08 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
As the virtio-rng-pci, virtio-rng-s390 and virtio-rng-ccw are
switched to the new API, we can use QOM casts.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
Reviewed-by: Andreas Färber <afaerber@suse.de>
---
hw/virtio/virtio-rng.c | 27 +++++++++++++++------------
include/hw/virtio/virtio-rng.h | 2 +-
2 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index a1dbd1e..96e8075 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;
@@ -39,6 +40,7 @@ static void virtio_rng_process(VirtIORNG *vrng);
static void chr_read(void *opaque, const void *buf, size_t size)
{
VirtIORNG *vrng = opaque;
+ VirtIODevice *vdev = VIRTIO_DEVICE(vrng);
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 = 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;
+ 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 = 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 4347818..debaa15 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] 10+ messages in thread
* Re: [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring.
2013-04-24 8:07 [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring fred.konrad
` (7 preceding siblings ...)
2013-04-24 8:08 ` [Qemu-devel] [PATCH RESEND v4 8/8] virtio-rng: cleanup: use QOM casts fred.konrad
@ 2013-04-24 18:24 ` Anthony Liguori
8 siblings, 0 replies; 10+ messages in thread
From: Anthony Liguori @ 2013-04-24 18:24 UTC (permalink / raw)
To: fred.konrad, qemu-devel, aliguori
Cc: cornelia.huck, peter.maydell, mark.burton
Applied. Thanks.
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2013-04-24 18:25 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-24 8:07 [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 1/8] virtio-rng: don't use pointer for configuration fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 2/8] virtio-rng: add virtio-rng device fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 3/8] virtio-rng-pci: switch to the new API fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 4/8] virtio-rng-s390: " fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 5/8] virtio-rng-ccw: " fred.konrad
2013-04-24 8:07 ` [Qemu-devel] [PATCH RESEND v4 6/8] virtio-rng: cleanup: init and exit functions fred.konrad
2013-04-24 8:08 ` [Qemu-devel] [PATCH RESEND v4 7/8] virtio-rng: cleanup: remove qdev field fred.konrad
2013-04-24 8:08 ` [Qemu-devel] [PATCH RESEND v4 8/8] virtio-rng: cleanup: use QOM casts fred.konrad
2013-04-24 18:24 ` [Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring Anthony Liguori
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).