]> 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 608653ded0cb61b3f8e7f2daf6673894152ee586..3156b6cbca5eb895a6fd64eb95720464a5431596 100644 (file)
@@ -237,7 +237,7 @@ my $rootfs_desc = {
     },
     ro => {
        type => 'boolean',
-       description => 'Read-only mountpoint',
+       description => 'Read-only mount point',
        optional => 1,
     },
     quota => {
@@ -245,6 +245,19 @@ 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\')',
+       verbose_description => "Mark this non-volume mount point as available on all nodes.\n\nWARNING: This option does not share the mount point automatically, it assumes it is shared already!",
+       optional => 1,
+       default => 0,
+    },
 };
 
 PVE::JSONSchema::register_standard_option('pve-ct-rootfs', {
@@ -432,8 +445,9 @@ my $valid_lxc_conf_keys = {
     'lxc.rootfs' => 'lxc.rootfs is auto generated from rootfs',
     'lxc.rootfs.mount' => 1,
     'lxc.rootfs.options' => 'lxc.rootfs.options is not supported' .
-                            ', please use mountpoint options in the "rootfs" key',
+                            ', 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,
@@ -578,18 +592,18 @@ my $mp_desc = {
     %$rootfs_desc,
     backup => {
        type => 'boolean',
-       description => 'Whether to include the mountpoint in backups.',
-       verbose_description => 'Whether to include the mountpoint in backups '.
-                              '(only used for volume mountpoints).',
+       description => 'Whether to include the mount point in backups.',
+       verbose_description => 'Whether to include the mount point in backups '.
+                              '(only used for volume mount points).',
        optional => 1,
     },
     mp => {
        type => 'string',
        format => 'pve-lxc-mp-string',
        format_description => 'Path',
-       description => 'Path to the mountpoint as seen from inside the container '.
+       description => 'Path to the mount point as seen from inside the container '.
                       '(must not contain symlinks).',
-       verbose_description => "Path to the mountpoint as seen from inside the container.\n\n".
+       verbose_description => "Path to the mount point as seen from inside the container.\n\n".
                               "NOTE: Must not contain any symlinks for security reasons."
     },
 };
@@ -654,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";
@@ -769,7 +783,7 @@ sub update_pct_config {
     if (defined($delete)) {
        foreach my $opt (@$delete) {
            if (!exists($conf->{$opt})) {
-               warn "no such option: $opt\n";
+               # silently ignore
                next;
            }
 
@@ -861,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};
     };
@@ -957,6 +972,7 @@ sub update_pct_config {
        } else {
            die "implement me: $opt";
        }
+
        PVE::LXC::Config->write_config($vmid, $conf) if $running;
     }
 
@@ -1230,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;