[pve-devel] [PATCH] qom ballon fix v2

Alexandre Derumier aderumier at odiso.com
Fri Mar 6 12:19:59 CET 2015


changelog:
- values are in bytes
- we need to skip values if they are = -1
  (guest don't have yet reported values)

- reuse again qmp query-balloon, to get actual value of the balloon device.

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 2509a0a..2399c79 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2486,17 +2486,33 @@ sub vmstatus {
 
     my $qmpclient = PVE::QMPClient->new();
 
-    my $ballooncb = sub {
-	my ($vmid, $resp) = @_;
+    my $balloon_guest_stats_cb = sub {
+        my ($vmid, $resp) = @_;
 
 	my $info = $resp->{'return'};
 	my $d = $res->{$vmid};
 
 	if (defined($info->{stats}->{"stat-total-memory"}) && defined($info->{stats}->{"stat-free-memory"})) {
-	    $d->{balloon} = int($info->{stats}->{"stat-total-memory"}/1024/1024);
-	    $d->{freemem} = int($info->{stats}->{"stat-free-memory"}/1024/1024);
-	    $d->{mem} = $d->{maxmem} - $d->{freemem};
+	    return if $info->{stats}->{"stat-total-memory"} eq "-1";
+
+	    $d->{freemem} = $info->{stats}->{"stat-free-memory"};
+	    $d->{mem} = ($d->{maxmem}*1024*1024) - $d->{freemem};
 	}
+    };
+
+    my $ballooncb = sub {
+	my ($vmid, $resp) = @_;
+
+	my $info = $resp->{'return'};
+	return if !$info->{actual};
+
+	my $d = $res->{$vmid};
+
+	$d->{balloon} = $info->{actual};
+
+        $qmpclient->queue_cmd($vmid, $balloon_guest_stats_cb, 'qom-get',  
+                              path => "machine/peripheral/balloon0", 
+                              property => "guest-stats");
 
     };
 
@@ -2517,15 +2533,8 @@ sub vmstatus {
 	my ($vmid, $resp) = @_;
 
 	$qmpclient->queue_cmd($vmid, $blockstatscb, 'query-blockstats');
-	# this fails if ballon driver is not loaded, so this must be
-	# the last commnand (following command are aborted if this fails).
-	# maybe is it fixed by
-	#http://git.qemu.org/?p=qemu.git;a=commit;h=38dbd48b247ebe05bdc6ef52ccdc60cc21274877
-
-	$qmpclient->queue_cmd($vmid, $ballooncb, 'qom-get',  
-			      path => "machine/peripheral/balloon0", 
-			      property => "guest-stats");
 
+	$qmpclient->queue_cmd($vmid, $ballooncb, 'query-balloon');
 
 	my $status = 'unknown';
 	if (!defined($status = $resp->{'return'}->{status})) {
-- 
1.7.10.4




More information about the pve-devel mailing list