[pve-devel] [PATCH storage 2/2] migrate: replace target ip parameter with sshinfo parameter
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue May 23 09:04:47 CEST 2017
---
PVE/API2/Storage/Content.pm | 3 ++-
PVE/Storage.pm | 28 ++++++++++++----------------
2 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/PVE/API2/Storage/Content.pm b/PVE/API2/Storage/Content.pm
index 20c2eda..3449e35 100644
--- a/PVE/API2/Storage/Content.pm
+++ b/PVE/API2/Storage/Content.pm
@@ -359,7 +359,8 @@ __PACKAGE__->register_method ({
# you need to get this working (fails currently, because storage_migrate() uses
# ssh to connect to local host (which is not needed
- PVE::Storage::storage_migrate($cfg, $src_volid, $target_node, $target_sid, $target_volname);
+ my $sshinfo = PVE::Cluster::get_ssh_info($target_node);
+ PVE::Storage::storage_migrate($cfg, $src_volid, $sshinfo, $target_sid, $target_volname);
print "DEBUG: end worker $upid\n";
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 73f2976..2be0230 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -525,7 +525,7 @@ sub abs_filesystem_path {
}
sub storage_migrate {
- my ($cfg, $volid, $target_host, $target_storeid, $target_volname, $base_snapshot, $snapshot) = @_;
+ my ($cfg, $volid, $target_sshinfo, $target_storeid, $target_volname, $base_snapshot, $snapshot) = @_;
my ($storeid, $volname) = parse_volume_id($volid);
$target_volname = $volname if !$target_volname;
@@ -539,12 +539,11 @@ sub storage_migrate {
my $target_volid = "${target_storeid}:${target_volname}";
+ my $target_host = $target_sshinfo->{name};
my $errstr = "unable to migrate '$volid' to '${target_volid}' on host '$target_host'";
- my $sshoptions = "-o 'BatchMode=yes'";
- my $ssh = "/usr/bin/ssh $sshoptions";
-
- local $ENV{RSYNC_RSH} = $ssh;
+ my $ssh = PVE::Cluster::ssh_info_to_command($target_sshinfo);
+ local $ENV{RSYNC_RSH} = PVE::Tools::cmd2string($ssh);
my $no_incremental = sub {
my ($type) = @_;
@@ -578,16 +577,14 @@ sub storage_migrate {
run_command(['/bin/cp', $src, $dst]);
} else {
- run_command(['/usr/bin/ssh', "root\@${target_host}",
- '/bin/mkdir', '-p', $dirname]);
+ run_command([@$ssh, '/bin/mkdir', '-p', $dirname]);
# we use rsync with --sparse, so we can't use --inplace,
# so we remove file on the target if it already exists to
# save space
my ($size, $format) = PVE::Storage::Plugin::file_size_info($src);
if ($format && ($format eq 'raw') && $size) {
- run_command(['/usr/bin/ssh', "root\@${target_host}",
- 'rm', '-f', $dst],
+ run_command([@$ssh, 'rm', '-f', $dst],
outfunc => sub {});
}
@@ -639,8 +636,8 @@ sub storage_migrate {
my $format = $formats[0];
my $send = ['pvesm', 'export', $volid, $format, '-', '-snapshot', $snapname, '-with-snapshots', '1'];
- my $recv = ['ssh', "root\@$target_host", '--', 'pvesm', 'import', $volid, $format, '-', '-with-snapshots', '1'];
- my $free = ['ssh', "root\@$target_host", '--', 'pvesm', 'free', $volid, '-snapshot', $snapname]
+ my $recv = [@$ssh, '--', 'pvesm', 'import', $volid, $format, '-', '-with-snapshots', '1'];
+ my $free = [@$ssh, '--', 'pvesm', 'free', $volid, '-snapshot', $snapname]
if !defined($snapshot);
if (defined($base_snapshot)) {
@@ -678,22 +675,21 @@ sub storage_migrate {
my $src = path($cfg, $volid);
my $dst = path($cfg, $target_volid);
- run_command(['/usr/bin/ssh', "root\@${target_host}",
+ run_command([@$ssh, '--',
'pvesm', 'alloc', $target_storeid, $vmid,
$target_volname, int($size/1024)]);
eval {
if ($tcfg->{type} eq 'lvmthin') {
- run_command([["dd", "if=$src", "bs=4k"],["/usr/bin/ssh", "root\@${target_host}",
+ run_command([["dd", "if=$src", "bs=4k"],[@$ssh,
"dd", 'conv=sparse', "of=$dst", "bs=4k"]]);
} else {
- run_command([["dd", "if=$src", "bs=4k"],["/usr/bin/ssh", "root\@${target_host}",
+ run_command([["dd", "if=$src", "bs=4k"],[@$ssh,
"dd", "of=$dst", "bs=4k"]]);
}
};
if (my $err = $@) {
- run_command(['/usr/bin/ssh', "root\@${target_host}",
- 'pvesm', 'free', $target_volid]);
+ run_command([@$ssh, 'pvesm', 'free', $target_volid]);
die $err;
}
} else {
--
2.11.0
More information about the pve-devel
mailing list