[pve-devel] [PATCH qemu-server] migrate: pass the with_snapshots parameter

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Jun 22 12:24:41 CEST 2017


---
Note that for qcow2/vmdk we enforce with_snapshots to 1 even if we don't
have any snapshots.
Currently this is required since we don't want to (and currently cannot)
trigger a "qcow2 => raw => qcow2" conversion during migration.
 PVE/QemuMigrate.pm | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index c749658..c1e2fe4 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -267,7 +267,7 @@ sub sync_disks {
 	    PVE::Storage::foreach_volid($dl, sub {
 		my ($volid, $sid, $volname) = @_;
 
-		$local_volumes->{$volid} = 'storage';
+		$local_volumes->{$volid}->{ref} = 'storage';
 	    });
 	}
 
@@ -275,7 +275,7 @@ sub sync_disks {
 	    my ($volid, $attr) = @_;
 
 	    if ($volid =~ m|^/|) {
-		$local_volumes->{$volid} = 'config';
+		$local_volumes->{$volid}->{ref} = 'config';
 		die "local file/device\n";
 	    }
 
@@ -305,7 +305,7 @@ sub sync_disks {
 
 	    $sharedvm = 0;
 
-	    $local_volumes->{$volid} = $attr->{referenced_in_config} ? 'config' : 'snapshot';
+	    $local_volumes->{$volid}->{ref} = $attr->{referenced_in_config} ? 'config' : 'snapshot';
 
 	    die "local cdrom image\n" if $attr->{cdrom};
 
@@ -314,11 +314,12 @@ sub sync_disks {
 	    die "owned by other VM (owner = VM $owner)\n"
 		if !$owner || ($owner != $self->{vmid});
 
+	    my $format = PVE::QemuServer::qemu_img_format($scfg, $volname);
+	    $local_volumes->{$volid}->{snapshots} = defined($snaprefs) || ($format =~ /^(?:qcow2|vmdk)$/);
 	    if (defined($snaprefs)) {
 		# we cannot migrate shapshots on local storage
 		# exceptions: 'zfspool' or 'qcow2' files (on directory storage)
 
-		my $format = PVE::QemuServer::qemu_img_format($scfg, $volname);
 		die "online storage migration not possible if snapshot exists\n" if $self->{running};
 		if (!($scfg->{type} eq 'zfspool' || $format eq 'qcow2')) {
 		    die "non-migratable snapshot exists\n";
@@ -338,13 +339,14 @@ sub sync_disks {
         });
 
 	foreach my $vol (sort keys %$local_volumes) {
-	    if ($local_volumes->{$vol} eq 'storage') {
+	    my $ref = $local_volumes->{$vol}->{ref};
+	    if ($ref eq 'storage') {
 		$self->log('info', "found local disk '$vol' (via storage)\n");
-	    } elsif ($local_volumes->{$vol} eq 'config') {
+	    } elsif ($ref eq 'config') {
 		&$log_error("can't live migrate attached local disks without with-local-disks option\n", $vol)
 		    if $self->{running} && !$self->{opts}->{"with-local-disks"};
 		$self->log('info', "found local disk '$vol' (in current VM config)\n");
-	    } elsif ($local_volumes->{$vol} eq 'snapshot') {
+	    } elsif ($ref eq 'snapshot') {
 		$self->log('info', "found local disk '$vol' (referenced by snapshot(s))\n");
 	    } else {
 		$self->log('info', "found local disk '$vol'\n");
@@ -399,14 +401,15 @@ sub sync_disks {
 
 	foreach my $volid (keys %$local_volumes) {
 	    my ($sid, $volname) = PVE::Storage::parse_volume_id($volid);
-	    if ($self->{running} && $self->{opts}->{targetstorage} && $local_volumes->{$volid} eq 'config') {
+	    if ($self->{running} && $self->{opts}->{targetstorage} && $local_volumes->{$volid}->{ref} eq 'config') {
 		push @{$self->{online_local_volumes}}, $volid;
 	    } else {
 		next if $rep_volumes->{$volid};
 		push @{$self->{volumes}}, $volid;
 		my $insecure = $self->{opts}->{migration_type} eq 'insecure';
+		my $with_snapshots = $local_volumes->{$volid}->{snapshots};
 		PVE::Storage::storage_migrate($self->{storecfg}, $volid, $self->{ssh_info}, $sid,
-					      undef, undef, undef, undef, $insecure);
+					      undef, undef, undef, undef, $insecure, $with_snapshots);
 	    }
 	}
     };
-- 
2.11.0





More information about the pve-devel mailing list