]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: improve cgroup mounting
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 15 Feb 2021 11:23:36 +0000 (12:23 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 15 Feb 2021 11:23:36 +0000 (12:23 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c
src/lxc/log.h

index dc5f0972b72ea3452077da2f2b21d013ce96c1c6..e982afa7a0991288aecda93f878baa212e27e8b8 100644 (file)
@@ -1931,16 +1931,23 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
                        return log_error_errno(-errno, errno, "Failed to open %d(%s)",
                                               rootfs->dfd_mnt, DEFAULT_CGROUP_MOUNTPOINT_RELATIVE);
 
-               if (in_cgroup_ns && wants_force_mount) {
-                       /*
-                        * If cgroup namespaces are supported but the container
-                        * will not have CAP_SYS_ADMIN after it has started we
-                        * need to mount the cgroups manually.
-                        */
-                       return cg_mount_in_cgroup_namespace(type, ops->unified, rootfs, dfd_mnt_cgroupfs, "") == 0;
-               }
+               /*
+                * If cgroup namespaces are supported but the container will
+                * not have CAP_SYS_ADMIN after it has started we need to mount
+                * the cgroups manually.
+                */
+               if (in_cgroup_ns && wants_force_mount)
+                       ret = cg_mount_in_cgroup_namespace(type, ops->unified, rootfs, dfd_mnt_cgroupfs, "");
+               else
+                       ret = cg_mount_cgroup_full(type, ops->unified, rootfs, dfd_mnt_cgroupfs, "");
+               if (ret < 0)
+                       return syserrno(false, "Failed to%s mount cgroup filesystem%s",
+                                       wants_force_mount ? " force mount" : "",
+                                       in_cgroup_ns ? " in cgroup namespace" : "");
 
-               return cg_mount_cgroup_full(type, ops->unified, rootfs, dfd_mnt_cgroupfs, "") == 0;
+               return log_trace(true, "%s cgroup filesystem%s",
+                                wants_force_mount ? "Force mounted" : "Mounted",
+                                in_cgroup_ns ? " in cgroup namespace" : "");
        }
 
        /*
index e4081950e26adefd7b1d6c5f202b9c38015962b7..6391b5488a8acf68448a947c19998e080577cac4 100644 (file)
@@ -494,6 +494,13 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo,       \
                __internal_ret__;                             \
        })
 
+#define syserrno(__ret__, format, ...)                        \
+       ({                                                    \
+               typeof(__ret__) __internal_ret__ = (__ret__); \
+               SYSERROR(format, ##__VA_ARGS__);              \
+               __internal_ret__;                             \
+       })
+
 #define log_error(__ret__, format, ...)                       \
        ({                                                    \
                typeof(__ret__) __internal_ret__ = (__ret__); \