]> git.proxmox.com Git - pve-guest-common.git/blobdiff - PVE/AbstractConfig.pm
call get_replicatable_volumes with $vmid parameter
[pve-guest-common.git] / PVE / AbstractConfig.pm
index 482f0e28c8bd99333da83e054ce5bd4631c30fa1..64d19e4c75ff32ff4e447206728dc68cfb88a6b6 100644 (file)
@@ -8,6 +8,9 @@ use PVE::INotify;
 use PVE::Cluster;
 use PVE::Storage;
 
+use PVE::ReplicationConfig;
+use PVE::Replication;
+
 my $nodename = PVE::INotify::nodename();
 
 # Printable string, currently either "VM" or "CT"
@@ -192,6 +195,15 @@ sub has_feature {
     die "implement me - abstract method\n";
 }
 
+# get all replicatable volume (hash $res->{$volid} = 1)
+# $cleanup: for cleanup - simply ignores volumes without replicate feature
+# $norerr: never raise exceptions - return undef instead
+sub get_replicatable_volumes {
+    my ($class, $storecfg, $vmid, $conf, $cleanup, $noerr) = @_;
+
+    die "implement me - abstract method\n";
+}
+
 # Internal snapshots
 
 # NOTE: Snapshot create/delete involves several non-atomic
@@ -332,6 +344,7 @@ sub __snapshot_apply_config {
     # keep description and list of unused disks
     foreach my $k (keys %$conf) {
        next if !($k =~ m/^unused\d+$/ || $k eq 'description');
+
        $newconf->{$k} = $conf->{$k};
     }
 
@@ -582,6 +595,17 @@ sub snapshot_rollback {
        return $res;
     };
 
+    my $repl_conf = PVE::ReplicationConfig->new();
+    if ($repl_conf->check_for_existing_jobs($vmid, 1)) {
+       # remove all replication snapshots
+       my $volumes = $class->get_replicatable_volumes($storecfg, $vmid, $conf, 1);
+       my $sorted_volids = [ sort keys %$volumes ];
+
+       # remove all local replication snapshots (jobid => undef)
+       my $logfunc = sub { my $line = shift; chomp $line; print "$line\n"; };
+       PVE::Replication::prepare($storecfg, $sorted_volids, undef, 0, undef, $logfunc);
+    }
+    
     my $snap = &$get_snapshot_config();
 
     $class->__snapshot_foreach_volume($snap, sub {