[pve-devel] [PATCH RFC container 1/2] Skip some additional config options when restoring

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Apr 19 15:59:15 CEST 2016


-unusedX in all cases
-parent also when merging config from backup, not only when
merging existing old config
-lxc.* when merging existing old config (update_pct_config
does not support lxc.*)
---
Note: this just fixes some error cases that are rather easy to run into

 src/PVE/API2/LXC.pm   | 2 +-
 src/PVE/LXC/Create.pm | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 90cdba6..8ab54d5 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -258,7 +258,7 @@ __PACKAGE__->register_method({
 	my $no_disk_param = {};
 	foreach my $opt (keys %$param) {
 	    my $value = $param->{$opt};
-	    if ($opt eq 'rootfs' || $opt =~ m/^mp\d+$/) {
+	    if ($opt eq 'rootfs' || $opt =~ m/^mp\d+$/ || $opt =~ m/^unused\d+$/ ) {
 		# allow to use simple numbers (add default storage in that case)
 		$param->{$opt} = "$storage:$value" if $value =~ m/^\d+(\.\d+)?$/;
 	    } else {
diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index 6c2c735..65e104f 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -154,8 +154,9 @@ sub restore_and_configure {
 	    my $oldconf = PVE::LXC::Config::parse_pct_config("/lxc/$vmid.conf", $raw);
 
 	    foreach my $key (keys %$oldconf) {
-		next if $key eq 'digest' || $key eq 'rootfs' || $key eq 'snapshots' || $key eq 'unprivileged';
+		next if $key eq 'digest' || $key eq 'rootfs' || $key eq 'snapshots' || $key eq 'unprivileged' || $key eq 'parent';
 		next if $key =~ /^mp\d+$/; # don't recover mountpoints
+		next if $key =~ /^unused\d+$/; # don't recover unused disks
 		$conf->{$key} = $oldconf->{$key} if !defined($conf->{$key});
 	    }
 	    unlink($pct_cfg_fn);
@@ -203,11 +204,12 @@ sub create_rootfs {
 	PVE::LXC::destroy_lxc_container($storage_cfg, $vmid, $old_conf);
 
 	# do not copy all settings to restored container
-	foreach my $opt (qw(rootfs digest snapshots arch ostype unprivileged parent)) {
+	foreach my $opt (qw(rootfs digest snapshots arch ostype unprivileged parent lxc)) {
 	    delete $old_conf->{$opt};
 	}
 	foreach my $opt (keys %$old_conf) {
 	    delete $old_conf->{$opt} if $opt =~ m/^mp\d+$/;
+	    delete $old_conf->{$opt} if $opt =~ m/^unused\d+$/;
 	}
 
 	PVE::LXC::Config->update_pct_config($vmid, $conf, 0, $old_conf);
-- 
2.1.4




More information about the pve-devel mailing list