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

Wolfgang Bumiller w.bumiller at proxmox.com
Tue Jun 27 11:51:10 CEST 2017


Unless replication is explicitly disabled for them.
---
Changes to v2:
  * take the mount point type into account (again)

 src/PVE/API2/LXC/Config.pm | 22 ++++++++++++++++++++++
 src/PVE/LXC.pm             |  3 ++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/PVE/API2/LXC/Config.pm b/src/PVE/API2/LXC/Config.pm
index e3909a3..fc027d7 100644
--- a/src/PVE/API2/LXC/Config.pm
+++ b/src/PVE/API2/LXC/Config.pm
@@ -128,6 +128,28 @@ __PACKAGE__->register_method({
 
 	my $storage_cfg = cfs_read_file("storage.cfg");
 
+	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 {
+		my ($opt, $mountpoint) = @_;
+		my $volid = $mountpoint->{volume};
+		return if !$volid || !($mountpoint->{replicate}//1);
+		if ($mountpoint->{type} eq 'volume') {
+		    my ($storeid, $format);
+		    if ($volid =~ $PVE::LXC::NEW_DISK_RE) {
+			$storeid = $1;
+			$format = $mountpoint->{format} || PVE::Storage::storage_default_format($storage_cfg, $storeid);
+		    } else {
+			($storeid, undef) = PVE::Storage::parse_volume_id($volid, 1);
+			$format = (PVE::Storage::parse_volname($storage_cfg, $volid))[6];
+		    }
+		    return if PVE::Storage::storage_can_replicate($storage_cfg, $storeid, $format);
+		}
+		die "cannot add non-replicatable volume to a replicated VM\n";
+	    });
+	}
+
 	my $code = sub {
 
 	    my $conf = PVE::LXC::Config->load_config($vmid);
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 8d91b22..3beba8c 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1331,6 +1331,7 @@ sub destroy_disks {
     }
 }
 
+our $NEW_DISK_RE = qr/^([^:\s]+):(\d+(\.\d+)?)$/;
 sub create_disks {
     my ($storecfg, $vmid, $settings, $conf) = @_;
 
@@ -1348,7 +1349,7 @@ sub create_disks {
 
 	    my ($storage, $volname) = PVE::Storage::parse_volume_id($volid, 1);
 
-	    if ($storage && ($volid =~ m/^([^:\s]+):(\d+(\.\d+)?)$/)) {
+	    if ($storage && ($volid =~ $NEW_DISK_RE)) {
 		my ($storeid, $size_gb) = ($1, $2);
 
 		my $size_kb = int(${size_gb}*1024) * 1024;
-- 
2.11.0





More information about the pve-devel mailing list