Skip to content

Commit

Permalink
virtio-rng: cleanup: use QOM casts.
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Tested-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Acked-by: Amit Shah <amit.shah@redhat.com>
Message-id: 1366790881-3026-9-git-send-email-fred.konrad@greensocs.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
  • Loading branch information
konrad-fred authored and Anthony Liguori committed Apr 24, 2013
1 parent 65f3b67 commit 611aa33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions hw/virtio/virtio-rng.c
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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);
}

Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/hw/virtio/virtio-rng.h
Expand Up @@ -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;
Expand Down

0 comments on commit 611aa33

Please sign in to comment.