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>
This commit is contained in:
Jiri Denemark 2015-02-16 15:17:00 +01:00
parent 2dbfa716e8
commit 18441ab914
4 changed files with 19 additions and 10 deletions

View File

@ -116,6 +116,7 @@ typedef enum {
VIR_DOMAIN_PAUSED_SHUTTING_DOWN = 8, /* paused during shutdown process */ VIR_DOMAIN_PAUSED_SHUTTING_DOWN = 8, /* paused during shutdown process */
VIR_DOMAIN_PAUSED_SNAPSHOT = 9, /* paused while creating a snapshot */ VIR_DOMAIN_PAUSED_SNAPSHOT = 9, /* paused while creating a snapshot */
VIR_DOMAIN_PAUSED_CRASHED = 10, /* paused due to a guest crash */ 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 # ifdef VIR_ENUM_SENTINELS
VIR_DOMAIN_PAUSED_LAST VIR_DOMAIN_PAUSED_LAST

View File

@ -661,7 +661,8 @@ VIR_ENUM_IMPL(virDomainPausedReason, VIR_DOMAIN_PAUSED_LAST,
"from snapshot", "from snapshot",
"shutdown", "shutdown",
"snapshot", "snapshot",
"panicked") "panicked",
"starting up")
VIR_ENUM_IMPL(virDomainShutdownReason, VIR_DOMAIN_SHUTDOWN_LAST, VIR_ENUM_IMPL(virDomainShutdownReason, VIR_DOMAIN_SHUTDOWN_LAST,
"unknown", "unknown",

View File

@ -3338,6 +3338,7 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm)
virDomainState state; virDomainState state;
virDomainPausedReason reason; virDomainPausedReason reason;
virDomainState newState = VIR_DOMAIN_NOSTATE; virDomainState newState = VIR_DOMAIN_NOSTATE;
int oldReason;
int newReason; int newReason;
bool running; bool running;
char *msg = NULL; char *msg = NULL;
@ -3351,9 +3352,16 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm)
if (ret < 0) if (ret < 0)
return -1; 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; newState = VIR_DOMAIN_RUNNING;
newReason = VIR_DOMAIN_RUNNING_UNPAUSED; newReason = VIR_DOMAIN_RUNNING_UNPAUSED;
ignore_value(VIR_STRDUP_QUIET(msg, "was unpaused")); ignore_value(VIR_STRDUP_QUIET(msg, "was unpaused"));
@ -3372,10 +3380,6 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm)
ignore_value(virAsprintf(&msg, "was paused (%s)", ignore_value(virAsprintf(&msg, "was paused (%s)",
virDomainPausedReasonTypeToString(reason))); 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) { if (newState != VIR_DOMAIN_NOSTATE) {
@ -3748,7 +3752,9 @@ qemuProcessReconnect(void *opaque)
goto error; goto error;
state = virDomainObjGetState(obj, &reason); 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", VIR_DEBUG("Domain '%s' wasn't fully started yet, killing it",
obj->def->name); obj->def->name);
goto error; goto error;
@ -4379,7 +4385,7 @@ int qemuProcessStart(virConnectPtr conn,
vm->def->id = qemuDriverAllocateID(driver); vm->def->id = qemuDriverAllocateID(driver);
qemuDomainSetFakeReboot(driver, vm, false); 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) if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback)
driver->inhibitCallback(true, driver->inhibitOpaque); driver->inhibitCallback(true, driver->inhibitOpaque);

View File

@ -199,7 +199,8 @@ VIR_ENUM_IMPL(vshDomainPausedReason,
N_("from snapshot"), N_("from snapshot"),
N_("shutting down"), N_("shutting down"),
N_("creating snapshot"), N_("creating snapshot"),
N_("crashed")) N_("crashed"),
N_("starting up"))
VIR_ENUM_DECL(vshDomainShutdownReason) VIR_ENUM_DECL(vshDomainShutdownReason)
VIR_ENUM_IMPL(vshDomainShutdownReason, VIR_ENUM_IMPL(vshDomainShutdownReason,