yeahuh / rpms / qemu-kvm

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