aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-07-09 10:08:08 -0400
committerTejun Heo <tj@kernel.org>2014-07-09 10:08:08 -0400
commit7b9a6ba56e9519ed5413a002dc0b0f01aa598bb5 (patch)
treea8fecb7d4e2506683792ad71eba5b442006ac4cf
parentaa6ec29bee8692ce232132f1a1ea2a1f9196610e (diff)
cgroup: clean up sane_behavior handling
After the previous patch to remove sane_behavior support from non-default hierarchies, CGRP_ROOT_SANE_BEHAVIOR is used only to indicate the default hierarchy while parsing mount options. This patch makes the following cleanups around it. * Don't show it in the mount option. Eventually the default hierarchy will be assigned a different filesystem type. * As sane_behavior is no longer effective on non-default hierarchies and the default hierarchy doesn't accept any mount options, parse_cgroupfs_options() can consider sane_behavior mount option as indicating the default hierarchy and fail if any other options are specified with it. While at it, remove one of the double blank lines in the function. * cgroup_mount() can now simply test CGRP_ROOT_SANE_BEHAVIOR to tell whether to mount the default hierarchy or not. * As CGROUP_ROOT_SANE_BEHAVIOR's only role now is indicating whether to select the default hierarchy or not during mount, it doesn't need to be set in the default hierarchy itself. cgroup_init_early() updated accordingly. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
-rw-r--r--kernel/cgroup.c66
1 files changed, 27 insertions, 39 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index fb07c6d43aff..28f7d47c1d4a 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1289,8 +1289,6 @@ static int cgroup_show_options(struct seq_file *seq,
1289 for_each_subsys(ss, ssid) 1289 for_each_subsys(ss, ssid)
1290 if (root->subsys_mask & (1 << ssid)) 1290 if (root->subsys_mask & (1 << ssid))
1291 seq_printf(seq, ",%s", ss->name); 1291 seq_printf(seq, ",%s", ss->name);
1292 if (root->flags & CGRP_ROOT_SANE_BEHAVIOR)
1293 seq_puts(seq, ",sane_behavior");
1294 if (root->flags & CGRP_ROOT_NOPREFIX) 1292 if (root->flags & CGRP_ROOT_NOPREFIX)
1295 seq_puts(seq, ",noprefix"); 1293 seq_puts(seq, ",noprefix");
1296 if (root->flags & CGRP_ROOT_XATTR) 1294 if (root->flags & CGRP_ROOT_XATTR)
@@ -1324,6 +1322,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
1324 bool all_ss = false, one_ss = false; 1322 bool all_ss = false, one_ss = false;
1325 unsigned int mask = -1U; 1323 unsigned int mask = -1U;
1326 struct cgroup_subsys *ss; 1324 struct cgroup_subsys *ss;
1325 int nr_opts = 0;
1327 int i; 1326 int i;
1328 1327
1329#ifdef CONFIG_CPUSETS 1328#ifdef CONFIG_CPUSETS
@@ -1333,6 +1332,8 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
1333 memset(opts, 0, sizeof(*opts)); 1332 memset(opts, 0, sizeof(*opts));
1334 1333
1335 while ((token = strsep(&o, ",")) != NULL) { 1334 while ((token = strsep(&o, ",")) != NULL) {
1335 nr_opts++;
1336
1336 if (!*token) 1337 if (!*token)
1337 return -EINVAL; 1338 return -EINVAL;
1338 if (!strcmp(token, "none")) { 1339 if (!strcmp(token, "none")) {
@@ -1417,37 +1418,33 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
1417 return -ENOENT; 1418 return -ENOENT;
1418 } 1419 }
1419 1420
1420 /* Consistency checks */
1421
1422 if (opts->flags & CGRP_ROOT_SANE_BEHAVIOR) { 1421 if (opts->flags & CGRP_ROOT_SANE_BEHAVIOR) {
1423 pr_warn("sane_behavior: this is still under development and its behaviors will change, proceed at your own risk\n"); 1422 pr_warn("sane_behavior: this is still under development and its behaviors will change, proceed at your own risk\n");
1424 1423 if (nr_opts != 1) {
1425 if ((opts->flags & (CGRP_ROOT_NOPREFIX | CGRP_ROOT_XATTR)) || 1424 pr_err("sane_behavior: no other mount options allowed\n");
1426 opts->cpuset_clone_children || opts->release_agent ||
1427 opts->name) {
1428 pr_err("sane_behavior: noprefix, xattr, clone_children, release_agent and name are not allowed\n");
1429 return -EINVAL; 1425 return -EINVAL;
1430 } 1426 }
1431 } else { 1427 return 0;
1432 /*
1433 * If the 'all' option was specified select all the
1434 * subsystems, otherwise if 'none', 'name=' and a subsystem
1435 * name options were not specified, let's default to 'all'
1436 */
1437 if (all_ss || (!one_ss && !opts->none && !opts->name))
1438 for_each_subsys(ss, i)
1439 if (!ss->disabled)
1440 opts->subsys_mask |= (1 << i);
1441
1442 /*
1443 * We either have to specify by name or by subsystems. (So
1444 * all empty hierarchies must have a name).
1445 */
1446 if (!opts->subsys_mask && !opts->name)
1447 return -EINVAL;
1448 } 1428 }
1449 1429
1450 /* 1430 /*
1431 * If the 'all' option was specified select all the subsystems,
1432 * otherwise if 'none', 'name=' and a subsystem name options were
1433 * not specified, let's default to 'all'
1434 */
1435 if (all_ss || (!one_ss && !opts->none && !opts->name))
1436 for_each_subsys(ss, i)
1437 if (!ss->disabled)
1438 opts->subsys_mask |= (1 << i);
1439
1440 /*
1441 * We either have to specify by name or by subsystems. (So all
1442 * empty hierarchies must have a name).
1443 */
1444 if (!opts->subsys_mask && !opts->name)
1445 return -EINVAL;
1446
1447 /*
1451 * Option noprefix was introduced just for backward compatibility 1448 * Option noprefix was introduced just for backward compatibility
1452 * with the old cpuset, so we allow noprefix only if mounting just 1449 * with the old cpuset, so we allow noprefix only if mounting just
1453 * the cpuset subsystem. 1450 * the cpuset subsystem.
@@ -1455,7 +1452,6 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
1455 if ((opts->flags & CGRP_ROOT_NOPREFIX) && (opts->subsys_mask & mask)) 1452 if ((opts->flags & CGRP_ROOT_NOPREFIX) && (opts->subsys_mask & mask))
1456 return -EINVAL; 1453 return -EINVAL;
1457 1454
1458
1459 /* Can't specify "none" and some subsystems */ 1455 /* Can't specify "none" and some subsystems */
1460 if (opts->subsys_mask && opts->none) 1456 if (opts->subsys_mask && opts->none)
1461 return -EINVAL; 1457 return -EINVAL;
@@ -1724,7 +1720,7 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
1724 goto out_unlock; 1720 goto out_unlock;
1725 1721
1726 /* look for a matching existing root */ 1722 /* look for a matching existing root */
1727 if (!opts.subsys_mask && !opts.none && !opts.name) { 1723 if (opts.flags & CGRP_ROOT_SANE_BEHAVIOR) {
1728 cgrp_dfl_root_visible = true; 1724 cgrp_dfl_root_visible = true;
1729 root = &cgrp_dfl_root; 1725 root = &cgrp_dfl_root;
1730 cgroup_get(&root->cgrp); 1726 cgroup_get(&root->cgrp);
@@ -1761,15 +1757,8 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
1761 goto out_unlock; 1757 goto out_unlock;
1762 } 1758 }
1763 1759
1764 if (root->flags ^ opts.flags) { 1760 if (root->flags ^ opts.flags)
1765 if ((root->flags | opts.flags) & CGRP_ROOT_SANE_BEHAVIOR) { 1761 pr_warn("new mount options do not match the existing superblock, will be ignored\n");
1766 pr_err("sane_behavior: new mount options should match the existing superblock\n");
1767 ret = -EINVAL;
1768 goto out_unlock;
1769 } else {
1770 pr_warn("new mount options do not match the existing superblock, will be ignored\n");
1771 }
1772 }
1773 1762
1774 /* 1763 /*
1775 * A root's lifetime is governed by its root cgroup. 1764 * A root's lifetime is governed by its root cgroup.
@@ -4809,8 +4798,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss, bool early)
4809 */ 4798 */
4810int __init cgroup_init_early(void) 4799int __init cgroup_init_early(void)
4811{ 4800{
4812 static struct cgroup_sb_opts __initdata opts = 4801 static struct cgroup_sb_opts __initdata opts;
4813 { .flags = CGRP_ROOT_SANE_BEHAVIOR };
4814 struct cgroup_subsys *ss; 4802 struct cgroup_subsys *ss;
4815 int i; 4803 int i;
4816 4804