qemu: Properly report error state in qemuDomainGetControlInfo()

Previously when a domain would get stuck in a domain job due to a
programming mistake we'd report the following control state:

$ virsh domcontrol domain
occupied (1424343406.150s)

The timestamp is invalid as the monitor was not entered for that domain.
We can use that to detect that the domain has an active job and report a
better error instead:

$ virsh domcontrol domain
error: internal (locking) error
This commit is contained in:
Peter Krempa
2015-02-19 11:53:42 +01:00
parent 53cae19561
commit 31a55c7cb4
3 changed files with 57 additions and 4 deletions

View File

@@ -128,6 +128,21 @@ vshDomainControlStateToString(int state)
return str ? _(str) : _("unknown");
}
VIR_ENUM_DECL(vshDomainControlErrorReason)
VIR_ENUM_IMPL(vshDomainControlErrorReason,
VIR_DOMAIN_CONTROL_ERROR_REASON_LAST,
"",
N_("unknown"),
N_("monitor failure"),
N_("internal (locking) error"))
static const char *
vshDomainControlErrorReasonToString(int reason)
{
const char *ret = vshDomainControlErrorReasonTypeToString(reason);
return ret ? _(ret) : _("unknown");
}
VIR_ENUM_DECL(vshDomainState)
VIR_ENUM_IMPL(vshDomainState,
VIR_DOMAIN_LAST,
@@ -815,6 +830,10 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd)
vshPrint(ctl, "%s (%0.3fs)\n",
vshDomainControlStateToString(info.state),
info.stateTime / 1000.0);
} else if (info.state == VIR_DOMAIN_CONTROL_ERROR && info.details > 0) {
vshPrint(ctl, "%s: %s\n",
vshDomainControlStateToString(info.state),
vshDomainControlErrorReasonToString(info.details));
} else {
vshPrint(ctl, "%s\n",
vshDomainControlStateToString(info.state));