]> git.proxmox.com Git - pve-container.git/commitdiff
Use foreach_volume instead of foreach_mountpoint-variants
authorFabian Ebner <f.ebner@proxmox.com>
Wed, 8 Apr 2020 09:24:57 +0000 (11:24 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 8 Apr 2020 20:44:12 +0000 (22:44 +0200)
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
src/PVE/API2/LXC.pm
src/PVE/API2/LXC/Config.pm
src/PVE/API2/LXC/Status.pm
src/PVE/CLI/pct.pm
src/PVE/LXC.pm
src/PVE/LXC/Config.pm
src/PVE/LXC/Create.pm
src/PVE/LXC/Migrate.pm
src/PVE/VZDump/LXC.pm
src/lxc-pve-prestart-hook

index f4c1a49fa795417ae18f34d8188c6699d5dda4d2..58f38f88cbb801fb5a6c59fc2756c4359aadf490 100644 (file)
@@ -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') {
index 08791721d8a7f6632079e45105b694418b5c1537..42e16d17f8e1adb37838130636e0228e7739a573 100644 (file)
@@ -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);
index 41f1f4ff9529b75c17d860f7778e1ac1901c1218..03d13a3db6839c8ee6e1d952469fc128416fc514 100644 (file)
@@ -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};
                    });
index 95c6921d16f4c66b1ebe57f7361b5cdc3d0534b7..33f564fd0ffb71c1a77c81808eae235ac7d4c199 100755 (executable)
@@ -379,7 +379,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};
 
@@ -783,7 +783,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"];
index b4ffc9bdc5508c3f058db6330b2bf0971b7c09c3..06524ef6547af357404074aa3947cc956695db05 100644 (file)
@@ -832,7 +832,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});
     });
@@ -1163,7 +1163,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};
@@ -1172,7 +1172,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};
@@ -1237,7 +1237,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};
@@ -1278,7 +1278,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;
@@ -1885,7 +1885,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};
@@ -1949,7 +1949,7 @@ sub update_disksize {
        }
     };
 
-    PVE::LXC::Config->foreach_mountpoint($conf, $update_mp);
+    PVE::LXC::Config->foreach_volume($conf, $update_mp);
 
     return $changes;
 }
index 70aee5a984a021af924abc59e741fa47ede5c46d..e613e78e0a3a6cdbc68855f965ad4f3bd7f1eccc 100644 (file)
@@ -67,7 +67,7 @@ sub has_feature {
        $opts = {'valid_target_formats' => ['raw', 'subvol']};
     }
 
-    $class->foreach_mountpoint($conf, sub {
+    $class->foreach_volume($conf, sub {
        my ($ms, $mountpoint) = @_;
 
        return if $err; # skip further test
@@ -1395,7 +1395,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;
@@ -1467,37 +1467,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;
@@ -1555,14 +1530,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);
         });
index 9faec63d4801533654a6c665363423e5bc479082..52b0b4882eae18461e81c8e65a5b6884d405a4be 100644 (file)
@@ -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};
        });
index 6c1e9c18542e0ae266992ef4dbed452450069e7b..638ce1f9cfaf86bd3de5c35b5acfb4715d87c266 100644 (file)
@@ -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
index 09c4d470a13ac443d72edffd01750e377f2d36d2..2d003d0f45cf7fb04a92682cfc6b416aa5817195 100644 (file)
@@ -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};
index 66569f99ba728739d36625fa7c65282db1bbe3f0..ed25aa4170931323bc081ec44e30258b893f3059 100755 (executable)
@@ -125,7 +125,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();