]> git.proxmox.com Git - pve-container.git/commitdiff
refuse to add non-replicatable disks to replicating VMs
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 27 Jun 2017 09:51:10 +0000 (11:51 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 27 Jun 2017 10:17:33 +0000 (12:17 +0200)
Unless replication is explicitly disabled for them.

src/PVE/API2/LXC/Config.pm
src/PVE/LXC.pm

index e3909a3bb885962eb2f3a5da4456619b5a8130ed..fc027d7ffdc6bd0712943ca51f122f16cc571022 100644 (file)
@@ -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);
index 8d91b228a8ae5b3014dccf15316ee8a88b7a14a6..3beba8cfe5ff53bf3283387e04c0f99451d5a508 100644 (file)
@@ -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;