[libvirt] [PATCH] Revert "lxc: Try harder to stop/reboot containers"

Daniel P. Berrangé berrange at redhat.com
Thu Jul 4 09:46:49 UTC 2019


This reverts commit 14b6a1854fb4c02c5fb2f51679f8ff099f28f53c.

If virLXCDomainSetRunlevel returns -1 this indicates a serious
error / failure that must be propagated to the caller. We must
not carry on with other shutdown methods in this case.

If virLXCDomainSetRunlevel return 0, this indicates that no
initctl was found and it is thus reasonable to fallback to
sending SIGTERM.

The commit being reverted is broken because it would fallback
to SIGTERM when virLXCDomainSetRunlevel returns -1, and would
not fallback when virLXCDomainSetRunlevel returns 0. ie it
did the exact opposite of what was required.

Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 src/lxc/lxc_driver.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 9db2a02dee..01af5f6db8 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3262,7 +3262,7 @@ lxcDomainShutdownFlags(virDomainPtr dom,
     virLXCDomainObjPrivatePtr priv;
     virDomainObjPtr vm;
     int ret = -1;
-    int rc = -1;
+    int rc;
 
     virCheckFlags(VIR_DOMAIN_SHUTDOWN_INITCTL |
                   VIR_DOMAIN_SHUTDOWN_SIGNAL, -1);
@@ -3291,17 +3291,19 @@ lxcDomainShutdownFlags(virDomainPtr dom,
         (flags & VIR_DOMAIN_SHUTDOWN_INITCTL)) {
         int command = VIR_INITCTL_RUNLEVEL_POWEROFF;
 
-        if ((rc = virLXCDomainSetRunlevel(vm, command)) < 0) {
-            if (flags != 0 &&
-                (flags & VIR_DOMAIN_SHUTDOWN_INITCTL)) {
-                virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                               _("Container does not provide an initctl pipe"));
-                goto endjob;
-            }
+        if ((rc = virLXCDomainSetRunlevel(vm, command)) < 0)
+            goto endjob;
+        if (rc == 0 && flags != 0 &&
+            ((flags & ~VIR_DOMAIN_SHUTDOWN_INITCTL) == 0)) {
+            virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                           _("Container does not provide an initctl pipe"));
+            goto endjob;
         }
+    } else {
+        rc = 0;
     }
 
-    if (rc < 0 &&
+    if (rc == 0 &&
         (flags == 0 ||
          (flags & VIR_DOMAIN_SHUTDOWN_SIGNAL))) {
         if (kill(priv->initpid, SIGTERM) < 0 &&
@@ -3338,7 +3340,7 @@ lxcDomainReboot(virDomainPtr dom,
     virLXCDomainObjPrivatePtr priv;
     virDomainObjPtr vm;
     int ret = -1;
-    int rc = -1;
+    int rc;
 
     virCheckFlags(VIR_DOMAIN_REBOOT_INITCTL |
                   VIR_DOMAIN_REBOOT_SIGNAL, -1);
@@ -3367,17 +3369,19 @@ lxcDomainReboot(virDomainPtr dom,
         (flags & VIR_DOMAIN_REBOOT_INITCTL)) {
         int command = VIR_INITCTL_RUNLEVEL_REBOOT;
 
-        if ((rc = virLXCDomainSetRunlevel(vm, command)) < 0) {
-            if (flags != 0 &&
-                (flags & VIR_DOMAIN_REBOOT_INITCTL)) {
-                virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                               _("Container does not provide an initctl pipe"));
-                goto endjob;
-            }
+        if ((rc = virLXCDomainSetRunlevel(vm, command)) < 0)
+            goto endjob;
+        if (rc == 0 && flags != 0 &&
+            ((flags & ~VIR_DOMAIN_SHUTDOWN_INITCTL) == 0)) {
+            virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                           _("Container does not provide an initctl pipe"));
+            goto endjob;
         }
+    } else {
+        rc = 0;
     }
 
-    if (rc < 0 &&
+    if (rc == 0 &&
         (flags == 0 ||
          (flags & VIR_DOMAIN_REBOOT_SIGNAL))) {
         if (kill(priv->initpid, SIGHUP) < 0 &&
-- 
2.21.0




More information about the libvir-list mailing list