[pve-devel] [PATCH container] refuse to add non-replicatable disks to replicating VMs

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Jun 26 16:00:14 CEST 2017


Unless replication is explicitly disabled for them.

Unfortunately for new disks we can only do this after it has
been created due to the volume_has_feature() interface
requiring a volume name.
---
 src/PVE/LXC.pm | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 8d91b22..ea597e4 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1336,6 +1336,18 @@ sub create_disks {
 
     my $vollist = [];
 
+    my $repl_conf = PVE::ReplicationConfig->new();
+    my $is_replicated = $repl_conf->check_for_existing_jobs($vmid, 1);
+    my $check_replication = sub {
+	my ($mp) = @_;
+	return if !$is_replicated;
+	return if !($mp->{replicate}//1);
+	die "cannot add non-replicatable volume to a replicated CT\n"
+	    if $mp->{type} ne 'volume' ||
+	       !PVE::Storage::volume_has_feature($storecfg, 'replicate', $mp->{volume});
+    };
+
+
     eval {
 	my (undef, $rootuid, $rootgid) = PVE::LXC::parse_id_maps($conf);
 	my $chown_vollist = [];
@@ -1387,9 +1399,11 @@ sub create_disks {
 		push @$vollist, $volid;
 		$mountpoint->{volume} = $volid;
 		$mountpoint->{size} = $size_kb * 1024;
+		$check_replication->($mountpoint);
 		$conf->{$ms} = PVE::LXC::Config->print_ct_mountpoint($mountpoint, $ms eq 'rootfs');
 	    } else {
                 # use specified/existing volid/dir/device
+		$check_replication->($mountpoint);
                 $conf->{$ms} = PVE::LXC::Config->print_ct_mountpoint($mountpoint, $ms eq 'rootfs');
 	    }
 	});
-- 
2.11.0





More information about the pve-devel mailing list