[pve-devel] [PATCH] balloon: use qom-get for guest balloon statistics

Alexandre Derumier aderumier at odiso.com
Fri Mar 6 06:43:18 CET 2015


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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index bb7a7f3..2bb907c 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2486,22 +2486,37 @@ sub vmstatus {
 
     my $qmpclient = PVE::QMPClient->new();
 
+    my $balloon_guest_stats_cb = sub {
+	my ($vmid, $resp) = @_;
+
+	my $info = $resp->{'return'};
+	my $d = $res->{$vmid};
+
+	if (defined($info->{total_mem}) && defined($info->{free_mem})) {
+	    $d->{mem} = $info->{total_mem} - $info->{free_mem};
+	    $d->{freemem} = $info->{free_mem};
+	}
+
+    };
+
     my $ballooncb = sub {
 	my ($vmid, $resp) = @_;
 
 	my $info = $resp->{'return'};
-	return if !$info->{max_mem};
+	return if !$info->{actual};
 
 	my $d = $res->{$vmid};
 
 	# use memory assigned to VM
-	$d->{maxmem} = $info->{max_mem};
 	$d->{balloon} = $info->{actual};
 
-	if (defined($info->{total_mem}) && defined($info->{free_mem})) {
-	    $d->{mem} = $info->{total_mem} - $info->{free_mem};
-	    $d->{freemem} = $info->{free_mem};
-	}
+	#this can be remove if we remove the pve-qemu-kvm balloon patch
+	$d->{maxmem} = $info->{max_mem} if $info->{max_mem};
+
+
+	$qmpclient->queue_cmd($vmid, $balloon_guest_stats_cb, 'qom-get',  
+			      path => "machine/peripheral/balloon0", 
+			      property => "guest-stats");
 
     };
 
@@ -2524,6 +2539,9 @@ sub vmstatus {
 	$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, 'query-balloon');
 
 	my $status = 'unknown';
-- 
1.7.10.4




More information about the pve-devel mailing list