From: Wolfgang Bumiller Date: Tue, 27 Jun 2017 09:51:10 +0000 (+0200) Subject: refuse to add non-replicatable disks to replicating VMs X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=2aee38e5ac637de60590b39611bf5d3a098c8e9f;p=pve-container.git refuse to add non-replicatable disks to replicating VMs Unless replication is explicitly disabled for them. --- 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;