From 8e0778982e9a71000c6a1d999e0caf5934bebd61 Mon Sep 17 00:00:00 2001
From: Alex Williamson <alex.williamson@redhat.com>
Date: Thu, 13 Dec 2018 21:54:44 +0100
Subject: [PATCH 2/5] balloon: Allow multiple inhibit users
RH-Author: Alex Williamson <alex.williamson@redhat.com>
Message-id: <154473808463.22725.5535931320059757090.stgit@gimli.home>
Patchwork-id: 83494
O-Subject: [RHEL-7.7 qemu-kvm PATCH 2/5] balloon: Allow multiple inhibit users
Bugzilla: 1659229
RH-Acked-by: Peter Xu <peterx@redhat.com>
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
Bugzilla: 1659229
A simple true/false internal state does not allow multiple users. Fix
this within the existing interface by converting to a counter, so long
as the counter is elevated, ballooning is inhibited.
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
(cherry picked from commit 01ccbec7bdf6f89f1b7d46dda05e4c1fd2dd5ade)
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
balloon.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/balloon.c b/balloon.c
index c7a0cf1..6a17096 100644
--- a/balloon.c
+++ b/balloon.c
@@ -25,6 +25,7 @@
*/
#include "monitor/monitor.h"
+#include "qemu/atomic.h"
#include "exec/cpu-common.h"
#include "sysemu/kvm.h"
#include "sysemu/balloon.h"
@@ -35,16 +36,22 @@
static QEMUBalloonEvent *balloon_event_fn;
static QEMUBalloonStatus *balloon_stat_fn;
static void *balloon_opaque;
-static bool balloon_inhibited;
+static int balloon_inhibit_count;
bool qemu_balloon_is_inhibited(void)
{
- return balloon_inhibited;
+ return atomic_read(&balloon_inhibit_count) > 0;
}
void qemu_balloon_inhibit(bool state)
{
- balloon_inhibited = state;
+ if (state) {
+ atomic_inc(&balloon_inhibit_count);
+ } else {
+ atomic_dec(&balloon_inhibit_count);
+ }
+
+ assert(atomic_read(&balloon_inhibit_count) >= 0);
}
int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
--
1.8.3.1