Blame SOURCES/kvm-balloon-Allow-multiple-inhibit-users.patch

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