]> git.proxmox.com Git - qemu-server.git/commitdiff
add check for snapshots at migration
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 16 Jun 2016 08:21:57 +0000 (10:21 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 16 Jun 2016 08:21:57 +0000 (10:21 +0200)
We cannot migrate snapshots on local disks, for example lvmthin snapshots.

PVE/QemuMigrate.pm

index eb3ced0ea3424b2a6f89468f3fa4f522e4964e40..f0734cbb8bb25ba4b27ca7b4eebd9f9caeefbcb5 100644 (file)
@@ -248,9 +248,9 @@ sub sync_disks {
             });
         }
 
-       # and add used, owned/non-shared disks (just to be sure we have all)
+       my $snapname;
 
-       PVE::QemuServer::foreach_volid($conf, sub {
+       my $test_volid = sub {
            my ($volid, $is_cdrom) = @_;
 
            return if !$volid;
@@ -271,17 +271,37 @@ sub sync_disks {
 
            return if $scfg->{shared};
 
-           die "can't migrate local cdrom '$volid'\n" if $cdromhash->{$volid};
-
            $sharedvm = 0;
 
+           die "can't migrate local cdrom '$volid'\n" if $cdromhash->{$volid};
+
            my ($path, $owner) = PVE::Storage::path($self->{storecfg}, $volid);
 
            die "can't migrate volume '$volid' - owned by other VM (owner = VM $owner)\n"
                if !$owner || ($owner != $self->{vmid});
 
-           $volhash->{$volid} = 1;
-       });
+           if (defined($snapname)) {
+               # we cannot migrate shapshots on local storage
+               # exceptions: 'zfspool' or 'qcow2' files (on directory storage)
+
+               my $format = PVE::QemuServer::qemu_img_format($scfg, $volname);
+
+               if (($scfg->{type} eq 'zfspool') || ($format eq 'qcow2')) {
+                   $volhash->{$volid} = 1;
+                   return;
+               }
+
+               die "can't migrate snapshot of local volume '$volid'\n";
+
+           } else {
+               $volhash->{$volid} = 1;
+           }
+       };
+
+       PVE::QemuServer::foreach_volid($conf, $test_volid);
+       foreach $snapname (keys %{$conf->{snapshots}}) {
+           PVE::QemuServer::foreach_volid($conf->{snapshots}->{$snapname}, $test_volid);
+       }
 
        if ($self->{running} && !$sharedvm) {
            die "can't do online migration - VM uses local disks\n";