Received: from eggs.gnu.org ([2001:4830:134:3::10]:47340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4iSt-0003S7-FF for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:18:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V4iSl-0006MV-3Y for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:18:07 -0400 Received: from cantor2.suse.de ([195.135.220.15]:32768 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4iSk-0006MC-Po for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:17:59 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 1 Aug 2013 04:17:38 +0200 Message-Id: <1375323463-32747-18-git-send-email-afaerber@suse.de> In-Reply-To: <1375323463-32747-1-git-send-email-afaerber@suse.de> References: <1375323463-32747-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH for-next v2 17/22] virtio-rng: Convert to QOM realize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= Signed-off-by: Andreas F=C3=A4rber --- 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 0accc9e..7c4526a 100644 --- a/hw/virtio/virtio-rng.c +++ b/hw/virtio/virtio-rng.c @@ -133,10 +133,12 @@ static void check_rate_limit(void *opaque) qemu_get_clock_ms(vm_clock) + vrng->conf.period_ms); } =20 -static int virtio_rng_device_init(VirtIODevice *vdev) +static void virtio_rng_device_realize(DeviceState *dev, Error **errp) { - DeviceState *dev =3D DEVICE(vdev); + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIORNG *vrng =3D VIRTIO_RNG(dev); + ObjectClass *parent_oc =3D VIRTIO_RNG_GET_PARENT_CLASS(dev); + DeviceClass *parent_dc =3D DEVICE_CLASS(parent_oc); Error *local_err =3D NULL; =20 if (vrng->conf.rng =3D=3D NULL) { @@ -156,15 +158,14 @@ static int virtio_rng_device_init(VirtIODevice *vde= v) =20 vrng->rng =3D vrng->conf.rng; if (vrng->rng =3D=3D NULL) { - qerror_report(QERR_INVALID_PARAMETER_VALUE, "rng", "a valid obje= ct"); - return -1; + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "rng", "a valid ob= ject"); + return; } =20 rng_backend_open(vrng->rng, &local_err); if (local_err) { - qerror_report_err(local_err); - error_free(local_err); - return -1; + error_propagate(errp, local_err); + return; } =20 vrng->vq =3D virtio_add_queue(vdev, 8, handle_input); @@ -181,19 +182,18 @@ static int virtio_rng_device_init(VirtIODevice *vde= v) register_savevm(dev, "virtio-rng", -1, 1, virtio_rng_save, virtio_rng_load, vrng); =20 - return 0; + parent_dc->realize(dev, errp); } =20 -static int virtio_rng_device_exit(DeviceState *dev) +static void virtio_rng_device_unrealize(DeviceState *dev, Error **errp) { - VirtIORNG *vrng =3D VIRTIO_RNG(dev); VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VirtIORNG *vrng =3D VIRTIO_RNG(dev); =20 qemu_del_timer(vrng->rate_limit_timer); qemu_free_timer(vrng->rate_limit_timer); unregister_savevm(dev, "virtio-rng", vrng); virtio_cleanup(vdev); - return 0; } =20 static Property virtio_rng_properties[] =3D { @@ -205,10 +205,11 @@ static void virtio_rng_class_init(ObjectClass *klas= s, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); - dc->exit =3D virtio_rng_device_exit; + + dc->realize =3D virtio_rng_device_realize; + dc->unrealize =3D virtio_rng_device_unrealize; dc->props =3D virtio_rng_properties; set_bit(DEVICE_CATEGORY_MISC, dc->categories); - vdc->init =3D virtio_rng_device_init; vdc->get_features =3D get_features; } =20 diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rn= g.h index debaa15..14e85a5 100644 --- a/include/hw/virtio/virtio-rng.h +++ b/include/hw/virtio/virtio-rng.h @@ -18,6 +18,8 @@ #define TYPE_VIRTIO_RNG "virtio-rng-device" #define VIRTIO_RNG(obj) \ OBJECT_CHECK(VirtIORNG, (obj), TYPE_VIRTIO_RNG) +#define VIRTIO_RNG_GET_PARENT_CLASS(obj) \ + OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_RNG) =20 /* The Virtio ID for the virtio rng device */ #define VIRTIO_ID_RNG 4 --=20 1.8.1.4