[PATCH 2/4] cpuset: Split up update_cpumask() so that itsfunctionality can be reused

From: Srivatsa S. Bhat
Date: Tue Feb 07 2012 - 13:56:53 EST


update_cpumask() expects the new cpuset in the form of characters (owing to
the fact that it expects cpuset updates from userspace). This might not be
appropriate if an in-kernel user wants to call it.

So, split up the function so that its functionality can be reused. That is,
introduce do_update_cpumask() and offload the core work to it.

Reported-by: Prashanth K. Nageshappa <prashanth@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@xxxxxxxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---

kernel/cpuset.c | 61 ++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 5e2323b..2be71da 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -864,13 +864,14 @@ static void update_tasks_cpumask(struct cpuset *cs, struct ptr_heap *heap)
cgroup_scan_tasks(&scan);
}

+
/**
- * update_cpumask - update the cpus_allowed mask of a cpuset and all tasks in it
+ * do_update_cpumask - update the cpus_allowed mask of a cpuset and all tasks
+ * in it
* @cs: the cpuset to consider
- * @buf: buffer of cpu numbers written to this cpuset
+ * @trialcs: the updated cpuset value requested
*/
-static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
- const char *buf)
+static int do_update_cpumask(struct cpuset *cs, struct cpuset *trialcs)
{
struct ptr_heap heap;
int retval;
@@ -880,22 +881,9 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
if (cs == &top_cpuset)
return -EACCES;

- /*
- * An empty cpus_allowed is ok only if the cpuset has no tasks.
- * Since cpulist_parse() fails on an empty mask, we special case
- * that parsing. The validate_change() call ensures that cpusets
- * with tasks have cpus.
- */
- if (!*buf) {
- cpumask_clear(trialcs->cpus_allowed);
- } else {
- retval = cpulist_parse(buf, trialcs->cpus_allowed);
- if (retval < 0)
- return retval;
-
- if (!cpumask_subset(trialcs->cpus_allowed, cpu_active_mask))
+ if (!cpumask_subset(trialcs->cpus_allowed, cpu_active_mask))
return -EINVAL;
- }
+
retval = validate_change(cs, trialcs);
if (retval < 0)
return retval;
@@ -925,9 +913,44 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,

if (is_load_balanced)
async_rebuild_sched_domains();
+
return 0;
}

+/**
+ * update_cpumask - update the cpus_allowed mask of a cpuset and all tasks in it
+ * @cs: the cpuset to consider
+ * @buf: buffer of cpu numbers written to this cpuset
+ */
+static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
+ const char *buf)
+{
+ int retval;
+
+ /* top_cpuset.cpus_allowed tracks cpu_online_map; it's read-only */
+ if (cs == &top_cpuset)
+ return -EACCES;
+
+ /*
+ * An empty cpus_allowed is ok only if the cpuset has no tasks.
+ * Since cpulist_parse() fails on an empty mask, we special case
+ * that parsing. The validate_change() call ensures that cpusets
+ * with tasks have cpus.
+ */
+ if (!*buf) {
+ cpumask_clear(trialcs->cpus_allowed);
+ } else {
+ retval = cpulist_parse(buf, trialcs->cpus_allowed);
+ if (retval < 0)
+ return retval;
+
+ if (!cpumask_subset(trialcs->cpus_allowed, cpu_active_mask))
+ return -EINVAL;
+ }
+
+ return do_update_cpumask(cs, trialcs);
+}
+
/*
* cpuset_migrate_mm
*

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/