From patchwork Mon Jan 7 18:40:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fred.konrad@greensocs.com X-Patchwork-Id: 210076 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CA9092C0189 for ; Tue, 8 Jan 2013 06:44:39 +1100 (EST) Received: from localhost ([::1]:43173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsIcg-0004u9-0k for incoming@patchwork.ozlabs.org; Mon, 07 Jan 2013 14:44:38 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsHem-0005ea-Se for qemu-devel@nongnu.org; Mon, 07 Jan 2013 13:42:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsHel-00060G-Nx for qemu-devel@nongnu.org; Mon, 07 Jan 2013 13:42:44 -0500 Received: from greensocs.com ([87.106.252.221]:53061 helo=s15328186.onlinehome-server.info) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsHel-00060A-Ey for qemu-devel@nongnu.org; Mon, 07 Jan 2013 13:42:43 -0500 Received: from localhost (unknown [127.0.0.1]) by s15328186.onlinehome-server.info (Postfix) with ESMTP id DD504439E49; Mon, 7 Jan 2013 18:42:42 +0000 (UTC) Received: from s15328186.onlinehome-server.info ([127.0.0.1]) by localhost (s15328186.onlinehome-server.info [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KDMpTiZh2WM4; Mon, 7 Jan 2013 19:42:40 +0100 (CET) Received: by s15328186.onlinehome-server.info (Postfix, from userid 491) id 686D3439E33; Mon, 7 Jan 2013 19:42:32 +0100 (CET) Received: from compaq.katmai.xl.cx.katmai.xl.cx (lan31-11-83-155-143-136.fbx.proxad.net [83.155.143.136]) by s15328186.onlinehome-server.info (Postfix) with ESMTPSA id 9AD23439E4E; Mon, 7 Jan 2013 19:42:30 +0100 (CET) From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org, aliguori@us.ibm.com Date: Mon, 7 Jan 2013 19:40:58 +0100 Message-Id: <1357584074-10852-46-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1357584074-10852-1-git-send-email-fred.konrad@greensocs.com> References: <1357584074-10852-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 87.106.252.221 Cc: kwolf@redhat.com, peter.maydell@linaro.org, e.voevodin@samsung.com, mst@redhat.com, mark.burton@greensocs.com, agraf@suse.de, amit.shah@redhat.com, aneesh.kumar@linux.vnet.ibm.com, stefanha@redhat.com, cornelia.huck@de.ibm.com, pbonzini@redhat.com, afaerber@suse.de, fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH 45/61] virtio-rng.c : cleanup : use QOM casts. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: KONRAD Frederic As the virtio-rng-pci and virtio-rng-s390 are switched to the new API, we can use QOM casts. This shouldn't been applyied before virtio-rng-pci and virtio-rg-s390 refactoring as their VirtIODevice were not a QOM object. Signed-off-by: KONRAD Frederic --- 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 4e84f9e..67407a7 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) @@ -174,7 +177,7 @@ static int virtio_rng_device_init(VirtIODevice *vdev) * This will disappear later in the serie. * We will use VirtioDeviceClass instead. */ - vrng->vdev.get_features = get_features; + vdev->get_features = get_features; /**/ assert(vrng->conf.max_bytes <= INT64_MAX); 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;