]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Restore lost shutdown reason
authorJohn Ferlan <jferlan@redhat.com>
Tue, 16 Oct 2018 12:38:27 +0000 (08:38 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 7 Nov 2018 12:41:41 +0000 (07:41 -0500)
When qemuProcessReconnectHelper was introduced (commit d38897a5d)
reconnection failure used VIR_DOMAIN_SHUTOFF_FAILED; however, that
was changed in commit bda2f17d to either VIR_DOMAIN_SHUTOFF_CRASHED
or VIR_DOMAIN_SHUTOFF_UNKNOWN.

When QEMU_CAPS_NO_SHUTDOWN checking was removed in commit fe35b1ad6
the conditional state was just left at VIR_DOMAIN_SHUTOFF_CRASHED.

So introduce qemuDomainIsUsingNoShutdown which will manage the
condition when the domain was started with -no-shutdown so that
when/if reconnection failure occurs we can restore the decision
point used to determine whether CRASHED or UNKNOWN is provided.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_command.c
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_process.c

index 24bf5f855c58ed689c12a8a51c053951a59552e5..f59cbf559e5131af12a497565836096980789b51 100644 (file)
@@ -6415,11 +6415,7 @@ qemuBuildPMCommandLine(virCommandPtr cmd,
     if (priv->allowReboot == VIR_TRISTATE_BOOL_NO)
         virCommandAddArg(cmd, "-no-reboot");
 
-    /* If JSON monitor is enabled, we can receive an event
-     * when QEMU stops. If we use no-shutdown, then we can
-     * watch for this event and do a soft/warm reboot.
-     */
-    if (priv->monJSON && priv->allowReboot == VIR_TRISTATE_BOOL_YES)
+    if (qemuDomainIsUsingNoShutdown(priv))
         virCommandAddArg(cmd, "-no-shutdown");
 
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NO_ACPI)) {
index ba3fff607a93533b9b47956cc2cfa70237e7c041..045a7b4ac0a1374d6ff7a950827be186cd005bda 100644 (file)
@@ -13561,3 +13561,20 @@ qemuDomainRunningReasonToResumeEvent(virDomainRunningReason reason)
 
     return VIR_DOMAIN_EVENT_RESUMED_UNPAUSED;
 }
+
+
+/* qemuDomainIsUsingNoShutdown:
+ * @priv: Domain private data
+ *
+ * If JSON monitor is enabled, we can receive an event when QEMU stops. If
+ * we use no-shutdown, then we can watch for this event and do a soft/warm
+ * reboot.
+ *
+ * Returns: @true when -no-shutdown either should be or was added to the
+ * command line.
+ */
+bool
+qemuDomainIsUsingNoShutdown(qemuDomainObjPrivatePtr priv)
+{
+    return priv->monJSON && priv->allowReboot == VIR_TRISTATE_BOOL_YES;
+}
index 80bd4bde9105f65029f0b58018a83c1ce6766d42..554435e0a9767a7363ce0085a51d49f026a3ef49 100644 (file)
@@ -1089,4 +1089,7 @@ void qemuDomainStorageIdReset(qemuDomainObjPrivatePtr priv);
 virDomainEventResumedDetailType
 qemuDomainRunningReasonToResumeEvent(virDomainRunningReason reason);
 
+bool
+qemuDomainIsUsingNoShutdown(qemuDomainObjPrivatePtr priv);
+
 #endif /* __QEMU_DOMAIN_H__ */
index c698c3b29cc5257e6775811dfd12c92aa8b8bb12..f1639463f008f17236f292563374dca0d35f8b40 100644 (file)
@@ -7988,11 +7988,16 @@ qemuProcessReconnect(void *opaque)
     if (virDomainObjIsActive(obj)) {
         /* We can't get the monitor back, so must kill the VM
          * to remove danger of it ending up running twice if
-         * user tries to start it again later
-         * If we couldn't get the monitor since QEMU supports
-         * no-shutdown, we can safely say that the domain
-         * crashed ... */
-        state = VIR_DOMAIN_SHUTOFF_CRASHED;
+         * user tries to start it again later.
+         *
+         * If we cannot get to the monitor when the QEMU command
+         * line used -no-shutdown, then we can safely say that the
+         * domain crashed; otherwise, we don't really know. */
+        if (qemuDomainIsUsingNoShutdown(priv))
+            state = VIR_DOMAIN_SHUTOFF_CRASHED;
+        else
+            state = VIR_DOMAIN_SHUTOFF_UNKNOWN;
+
         /* If BeginJob failed, we jumped here without a job, let's hope another
          * thread didn't have a chance to start playing with the domain yet
          * (it's all we can do anyway).