block-job-cancel is async, we need to check that job is really finished

before try to free the volume

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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 98264d1..a79606c 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5215,12 +5215,24 @@ sub qemu_drive_mirror {
        };
        if (my $err = $@) {
            eval { vm_mon_cmd($vmid, "block-job-cancel", device => 
"drive-$drive"); };
+           while (1) {
+               my $stats = vm_mon_cmd($vmid, "query-block-jobs");
+               my $stat = @$stats[0];
+               last if !$stat;
+               sleep 1;
+           }
            die "mirroring error: $err";
        }
 
        if ($vmiddst != $vmid) {
            # if we clone a disk for a new target vm, we don't switch the disk
            vm_mon_cmd($vmid, "block-job-cancel", device => "drive-$drive");
+           while (1) {
+               my $stats = vm_mon_cmd($vmid, "query-block-jobs");
+               my $stat = @$stats[0];
+               last if !$stat;
+               sleep 1;
+           }
        }
     }
 }
-- 
1.7.10.4

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

Reply via email to