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

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Jun 26 16:00:01 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.
---
 PVE/API2/Qemu.pm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 76fd0e4..28dd366 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -122,6 +122,16 @@ my $create_disks = sub {
 
     my $res = {};
 
+    my $repl_conf = PVE::ReplicationConfig->new();
+    my $is_replicated = $repl_conf->check_for_existing_jobs($vmid, 1);
+    my $check_replication = sub {
+	my ($disk, $volid) = @_;
+	return if !$is_replicated;
+	return if !($disk->{replicate}//1);
+	die "cannot add non-replicatable volume to a replicated VM\n"
+	    if !PVE::Storage::volume_has_feature($storecfg, 'replicate', $volid);
+    };
+
     my $code = sub {
 	my ($ds, $disk) = @_;
 
@@ -166,10 +176,12 @@ my $create_disks = sub {
 	    }
 	    push @$vollist, $volid;
 	    delete $disk->{format}; # no longer needed
+	    $check_replication->($disk, $volid);
 	    $res->{$ds} = PVE::QemuServer::print_drive($vmid, $disk);
 	} else {
 
 	    PVE::Storage::check_volume_access($rpcenv, $authuser, $storecfg, $vmid, $volid);
+	    $check_replication->($disk, $volid);
 
 	    my $volid_is_new = 1;
 
-- 
2.11.0





More information about the pve-devel mailing list