1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03: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:
Eric Blake 2011-08-30 09:51:25 -06:00
parent 59d4b170fc
commit 691ec08bac

View File

@ -1550,11 +1550,12 @@ static bool
cmdStart(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
bool ret = true;
bool ret = false;
#ifndef WIN32
int console = vshCommandOptBool(cmd, "console");
#endif
unsigned int flags = VIR_DOMAIN_NONE;
int rc;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
@ -1578,19 +1579,49 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "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. */
if ((flags ? virDomainCreateWithFlags(dom, flags)
: virDomainCreate(dom)) == 0) {
vshPrint(ctl, _("Domain %s started\n"),
virDomainGetName(dom));
#ifndef WIN32
if (console)
cmdRunConsole(ctl, dom, NULL);
#endif
} else {
: virDomainCreate(dom)) < 0) {
vshError(ctl, _("Failed to start domain %s"), virDomainGetName(dom));
ret = false;
goto cleanup;
}
started:
vshPrint(ctl, _("Domain %s started\n"),
virDomainGetName(dom));
#ifndef WIN32
if (console && !cmdRunConsole(ctl, dom, NULL))
goto cleanup;
#endif
ret = true;
cleanup:
virDomainFree(dom);
return ret;
}