]> git.proxmox.com Git - pve-storage.git/commitdiff
migrate: cleanup & fixup
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 23 May 2017 10:30:19 +0000 (12:30 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 23 May 2017 11:30:51 +0000 (13:30 +0200)
The volume_snapshot call was missing the condition when to
create a snapshot. Make the whole logic easier to follow
with a $migration_snapshot boolean.
Also get rid of the remote `pvesm free -snapshot` call by
using import's new -delete-snapshot parameter.

PVE/Storage.pm

index 80aa7f275622358a122864285dc4a480d9844d33..ee2295a477914c3b9e2de33f5dbf2f9a6e4004fb 100755 (executable)
@@ -626,19 +626,24 @@ sub storage_migrate {
            die "$errstr - pool on target does not have the same name as on source!"
                if $tcfg->{pool} ne $scfg->{pool};
 
-           my $snapname = $snapshot // '__migration__';
+           my $migration_snapshot;
+           if (!defined($snapshot)) {
+               $migration_snapshot = 1;
+               $snapshot = '__migration__';
+           }
 
            my (undef, $volname) = parse_volname($cfg, $volid);
            my $zfspath = "$scfg->{pool}\/$volname";
 
-           my @formats = volume_transfer_formats($cfg, $volid, $volid, $snapname, $base_snapshot, 1);
+           my @formats = volume_transfer_formats($cfg, $volid, $volid, $snapshot, $base_snapshot, 1);
            die "cannot migrate from storage type '$scfg->{type}' to '$tcfg->{type}'\n" if !@formats;
            my $format = $formats[0];
 
-           my $send = ['pvesm', 'export', $volid, $format, '-', '-snapshot', $snapname, '-with-snapshots', '1'];
+           my $send = ['pvesm', 'export', $volid, $format, '-', '-snapshot', $snapshot, '-with-snapshots', '1'];
            my $recv = [@$ssh, '--', 'pvesm', 'import', $volid, $format, '-', '-with-snapshots', '1'];
-           my $free = [@$ssh, '--', 'pvesm', 'free', $volid, '-snapshot', $snapname]
-               if !defined($snapshot);
+           if ($migration_snapshot) {
+               push @$recv, '-delete-snapshot', $snapshot;
+           }
 
            if (defined($base_snapshot)) {
                # Check if the snapshot exists on the remote side:
@@ -646,17 +651,15 @@ sub storage_migrate {
                push @$recv, '-base', $base_snapshot;
            }
 
-           volume_snapshot($cfg, $volid, $snapname);
+           volume_snapshot($cfg, $volid, $snapshot) if $migration_snapshot;
            eval {
                run_command([$send, $recv]);
            };
            my $err = $@;
            warn "send/receive failed, cleaning up snapshot(s)..\n" if $err;
-           if (!defined($snapshot)) {
-               eval { volume_snapshot_delete($cfg, $volid, $snapname, 0) };
+           if ($migration_snapshot) {
+               eval { volume_snapshot_delete($cfg, $volid, $snapshot, 0) };
                warn "could not remove source snapshot: $@\n" if $@;
-               eval { run_command($free) };
-               warn "could not remove target snapshot: $@\n" if $@;
            }
            die $err if $err;
        } else {