]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: simplify mount opening
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 17 Feb 2021 09:45:35 +0000 (10:45 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 17 Feb 2021 09:45:35 +0000 (10:45 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c

index 463fc6805bcfeb22fbca2335f58b59de6b28f208..8400011d1af98dd47e2b2c3b797aefa051f520e2 100644 (file)
@@ -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];