[pve-devel] [PATCH 1/2] qemu-mirror : block job complete : use ready flag

Alexandre Derumier aderumier at odiso.com
Mon May 11 15:55:21 CEST 2015


Since qemu 2.2, a new "ready" flag has been added to blockjob
http://git.qemu.org/?p=qemu.git;a=commit;h=ef6dbf1e46ebd1d41ab669df5bba0bbdec6bd374
to known if we can complete it.

we can't use len==offset to known if all block are mirrored, because behaviour will change soon in qemu 2.3

http://git.qemu.org/?p=qemu.git;a=commit;h=b21c76529d55bf7bb02ac736b312f5f8bf033ea2
"block/mirror: Improve progress report

Instead of taking the total length of the block device as the block
job's length, use the number of dirty sectors. The progress is now the
number of sectors mirrored to the target block device. Note that this
may result in the job's length increasing during operation, which is
however in fact desirable.
"

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm | 31 ++++++++-----------------------
 1 file changed, 8 insertions(+), 23 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index e14a042..869dcfe 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5970,11 +5970,6 @@ sub qemu_img_format {
 sub qemu_drive_mirror {
     my ($vmid, $drive, $dst_volid, $vmiddst) = @_;
 
-    my $count = 0;
-    my $old_len = 0;
-    my $frozen = undef;
-    my $maxwait = 120;
-
     my $storecfg = PVE::Storage::config();
     my ($dst_storeid, $dst_volname) = PVE::Storage::parse_volume_id($dst_volid);
 
@@ -6003,39 +5998,29 @@ sub qemu_drive_mirror {
 	    die "error job is not mirroring" if $stat->{type} ne "mirror";
 
 	    my $busy = $stat->{busy};
+	    my $ready = $stat->{ready};
 
 	    if (my $total = $stat->{len}) {
 		my $transferred = $stat->{offset} || 0;
 		my $remaining = $total - $transferred;
 		my $percent = sprintf "%.2f", ($transferred * 100 / $total);
 
-		print "transferred: $transferred bytes remaining: $remaining bytes total: $total bytes progression: $percent % busy: $busy\n";
+		print "transferred: $transferred bytes remaining: $remaining bytes total: $total bytes progression: $percent % busy: $busy ready: $ready \n";
 	    }
 
-	    if ($stat->{len} == $stat->{offset}) {
-		if ($busy eq 'false') {
 
-		    last if $vmiddst != $vmid;
+	    if ($stat->{ready} eq 'true') {
 
-		    # try to switch the disk if source and destination are on the same guest
-		    eval { vm_mon_cmd($vmid, "block-job-complete", device => "drive-$drive") };
-		    last if !$@;
-		    die $@ if $@ !~ m/cannot be completed/;
-		}
+		last if $vmiddst != $vmid;
 
-		if ($count > $maxwait) {
-		    # if too much writes to disk occurs at the end of migration
-		    #the disk needs to be freezed to be able to complete the migration
-		    vm_suspend($vmid,1);
-		    $frozen = 1;
-		}
-		$count ++
+		# try to switch the disk if source and destination are on the same guest
+		eval { vm_mon_cmd($vmid, "block-job-complete", device => "drive-$drive") };
+		last if !$@;
+		die $@ if $@ !~ m/cannot be completed/;
 	    }
-	    $old_len = $stat->{offset};
 	    sleep 1;
 	}
 
-	vm_resume($vmid, 1) if $frozen;
 
     };
     my $err = $@;
-- 
2.1.4



More information about the pve-devel mailing list