Ballooning operations can fail (e.g. driver in guest not available). Let the user know of such an error condition instead of silently ignoring errors.
Signed-off-by: Amit Shah <amit.s...@redhat.com> --- balloon.c | 7 +++++-- balloon.h | 2 +- hw/virtio-balloon.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/balloon.c b/balloon.c index 2b7131a..b05c9e2 100644 --- a/balloon.c +++ b/balloon.c @@ -63,12 +63,15 @@ void qemu_remove_balloon_handler(void *opaque) static int qemu_balloon(ram_addr_t target) { + int ret; + if (!balloon_event_fn) { return -1; } trace_balloon_event(balloon_opaque, target); - balloon_event_fn(balloon_opaque, target); - return 0; + ret = balloon_event_fn(balloon_opaque, target); + + return ret < 0 ? -1 : 0; } static int qemu_balloon_status(BalloonInfo *info) diff --git a/balloon.h b/balloon.h index b36abea..23b43bd 100644 --- a/balloon.h +++ b/balloon.h @@ -17,7 +17,7 @@ #include "monitor.h" #include "qapi-types.h" -typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target); +typedef int (QEMUBalloonEvent)(void *opaque, ram_addr_t target); typedef void (QEMUBalloonStatus)(void *opaque, BalloonInfo *info); int qemu_add_balloon_handler(QEMUBalloonEvent *event_func, diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c index e24a2bf..a8ecb51 100644 --- a/hw/virtio-balloon.c +++ b/hw/virtio-balloon.c @@ -180,7 +180,7 @@ static void virtio_balloon_stat(void *opaque, BalloonInfo *info) VIRTIO_BALLOON_PFN_SHIFT); } -static void virtio_balloon_to_target(void *opaque, ram_addr_t target) +static int virtio_balloon_to_target(void *opaque, ram_addr_t target) { VirtIOBalloon *dev = opaque; @@ -191,6 +191,7 @@ static void virtio_balloon_to_target(void *opaque, ram_addr_t target) dev->num_pages = (ram_size - target) >> VIRTIO_BALLOON_PFN_SHIFT; virtio_notify_config(&dev->vdev); } + return 0; } static void virtio_balloon_save(QEMUFile *f, void *opaque) -- 1.7.7.3