[pve-devel] [PATCH v4 container 10/27] Use foreach_volume instead of foreach_mountpoint-variants

Fabian Ebner f.ebner at proxmox.com
Thu Mar 26 09:09:40 CET 2020


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/PVE/API2/LXC.pm        |  6 +++---
 src/PVE/API2/LXC/Config.pm |  2 +-
 src/PVE/API2/LXC/Status.pm |  2 +-
 src/PVE/CLI/pct.pm         |  4 ++--
 src/PVE/LXC.pm             | 14 +++++++-------
 src/PVE/LXC/Config.pm      | 35 +++++------------------------------
 src/PVE/LXC/Create.pm      |  4 ++--
 src/PVE/LXC/Migrate.pm     |  6 +++---
 src/PVE/VZDump/LXC.pm      |  2 +-
 src/lxc-pve-prestart-hook  |  2 +-
 10 files changed, 26 insertions(+), 51 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 556fd33..c5d42ff 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -316,7 +316,7 @@ __PACKAGE__->register_method({
 
 	# check storage access, activate storage
 	my $delayed_mp_param = {};
-	PVE::LXC::Config->foreach_mountpoint($mp_param, sub {
+	PVE::LXC::Config->foreach_volume($mp_param, sub {
 	    my ($ms, $mountpoint) = @_;
 
 	    my $volid = $mountpoint->{volume};
@@ -371,7 +371,7 @@ __PACKAGE__->register_method({
 			$mp_param = $orig_mp_param;
 			die "rootfs configuration could not be recovered, please check and specify manually!\n"
 			    if !defined($mp_param->{rootfs});
-			PVE::LXC::Config->foreach_mountpoint($mp_param, sub {
+			PVE::LXC::Config->foreach_volume($mp_param, sub {
 			    my ($ms, $mountpoint) = @_;
 			    my $type = $mountpoint->{type};
 			    if ($type eq 'volume') {
@@ -473,7 +473,7 @@ sub check_storage_supports_templates {
 
     my $scfg = PVE::Storage::config();
     eval {
-	PVE::LXC::Config->foreach_mountpoint($conf, sub {
+	PVE::LXC::Config->foreach_volume($conf, sub {
 	    my ($ms, $mp) = @_;
 
 	    my ($sid) = PVE::Storage::parse_volume_id($mp->{volume}, 0);
diff --git a/src/PVE/API2/LXC/Config.pm b/src/PVE/API2/LXC/Config.pm
index 0879172..42e16d1 100644
--- a/src/PVE/API2/LXC/Config.pm
+++ b/src/PVE/API2/LXC/Config.pm
@@ -173,7 +173,7 @@ __PACKAGE__->register_method({
 	my $repl_conf = PVE::ReplicationConfig->new();
 	my $is_replicated = $repl_conf->check_for_existing_jobs($vmid, 1);
 	if ($is_replicated) {
-	    PVE::LXC::Config->foreach_mountpoint_full($param, 0, sub {
+	    PVE::LXC::Config->foreach_volume($param, sub {
 		my ($opt, $mountpoint) = @_;
 		my $volid = $mountpoint->{volume};
 		return if !$volid || !($mountpoint->{replicate}//1);
diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm
index 41f1f4f..03d13a3 100644
--- a/src/PVE/API2/LXC/Status.pm
+++ b/src/PVE/API2/LXC/Status.pm
@@ -182,7 +182,7 @@ __PACKAGE__->register_method({
 		}
 
 		if ($conf->{unprivileged}) {
-		    PVE::LXC::Config->foreach_mountpoint($conf, sub {
+		    PVE::LXC::Config->foreach_volume($conf, sub {
 			my ($ms, $mountpoint) = @_;
 			die "Quotas are not supported by unprivileged containers.\n" if $mountpoint->{quota};
 		    });
diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index 934d9aa..a880705 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -378,7 +378,7 @@ __PACKAGE__->register_method({
 	    my @len = map { length($_) } @{$list[0]};
 
 	    eval {
-		PVE::LXC::Config->foreach_mountpoint($conf, sub {
+		PVE::LXC::Config->foreach_volume($conf, sub {
 		    my ($name, $mp) = @_;
 		    my $path = $mp->{mp};
 
@@ -779,7 +779,7 @@ __PACKAGE__->register_method ({
 	eval {
 	    my $path = "";
 	    PVE::LXC::mount_all($vmid, $storecfg, $conf);
-	    PVE::LXC::Config->foreach_mountpoint($conf, sub {
+	    PVE::LXC::Config->foreach_volume($conf, sub {
 		my ($name, $mp) = @_;
 		$path = $mp->{mp};
 		my $cmd = ["fstrim", "-v", "$rootdir$path"];
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index df52afa..e20005a 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -860,7 +860,7 @@ sub delete_mountpoint_volume {
 sub destroy_lxc_container {
     my ($storage_cfg, $vmid, $conf, $replacement_conf) = @_;
 
-    PVE::LXC::Config->foreach_mountpoint($conf, sub {
+    PVE::LXC::Config->foreach_volume($conf, sub {
 	my ($ms, $mountpoint) = @_;
 	delete_mountpoint_volume($storage_cfg, $vmid, $mountpoint->{volume});
     });
@@ -1191,7 +1191,7 @@ sub template_create {
 
     my $storecfg = PVE::Storage::config();
 
-    PVE::LXC::Config->foreach_mountpoint($conf, sub {
+    PVE::LXC::Config->foreach_volume($conf, sub {
 	my ($ms, $mountpoint) = @_;
 
 	my $volid = $mountpoint->{volume};
@@ -1200,7 +1200,7 @@ sub template_create {
 	    if !PVE::Storage::volume_has_feature($storecfg, 'template', $volid);
     });
 
-    PVE::LXC::Config->foreach_mountpoint($conf, sub {
+    PVE::LXC::Config->foreach_volume($conf, sub {
 	my ($ms, $mountpoint) = @_;
 
 	my $volid = $mountpoint->{volume};
@@ -1265,7 +1265,7 @@ sub umount_all {
 
     my $res = 1;
 
-    PVE::LXC::Config->foreach_mountpoint_reverse($conf, sub {
+    PVE::LXC::Config->foreach_volume_full($conf, {'reverse' => 1}, sub {
 	my ($ms, $mountpoint) = @_;
 
 	my $volid = $mountpoint->{volume};
@@ -1306,7 +1306,7 @@ sub mount_all {
     my (undef, $rootuid, $rootgid) = parse_id_maps($conf);
 
     eval {
-	PVE::LXC::Config->foreach_mountpoint($conf, sub {
+	PVE::LXC::Config->foreach_volume($conf, sub {
 	    my ($ms, $mountpoint) = @_;
 
 	    $mountpoint->{ro} = 0 if $ignore_ro;
@@ -1913,7 +1913,7 @@ sub create_disks {
 	my (undef, $rootuid, $rootgid) = PVE::LXC::parse_id_maps($conf);
 	my $chown_vollist = [];
 
-	PVE::LXC::Config->foreach_mountpoint($settings, sub {
+	PVE::LXC::Config->foreach_volume($settings, sub {
 	    my ($ms, $mountpoint) = @_;
 
 	    my $volid = $mountpoint->{volume};
@@ -1977,7 +1977,7 @@ sub update_disksize {
 	}
     };
 
-    PVE::LXC::Config->foreach_mountpoint($conf, $update_mp);
+    PVE::LXC::Config->foreach_volume($conf, $update_mp);
 
     return $changes;
 }
diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index 9f68ac1..821e84d 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -62,7 +62,7 @@ sub has_feature {
     my ($class, $feature, $conf, $storecfg, $snapname, $running, $backup_only) = @_;
     my $err;
 
-    $class->foreach_mountpoint($conf, sub {
+    $class->foreach_volume($conf, sub {
 	my ($ms, $mountpoint) = @_;
 
 	return if $err; # skip further test
@@ -1408,7 +1408,7 @@ my $__is_volume_in_use = sub {
     my ($class, $config, $volid) = @_;
     my $used = 0;
 
-    $class->foreach_mountpoint($config, sub {
+    $class->foreach_volume($config, sub {
 	my ($ms, $mountpoint) = @_;
 	return if $used;
 	$used = $mountpoint->{type} eq 'volume' && $mountpoint->{volume} eq $volid;
@@ -1480,37 +1480,12 @@ sub valid_volume_keys {
     return $reverse ? reverse @names : @names;
 }
 
-sub foreach_mountpoint_full {
-    my ($class, $conf, $reverse, $func, @param) = @_;
-
-    my $mps = [ grep { defined($conf->{$_}) } $class->valid_volume_keys($reverse) ];
-    foreach my $key (@$mps) {
-	my $value = $conf->{$key};
-	my $mountpoint = $key eq 'rootfs' ? $class->parse_ct_rootfs($value, 1) : $class->parse_ct_mountpoint($value, 1);
-	next if !defined($mountpoint);
-
-	&$func($key, $mountpoint, @param);
-    }
-}
-
-sub foreach_mountpoint {
-    my ($class, $conf, $func, @param) = @_;
-
-    $class->foreach_mountpoint_full($conf, 0, $func, @param);
-}
-
-sub foreach_mountpoint_reverse {
-    my ($class, $conf, $func, @param) = @_;
-
-    $class->foreach_mountpoint_full($conf, 1, $func, @param);
-}
-
 sub get_vm_volumes {
     my ($class, $conf, $excludes) = @_;
 
     my $vollist = [];
 
-    $class->foreach_mountpoint($conf, sub {
+    $class->foreach_volume($conf, sub {
 	my ($ms, $mountpoint) = @_;
 
 	return if $excludes && $ms eq $excludes;
@@ -1568,14 +1543,14 @@ sub get_replicatable_volumes {
 	$volhash->{$volid} = 1;
     };
 
-    $class->foreach_mountpoint($conf, sub {
+    $class->foreach_volume($conf, sub {
 	my ($ms, $mountpoint) = @_;
 	$test_volid->($mountpoint->{volume}, $mountpoint);
     });
 
     foreach my $snapname (keys %{$conf->{snapshots}}) {
 	my $snap = $conf->{snapshots}->{$snapname};
-	$class->foreach_mountpoint($snap, sub {
+	$class->foreach_volume($snap, sub {
 	    my ($ms, $mountpoint) = @_;
 	    $test_volid->($mountpoint->{volume}, $mountpoint);
         });
diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index 9faec63..52b0b48 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -212,7 +212,7 @@ sub recover_config_from_proxmox_backup {
     delete $conf->{snapshots};
 
     my $mp_param = {};
-    PVE::LXC::Config->foreach_mountpoint($conf, sub {
+    PVE::LXC::Config->foreach_volume($conf, sub {
 	my ($ms, $mountpoint) = @_;
 	$mp_param->{$ms} = $conf->{$ms};
     });
@@ -233,7 +233,7 @@ sub recover_config_from_tar {
 
 	delete $conf->{snapshots};
 
-	PVE::LXC::Config->foreach_mountpoint($conf, sub {
+	PVE::LXC::Config->foreach_volume($conf, sub {
 	    my ($ms, $mountpoint) = @_;
 	    $mp_param->{$ms} = $conf->{$ms};
 	});
diff --git a/src/PVE/LXC/Migrate.pm b/src/PVE/LXC/Migrate.pm
index 6c1e9c1..638ce1f 100644
--- a/src/PVE/LXC/Migrate.pm
+++ b/src/PVE/LXC/Migrate.pm
@@ -47,7 +47,7 @@ sub prepare {
     my $force = $self->{opts}->{force} // 0;
     my $need_activate = [];
 
-    PVE::LXC::Config->foreach_mountpoint($conf, sub {
+    PVE::LXC::Config->foreach_volume($conf, sub {
 	my ($ms, $mountpoint) = @_;
 
 	my $volid = $mountpoint->{volume};
@@ -217,11 +217,11 @@ sub phase1 {
     foreach my $snapname (keys %{$conf->{snapshots}}) {
 	&$test_volid($conf->{snapshots}->{$snapname}->{'vmstate'}, 0, undef)
 	    if defined($conf->{snapshots}->{$snapname}->{'vmstate'});
-	PVE::LXC::Config->foreach_mountpoint($conf->{snapshots}->{$snapname}, $test_mp, $snapname);
+	PVE::LXC::Config->foreach_volume($conf->{snapshots}->{$snapname}, $test_mp, $snapname);
     }
 
     # finally all currently used volumes
-    PVE::LXC::Config->foreach_mountpoint($conf, $test_mp);
+    PVE::LXC::Config->foreach_volume($conf, $test_mp);
 
 
     # additional checks for local storage
diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index 25a50d1..5bda472 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -120,7 +120,7 @@ sub prepare {
     $task->{rootgid} = $rootgid;
 
     my $volids = $task->{volids} = [];
-    PVE::LXC::Config->foreach_mountpoint($conf, sub {
+    PVE::LXC::Config->foreach_volume($conf, sub {
 	my ($name, $data) = @_;
 	my $volid = $data->{volume};
 	my $mount = $data->{mp};
diff --git a/src/lxc-pve-prestart-hook b/src/lxc-pve-prestart-hook
index 1d62f3b..d4cadca 100755
--- a/src/lxc-pve-prestart-hook
+++ b/src/lxc-pve-prestart-hook
@@ -123,7 +123,7 @@ PVE::LXC::Tools::lxc_hook('pre-start', 'lxc', sub {
 	};
     }
 
-    PVE::LXC::Config->foreach_mountpoint($conf, $setup_mountpoint);
+    PVE::LXC::Config->foreach_volume($conf, $setup_mountpoint);
 
     my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir);
     $lxc_setup->pre_start_hook();
-- 
2.20.1





More information about the pve-devel mailing list