lxc container stopped not each time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Hi all.

I download  ftp://libvirt.org/libvirt/libvirt-5.1.0.tar.xz and build
rpms with lxc support.
LXC containers can be started, but time to time  can't be stopped.
With option --mode initctl containers always stopped, but virsh reported error:
"Container does not provide an initctl pipe"
Inside container present /dev/initctl:
# ls -la /dev/initctl
lrwxrwxrwx 1 root root 25 Mar  5 18:40 /dev/initctl -> /run/systemd/initctl/fifo

With option --mode signal, centos 7.5/7.6  systemd not stopped and
rebooted, in containers log:
systemd: Received SIGTERM.
systemd: Reexecuting.
systemd: systemd 219 running in system mode. (+PAM +AUDIT +SELINUX
+IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS
+ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN)
systemd: Detected virtualization lxc-libvirt.
systemd: Detected architecture x86-64.
Runlevel inside container  before and after  - is 5.

Without option --mode container can stop, mostly when you in gdb
step-by-step debug.
But most often not, with simptoms as with --mode signal. Patch in
attachment fix problem for my environment. Tested only with host
centos 7.6 and guests centos 7.5/7.6

Short comments on patch.
lxcDomainShutdownFlags() return rc 0  and container begin  stopped.
We not go to endjob label, but later we pass check:
  if (rc == 0 &&
        (flags == 0 ||
         (flags & VIR_DOMAIN_SHUTDOWN_SIGNAL))) {
and  trying next shutdown method with sigterm to pid1.
If container heavy loaded (or waiting in gdb for input), it not
stopped.  But if container small, first method with initctl stop
container before second method would be call

b.r.
  Maxim Kozin
--- libvirt/src/lxc/lxc_driver.c	2019-02-20 20:02:31.518222772 +0300
+++ libvirt-5.1.0.patched/src/lxc/lxc_driver.c	2019-03-05 17:47:36.371221512 +0300
@@ -3280,7 +3280,7 @@
     virLXCDomainObjPrivatePtr priv;
     virDomainObjPtr vm;
     int ret = -1;
-    int rc;
+    int rc = -1;
 
     virCheckFlags(VIR_DOMAIN_SHUTDOWN_INITCTL |
                   VIR_DOMAIN_SHUTDOWN_SIGNAL, -1);
@@ -3309,19 +3309,17 @@
         (flags & VIR_DOMAIN_SHUTDOWN_INITCTL)) {
         int command = VIR_INITCTL_RUNLEVEL_POWEROFF;
 
-        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;
+        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;
+            }
         }
-    } else {
-        rc = 0;
     }
 
-    if (rc == 0 &&
+    if (rc < 0 &&
         (flags == 0 ||
          (flags & VIR_DOMAIN_SHUTDOWN_SIGNAL))) {
         if (kill(priv->initpid, SIGTERM) < 0 &&
@@ -3358,7 +3356,7 @@
     virLXCDomainObjPrivatePtr priv;
     virDomainObjPtr vm;
     int ret = -1;
-    int rc;
+    int rc = -1;
 
     virCheckFlags(VIR_DOMAIN_REBOOT_INITCTL |
                   VIR_DOMAIN_REBOOT_SIGNAL, -1);
@@ -3387,19 +3385,17 @@
         (flags & VIR_DOMAIN_REBOOT_INITCTL)) {
         int command = VIR_INITCTL_RUNLEVEL_REBOOT;
 
-        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;
+        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;
+            }
         }
-    } else {
-        rc = 0;
     }
 
-    if (rc == 0 &&
+    if (rc < 0 &&
         (flags == 0 ||
          (flags & VIR_DOMAIN_REBOOT_SIGNAL))) {
         if (kill(priv->initpid, SIGHUP) < 0 &&
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux