[pve-devel] [PATCH V3 qemu-server 3/3] add check for snapshots at migration

Wolfgang Link w.link at proxmox.com
Mon Jun 13 15:54:16 CEST 2016


This check ensure that no volume can have snapshots where we are not able to migrate it.
---
 PVE/QemuMigrate.pm |  9 ++++++++-
 PVE/QemuServer.pm  | 11 +++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index ef5d9e6..ddcfa44 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -226,6 +226,7 @@ sub sync_disks {
 
 	my $volhash = {};
 	my $cdromhash = {};
+	my $keyhash = {};
 
 	my $sharedvm = 1;
 
@@ -251,7 +252,7 @@ sub sync_disks {
 	# and add used, owned/non-shared disks (just to be sure we have all)
 
 	PVE::QemuServer::foreach_volid($conf, sub {
-	    my ($volid, $is_cdrom) = @_;
+	    my ($volid, $is_cdrom, $key) = @_;
 
 	    return if !$volid;
 
@@ -281,6 +282,7 @@ sub sync_disks {
 		if !$owner || ($owner != $self->{vmid});
 
 	    $volhash->{$volid} = 1;
+	    $keyhash->{$volid} = $key;
 	});
 
 	if ($self->{running} && !$sharedvm) {
@@ -301,6 +303,11 @@ sub sync_disks {
 		    #if a basename exists there must be a parent.
 		    my $basename = (PVE::Storage::parse_volname($self->{storecfg}, $volid))[3];
 		    die "can't migrate '$volid' as it's a clone of '$basename'" if $basename;
+
+		    #check if volume is used in snapshot
+		    die "Remove all snapshots before migrate.\n"
+			if PVE::QemuServer::is_volume_in_use($self->{storecfg}, $conf, $keyhash->{$volid}, $volid)
+			&&  $scfg->{type} eq 'lvmthin';
 		}
 	    }
 	}
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 666b756..de95306 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2661,18 +2661,20 @@ sub foreach_volid {
     my ($conf, $func) = @_;
 
     my $volhash = {};
+    my $keyhash = {};
 
     my $test_volid = sub {
-	my ($volid, $is_cdrom) = @_;
+	my ($volid, $is_cdrom, $key) = @_;
 
 	return if !$volid;
 
 	$volhash->{$volid} = $is_cdrom || 0;
+	$keyhash->{$volid} = $key;
     };
 
     foreach_drive($conf, sub {
 	my ($ds, $drive) = @_;
-	&$test_volid($drive->{file}, drive_is_cdrom($drive));
+	&$test_volid($drive->{file}, drive_is_cdrom($drive), $ds);
     });
 
     foreach my $snapname (keys %{$conf->{snapshots}}) {
@@ -2680,12 +2682,13 @@ sub foreach_volid {
 	&$test_volid($snap->{vmstate}, 0);
 	foreach_drive($snap, sub {
 	    my ($ds, $drive) = @_;
-	    &$test_volid($drive->{file}, drive_is_cdrom($drive));
+
+	    &$test_volid($drive->{file}, drive_is_cdrom($drive), $ds);
         });
     }
 
     foreach my $volid (keys %$volhash) {
-	&$func($volid, $volhash->{$volid});
+	&$func($volid, $volhash->{$volid}, $keyhash->{$volid});
     }
 }
 
-- 
2.1.4





More information about the pve-devel mailing list