Browse Source

balloon: Allow multiple inhibit users

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>
tags/v3.1.0-rc0
Alex Williamson 10 months ago
parent
commit
01ccbec7bd
1 changed files with 10 additions and 3 deletions
  1. 10
    3
      balloon.c

+ 10
- 3
balloon.c View File

@@ -26,6 +26,7 @@
26 26
 
27 27
 #include "qemu/osdep.h"
28 28
 #include "qemu-common.h"
29
+#include "qemu/atomic.h"
29 30
 #include "exec/cpu-common.h"
30 31
 #include "sysemu/kvm.h"
31 32
 #include "sysemu/balloon.h"
@@ -37,16 +38,22 @@
37 38
 static QEMUBalloonEvent *balloon_event_fn;
38 39
 static QEMUBalloonStatus *balloon_stat_fn;
39 40
 static void *balloon_opaque;
40
-static bool balloon_inhibited;
41
+static int balloon_inhibit_count;
41 42
 
42 43
 bool qemu_balloon_is_inhibited(void)
43 44
 {
44
-    return balloon_inhibited;
45
+    return atomic_read(&balloon_inhibit_count) > 0;
45 46
 }
46 47
 
47 48
 void qemu_balloon_inhibit(bool state)
48 49
 {
49
-    balloon_inhibited = state;
50
+    if (state) {
51
+        atomic_inc(&balloon_inhibit_count);
52
+    } else {
53
+        atomic_dec(&balloon_inhibit_count);
54
+    }
55
+
56
+    assert(atomic_read(&balloon_inhibit_count) >= 0);
50 57
 }
51 58
 
52 59
 static bool have_balloon(Error **errp)

Loading…
Cancel
Save