Blob Blame History Raw
From 48fc7e172ed82fbe8b377c11cff2c9d47fbb37c8 Mon Sep 17 00:00:00 2001
Message-Id: <48fc7e172ed82fbe8b377c11cff2c9d47fbb37c8@dist-git>
From: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Date: Fri, 7 Apr 2017 14:06:25 +0300
Subject: [PATCH] qemu: migration: fix race on cancelling drive mirror

0feebab2 adds calling qemuBlockNodeNamesDetect for completed job
on updating block jobs. This affects cancelling drive mirror logic as
this function drops vm lock. Now we have to recheck all disks
before the disk with the completed block job before going
to wait for block job events.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit bc82d1eaf66bfdfde80a64e7feedb60c6d1d2505)

https://bugzilla.redhat.com/show_bug.cgi?id=1530129

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_migration.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index d2b691bd2b..60722cbf6c 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -654,9 +654,11 @@ qemuMigrationDriveMirrorCancelled(virQEMUDriverPtr driver,
 {
     size_t i;
     size_t active = 0;
+    size_t completed = 0;
     int status;
     bool failed = false;
 
+ retry:
     for (i = 0; i < vm->def->ndisks; i++) {
         virDomainDiskDefPtr disk = vm->def->disks[i];
         qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
@@ -683,6 +685,19 @@ qemuMigrationDriveMirrorCancelled(virQEMUDriverPtr driver,
         default:
             active++;
         }
+
+        if (status == VIR_DOMAIN_BLOCK_JOB_COMPLETED)
+            completed++;
+    }
+
+    /* Updating completed block job drops the lock thus we have to recheck
+     * block jobs for disks that reside before the disk(s) with completed
+     * block job.
+     */
+    if (completed > 0) {
+        completed = 0;
+        active = 0;
+        goto retry;
     }
 
     if (failed) {
-- 
2.15.1