From: Christian Brauner Date: Wed, 17 Feb 2021 15:59:40 +0000 (+0100) Subject: cgroups: make it extremely obvious that we're transitioning from a flag to a type X-Git-Tag: lxc-5.0.0~278^2~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd09ee987dce37f6204a35bb0c147438351b1cfd;p=thirdparty%2Flxc.git cgroups: make it extremely obvious that we're transitioning from a flag to a type Signed-off-by: Christian Brauner --- diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index fb4f9fb7f..501d71a9f 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -1770,9 +1770,9 @@ __cgfsng_ops static void cgfsng_payload_finalize(struct cgroup_ops *ops) } /* cgroup-full:* is done, no need to create subdirs */ -static inline bool cg_mount_needs_subdirs(int cg_flags) +static inline bool cg_mount_needs_subdirs(int cgroup_automount_type) { - switch (cg_flags) { + switch (cgroup_automount_type) { case LXC_AUTO_CGROUP_RO: return true; case LXC_AUTO_CGROUP_RW: @@ -1788,7 +1788,7 @@ static inline bool cg_mount_needs_subdirs(int cg_flags) * remount controller ro if needed and bindmount the cgroupfs onto * control/the/cg/path. */ -static int cg_legacy_mount_controllers(int cg_flags, struct hierarchy *h, +static int cg_legacy_mount_controllers(int cgroup_automount_type, struct hierarchy *h, char *controllerpath, char *cgpath, const char *container_cgroup) { @@ -1796,7 +1796,8 @@ static int cg_legacy_mount_controllers(int cg_flags, struct hierarchy *h, int ret, remount_flags; int flags = MS_BIND; - if ((cg_flags == LXC_AUTO_CGROUP_RO) || (cg_flags == LXC_AUTO_CGROUP_MIXED)) { + if ((cgroup_automount_type == LXC_AUTO_CGROUP_RO) || + (cgroup_automount_type == LXC_AUTO_CGROUP_MIXED)) { ret = mount(controllerpath, controllerpath, "cgroup", MS_BIND, NULL); if (ret < 0) return log_error_errno(-1, errno, "Failed to bind mount \"%s\" onto \"%s\"", @@ -1816,7 +1817,7 @@ static int cg_legacy_mount_controllers(int cg_flags, struct hierarchy *h, sourcepath = must_make_path(h->mountpoint, h->container_base_path, container_cgroup, NULL); - if (cg_flags == LXC_AUTO_CGROUP_RO) + if (cgroup_automount_type == LXC_AUTO_CGROUP_RO) flags |= MS_RDONLY; ret = mount(sourcepath, cgpath, "cgroup", flags, NULL); @@ -1844,7 +1845,7 @@ static int cg_legacy_mount_controllers(int cg_flags, struct hierarchy *h, * uses-cases are mounting cgroup hierarchies in cgroup namespaces and mounting * cgroups for the LXC_AUTO_CGROUP_FULL option. */ -static int __cgroupfs_mount(int cg_flags, struct hierarchy *h, +static int __cgroupfs_mount(int cgroup_automount_type, struct hierarchy *h, struct lxc_rootfs *rootfs, int dfd_mnt_cgroupfs, const char *hierarchy_mnt) { @@ -1861,15 +1862,14 @@ static int __cgroupfs_mount(int cg_flags, struct hierarchy *h, flags |= MOUNT_ATTR_NODEV; flags |= MOUNT_ATTR_RELATIME; - if ((cg_flags == LXC_AUTO_CGROUP_RO) || - (cg_flags == LXC_AUTO_CGROUP_FULL_RO)) + if ((cgroup_automount_type == LXC_AUTO_CGROUP_RO) || + (cgroup_automount_type == LXC_AUTO_CGROUP_FULL_RO)) flags |= MOUNT_ATTR_RDONLY; - if (is_unified_hierarchy(h)) { + if (is_unified_hierarchy(h)) fstype = "cgroup2"; - } else { + else fstype = "cgroup"; - } if (can_use_mount_api()) { fd_fs = fs_prepare(fstype, -EBADF, "", 0, 0); @@ -1918,19 +1918,20 @@ static int __cgroupfs_mount(int cg_flags, struct hierarchy *h, return 0; } -static inline int cgroupfs_mount(int cg_flags, struct hierarchy *h, +static inline int cgroupfs_mount(int cgroup_automount_type, struct hierarchy *h, struct lxc_rootfs *rootfs, int dfd_mnt_cgroupfs, const char *hierarchy_mnt) { - return __cgroupfs_mount(cg_flags, h, rootfs, dfd_mnt_cgroupfs, hierarchy_mnt); + return __cgroupfs_mount(cgroup_automount_type, h, rootfs, + dfd_mnt_cgroupfs, hierarchy_mnt); } -static inline int cgroupfs_bind_mount(int cg_flags, struct hierarchy *h, +static inline int cgroupfs_bind_mount(int cgroup_automount_type, struct hierarchy *h, struct lxc_rootfs *rootfs, int dfd_mnt_cgroupfs, const char *hierarchy_mnt) { - switch (cg_flags) { + switch (cgroup_automount_type) { case LXC_AUTO_CGROUP_FULL_RO: break; case LXC_AUTO_CGROUP_FULL_RW: @@ -1941,7 +1942,8 @@ static inline int cgroupfs_bind_mount(int cg_flags, struct hierarchy *h, return 0; } - return __cgroupfs_mount(cg_flags, h, rootfs, dfd_mnt_cgroupfs, hierarchy_mnt); + return __cgroupfs_mount(cgroup_automount_type, h, rootfs, + dfd_mnt_cgroupfs, hierarchy_mnt); } __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops, @@ -1949,6 +1951,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops, { __do_close int dfd_mnt_tmpfs = -EBADF, fd_fs = -EBADF; __do_free char *cgroup_root = NULL; + int cgroup_automount_type; bool in_cgroup_ns = false, wants_force_mount = false; struct lxc_conf *conf = handler->conf; struct lxc_rootfs *rootfs = &conf->rootfs; @@ -1994,6 +1997,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops, default: return log_error_errno(false, EINVAL, "Invalid cgroup mount options specified"); } + cgroup_automount_type = cg_flags; if (!wants_force_mount) { wants_force_mount = !lxc_wants_cap(CAP_SYS_ADMIN, conf); @@ -2021,8 +2025,8 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops, * since the parent directory of the container's cgroup is not * accessible to the container. */ - cg_flags &= ~LXC_AUTO_CGROUP_MIXED; - cg_flags &= ~LXC_AUTO_CGROUP_FULL_MIXED; + cgroup_automount_type &= ~LXC_AUTO_CGROUP_MIXED; + cgroup_automount_type &= ~LXC_AUTO_CGROUP_FULL_MIXED; } if (in_cgroup_ns && !wants_force_mount) @@ -2067,7 +2071,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops, * 11. cgroup-full:ro:force -> Not supported. * 12. cgroup-full:mixed:force -> Not supported. */ - ret = cgroupfs_mount(cg_flags, ops->unified, rootfs, dfd_mnt_unified, ""); + ret = cgroupfs_mount(cgroup_automount_type, ops->unified, rootfs, dfd_mnt_unified, ""); if (ret < 0) return syserrno(false, "Failed to force mount cgroup filesystem in cgroup namespace"); @@ -2160,7 +2164,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops, * will not have CAP_SYS_ADMIN after it has started we * need to mount the cgroups manually. */ - ret = cgroupfs_mount(cg_flags, h, rootfs, dfd_mnt_tmpfs, controller); + ret = cgroupfs_mount(cgroup_automount_type, h, rootfs, dfd_mnt_tmpfs, controller); if (ret < 0) return false; @@ -2168,11 +2172,11 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops, } /* Here is where the ancient kernel section begins. */ - ret = cgroupfs_bind_mount(cg_flags, h, rootfs, dfd_mnt_tmpfs, controller); + ret = cgroupfs_bind_mount(cgroup_automount_type, h, rootfs, dfd_mnt_tmpfs, controller); if (ret < 0) return false; - if (!cg_mount_needs_subdirs(cg_flags)) + if (!cg_mount_needs_subdirs(cgroup_automount_type)) continue; if (!cgroup_root) @@ -2184,7 +2188,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops, if (ret < 0 && (errno != EEXIST)) return false; - ret = cg_legacy_mount_controllers(cg_flags, h, controllerpath, path2, ops->container_cgroup); + ret = cg_legacy_mount_controllers(cgroup_automount_type, h, controllerpath, path2, ops->container_cgroup); if (ret < 0) return false; }