From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qly7N-0004S4-2x for qemu-devel@nongnu.org; Wed, 27 Jul 2011 03:01:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qly7L-0005Oq-TL for qemu-devel@nongnu.org; Wed, 27 Jul 2011 03:01:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13433) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qly7L-0005Ob-JP for qemu-devel@nongnu.org; Wed, 27 Jul 2011 03:01:19 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6R71Ioh009520 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 27 Jul 2011 03:01:18 -0400 From: Amit Shah Date: Wed, 27 Jul 2011 12:31:08 +0530 Message-Id: In-Reply-To: <437e364393661cf06deaad6f29f1039d3a672d1d.1311750065.git.amit.shah@redhat.com> References: <437e364393661cf06deaad6f29f1039d3a672d1d.1311750065.git.amit.shah@redhat.com> In-Reply-To: <437e364393661cf06deaad6f29f1039d3a672d1d.1311750065.git.amit.shah@redhat.com> References: <437e364393661cf06deaad6f29f1039d3a672d1d.1311750065.git.amit.shah@redhat.com> Subject: [Qemu-devel] [PATCH 2/2] virtio-balloon: Check if balloon registration failed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu list Cc: Amit Shah , Markus Armbruster Multiple balloon registrations are not allowed; check if the registration with the qemu balloon api succeeded. If not, fail the device init. Signed-off-by: Amit Shah --- hw/virtio-balloon.c | 10 +++++++++- hw/virtio-pci.c | 3 +++ 2 files changed, 12 insertions(+), 1 deletions(-) diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c index 2ba7e95..304a31a 100644 --- a/hw/virtio-balloon.c +++ b/hw/virtio-balloon.c @@ -269,6 +269,7 @@ static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id) VirtIODevice *virtio_balloon_init(DeviceState *dev) { VirtIOBalloon *s; + int ret; s = (VirtIOBalloon *)virtio_common_init("virtio-balloon", VIRTIO_ID_BALLOON, @@ -278,12 +279,19 @@ VirtIODevice *virtio_balloon_init(DeviceState *dev) s->vdev.set_config = virtio_balloon_set_config; s->vdev.get_features = virtio_balloon_get_features; + ret = qemu_add_balloon_handler(virtio_balloon_to_target, + virtio_balloon_stat, s); + if (ret < 0) { + error_report("Another balloon device already registered"); + virtio_cleanup(&s->vdev); + return NULL; + } + s->ivq = virtio_add_queue(&s->vdev, 128, virtio_balloon_handle_output); s->dvq = virtio_add_queue(&s->vdev, 128, virtio_balloon_handle_output); s->svq = virtio_add_queue(&s->vdev, 128, virtio_balloon_receive_stats); reset_stats(s); - qemu_add_balloon_handler(virtio_balloon_to_target, virtio_balloon_stat, s); register_savevm(dev, "virtio-balloon", -1, 1, virtio_balloon_save, virtio_balloon_load, s); diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index d685243..ca5f125 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -788,6 +788,9 @@ static int virtio_balloon_init_pci(PCIDevice *pci_dev) VirtIODevice *vdev; vdev = virtio_balloon_init(&pci_dev->qdev); + if (!vdev) { + return -1; + } virtio_init_pci(proxy, vdev); return 0; } -- 1.7.6