[pve-devel] [PATCH storage 3/6] migrate: use pvesm import/export for zfs

Wolfgang Bumiller w.bumiller at proxmox.com
Thu May 11 09:36:17 CEST 2017


The only leftover zfs specific part here is the zfs format
type parameter.
---
 PVE/Storage.pm | 33 ++++++++-------------------------
 1 file changed, 8 insertions(+), 25 deletions(-)

diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 75ebdde..08e9ffd 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -650,40 +650,23 @@ sub storage_migrate {
 		if $tcfg->{pool} ne $scfg->{pool};
 
 	    my (undef, $volname) = parse_volname($cfg, $volid);
-
 	    my $zfspath = "$scfg->{pool}\/$volname";
 
-	    my $snap = ['zfs', 'snapshot', "$zfspath\@__migration__"];
-	    my $send = ['zfs', 'send', '-Rpv'];
-	    my $rec = ['ssh', "root\@$target_host", 'zfs', 'recv','-F' ,$zfspath];
-
-	    if (my $snapname = PVE::ReplicationTools::get_last_replica_snap($volid)) {
-
-		#check if target snapshot exists.
-		my $checksnap = ['/usr/bin/ssh', "root\@${target_host}", "-o",
-		    'BatchMode=yes', 'zfs', 'list', '-Hrt', 'snap',
-		    "$zfspath\@$snapname "];
-		eval {
-		    run_command($checksnap);
-		    push @$send, '-I', "$zfspath\@$snapname";
-		};
+	    my $send = ['pvesm', 'export', $volid, 'zfs', '-', '-snapshot', '__migration__', '-with-snapshots', '1'];
+	    my $recv = ['ssh', "root\@$target_host", '--', 'pvesm', 'import', $volid, 'zfs', '-', '-with-snapshots', '1'];
+	    my $cleanup_target = ['ssh', "root\@$target_host", '--', 'pvesm', 'delsnapshot', $volid, '__migration__'];
 
-	    }
-	    push @$send, "--", "$zfspath\@__migration__";
-
-	    my $destroy_target = ['ssh', "root\@$target_host", 'zfs', 'destroy', "$zfspath\@__migration__"];
- 	    run_command($snap);
+	    volume_snapshot($cfg, $volid, '__migration__');
 	    eval{
-		run_command([$send,$rec]);
+		run_command([$send, $recv]);
 	    };
 	    my $err = $@;
-	    warn "zfs send/receive failed, cleaning up snapshot(s)..\n" if $err;
-	    eval { run_command(['zfs', 'destroy', "$zfspath\@__migration__"]); };
+	    warn "send/receive failed, cleaning up snapshot(s)..\n" if $err;
+	    eval { volume_snapshot_delete($cfg, $volid, '__migration__', 0) };
 	    warn "could not remove source snapshot: $@\n" if $@;
-	    eval { run_command($destroy_target); };
+	    eval { run_command($cleanup_target); };
 	    warn "could not remove target snapshot: $@\n" if $@;
 	    die $err if $err;
-
  	} else {
  	    die "$errstr - target type $tcfg->{type} is not valid\n";
  	}
-- 
2.11.0





More information about the pve-devel mailing list