7a3408
From 73cc6287624a227f16c27e138258b5199c8687a0 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <73cc6287624a227f16c27e138258b5199c8687a0@dist-git>
7a3408
From: Jiri Denemark <jdenemar@redhat.com>
7a3408
Date: Thu, 30 Jul 2015 16:42:43 +0200
7a3408
Subject: [PATCH] qemu: Do not reset labels when migration fails
7a3408
7a3408
When stopping a domain on the destination host after a failed migration,
7a3408
we need to avoid reseting security labels since the domain is still
7a3408
running on the source host. While we were correctly doing so in some
7a3408
cases, there were still some paths which did this wrong.
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1242904
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
(cherry picked from commit e8d0166e1d27c18aacea4b1316760fad4106e1c7)
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_driver.c    |  5 ++++-
7a3408
 src/qemu/qemu_migration.c |  3 ++-
7a3408
 src/qemu/qemu_process.c   | 19 ++++++++++++++-----
7a3408
 3 files changed, 20 insertions(+), 7 deletions(-)
7a3408
7a3408
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
7a3408
index 204ed72..fbe37c2 100644
7a3408
--- a/src/qemu/qemu_driver.c
7a3408
+++ b/src/qemu/qemu_driver.c
7a3408
@@ -2199,6 +2199,7 @@ qemuDomainDestroyFlags(virDomainPtr dom,
7a3408
     int ret = -1;
7a3408
     virObjectEventPtr event = NULL;
7a3408
     qemuDomainObjPrivatePtr priv;
7a3408
+    unsigned int stopFlags = 0;
7a3408
 
7a3408
     virCheckFlags(VIR_DOMAIN_DESTROY_GRACEFUL, -1);
7a3408
 
7a3408
@@ -2212,6 +2213,8 @@ qemuDomainDestroyFlags(virDomainPtr dom,
7a3408
 
7a3408
     qemuDomainSetFakeReboot(driver, vm, false);
7a3408
 
7a3408
+    if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_IN)
7a3408
+        stopFlags |= VIR_QEMU_PROCESS_STOP_MIGRATED;
7a3408
 
7a3408
     /* We need to prevent monitor EOF callback from doing our work (and sending
7a3408
      * misleading events) while the vm is unlocked inside BeginJob/ProcessKill API
7a3408
@@ -2246,7 +2249,7 @@ qemuDomainDestroyFlags(virDomainPtr dom,
7a3408
         goto endjob;
7a3408
     }
7a3408
 
7a3408
-    qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED, 0);
7a3408
+    qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED, stopFlags);
7a3408
     event = virDomainEventLifecycleNewFromObj(vm,
7a3408
                                      VIR_DOMAIN_EVENT_STOPPED,
7a3408
                                      VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
7a3408
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
7a3408
index 6386744..16bb1af 100644
7a3408
--- a/src/qemu/qemu_migration.c
7a3408
+++ b/src/qemu/qemu_migration.c
7a3408
@@ -3474,7 +3474,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
7a3408
 
7a3408
  stop:
7a3408
     virDomainAuditStart(vm, "migrated", false);
7a3408
-    qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, 0);
7a3408
+    qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED,
7a3408
+                    VIR_QEMU_PROCESS_STOP_MIGRATED);
7a3408
 
7a3408
  endjob:
7a3408
     qemuMigrationJobFinish(driver, vm);
7a3408
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
7a3408
index 31315b1..f41fd9d 100644
7a3408
--- a/src/qemu/qemu_process.c
7a3408
+++ b/src/qemu/qemu_process.c
7a3408
@@ -285,6 +285,7 @@ qemuProcessHandleMonitorEOF(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
7a3408
     int eventReason = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN;
7a3408
     int stopReason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
7a3408
     const char *auditReason = "shutdown";
7a3408
+    unsigned int stopFlags = 0;
7a3408
 
7a3408
     VIR_DEBUG("Received EOF on %p '%s'", vm, vm->def->name);
7a3408
 
7a3408
@@ -310,14 +311,16 @@ qemuProcessHandleMonitorEOF(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
7a3408
         auditReason = "failed";
7a3408
     }
7a3408
 
7a3408
-    if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_IN)
7a3408
+    if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_IN) {
7a3408
+        stopFlags |= VIR_QEMU_PROCESS_STOP_MIGRATED;
7a3408
         qemuMigrationErrorSave(driver, vm->def->name,
7a3408
                                qemuMonitorLastError(priv->mon));
7a3408
+    }
7a3408
 
7a3408
     event = virDomainEventLifecycleNewFromObj(vm,
7a3408
                                      VIR_DOMAIN_EVENT_STOPPED,
7a3408
                                      eventReason);
7a3408
-    qemuProcessStop(driver, vm, stopReason, 0);
7a3408
+    qemuProcessStop(driver, vm, stopReason, stopFlags);
7a3408
     virDomainAuditStop(vm, auditReason);
7a3408
 
7a3408
     if (!vm->persistent) {
7a3408
@@ -3732,10 +3735,13 @@ qemuProcessReconnect(void *opaque)
7a3408
     virQEMUDriverConfigPtr cfg;
7a3408
     size_t i;
7a3408
     int ret;
7a3408
+    unsigned int stopFlags = 0;
7a3408
 
7a3408
     VIR_FREE(data);
7a3408
 
7a3408
     qemuDomainObjRestoreJob(obj, &oldjob);
7a3408
+    if (oldjob.asyncJob == QEMU_ASYNC_JOB_MIGRATION_IN)
7a3408
+        stopFlags |= VIR_QEMU_PROCESS_STOP_MIGRATED;
7a3408
 
7a3408
     cfg = virQEMUDriverGetConfig(driver);
7a3408
     priv = obj->privateData;
7a3408
@@ -3916,7 +3922,7 @@ qemuProcessReconnect(void *opaque)
7a3408
              * really is and FAILED means "failed to start" */
7a3408
             state = VIR_DOMAIN_SHUTOFF_UNKNOWN;
7a3408
         }
7a3408
-        qemuProcessStop(driver, obj, state, 0);
7a3408
+        qemuProcessStop(driver, obj, state, stopFlags);
7a3408
     }
7a3408
 
7a3408
     if (!obj->persistent)
7a3408
@@ -5692,9 +5698,13 @@ qemuProcessAutoDestroy(virDomainObjPtr dom,
7a3408
     virQEMUDriverPtr driver = opaque;
7a3408
     qemuDomainObjPrivatePtr priv = dom->privateData;
7a3408
     virObjectEventPtr event = NULL;
7a3408
+    unsigned int stopFlags = 0;
7a3408
 
7a3408
     VIR_DEBUG("vm=%s, conn=%p", dom->def->name, conn);
7a3408
 
7a3408
+    if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_IN)
7a3408
+        stopFlags |= VIR_QEMU_PROCESS_STOP_MIGRATED;
7a3408
+
7a3408
     if (priv->job.asyncJob) {
7a3408
         VIR_DEBUG("vm=%s has long-term job active, cancelling",
7a3408
                   dom->def->name);
7a3408
@@ -5707,8 +5717,7 @@ qemuProcessAutoDestroy(virDomainObjPtr dom,
7a3408
 
7a3408
     VIR_DEBUG("Killing domain");
7a3408
 
7a3408
-    qemuProcessStop(driver, dom, VIR_DOMAIN_SHUTOFF_DESTROYED,
7a3408
-                    VIR_QEMU_PROCESS_STOP_MIGRATED);
7a3408
+    qemuProcessStop(driver, dom, VIR_DOMAIN_SHUTOFF_DESTROYED, stopFlags);
7a3408
 
7a3408
     virDomainAuditStop(dom, "destroyed");
7a3408
     event = virDomainEventLifecycleNewFromObj(dom,
7a3408
-- 
7a3408
2.5.0
7a3408