Signed-off-by: Alexandre Derumier <aderum...@odiso.com> --- src/PVE/LXC.pm | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 068b46f..0f21bcb 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -964,8 +964,7 @@ sub verify_searchdomain_list { sub update_lxc_config { my ($vmid, $conf, $running, $param, $delete) = @_; - # fixme: hotplug - die "unable to modify config while container is running\n" if $running; + my $nohotplug; if (defined($delete)) { foreach my $opt (@$delete) { @@ -981,10 +980,13 @@ sub update_lxc_config { delete $conf->{'pve.startup'}; } elsif ($opt eq 'nameserver') { delete $conf->{'pve.nameserver'}; + $nohotplug = 1; } elsif ($opt eq 'searchdomain') { delete $conf->{'pve.searchdomain'}; + $nohotplug = 1; } elsif ($opt =~ m/^net\d$/) { delete $conf->{$opt}; + $nohotplug = 1; } else { die "implement me" } @@ -1002,9 +1004,11 @@ sub update_lxc_config { } elsif ($opt eq 'nameserver') { my $list = verify_nameserver_list($value); $conf->{'pve.nameserver'} = $list; + $nohotplug = 1; } elsif ($opt eq 'searchdomain') { my $list = verify_searchdomain_list($value); $conf->{'pve.searchdomain'} = $list; + $nohotplug = 1; } elsif ($opt eq 'memory') { $conf->{'lxc.cgroup.memory.limit_in_bytes'} = $value*1024*1024; } elsif ($opt eq 'swap') { @@ -1026,15 +1030,64 @@ sub update_lxc_config { $conf->{'pve.comment'} = PVE::Tools::encode_text($value); } elsif ($opt eq 'disk') { $conf->{'pve.disksize'} = $value; + $nohotplug = 1; } elsif ($opt =~ m/^net(\d+)$/) { my $netid = $1; my $net = PVE::LXC::parse_lxc_network($value); $net->{'veth.pair'} = "veth${vmid}.$netid"; $conf->{$opt} = $net; + $nohotplug = 1; } else { die "implement me" } } + + if($running) { + die "unable to modify theses options while container is running\n" if $nohotplug; + hotplug_lxc_config( $vmid, $conf, $param, $delete); + } + +} + +sub hotplug_lxc_config { + my ($vmid, $conf, $param, $delete) = @_; + + if (defined($delete)) { + foreach my $opt (@$delete) { + if ($opt eq 'swap') { + cgroups_write("memory", $vmid, "memory.memsw.limit_in_bytes", -1); + } elsif ($opt =~ m/^net\d$/) { + #implement me + } + } + } + + foreach my $opt (keys %$param) { + my $value = $param->{$opt}; + if ($opt eq 'memory') { + cgroups_write("memory", $vmid, "memory.limit_in_bytes", $value*1024*1024); + } elsif ($opt eq 'swap') { + my $mem = $conf->{'lxc.cgroup.memory.limit_in_bytes'}; + $mem = $param->{memory}*1024*1024 if $param->{memory}; + cgroups_write("memory", $vmid, "memory.memsw.limit_in_bytes", $mem + $value*1024*1024); + } elsif ($opt eq 'cpulimit') { + if ($value > 0) { + my $cfs_period_us = 100000; + cgroups_write("cpu", $vmid, "cpu.cfs_quota_us", $cfs_period_us*$value); + } else { + cgroups_write("cpu", $vmid, "cpu.cfs_quota_us", -1); + } + } elsif ($opt eq 'cpuunits') { + cgroups_write("cpu", $vmid, "cpu.shares", $value); + } elsif ($opt =~ m/^net(\d+)$/) { + my $netid = $1; + my $net = PVE::LXC::parse_lxc_network($value); + $net->{'veth.pair'} = "veth${vmid}.$netid"; + $conf->{$opt} = $net; + #implement me + } + } + } sub get_primary_ips { @@ -1071,5 +1124,13 @@ sub destory_lxc_container { PVE::Tools::run_command($cmd); } } + +sub cgroups_write { + my ($controller, $vmid, $option, $value) = @_; + + my $path = "/sys/fs/cgroup/$controller/lxc/$vmid/$option"; + PVE::ProcFSTools::write_proc_entry($path, $value); + +} 1; -- 2.1.4 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel