When the drive-mirror is at 100%, and write occurs, the busy flag can change 
from false->true

- 100% no new writes

transferred: 1073741824 bytes remaining: 0 bytes total: 1073741824 bytes 
progression: 100.00 % busy: false
transferred: 1073741824 bytes remaining: 0 bytes total: 1073741824 bytes 
progression: 100.00 % busy: false
transferred: 1073741824 bytes remaining: 0 bytes total: 1073741824 bytes 
progression: 100.00 % busy: false

- 100% new writes

transferred: 1073741824 bytes remaining: 0 bytes total: 1073741824 bytes 
progression: 100.00 % busy: true
transferred: 1073741824 bytes remaining: 0 bytes total: 1073741824 bytes 
progression: 100.00 % busy: true
transferred: 1073741824 bytes remaining: 0 bytes total: 1073741824 bytes 
progression: 100.00 % busy: true

- 100% no new writes

transferred: 1073741824 bytes remaining: 0 bytes total: 1073741824 bytes 
progression: 100.00 % busy: false
transferred: 1073741824 bytes remaining: 0 bytes total: 1073741824 bytes 
progression: 100.00 % busy: false
transferred: 1073741824 bytes remaining: 0 bytes total: 1073741824 bytes 
progression: 100.00 % busy: false

So, we need to check that busy is false before doing the block-job-complete.

Also, we force the vm to pause, if it's busy for more than 120s when 
drive-mirror is at 100%

Signed-off-by: Alexandre Derumier <[email protected]>
---
 PVE/QemuServer.pm |   28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index a79606c..85ce28a 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5146,11 +5146,12 @@ sub qemu_img_format {
 }
 
 sub qemu_drive_mirror {
-    my ($vmid, $drive, $dst_volid, $vmiddst, $maxwait) = @_;
+    my ($vmid, $drive, $dst_volid, $vmiddst) = @_;
 
-    my $count = 1;
+    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, 1);
@@ -5186,23 +5187,19 @@ sub qemu_drive_mirror {
                my $total = $stat->{len};
                my $remaining = $total - $transferred;
                my $percent = sprintf "%.2f", ($transferred * 100 / $total);
+               my $busy = $stat->{busy};
 
-                print "transferred: $transferred bytes remaining: $remaining 
bytes total: $total bytes progression: $percent %\n";
+                print "transferred: $transferred bytes remaining: $remaining 
bytes total: $total bytes progression: $percent % busy: $busy\n";
 
-               last if ($stat->{len} == $stat->{offset});
-               if ($old_len == $stat->{offset}) {
-                   if ($maxwait && $count > $maxwait) {
-                   # if writes to disk occurs the disk needs to be freezed
-                   # to be able to complete the migration
+               if ($stat->{len} == $stat->{offset}) {
+                   last if $busy eq 'false';
+                   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);
-                       $count = 0;
                        $frozen = 1;
-                   } else {
-                       $count++ unless $frozen;
                    }
-               } elsif ($frozen) {
-                   vm_resume($vmid,1);
-                   $count = 0;
+                   $count ++
                }
                $old_len = $stat->{offset};
                sleep 1;
@@ -5212,6 +5209,9 @@ sub qemu_drive_mirror {
                # switch the disk if source and destination are on the same 
guest
                vm_mon_cmd($vmid, "block-job-complete", device => 
"drive-$drive");
            }
+
+           vm_resume($vmid, 1) if $frozen;
+           
        };
        if (my $err = $@) {
            eval { vm_mon_cmd($vmid, "block-job-cancel", device => 
"drive-$drive"); };
-- 
1.7.10.4

_______________________________________________
pve-devel mailing list
[email protected]
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to