On Wed, May 09, 2018 at 04:56 PM +0200, Marc Hartmayer <mhartmay@xxxxxxxxxxxxxxxxxx> wrote: > The force boot emulation is only required for virDomainCreateWithFlags > as the flag VIR_DOMAIN_START_FORCE_BOOT was introduced with the commit > 27c85260532f879be5674a4eed0811c21fd34f94 (2011). But > virDomainCreateXMLWithFiles is newer and therefore already had support > for VIR_DOMAIN_START_FORCE_BOOT. This means there is now no second > call with VIR_DOMAIN_START_FORCE_BOOT removed from flags for > virDomainCreateXMLWithFiles in case the first call > fails. virDomainCreateXMLWithFiles was introduced with commit > d76227bea35cc49374a94414f6d46e3493ac2a52 (2013). > > This patch takes this into account and simplifies the function. In > addition, it's now easier to extend the function. > > Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxxxxxxx> > Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx> > --- > tools/virsh-domain.c | 52 ++++++++++++++++++++++++++++------------------------ > 1 file changed, 28 insertions(+), 24 deletions(-) > > diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c > index 598d2fa4a4bd..7cf8373f05bc 100644 > --- a/tools/virsh-domain.c > +++ b/tools/virsh-domain.c > @@ -4038,40 +4038,44 @@ 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 ((nfds ? > - virDomainCreateWithFiles(dom, nfds, fds, flags) : > - virDomainCreateWithFlags(dom, flags)) == 0) > - goto started; > - if (last_error->code != VIR_ERR_NO_SUPPORT && > - last_error->code != VIR_ERR_INVALID_ARG) { > - vshReportError(ctl); > - goto cleanup; > - } > - vshResetLibvirtError(); > - rc = virDomainHasManagedSaveImage(dom, 0); > - if (rc < 0) { > - /* No managed save image to remove */ > - vshResetLibvirtError(); > - } else if (rc > 0) { > - if (virDomainManagedSaveRemove(dom, 0) < 0) { > + /* Prefer older API unless we have to pass extra parameters */ > + if (nfds) { > + rc = virDomainCreateWithFiles(dom, nfds, fds, flags); > + } else if (flags) { > + rc = virDomainCreateWithFlags(dom, flags); > + /* We can emulate force boot, even for older servers that > + * reject it. */ > + if (rc < 0 && flags & VIR_DOMAIN_START_FORCE_BOOT) { > + if (last_error->code != VIR_ERR_NO_SUPPORT && > + last_error->code != VIR_ERR_INVALID_ARG) { > vshReportError(ctl); > goto cleanup; > } > + vshResetLibvirtError(); > + rc = virDomainHasManagedSaveImage(dom, 0); > + if (rc < 0) { > + /* No managed save image to remove */ > + vshResetLibvirtError(); > + } else if (rc > 0) { > + if (virDomainManagedSaveRemove(dom, 0) < 0) { > + vshReportError(ctl); > + goto cleanup; > + } > + } > + > + /* now try it again without the force boot flag */ > + flags &= ~VIR_DOMAIN_START_FORCE_BOOT; > + rc = virDomainCreateWithFlags(dom, flags); > } > - flags &= ~VIR_DOMAIN_START_FORCE_BOOT; > + } else { > + rc = virDomainCreate(dom); > } > > - /* Prefer older API unless we have to pass a flag. */ > - if ((nfds ? virDomainCreateWithFiles(dom, nfds, fds, flags) : > - (flags ? virDomainCreateWithFlags(dom, flags) > - : virDomainCreate(dom))) < 0) { > + if (rc < 0) { > vshError(ctl, _("Failed to start domain %s"), virDomainGetName(dom)); > goto cleanup; > } > > - started: > vshPrintExtra(ctl, _("Domain %s started\n"), > virDomainGetName(dom)); > #ifndef WIN32 > -- > 2.13.4 > > -- > libvir-list mailing list > libvir-list@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/libvir-list Since this patch is not directly related to the proposed API it may be still useful => polite ping :) Beste Grüße / Kind regards Marc Hartmayer IBM Deutschland Research & Development GmbH Vorsitzende des Aufsichtsrats: Martina Koederitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list