[libvirt] [PATCH 01/12] virsh: Force boot emulation is only required for virDomainCreateWithFlags

Marc Hartmayer mhartmay at linux.vnet.ibm.com
Wed May 9 14:56:11 UTC 2018


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 at linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy at linux.ibm.com>
---
 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




More information about the libvir-list mailing list