[pve-devel] [PATCH v4 container 10/12] config: apply_pending_mountpoint helper

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Nov 20 08:31:05 CET 2019


for reuse in hotplug code

Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 src/PVE/LXC/Config.pm | 65 ++++++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 26 deletions(-)

diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index 6203c42..573eaff 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -1243,15 +1243,6 @@ sub vmconfig_apply_pending {
 	warn $err_msg;
     };
 
-    my $rescan_volume = sub {
-	my ($mp) = @_;
-	eval {
-	    $mp->{size} = PVE::Storage::volume_size_info($storecfg, $mp->{volume}, 5)
-		if !defined($mp->{size});
-	};
-	warn "Could not rescan volume size - $@\n" if $@;
-    };
-
     my $pending_delete_hash = $class->parse_pending_delete($conf->{pending}->{delete});
     # FIXME: $force deletion is not implemented for CTs
     foreach my $opt (sort keys %$pending_delete_hash) {
@@ -1282,23 +1273,7 @@ sub vmconfig_apply_pending {
 	next if $selection && !$selection->{$opt};
 	eval {
 	    if ($opt =~ m/^mp(\d+)$/) {
-		my $mp = $class->parse_ct_mountpoint($conf->{pending}->{$opt});
-		my $old = $conf->{$opt};
-		if ($mp->{type} eq 'volume') {
-		    if ($mp->{volume} =~ $PVE::LXC::NEW_DISK_RE) {
-			PVE::LXC::create_disks($storecfg, $vmid, { $opt => $conf->{pending}->{$opt} }, $conf, 1);
-		    } else {
-			$rescan_volume->($mp);
-			$conf->{pending}->{$opt} = $class->print_ct_mountpoint($mp);
-		    }
-		}
-		if (defined($old)) {
-		    my $mp = $class->parse_ct_mountpoint($old);
-		    if ($mp->{type} eq 'volume') {
-			$class->add_unused_volume($conf, $mp->{volume})
-			    if !$class->is_volume_in_use($conf, $conf->{$opt}, 1, 1);
-		    }
-		}
+		$class->apply_pending_mountpoint($vmid, $conf, $opt, $storecfg, 0);
 	    } elsif ($opt =~ m/^net(\d+)$/) {
 		my $netid = $1;
 		my $net = $class->parse_lxc_network($conf->{pending}->{$opt});
@@ -1316,6 +1291,44 @@ sub vmconfig_apply_pending {
     $class->write_config($vmid, $conf);
 }
 
+my $rescan_volume = sub {
+    my ($storecfg, $mp) = @_;
+    eval {
+	$mp->{size} = PVE::Storage::volume_size_info($storecfg, $mp->{volume}, 5)
+	    if !defined($mp->{size});
+    };
+    warn "Could not rescan volume size - $@\n" if $@;
+};
+
+sub apply_pending_mountpoint {
+    my ($class, $vmid, $conf, $opt, $storecfg, $running) = @_;
+
+    my $mp = $class->parse_ct_mountpoint($conf->{pending}->{$opt});
+    my $old = $conf->{$opt};
+    if ($mp->{type} eq 'volume') {
+	if ($mp->{volume} =~ $PVE::LXC::NEW_DISK_RE) {
+	    my $vollist = PVE::LXC::create_disks(
+		$storecfg,
+		$vmid,
+		{ $opt => $conf->{pending}->{$opt} },
+		$conf,
+		1,
+	    );
+	} else {
+	    $rescan_volume->($storecfg, $mp);
+	    $conf->{pending}->{$opt} = $class->print_ct_mountpoint($mp);
+	}
+    }
+
+    if (defined($old)) {
+	my $mp = $class->parse_ct_mountpoint($old);
+	if ($mp->{type} eq 'volume') {
+	    $class->add_unused_volume($conf, $mp->{volume})
+		if !$class->is_volume_in_use($conf, $conf->{$opt}, 1, 1);
+	}
+    }
+}
+
 sub classify_mountpoint {
     my ($class, $vol) = @_;
     if ($vol =~ m!^/!) {
-- 
2.20.1





More information about the pve-devel mailing list