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

Wolfgang Bumiller w.bumiller at proxmox.com
Tue Jun 27 11:38:55 CEST 2017


Unless replication is explicitly disabled for them.
---
Changes to v1: (same as on the qemu-server side)
  * Use new PVE::Storage::storage_can_replicate()
  * Do the check early in the API call instead of LXC::create_disks().

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

diff --git a/src/PVE/API2/LXC/Config.pm b/src/PVE/API2/LXC/Config.pm
index e3909a3..bf6b399 100644
--- a/src/PVE/API2/LXC/Config.pm
+++ b/src/PVE/API2/LXC/Config.pm
@@ -128,6 +128,26 @@ __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);
+		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