]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/LXC/Config.pm
get_replicatable_volumes: pass $vmid parameter
[pve-container.git] / src / PVE / LXC / Config.pm
index 05cd970db6b352fcbf48bbbadf2c0ff609bdbc86..3156b6cbca5eb895a6fd64eb95720464a5431596 100644 (file)
@@ -245,6 +245,12 @@ my $rootfs_desc = {
        description => 'Enable user quotas inside the container (not supported with zfs subvolumes)',
        optional => 1,
     },
+    replicate => {
+       type => 'boolean',
+       description => 'Will include this volume to a storage replica job.',
+       optional => 1,
+       default => 1,
+    },
     shared => {
        type => 'boolean',
        description => 'Mark this non-volume mount point as available on multiple nodes (see \'nodes\')',
@@ -441,6 +447,7 @@ my $valid_lxc_conf_keys = {
     'lxc.rootfs.options' => 'lxc.rootfs.options is not supported' .
                             ', please use mount point options in the "rootfs" key',
     # lxc.cgroup.*
+    # lxc.limit.*
     'lxc.cap.drop' => 1,
     'lxc.cap.keep' => 1,
     'lxc.aa_profile' => 1,
@@ -661,7 +668,7 @@ sub parse_pct_config {
            my $key = $1;
            my $value = $3;
            my $validity = $valid_lxc_conf_keys->{$key} || 0;
-           if ($validity eq 1 || $key =~ m/^lxc\.cgroup\./) {
+           if ($validity eq 1 || $key =~ m/^lxc\.(?:cgroup|limit)\./) {
                push @{$conf->{lxc}}, [$key, $value];
            } elsif (my $errmsg = $validity) {
                warn "vm $vmid - $key: $errmsg\n";
@@ -868,12 +875,13 @@ sub update_pct_config {
        PVE::LXC::Config->write_config($vmid, $conf) if $running;
     }
 
+    my $storecfg = PVE::Storage::config();
+
     my $used_volids = {};
     my $check_content_type = sub {
        my ($mp) = @_;
        my $sid = PVE::Storage::parse_volume_id($mp->{volume});
-       my $scfg = PVE::Storage::config();
-       my $storage_config = PVE::Storage::storage_config($scfg, $sid);
+       my $storage_config = PVE::Storage::storage_config($storecfg, $sid);
        die "storage '$sid' does not allow content type 'rootdir' (Container)\n"
            if !$storage_config->{content}->{rootdir};
     };
@@ -964,6 +972,7 @@ sub update_pct_config {
        } else {
            die "implement me: $opt";
        }
+
        PVE::LXC::Config->write_config($vmid, $conf) if $running;
     }
 
@@ -1237,4 +1246,40 @@ sub get_vm_volumes {
     return $vollist;
 }
 
-return 1;
+sub get_replicatable_volumes {
+    my ($class, $storecfg, $vmid, $conf, $cleanup, $noerr) = @_;
+
+    my $volhash = {};
+
+    my $test_volid = sub {
+       my ($volid, $mountpoint) = @_;
+
+       return if !$volid;
+
+       return if !$cleanup && defined($mountpoint->{replicate}) && !$mountpoint->{replicate};
+
+       if (!PVE::Storage::volume_has_feature($storecfg, 'replicate', $volid)) {
+           return if $cleanup || $noerr;
+           die "missing replicate feature on volume '$volid'\n";
+       }
+
+       $volhash->{$volid} = 1;
+    };
+
+    $class->foreach_mountpoint($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 {
+           my ($ms, $mountpoint) = @_;
+           $test_volid->($mountpoint->{volume}, $mountpoint);
+        });
+    }
+
+    return $volhash;
+}
+
+1;