yeahuh / rpms / qemu-kvm

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