From: Christian Brauner Date: Wed, 17 Feb 2021 09:45:35 +0000 (+0100) Subject: cgroups: simplify mount opening X-Git-Tag: lxc-5.0.0~281^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f45c49bb1ba70e2eb1af2e64f10df853c4c22bf;p=thirdparty%2Flxc.git cgroups: simplify mount opening Signed-off-by: Christian Brauner --- 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];