Received: from eggs.gnu.org ([2001:4830:134:3::10]:47297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4iSr-0003QB-A9 for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:18:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V4iSj-0006LK-Uq for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:18:05 -0400 Received: from cantor2.suse.de ([195.135.220.15]:60997 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4iSj-0006Ky-MH for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:17:57 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 1 Aug 2013 04:17:36 +0200 Message-Id: <1375323463-32747-16-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 15/22] virtio-balloon: 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-balloon.c | 22 +++++++++++++--------- include/hw/virtio/virtio-balloon.h | 2 ++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 3bab5db..9b65732 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -337,10 +337,12 @@ static int virtio_balloon_load(QEMUFile *f, void *o= paque, int version_id) return 0; } =20 -static int virtio_balloon_device_init(VirtIODevice *vdev) +static void virtio_balloon_device_realize(DeviceState *dev, Error **errp= ) { - DeviceState *dev =3D DEVICE(vdev); + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIOBalloon *s =3D VIRTIO_BALLOON(dev); + ObjectClass *parent_oc =3D VIRTIO_BALLOON_GET_PARENT_CLASS(dev); + DeviceClass *parent_dc =3D DEVICE_CLASS(parent_oc); int ret; =20 virtio_init(vdev, "virtio-balloon", VIRTIO_ID_BALLOON, 8); @@ -349,8 +351,9 @@ static int virtio_balloon_device_init(VirtIODevice *v= dev) virtio_balloon_stat, s); =20 if (ret < 0) { + error_setg(errp, "Adding balloon handler failed"); virtio_cleanup(vdev); - return -1; + return; } =20 s->ivq =3D virtio_add_queue(vdev, 128, virtio_balloon_handle_output)= ; @@ -367,19 +370,19 @@ static int virtio_balloon_device_init(VirtIODevice = *vdev) balloon_stats_get_poll_interval, balloon_stats_set_poll_interval, NULL, s, NULL); - return 0; + + parent_dc->realize(dev, errp); } =20 -static int virtio_balloon_device_exit(DeviceState *dev) +static void virtio_balloon_device_unrealize(DeviceState *dev, Error **er= rp) { - VirtIOBalloon *s =3D VIRTIO_BALLOON(dev); VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VirtIOBalloon *s =3D VIRTIO_BALLOON(dev); =20 balloon_stats_destroy_timer(s); qemu_remove_balloon_handler(s); unregister_savevm(dev, "virtio-balloon", s); virtio_cleanup(vdev); - return 0; } =20 static Property virtio_balloon_properties[] =3D { @@ -390,10 +393,11 @@ static void virtio_balloon_class_init(ObjectClass *= klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); - dc->exit =3D virtio_balloon_device_exit; + + dc->realize =3D virtio_balloon_device_realize; + dc->unrealize =3D virtio_balloon_device_unrealize; dc->props =3D virtio_balloon_properties; set_bit(DEVICE_CATEGORY_MISC, dc->categories); - vdc->init =3D virtio_balloon_device_init; vdc->get_config =3D virtio_balloon_get_config; vdc->set_config =3D virtio_balloon_set_config; vdc->get_features =3D virtio_balloon_get_features; diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virti= o-balloon.h index f863bfe..bf3846c 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -21,6 +21,8 @@ #define TYPE_VIRTIO_BALLOON "virtio-balloon-device" #define VIRTIO_BALLOON(obj) \ OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON) +#define VIRTIO_BALLOON_GET_PARENT_CLASS(obj) \ + OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_BALLOON) =20 /* from Linux's linux/virtio_balloon.h */ =20 --=20 1.8.1.4