migrate: implement rate limiting

Note that it does not apply to the local 'mkdir && cp' case.
This commit is contained in:
Wolfgang Bumiller
2017-05-29 15:16:58 +02:00
committed by Dietmar Maurer
parent 9dc3d2ff40
commit 01f7e902e9

View File

@ -525,7 +525,7 @@ sub abs_filesystem_path {
}
sub storage_migrate {
my ($cfg, $volid, $target_sshinfo, $target_storeid, $target_volname, $base_snapshot, $snapshot) = @_;
my ($cfg, $volid, $target_sshinfo, $target_storeid, $target_volname, $base_snapshot, $snapshot, $ratelimit_bps) = @_;
my ($storeid, $volname) = parse_volume_id($volid);
$target_volname = $volname if !$target_volname;
@ -557,6 +557,9 @@ sub storage_migrate {
if defined($snapshot);
};
my @cstream = ([ '/usr/bin/cstream', '-t', $ratelimit_bps ])
if defined($ratelimit_bps);
# only implemented for file system based storage
if ($scfg->{path}) {
$no_incremental->($scfg->{type});
@ -589,12 +592,15 @@ sub storage_migrate {
}
my $cmd;
my @bwlimit = ("--bwlimit=${ratelimit_bps}b") if defined($ratelimit_bps);
if ($format eq 'subvol') {
$cmd = ['/usr/bin/rsync', '--progress', '-X', '-A', '--numeric-ids',
'-aH', '--delete', '--no-whole-file', '--inplace',
'--one-file-system', "$src/", "[root\@${target_host}]:$dst"];
'--one-file-system', @bwlimit,
"$src/", "[root\@${target_host}]:$dst"];
} else {
$cmd = ['/usr/bin/rsync', '--progress', '--sparse', '--whole-file',
@bwlimit,
$src, "[root\@${target_host}]:$dst"];
}
@ -653,7 +659,7 @@ sub storage_migrate {
volume_snapshot($cfg, $volid, $snapshot) if $migration_snapshot;
eval {
run_command([$send, $recv]);
run_command([$send, @cstream, $recv]);
};
my $err = $@;
warn "send/receive failed, cleaning up snapshot(s)..\n" if $err;
@ -684,11 +690,11 @@ sub storage_migrate {
eval {
if ($tcfg->{type} eq 'lvmthin') {
run_command([["dd", "if=$src", "bs=4k"],[@$ssh,
"dd", 'conv=sparse', "of=$dst", "bs=4k"]]);
run_command([["dd", "if=$src", "bs=4k"], @cstream,
[@$ssh, "dd", 'conv=sparse', "of=$dst", "bs=4k"]]);
} else {
run_command([["dd", "if=$src", "bs=4k"],[@$ssh,
"dd", "of=$dst", "bs=4k"]]);
run_command([["dd", "if=$src", "bs=4k"], @cstream,
[@$ssh, "dd", "of=$dst", "bs=4k"]]);
}
};
if (my $err = $@) {