[pve-devel] [PATCH] Balloon ugly hack

Derumier Alexandre aderumier at odiso.com
Fri Sep 16 04:46:26 CEST 2011


add balloon:  parameter to config file

and set balloon at vm start.

Signed-off-by: Derumier Alexandre <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 1d14060..aa2b184 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -187,6 +187,12 @@ my $confdesc = {
 	minimum => 16,
 	default => 512,
     },
+    balloon => {
+        optional => 1,
+        type => 'integer',
+        description => "Amount of target RAM for the VM in MB.",
+        default => 0,
+    },
     keyboard => {
 	optional => 1,
 	type => 'string',
@@ -2095,6 +2101,7 @@ sub config_to_command {
     #my $soundhw = $conf->{soundhw} || $defaults->{soundhw};
     #push @$cmd, '-soundhw', 'es1370';
     #push @$cmd, '-soundhw', $soundhw if $soundhw;
+    push @$cmd, '-device', 'virtio-balloon-pci,id=balloon0' if $conf->{balloon};
 
     if ($conf->{watchdog}) {
 	my $wdopts = parse_watchdog($conf->{watchdog});
@@ -2330,6 +2337,28 @@ sub vm_start {
 	    eval { vm_monitor_command($vmid, $cmd, 1); };
 	}
 
+        if($conf->{balloon})
+        {
+          my $newmemorysize=0;
+          my $timewait=0;
+          #set balloon
+          print "try to balloon to $conf->{balloon}\n";
+          vm_balloonset($vmid,$conf->{balloon});
+          #display memory until balloon activate
+          $cmd = "info balloon";
+          while ($conf->{balloon} ne $newmemorysize && $timewait < 120) {
+             my $result=vm_monitor_command ($vmid, $cmd, 1);
+             if ($result =~ m/^balloon: actual=(\d+)$/) {
+                $newmemorysize=$1;
+                print "current memory:$newmemorysize\n";
+             }
+             $timewait++;
+             sleep 1;
+          }
+        print "can't set balloon to $conf->{balloon}, do you have balloon device driver installed?\n" if $timewait > 60;
+
+        }
+
     });
 }
 
@@ -2809,4 +2838,11 @@ sub print_pci_addr {
 
 }
 
+sub vm_balloonset {
+    my ($vmid,$value) = @_;
+
+    vm_monitor_command ($vmid, "balloon $value", 1);
+
+}
+
 1;
-- 
1.7.2.5




More information about the pve-devel mailing list