Balloon ugly hack

add balloon:  parameter to config file

and set balloon at vm start.

Signed-off-by: Derumier Alexandre <aderumier@odiso.com>
This commit is contained in:
Derumier Alexandre 2011-09-16 04:46:26 +02:00 committed by Dietmar Maurer
parent 6b64503eb2
commit 13a4862059

View File

@ -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;