Merge branch 'for-linus' of git://git.kernel.dk/linux-block
[cascardo/linux.git] / kernel / cpuset.c
index 37ca0a5..f6b33c6 100644 (file)
 #include <linux/cgroup.h>
 #include <linux/wait.h>
 
-/*
- * Tracks how many cpusets are currently defined in system.
- * When there is only one cpuset (the root cpuset) we can
- * short circuit some hooks.
- */
-int number_of_cpusets __read_mostly;
+struct static_key cpusets_enabled_key __read_mostly = STATIC_KEY_INIT_FALSE;
 
 /* See "Frequency meter" comments, below. */
 
@@ -124,7 +119,7 @@ static inline struct cpuset *task_cs(struct task_struct *task)
 
 static inline struct cpuset *parent_cs(struct cpuset *cs)
 {
-       return css_cs(css_parent(&cs->css));
+       return css_cs(cs->css.parent);
 }
 
 #ifdef CONFIG_NUMA
@@ -611,7 +606,7 @@ static int generate_sched_domains(cpumask_var_t **domains,
                goto done;
        }
 
-       csa = kmalloc(number_of_cpusets * sizeof(cp), GFP_KERNEL);
+       csa = kmalloc(nr_cpusets() * sizeof(cp), GFP_KERNEL);
        if (!csa)
                goto done;
        csn = 0;
@@ -1603,13 +1598,15 @@ out_unlock:
 /*
  * Common handling for a write to a "cpus" or "mems" file.
  */
-static int cpuset_write_resmask(struct cgroup_subsys_state *css,
-                               struct cftype *cft, char *buf)
+static ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
+                                   char *buf, size_t nbytes, loff_t off)
 {
-       struct cpuset *cs = css_cs(css);
+       struct cpuset *cs = css_cs(of_css(of));
        struct cpuset *trialcs;
        int retval = -ENODEV;
 
+       buf = strstrip(buf);
+
        /*
         * CPU or memory hotunplug may leave @cs w/o any execution
         * resources, in which case the hotplug code asynchronously updates
@@ -1633,7 +1630,7 @@ static int cpuset_write_resmask(struct cgroup_subsys_state *css,
                goto out_unlock;
        }
 
-       switch (cft->private) {
+       switch (of_cft(of)->private) {
        case FILE_CPULIST:
                retval = update_cpumask(cs, trialcs, buf);
                break;
@@ -1648,7 +1645,7 @@ static int cpuset_write_resmask(struct cgroup_subsys_state *css,
        free_trial_cpuset(trialcs);
 out_unlock:
        mutex_unlock(&cpuset_mutex);
-       return retval;
+       return retval ?: nbytes;
 }
 
 /*
@@ -1750,7 +1747,7 @@ static struct cftype files[] = {
        {
                .name = "cpus",
                .seq_show = cpuset_common_seq_show,
-               .write_string = cpuset_write_resmask,
+               .write = cpuset_write_resmask,
                .max_write_len = (100U + 6 * NR_CPUS),
                .private = FILE_CPULIST,
        },
@@ -1758,7 +1755,7 @@ static struct cftype files[] = {
        {
                .name = "mems",
                .seq_show = cpuset_common_seq_show,
-               .write_string = cpuset_write_resmask,
+               .write = cpuset_write_resmask,
                .max_write_len = (100U + 6 * MAX_NUMNODES),
                .private = FILE_MEMLIST,
        },
@@ -1886,7 +1883,7 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
        if (is_spread_slab(parent))
                set_bit(CS_SPREAD_SLAB, &cs->flags);
 
-       number_of_cpusets++;
+       cpuset_inc();
 
        if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags))
                goto out_unlock;
@@ -1937,7 +1934,7 @@ static void cpuset_css_offline(struct cgroup_subsys_state *css)
        if (is_sched_load_balance(cs))
                update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);
 
-       number_of_cpusets--;
+       cpuset_dec();
        clear_bit(CS_ONLINE, &cs->flags);
 
        mutex_unlock(&cpuset_mutex);
@@ -1990,7 +1987,6 @@ int __init cpuset_init(void)
        if (!alloc_cpumask_var(&cpus_attach, GFP_KERNEL))
                BUG();
 
-       number_of_cpusets = 1;
        return 0;
 }