[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V3 34/44] virtio-rng.c: cleanup: use QOM casts.
From: |
fred . konrad |
Subject: |
[Qemu-devel] [PATCH V3 34/44] virtio-rng.c: cleanup: use QOM casts. |
Date: |
Tue, 15 Jan 2013 15:09:48 +0100 |
From: KONRAD Frederic <address@hidden>
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 <address@hidden>
---
hw/virtio-rng.c | 31 +++++++++++++++++--------------
hw/virtio-rng.h | 2 +-
2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c
index daeb734..40d4d7e 100644
--- a/hw/virtio-rng.c
+++ b/hw/virtio-rng.c
@@ -17,8 +17,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;
@@ -37,7 +38,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;
@@ -59,7 +61,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)
@@ -85,7 +87,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);
}
@@ -96,19 +98,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
@@ -121,12 +124,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);
}
void virtio_rng_set_conf(DeviceState *dev, VirtIORNGConf *conf)
@@ -171,7 +174,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/hw/virtio-rng.h b/hw/virtio-rng.h
index ae0c56da..ee0847a 100644
--- a/hw/virtio-rng.h
+++ b/hw/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
- [Qemu-devel] [PATCH V3 33/44] virtio-rng.c: cleanup: remove qdev field., (continued)
- [Qemu-devel] [PATCH V3 33/44] virtio-rng.c: cleanup: remove qdev field., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 32/44] virtio-rng.c: cleanup: init and exit functions., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 41/44] virtio-9p: add the virtio-9p device., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 18/44] virtio-scsi-pci: switch to new API., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 13/44] virtio-net: cleanup: remove qdev field., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 06/44] virtio-blk: cleanup: use QOM cast., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 36/44] virtio-serial-pci: switch to the new API., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 19/44] virtio-scsi-s390: switch to the new API., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 26/44] virtio-balloon: cleanup: QOM casts., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 34/44] virtio-rng.c: cleanup: use QOM casts.,
fred . konrad <=
- [Qemu-devel] [PATCH V3 27/44] virtio-balloon: cleanup: remove qdev field., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 29/44] virtio-rng: add virtio-rng device., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 42/44] virtio-9p-pci: switch to the new API., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 21/44] virtio-scsi: cleanup: init and exit functions., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 30/44] virtio-rng-s390: switch to the new API., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 35/44] virtio-serial: add the virtio-serial device., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 43/44] virtio-9p: cleanup: init function., fred . konrad, 2013/01/15
- [Qemu-devel] [PATCH V3 24/44] virtio-balloon-pci: switch to the new API., fred . konrad, 2013/01/15