[pve-devel] [RFC qemu-server 1/2] move disk: simplify and remove progress output

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Jun 28 14:14:17 CEST 2018


Add a small helper which transforms a byte value to the highest
possible size unit.
Remove redundant information from the for offline mirroring used
qemu_img_convert and the for online mirroring used
qemu_drive_mirror_monitor periodic progress outputs and use the new
helper to print an, for humans, easy to parse transfer progress size.

Previous output:

[...]
drive mirror is starting for drive-scsi0
drive-scsi0: transferred: 0 bytes remaining: 4294967296 bytes total: 4294967296 bytes progression: 0.00 % busy: 1 ready: 0
drive-scsi0: transferred: 469762048 bytes remaining: 3825205248 bytes total: 4294967296 bytes progression: 10.94 % busy: 1 ready: 0
drive-scsi0: transferred: 2706374656 bytes remaining: 1588592640 bytes total: 4294967296 bytes progression: 63.01 % busy: 0 ready: 0
[...]
drive-scsi0: transferred: 4295163904 bytes remaining: 0 bytes total: 4295163904 bytes progression: 100.00 % busy: 0 ready: 1
all mirroring jobs are ready

Output now:

[...]
drive mirror is starting for drive-scsi0
drive-scsi0: transferred: 0.00 b from 4.00 gb (0.00 %)
drive-scsi0: transferred: 128.00 mb from 4.00 gb (3.12 %)
drive-scsi0: transferred: 480.00 mb from 4.00 gb (11.72 %)
[...]
drive-scsi0: transferred: 4.00 gb from 4.00 gb (100.00 %) - job ready
all mirroring jobs are ready

The combination of busy and ready is not useful, just output that the
job is ready once it gets true, it should be finished and removed
from monitoring the next round.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

RFC for basic idea.

bytes2human helper could be added to PVE::Tools, where a related helper,
convert_size, already lifes. method naming is also changeable.

 PVE/QemuServer.pm | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index d6efb3a..b4fa30a 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -6134,6 +6134,29 @@ sub template_create {
     });
 }
 
+sub bytes2human {
+    my ($value) = @_;
+
+    my $units = {
+	0  => 'b',
+	1 => 'kb',
+	2 => 'mb',
+	3 => 'gb',
+	4 => 'tb',
+	5 => 'pb',
+    };
+
+    my $to = 0;
+    if ($value > 0) {
+	$to = int(log($value)/log(1024));
+	$value *= 2**($to * -10);
+    }
+
+    my $res = sprintf "%.1f $units->{$to}", ($value);
+    return $res
+}
+
+
 sub qemu_img_convert {
     my ($src_volid, $dst_volid, $size, $snapname, $is_zero_initialized) = @_;
 
@@ -6166,14 +6189,17 @@ sub qemu_img_convert {
 	    push @$cmd, $dst_path;
 	}
 
+	my $size_str = bytes2human($size);
+
 	my $parser = sub {
 	    my $line = shift;
 	    if($line =~ m/\((\S+)\/100\%\)/){
 		my $percent = $1;
 		my $transferred = int($size * $percent / 100);
-		my $remaining = $size - $transferred;
 
-		print "transferred: $transferred bytes remaining: $remaining bytes total: $size bytes progression: $percent %\n";
+		my $stats = bytes2human($transferred) . " from $size_str";
+
+		print "transferred: $stats ($percent %)\n";
 	    }
 
 	};
@@ -6263,14 +6289,16 @@ sub qemu_drive_mirror_monitor {
 
 		die "$job: mirroring has been cancelled\n" if !defined($running_mirror_jobs->{$job});
 
-		my $busy = $running_mirror_jobs->{$job}->{busy};
 		my $ready = $running_mirror_jobs->{$job}->{ready};
 		if (my $total = $running_mirror_jobs->{$job}->{len}) {
 		    my $transferred = $running_mirror_jobs->{$job}->{offset} || 0;
-		    my $remaining = $total - $transferred;
 		    my $percent = sprintf "%.2f", ($transferred * 100 / $total);
 
-		    print "$job: transferred: $transferred bytes remaining: $remaining bytes total: $total bytes progression: $percent % busy: $busy ready: $ready \n";
+		    my $stats = bytes2human($transferred) . ' from ' . bytes2human($total);
+
+		    print "$job: transferred: $stats ($percent %)";
+		    print " - job ready" if $ready;
+		    print "\n";
 		}
 
 		$readycounter++ if $running_mirror_jobs->{$job}->{ready};
-- 
2.17.1





More information about the pve-devel mailing list