mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-09 09:14:57 +00:00
virsh: support 'virsh start --force-boot' on older servers
Managed save was added in 0.8.0, virDomainCreateWithFlags in 0.8.2, and FORCE_BOOT in 0.9.5. The virsh flag is more useful if we emulate it for all older servers (note that if a hypervisor fails the query for a managed save image, then it does not have one to be removed, so the flag can be safely ignored). * tools/virsh.c (cmdStart): Add emulation for new flag.
This commit is contained in:
parent
59d4b170fc
commit
691ec08bac
@ -1550,11 +1550,12 @@ static bool
|
|||||||
cmdStart(vshControl *ctl, const vshCmd *cmd)
|
cmdStart(vshControl *ctl, const vshCmd *cmd)
|
||||||
{
|
{
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
bool ret = true;
|
bool ret = false;
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
int console = vshCommandOptBool(cmd, "console");
|
int console = vshCommandOptBool(cmd, "console");
|
||||||
#endif
|
#endif
|
||||||
unsigned int flags = VIR_DOMAIN_NONE;
|
unsigned int flags = VIR_DOMAIN_NONE;
|
||||||
|
int rc;
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
return false;
|
return false;
|
||||||
@ -1578,19 +1579,49 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptBool(cmd, "force-boot"))
|
if (vshCommandOptBool(cmd, "force-boot"))
|
||||||
flags |= VIR_DOMAIN_START_FORCE_BOOT;
|
flags |= VIR_DOMAIN_START_FORCE_BOOT;
|
||||||
|
|
||||||
|
/* We can emulate force boot, even for older servers that reject it. */
|
||||||
|
if (flags & VIR_DOMAIN_START_FORCE_BOOT) {
|
||||||
|
if (virDomainCreateWithFlags(dom, flags) == 0)
|
||||||
|
goto started;
|
||||||
|
if (last_error->code != VIR_ERR_NO_SUPPORT &&
|
||||||
|
last_error->code != VIR_ERR_INVALID_ARG) {
|
||||||
|
virshReportError(ctl);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
virFreeError(last_error);
|
||||||
|
last_error = NULL;
|
||||||
|
rc = virDomainHasManagedSaveImage(dom, 0);
|
||||||
|
if (rc < 0) {
|
||||||
|
/* No managed save image to remove */
|
||||||
|
virFreeError(last_error);
|
||||||
|
last_error = NULL;
|
||||||
|
} else if (rc > 0) {
|
||||||
|
if (virDomainManagedSaveRemove(dom, 0) < 0) {
|
||||||
|
virshReportError(ctl);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flags &= ~VIR_DOMAIN_START_FORCE_BOOT;
|
||||||
|
}
|
||||||
|
|
||||||
/* Prefer older API unless we have to pass a flag. */
|
/* Prefer older API unless we have to pass a flag. */
|
||||||
if ((flags ? virDomainCreateWithFlags(dom, flags)
|
if ((flags ? virDomainCreateWithFlags(dom, flags)
|
||||||
: virDomainCreate(dom)) == 0) {
|
: virDomainCreate(dom)) < 0) {
|
||||||
|
vshError(ctl, _("Failed to start domain %s"), virDomainGetName(dom));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
started:
|
||||||
vshPrint(ctl, _("Domain %s started\n"),
|
vshPrint(ctl, _("Domain %s started\n"),
|
||||||
virDomainGetName(dom));
|
virDomainGetName(dom));
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
if (console)
|
if (console && !cmdRunConsole(ctl, dom, NULL))
|
||||||
cmdRunConsole(ctl, dom, NULL);
|
goto cleanup;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
|
||||||
vshError(ctl, _("Failed to start domain %s"), virDomainGetName(dom));
|
ret = true;
|
||||||
ret = false;
|
|
||||||
}
|
cleanup:
|
||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user