fix #3004: show progress of offline migration in task log
dd supports a 'status' flag, which enables it to show the copied bytes, duration, and the transfer rate, which then get printed to stderr. Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
This commit is contained in:
committed by
Thomas Lamprecht
parent
122ccde412
commit
aa82ad5c25
@ -821,12 +821,25 @@ sub storage_migrate {
|
|||||||
|
|
||||||
my $new_volid;
|
my $new_volid;
|
||||||
my $pattern = volume_imported_message(undef, 1);
|
my $pattern = volume_imported_message(undef, 1);
|
||||||
|
# Matches new volid and rate-limits dd output
|
||||||
my $match_volid_and_log = sub {
|
my $match_volid_and_log = sub {
|
||||||
my $line = shift;
|
my $line = shift;
|
||||||
|
my $show = 1;
|
||||||
|
|
||||||
|
# rate-limit dd logs
|
||||||
|
if ($line =~ /(?:\d+ bytes)(?:.+?copied, )(\d+) s/) {
|
||||||
|
if ($1 < 60) { # if < 60s, print every 3s
|
||||||
|
$show = !($1 % 3);
|
||||||
|
} elsif ($1 < 600) { # if < 10mins, print every 10s
|
||||||
|
$show = !($1 % 10);
|
||||||
|
} else { # else, print every 30s
|
||||||
|
$show = !($1 % 30);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$new_volid = $1 if ($line =~ $pattern);
|
$new_volid = $1 if ($line =~ $pattern);
|
||||||
|
|
||||||
if ($logfunc) {
|
if ($logfunc && $show) {
|
||||||
chomp($line);
|
chomp($line);
|
||||||
$logfunc->($line);
|
$logfunc->($line);
|
||||||
}
|
}
|
||||||
@ -855,7 +868,7 @@ sub storage_migrate {
|
|||||||
# we won't be reading from the socket
|
# we won't be reading from the socket
|
||||||
shutdown($socket, 0);
|
shutdown($socket, 0);
|
||||||
|
|
||||||
eval { run_command($cmds, output => '>&'.fileno($socket), errfunc => $logfunc); };
|
eval { run_command($cmds, output => '>&'.fileno($socket), errfunc => $match_volid_and_log); };
|
||||||
my $send_error = $@;
|
my $send_error = $@;
|
||||||
|
|
||||||
# don't close the connection entirely otherwise the receiving end
|
# don't close the connection entirely otherwise the receiving end
|
||||||
|
|||||||
@ -645,7 +645,7 @@ sub volume_export {
|
|||||||
$size = int($1);
|
$size = int($1);
|
||||||
});
|
});
|
||||||
PVE::Storage::Plugin::write_common_header($fh, $size);
|
PVE::Storage::Plugin::write_common_header($fh, $size);
|
||||||
run_command(['dd', "if=$file", "bs=64k"], output => '>&'.fileno($fh));
|
run_command(['dd', "if=$file", "bs=64k", "status=progress"], output => '>&'.fileno($fh));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub volume_import_formats {
|
sub volume_import_formats {
|
||||||
|
|||||||
@ -1577,7 +1577,7 @@ sub volume_export {
|
|||||||
goto unsupported if $with_snapshots || $file_format eq 'subvol';
|
goto unsupported if $with_snapshots || $file_format eq 'subvol';
|
||||||
write_common_header($fh, $size);
|
write_common_header($fh, $size);
|
||||||
if ($file_format eq 'raw') {
|
if ($file_format eq 'raw') {
|
||||||
run_command(['dd', "if=$file", "bs=4k"], output => '>&'.fileno($fh));
|
run_command(['dd', "if=$file", "bs=4k", "status=progress"], output => '>&'.fileno($fh));
|
||||||
} else {
|
} else {
|
||||||
run_command(['qemu-img', 'convert', '-f', $file_format, '-O', 'raw', $file, '/dev/stdout'],
|
run_command(['qemu-img', 'convert', '-f', $file_format, '-O', 'raw', $file, '/dev/stdout'],
|
||||||
output => '>&'.fileno($fh));
|
output => '>&'.fileno($fh));
|
||||||
@ -1587,7 +1587,7 @@ sub volume_export {
|
|||||||
my $data_format = $1;
|
my $data_format = $1;
|
||||||
goto unsupported if !$with_snapshots || $file_format ne $data_format;
|
goto unsupported if !$with_snapshots || $file_format ne $data_format;
|
||||||
write_common_header($fh, $size);
|
write_common_header($fh, $size);
|
||||||
run_command(['dd', "if=$file", "bs=4k"], output => '>&'.fileno($fh));
|
run_command(['dd', "if=$file", "bs=4k", "status=progress"], output => '>&'.fileno($fh));
|
||||||
return;
|
return;
|
||||||
} elsif ($format eq 'tar+size') {
|
} elsif ($format eq 'tar+size') {
|
||||||
goto unsupported if $file_format ne 'subvol';
|
goto unsupported if $file_format ne 'subvol';
|
||||||
|
|||||||
Reference in New Issue
Block a user