yeahuh / rpms / qemu-kvm

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