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

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Jun 28 15:07:45 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>
---

changes v1 -> v2:
* simplify bytes2human, i.e., use an array for units as the hash was
  effectively an expensive array and some other minor refactoring


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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index d6efb3a..ae7d503 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -6134,6 +6134,20 @@ sub template_create {
     });
 }
 
+sub bytes2human {
+    my ($value) = @_;
+
+    my @units = qw(b kb mb gb tb pb);
+
+    my $max_unit = 0;
+    if ($value > 0) {
+	$max_unit = int(log($value)/log(1024));
+	$value *= 2**($max_unit * -10);
+    }
+
+    return sprintf "%.2f $units[$max_unit]", $value;
+}
+
 sub qemu_img_convert {
     my ($src_volid, $dst_volid, $size, $snapname, $is_zero_initialized) = @_;
 
@@ -6166,14 +6180,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 +6280,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