]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/LXC/Config.pm
use full module path for storage_config
[pve-container.git] / src / PVE / LXC / Config.pm
index c0a2861411ad2b77d7cba75392c0115aa264a333..e76d55888c097afff8051febb8d47fa4a3b50bda 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\')',
@@ -869,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};
     };
@@ -965,6 +972,7 @@ sub update_pct_config {
        } else {
            die "implement me: $opt";
        }
+
        PVE::LXC::Config->write_config($vmid, $conf) if $running;
     }
 
@@ -1238,4 +1246,62 @@ 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;
+
+       my $mptype = $mountpoint->{type};
+       die "unable to replicate mountpoint type '$mptype'\n"
+           if $mptype ne 'volume';
+
+       my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, $noerr);
+       return if !$storeid;
+
+       my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+       return if $scfg->{shared};
+
+       my ($path, $owner, $vtype) = PVE::Storage::path($storecfg, $volid);
+       return if !$owner || ($owner != $vmid);
+
+       die "unable to replicate volume '$volid', type '$vtype'\n" if $vtype ne 'images';
+
+       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);
+        });
+    }
+
+    # add 'unusedX' volumes to volhash
+    foreach my $key (keys %$conf) {
+       if ($key =~ m/^unused/) {
+           $test_volid->($conf->{$key}, { type => 'volume', replicate => 1 });
+       }
+    }
+
+    return $volhash;
+}
+
+1;