From: Christian Brauner Date: Mon, 15 Feb 2021 11:23:36 +0000 (+0100) Subject: cgroups: improve cgroup mounting X-Git-Tag: lxc-5.0.0~287^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7e45fdffc6158974af96749aac04257790b65d8;p=thirdparty%2Flxc.git cgroups: improve cgroup mounting Signed-off-by: Christian Brauner --- diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index dc5f0972b..e982afa7a 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -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" : ""); } /* diff --git a/src/lxc/log.h b/src/lxc/log.h index e4081950e..6391b5488 100644 --- a/src/lxc/log.h +++ b/src/lxc/log.h @@ -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__); \