]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Introduce qemuProcessBeginStopJob
authorJiri Denemark <jdenemar@redhat.com>
Thu, 11 Feb 2016 14:13:09 +0000 (15:13 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Fri, 19 Feb 2016 14:41:57 +0000 (15:41 +0100)
When destroying a domain we need to make sure we will be able to start a
job no matter what other operations are running or even stuck in a job.
This is done by killing the domain before starting the destroy job.

Let's introduce qemuProcessBeginStopJob which combines killing a domain
and starting a job in a single API which can be called everywhere we
need a job to stop a domain.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_driver.c
src/qemu/qemu_process.c
src/qemu/qemu_process.h

index b1f94bd24da417aea01ed4a7b1d855abf561e58d..ffdbdb12db3412b9fc454208897294c958f4e3ff 100644 (file)
@@ -2279,33 +2279,10 @@ qemuDomainDestroyFlags(virDomainPtr dom,
     if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_IN)
         stopFlags |= VIR_QEMU_PROCESS_STOP_MIGRATED;
 
-    /* We need to prevent monitor EOF callback from doing our work (and sending
-     * misleading events) while the vm is unlocked inside BeginJob/ProcessKill API
-     */
-    priv->beingDestroyed = true;
-
-    /* Although qemuProcessStop does this already, there may
-     * be an outstanding job active. We want to make sure we
-     * can kill the process even if a job is active. Killing
-     * it now means the job will be released
-     */
-    if (flags & VIR_DOMAIN_DESTROY_GRACEFUL) {
-        if (qemuProcessKill(vm, 0) < 0) {
-            priv->beingDestroyed = false;
-            goto cleanup;
-        }
-    } else {
-        if (qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_FORCE) < 0) {
-            priv->beingDestroyed = false;
-            goto cleanup;
-        }
-    }
-
-    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_DESTROY) < 0)
+    if (qemuProcessBeginStopJob(driver, vm, QEMU_JOB_DESTROY,
+                                !(flags & VIR_DOMAIN_DESTROY_GRACEFUL)) < 0)
         goto cleanup;
 
-    priv->beingDestroyed = false;
-
     if (!virDomainObjIsActive(vm)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        "%s", _("domain is not running"));
index bc53c44524b24608fc7034a8586ff374751cda93..fd301c3e1fad719495ffc20ffb5ede7a17ad248f 100644 (file)
@@ -5403,6 +5403,45 @@ qemuProcessKill(virDomainObjPtr vm, unsigned int flags)
 }
 
 
+/**
+ * qemuProcessBeginStopJob:
+ *
+ * Stop all current jobs by killing the domain and start a new one for
+ * qemuProcessStop.
+ */
+int
+qemuProcessBeginStopJob(virQEMUDriverPtr driver,
+                        virDomainObjPtr vm,
+                        qemuDomainJob job,
+                        bool forceKill)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    unsigned int killFlags = forceKill ? VIR_QEMU_PROCESS_KILL_FORCE : 0;
+    int ret = -1;
+
+    /* We need to prevent monitor EOF callback from doing our work (and
+     * sending misleading events) while the vm is unlocked inside
+     * BeginJob/ProcessKill API
+     */
+    priv->beingDestroyed = true;
+
+    if (qemuProcessKill(vm, killFlags) < 0)
+        goto cleanup;
+
+    /* Wake up anything waiting on domain condition */
+    virDomainObjBroadcast(vm);
+
+    if (qemuDomainObjBeginJob(driver, vm, job) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    priv->beingDestroyed = false;
+    return ret;
+}
+
+
 void qemuProcessStop(virQEMUDriverPtr driver,
                      virDomainObjPtr vm,
                      virDomainShutoffReason reason,
index b16919d339d0a85dfd18a2717ee7b149b264643e..69be99e2e0a0671fb33f12c0bcebf9766287efed 100644 (file)
@@ -114,6 +114,10 @@ typedef enum {
     VIR_QEMU_PROCESS_STOP_NO_RELABEL    = 1 << 1,
 } qemuProcessStopFlags;
 
+int qemuProcessBeginStopJob(virQEMUDriverPtr driver,
+                            virDomainObjPtr vm,
+                            qemuDomainJob job,
+                            bool forceKill);
 void qemuProcessStop(virQEMUDriverPtr driver,
                      virDomainObjPtr vm,
                      virDomainShutoffReason reason,