From d97a651f93367df0739d7b3f5c9a760cdcfbebd7 Mon Sep 17 00:00:00 2001 From: Amit Shah Date: Mon, 1 Aug 2011 11:40:56 -0300 Subject: [RHEL6 qemu-kvm PATCH 55/65] virtio-balloon: Check if balloon registration failed RH-Author: Amit Shah Message-id: <17e9cc2551fa83725b52f2c51eea84d31fa1c725.1312198249.git.amit.shah@redhat.com> Patchwork-id: 30729 O-Subject: [RHEL6.2 qemu PATCH 10/13] virtio-balloon: Check if balloon registration failed Bugzilla: 725625 RH-Acked-by: Markus Armbruster RH-Acked-by: Jes Sorensen RH-Acked-by: Alex Williamson 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 Reviewed-by: Markus Armbruster Acked-by: Michael S. Tsirkin (cherry picked from commit ab640dbfc04651ede92495a4067c826db068c1a7) Conflicts: hw/virtio-pci.c Bugzilla: 725625 Signed-off-by: Amit Shah --- hw/virtio-balloon.c | 9 ++++++++- hw/virtio-pci.c | 3 +++ 2 files changed, 11 insertions(+), 1 deletions(-) Signed-off-by: Eduardo Habkost --- hw/virtio-balloon.c | 9 ++++++++- hw/virtio-pci.c | 3 +++ 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c index 2be5c81..cfdc44a 100644 --- a/hw/virtio-balloon.c +++ b/hw/virtio-balloon.c @@ -271,6 +271,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, @@ -280,12 +281,18 @@ 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) { + 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 d1a0c84..51d6adc 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -906,6 +906,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, PCI_VENDOR_ID_REDHAT_QUMRANET, PCI_DEVICE_ID_VIRTIO_BALLOON, -- 1.7.3.2