static inline bool is_unified_hierarchy(const struct hierarchy *h)
{
- return h->version == CGROUP2_SUPER_MAGIC;
+ return h->fs_type == UNIFIED_HIERARCHY;
}
/* Return true if the controller @entry is found in the null-terminated list of
static int cgroup_hierarchy_add(struct cgroup_ops *ops, int dfd_mnt, char *mnt,
int dfd_base, char *base_cgroup,
- char **controllers, int type)
+ char **controllers, cgroupfs_type_magic_t fs_type)
{
__do_free struct hierarchy *new = NULL;
int idx;
new->cgfd_limit = -EBADF;
new->cgfd_mon = -EBADF;
- new->version = type;
+ new->fs_type = fs_type;
new->controllers = controllers;
new->mountpoint = mnt;
new->container_base_path = base_cgroup;
if (idx < 0)
return ret_errno(idx);
- if (type == CGROUP2_SUPER_MAGIC)
+ if (fs_type == UNIFIED_HIERARCHY)
ops->unified = new;
(ops->hierarchies)[idx] = move_ptr(new);
* files (which systemd in wily insists on doing).
*/
- if (arg->hierarchies[i]->version == CGROUP_SUPER_MAGIC)
+ if (arg->hierarchies[i]->fs_type == LEGACY_HIERARCHY)
(void)fchowmodat(dirfd, "tasks", destuid, nsgid, 0664);
(void)fchowmodat(dirfd, "cgroup.procs", destuid, nsgid, 0664);
- if (arg->hierarchies[i]->version != CGROUP2_SUPER_MAGIC)
+ if (arg->hierarchies[i]->fs_type != UNIFIED_HIERARCHY)
continue;
for (char **p = arg->hierarchies[i]->cgroup2_chown; p && *p; p++)
__do_free char *fullpath = NULL, *path = NULL;
struct hierarchy *h = ops->hierarchies[i];
- if (h->version == CGROUP2_SUPER_MAGIC) {
+ if (h->fs_type == UNIFIED_HIERARCHY) {
ret = __cg_unified_attach(h, conf, name, lxcpath, pid,
h->controllers[0]);
if (ret < 0)
if (unified_cgroup(line)) {
char *unified_mnt;
+ type = UNIFIED_HIERARCHY;
+
current_cgroup = current_unified_cgroup(relative, line);
if (IS_ERR(current_cgroup))
return PTR_ERR(current_cgroup);
return syserrno(-ENOMEM, "Failed to create empty controller list");
}
- type = CGROUP2_SUPER_MAGIC;
controllers = strdup(unified_mnt);
if (!controllers)
return ret_errno(ENOMEM);
} else {
char *__controllers, *__current_cgroup;
+ type = LEGACY_HIERARCHY;
+
__controllers = strchr(line, ':');
if (!__controllers)
return ret_errno(EINVAL);
if (skip_hierarchy(ops, controller_list))
continue;
- type = CGROUP_SUPER_MAGIC;
ops->cgroup_layout = CGROUP_LAYOUT_LEGACY;
}
move_ptr(current_cgroup);
move_ptr(controllers);
move_ptr(controller_list);
- if (type == CGROUP2_SUPER_MAGIC)
+ if (type == UNIFIED_HIERARCHY)
ops->unified->cgroup2_chown = move_ptr(delegate);
}
#include <stdbool.h>
#include <stddef.h>
#include <sys/types.h>
+#include <linux/magic.h>
#include "compiler.h"
#include "macro.h"
CGROUP_LAYOUT_UNIFIED = 2,
} cgroup_layout_t;
+typedef enum {
+ LEGACY_HIERARCHY = CGROUP_SUPER_MAGIC,
+ UNIFIED_HIERARCHY = CGROUP2_SUPER_MAGIC,
+} cgroupfs_type_magic_t;
+
/* A descriptor for a mounted hierarchy
*
* @controllers
char *container_base_path;
char *container_full_path;
char *container_limit_path;
- int version;
+ cgroupfs_type_magic_t fs_type;
/* cgroup2 only */
unsigned int bpf_device_controller:1;