Skip to content

Commit d5f68d3

Browse files
author
Al Viro
committed
cpuset: move mount -t cpuset logics into cgroup.c
... and get rid of the weird dances in ->get_tree() - that logics can be easily handled in ->init_fs_context(). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 46cf047 commit d5f68d3

2 files changed

Lines changed: 48 additions & 60 deletions

File tree

‎kernel/cgroup/cgroup.c‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,50 @@ static struct file_system_type cgroup2_fs_type = {
22252225
.fs_flags = FS_USERNS_MOUNT,
22262226
};
22272227

2228+
#ifdef CONFIG_CPUSETS
2229+
static const struct fs_context_operations cpuset_fs_context_ops = {
2230+
.get_tree = cgroup1_get_tree,
2231+
.free = cgroup_fs_context_free,
2232+
};
2233+
2234+
/*
2235+
* This is ugly, but preserves the userspace API for existing cpuset
2236+
* users. If someone tries to mount the "cpuset" filesystem, we
2237+
* silently switch it to mount "cgroup" instead
2238+
*/
2239+
static int cpuset_init_fs_context(struct fs_context *fc)
2240+
{
2241+
char *agent = kstrdup("/sbin/cpuset_release_agent", GFP_USER);
2242+
struct cgroup_fs_context *ctx;
2243+
int err;
2244+
2245+
err = cgroup_init_fs_context(fc);
2246+
if (err) {
2247+
kfree(agent);
2248+
return err;
2249+
}
2250+
2251+
fc->ops = &cpuset_fs_context_ops;
2252+
2253+
ctx = cgroup_fc2context(fc);
2254+
ctx->subsys_mask = 1 << cpuset_cgrp_id;
2255+
ctx->flags |= CGRP_ROOT_NOPREFIX;
2256+
ctx->release_agent = agent;
2257+
2258+
get_filesystem(&cgroup_fs_type);
2259+
put_filesystem(fc->fs_type);
2260+
fc->fs_type = &cgroup_fs_type;
2261+
2262+
return 0;
2263+
}
2264+
2265+
static struct file_system_type cpuset_fs_type = {
2266+
.name = "cpuset",
2267+
.init_fs_context = cpuset_init_fs_context,
2268+
.fs_flags = FS_USERNS_MOUNT,
2269+
};
2270+
#endif
2271+
22282272
int cgroup_path_ns_locked(struct cgroup *cgrp, char *buf, size_t buflen,
22292273
struct cgroup_namespace *ns)
22302274
{
@@ -5710,6 +5754,9 @@ int __init cgroup_init(void)
57105754
WARN_ON(register_filesystem(&cgroup_fs_type));
57115755
WARN_ON(register_filesystem(&cgroup2_fs_type));
57125756
WARN_ON(!proc_create_single("cgroups", 0, NULL, proc_cgroupstats_show));
5757+
#ifdef CONFIG_CPUSETS
5758+
WARN_ON(register_filesystem(&cpuset_fs_type));
5759+
#endif
57135760

57145761
return 0;
57155762
}

‎kernel/cgroup/cpuset.c‎

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -355,59 +355,6 @@ static inline bool is_in_v2_mode(void)
355355
(cpuset_cgrp_subsys.root->flags & CGRP_ROOT_CPUSET_V2_MODE);
356356
}
357357

358-
/*
359-
* This is ugly, but preserves the userspace API for existing cpuset
360-
* users. If someone tries to mount the "cpuset" filesystem, we
361-
* silently switch it to mount "cgroup" instead
362-
*/
363-
static int cpuset_get_tree(struct fs_context *fc)
364-
{
365-
struct file_system_type *cgroup_fs;
366-
struct fs_context *new_fc;
367-
int ret;
368-
369-
cgroup_fs = get_fs_type("cgroup");
370-
if (!cgroup_fs)
371-
return -ENODEV;
372-
373-
new_fc = fs_context_for_mount(cgroup_fs, fc->sb_flags);
374-
if (IS_ERR(new_fc)) {
375-
ret = PTR_ERR(new_fc);
376-
} else {
377-
static const char agent_path[] = "/sbin/cpuset_release_agent";
378-
ret = vfs_parse_fs_string(new_fc, "cpuset", NULL, 0);
379-
if (!ret)
380-
ret = vfs_parse_fs_string(new_fc, "noprefix", NULL, 0);
381-
if (!ret)
382-
ret = vfs_parse_fs_string(new_fc, "release_agent",
383-
agent_path, sizeof(agent_path) - 1);
384-
if (!ret)
385-
ret = vfs_get_tree(new_fc);
386-
if (!ret) { /* steal the result */
387-
fc->root = new_fc->root;
388-
new_fc->root = NULL;
389-
}
390-
put_fs_context(new_fc);
391-
}
392-
put_filesystem(cgroup_fs);
393-
return ret;
394-
}
395-
396-
static const struct fs_context_operations cpuset_fs_context_ops = {
397-
.get_tree = cpuset_get_tree,
398-
};
399-
400-
static int cpuset_init_fs_context(struct fs_context *fc)
401-
{
402-
fc->ops = &cpuset_fs_context_ops;
403-
return 0;
404-
}
405-
406-
static struct file_system_type cpuset_fs_type = {
407-
.name = "cpuset",
408-
.init_fs_context = cpuset_init_fs_context,
409-
};
410-
411358
/*
412359
* Return in pmask the portion of a cpusets's cpus_allowed that
413360
* are online. If none are online, walk up the cpuset hierarchy
@@ -2853,13 +2800,11 @@ struct cgroup_subsys cpuset_cgrp_subsys = {
28532800
/**
28542801
* cpuset_init - initialize cpusets at system boot
28552802
*
2856-
* Description: Initialize top_cpuset and the cpuset internal file system,
2803+
* Description: Initialize top_cpuset
28572804
**/
28582805

28592806
int __init cpuset_init(void)
28602807
{
2861-
int err = 0;
2862-
28632808
BUG_ON(!alloc_cpumask_var(&top_cpuset.cpus_allowed, GFP_KERNEL));
28642809
BUG_ON(!alloc_cpumask_var(&top_cpuset.effective_cpus, GFP_KERNEL));
28652810
BUG_ON(!zalloc_cpumask_var(&top_cpuset.subparts_cpus, GFP_KERNEL));
@@ -2873,10 +2818,6 @@ int __init cpuset_init(void)
28732818
set_bit(CS_SCHED_LOAD_BALANCE, &top_cpuset.flags);
28742819
top_cpuset.relax_domain_level = -1;
28752820

2876-
err = register_filesystem(&cpuset_fs_type);
2877-
if (err < 0)
2878-
return err;
2879-
28802821
BUG_ON(!alloc_cpumask_var(&cpus_attach, GFP_KERNEL));
28812822

28822823
return 0;

0 commit comments

Comments
 (0)