From 8f45c49bb1ba70e2eb1af2e64f10df853c4c22bf Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Wed, 17 Feb 2021 10:45:35 +0100 Subject: [PATCH] cgroups: simplify mount opening Signed-off-by: Christian Brauner --- src/lxc/cgroups/cgfsng.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 463fc6805..8400011d1 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -1991,16 +1991,16 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops, else if (cg_flags & LXC_AUTO_CGROUP_FULL_NOSPEC) cg_flags = LXC_AUTO_CGROUP_FULL_MIXED; + dfd_mnt_cgroupfs = open_at(rootfs->dfd_mnt, + DEFAULT_CGROUP_MOUNTPOINT_RELATIVE, + PROTECT_OPATH_DIRECTORY, + PROTECT_LOOKUP_BENEATH_XDEV, 0); + if (dfd_mnt_cgroupfs < 0) + return syserrno(-errno, "Failed to open %d(%s)", rootfs->dfd_mnt, + DEFAULT_CGROUP_MOUNTPOINT_RELATIVE); + /* This is really the codepath that we want. */ if (pure_unified_layout(ops)) { - dfd_mnt_cgroupfs = open_at(rootfs->dfd_mnt, - DEFAULT_CGROUP_MOUNTPOINT_RELATIVE, - PROTECT_OPATH_DIRECTORY, - PROTECT_LOOKUP_BENEATH_XDEV, 0); - if (dfd_mnt_cgroupfs < 0) - return log_error_errno(-errno, errno, "Failed to open %d(%s)", - rootfs->dfd_mnt, DEFAULT_CGROUP_MOUNTPOINT_RELATIVE); - /* * If cgroup namespaces are supported but the container will * not have CAP_SYS_ADMIN after it has started we need to mount @@ -2099,14 +2099,6 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops, return log_error_errno(false, errno, "Failed to mount tmpfs on %s", DEFAULT_CGROUP_MOUNTPOINT_RELATIVE); - dfd_mnt_cgroupfs = open_at(rootfs->dfd_mnt, - DEFAULT_CGROUP_MOUNTPOINT_RELATIVE, - PROTECT_OPATH_DIRECTORY, - PROTECT_LOOKUP_BENEATH_XDEV, 0); - if (dfd_mnt_cgroupfs < 0) - return log_error_errno(-errno, errno, "Failed to open %d(%s)", - rootfs->dfd_mnt, DEFAULT_CGROUP_MOUNTPOINT_RELATIVE); - for (int i = 0; ops->hierarchies[i]; i++) { __do_free char *controllerpath = NULL, *path2 = NULL; struct hierarchy *h = ops->hierarchies[i]; -- 2.47.2