File 18441ab9-qemu-dom-startup-state.patch of Package libvirt.11695

commit 18441ab914459cd4439a578aa3c8d667697393ee
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Mon Feb 16 15:17:00 2015 +0100

    Use PAUSED state for domains that are starting up
    
    When libvirt is starting a domain, it reports the state as SHUTOFF until
    it's RUNNING. This is not ideal because domain startup may take a long
    time (usually because of some configuration issues, firewalls blocking
    access to network disks, etc.) and domain lists provided by libvirt look
    awkward. One can see weird shutoff domains with IDs in a list of active
    domains or even shutoff transient domains. In any case, it looks more
    like a bug in libvirt than a normal state a domain goes through.
    
    Signed-off-by: Jiri Denemark <jdenemar@redhat.com>

Index: libvirt-1.2.5/src/conf/domain_conf.c
===================================================================
--- libvirt-1.2.5.orig/src/conf/domain_conf.c
+++ libvirt-1.2.5/src/conf/domain_conf.c
@@ -706,7 +706,8 @@ VIR_ENUM_IMPL(virDomainPausedReason, VIR
               "from snapshot",
               "shutdown",
               "snapshot",
-              "panicked")
+              "panicked",
+              "starting up")
 
 VIR_ENUM_IMPL(virDomainShutdownReason, VIR_DOMAIN_SHUTDOWN_LAST,
               "unknown",
Index: libvirt-1.2.5/src/qemu/qemu_process.c
===================================================================
--- libvirt-1.2.5.orig/src/qemu/qemu_process.c
+++ libvirt-1.2.5/src/qemu/qemu_process.c
@@ -2856,6 +2856,7 @@ qemuProcessUpdateState(virQEMUDriverPtr
     virDomainState state;
     virDomainPausedReason reason;
     virDomainState newState = VIR_DOMAIN_NOSTATE;
+    int oldReason;
     int newReason;
     bool running;
     char *msg = NULL;
@@ -2868,9 +2869,16 @@ qemuProcessUpdateState(virQEMUDriverPtr
     if (ret < 0 || !virDomainObjIsActive(vm))
         return -1;
 
-    state = virDomainObjGetState(vm, NULL);
+    state = virDomainObjGetState(vm, &oldReason);
 
-    if (state == VIR_DOMAIN_PAUSED && running) {
+    if (running &&
+        (state == VIR_DOMAIN_SHUTOFF ||
+         (state == VIR_DOMAIN_PAUSED &&
+          oldReason == VIR_DOMAIN_PAUSED_STARTING_UP))) {
+        newState = VIR_DOMAIN_RUNNING;
+        newReason = VIR_DOMAIN_RUNNING_BOOTED;
+        ignore_value(VIR_STRDUP_QUIET(msg, "finished booting"));
+    } else if (state == VIR_DOMAIN_PAUSED && running) {
         newState = VIR_DOMAIN_RUNNING;
         newReason = VIR_DOMAIN_RUNNING_UNPAUSED;
         ignore_value(VIR_STRDUP_QUIET(msg, "was unpaused"));
@@ -2889,10 +2897,6 @@ qemuProcessUpdateState(virQEMUDriverPtr
             ignore_value(virAsprintf(&msg, "was paused (%s)",
                                  virDomainPausedReasonTypeToString(reason)));
         }
-    } else if (state == VIR_DOMAIN_SHUTOFF && running) {
-        newState = VIR_DOMAIN_RUNNING;
-        newReason = VIR_DOMAIN_RUNNING_BOOTED;
-        ignore_value(VIR_STRDUP_QUIET(msg, "finished booting"));
     }
 
     if (newState != VIR_DOMAIN_NOSTATE) {
@@ -3245,7 +3249,9 @@ qemuProcessReconnect(void *opaque)
         goto error;
 
     state = virDomainObjGetState(obj, &reason);
-    if (state == VIR_DOMAIN_SHUTOFF) {
+    if (state == VIR_DOMAIN_SHUTOFF ||
+        (state == VIR_DOMAIN_PAUSED &&
+         reason == VIR_DOMAIN_PAUSED_STARTING_UP)) {
         VIR_DEBUG("Domain '%s' wasn't fully started yet, killing it",
                   obj->def->name);
         goto error;
@@ -3703,7 +3709,7 @@ int qemuProcessStart(virConnectPtr conn,
 
     vm->def->id = qemuDriverAllocateID(driver);
     qemuDomainSetFakeReboot(driver, vm, false);
-    virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_UNKNOWN);
+    virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_STARTING_UP);
 
     if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback)
         driver->inhibitCallback(true, driver->inhibitOpaque);
Index: libvirt-1.2.5/tools/virsh-domain-monitor.c
===================================================================
--- libvirt-1.2.5.orig/tools/virsh-domain-monitor.c
+++ libvirt-1.2.5/tools/virsh-domain-monitor.c
@@ -184,7 +184,8 @@ VIR_ENUM_IMPL(vshDomainPausedReason,
               N_("from snapshot"),
               N_("shutting down"),
               N_("creating snapshot"),
-              N_("crashed"))
+              N_("crashed"),
+              N_("starting up"))
 
 VIR_ENUM_DECL(vshDomainShutdownReason)
 VIR_ENUM_IMPL(vshDomainShutdownReason,
Index: libvirt-1.2.5/include/libvirt/libvirt.h.in
===================================================================
--- libvirt-1.2.5.orig/include/libvirt/libvirt.h.in
+++ libvirt-1.2.5/include/libvirt/libvirt.h.in
@@ -182,6 +182,7 @@ typedef enum {
     VIR_DOMAIN_PAUSED_SHUTTING_DOWN = 8, /* paused during shutdown process */
     VIR_DOMAIN_PAUSED_SNAPSHOT = 9,      /* paused while creating a snapshot */
     VIR_DOMAIN_PAUSED_CRASHED = 10,     /* paused due to a guest crash */
+    VIR_DOMAIN_PAUSED_STARTING_UP = 11, /* the domain is being started */
 
 #ifdef VIR_ENUM_SENTINELS
     VIR_DOMAIN_PAUSED_LAST