提交 4e74339a 编写于 作者: L Li Zefan 提交者: Linus Torvalds

cpuset: avoid changing cpuset's cpus when -errno returned

After the patch:

commit 0b2f630a
Author: Miao Xie <miaox@cn.fujitsu.com>
Date:   Fri Jul 25 01:47:21 2008 -0700

    cpusets: restructure the function update_cpumask() and update_nodemask()

It might happen that 'echo 0 > /cpuset/sub/cpus' returned failure but 'cpus'
has been changed, because cpus was changed before calling heap_init() which
may return -ENOMEM.

This patch restores the orginal behavior.
Signed-off-by: NLi Zefan <lizf@cn.fujitsu.com>
Acked-by: NPaul Menage <menage@google.com>
Cc: Paul Jackson <pj@sgi.com>
Cc: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 dea420ce
...@@ -843,37 +843,25 @@ static void cpuset_change_cpumask(struct task_struct *tsk, ...@@ -843,37 +843,25 @@ static void cpuset_change_cpumask(struct task_struct *tsk,
/** /**
* update_tasks_cpumask - Update the cpumasks of tasks in the cpuset. * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset.
* @cs: the cpuset in which each task's cpus_allowed mask needs to be changed * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed
* @heap: if NULL, defer allocating heap memory to cgroup_scan_tasks()
* *
* Called with cgroup_mutex held * Called with cgroup_mutex held
* *
* The cgroup_scan_tasks() function will scan all the tasks in a cgroup, * The cgroup_scan_tasks() function will scan all the tasks in a cgroup,
* calling callback functions for each. * calling callback functions for each.
* *
* Return 0 if successful, -errno if not. * No return value. It's guaranteed that cgroup_scan_tasks() always returns 0
* if @heap != NULL.
*/ */
static int update_tasks_cpumask(struct cpuset *cs) static void update_tasks_cpumask(struct cpuset *cs, struct ptr_heap *heap)
{ {
struct cgroup_scanner scan; struct cgroup_scanner scan;
struct ptr_heap heap;
int retval;
/*
* cgroup_scan_tasks() will initialize heap->gt for us.
* heap_init() is still needed here for we should not change
* cs->cpus_allowed when heap_init() fails.
*/
retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
if (retval)
return retval;
scan.cg = cs->css.cgroup; scan.cg = cs->css.cgroup;
scan.test_task = cpuset_test_cpumask; scan.test_task = cpuset_test_cpumask;
scan.process_task = cpuset_change_cpumask; scan.process_task = cpuset_change_cpumask;
scan.heap = &heap; scan.heap = heap;
retval = cgroup_scan_tasks(&scan); cgroup_scan_tasks(&scan);
heap_free(&heap);
return retval;
} }
/** /**
...@@ -883,6 +871,7 @@ static int update_tasks_cpumask(struct cpuset *cs) ...@@ -883,6 +871,7 @@ static int update_tasks_cpumask(struct cpuset *cs)
*/ */
static int update_cpumask(struct cpuset *cs, const char *buf) static int update_cpumask(struct cpuset *cs, const char *buf)
{ {
struct ptr_heap heap;
struct cpuset trialcs; struct cpuset trialcs;
int retval; int retval;
int is_load_balanced; int is_load_balanced;
...@@ -917,6 +906,10 @@ static int update_cpumask(struct cpuset *cs, const char *buf) ...@@ -917,6 +906,10 @@ static int update_cpumask(struct cpuset *cs, const char *buf)
if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed)) if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed))
return 0; return 0;
retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
if (retval)
return retval;
is_load_balanced = is_sched_load_balance(&trialcs); is_load_balanced = is_sched_load_balance(&trialcs);
mutex_lock(&callback_mutex); mutex_lock(&callback_mutex);
...@@ -927,9 +920,9 @@ static int update_cpumask(struct cpuset *cs, const char *buf) ...@@ -927,9 +920,9 @@ static int update_cpumask(struct cpuset *cs, const char *buf)
* Scan tasks in the cpuset, and update the cpumasks of any * Scan tasks in the cpuset, and update the cpumasks of any
* that need an update. * that need an update.
*/ */
retval = update_tasks_cpumask(cs); update_tasks_cpumask(cs, &heap);
if (retval < 0)
return retval; heap_free(&heap);
if (is_load_balanced) if (is_load_balanced)
async_rebuild_sched_domains(); async_rebuild_sched_domains();
...@@ -1965,7 +1958,7 @@ static void scan_for_empty_cpusets(const struct cpuset *root) ...@@ -1965,7 +1958,7 @@ static void scan_for_empty_cpusets(const struct cpuset *root)
nodes_empty(cp->mems_allowed)) nodes_empty(cp->mems_allowed))
remove_tasks_in_empty_cpuset(cp); remove_tasks_in_empty_cpuset(cp);
else { else {
update_tasks_cpumask(cp); update_tasks_cpumask(cp, NULL);
update_tasks_nodemask(cp, &oldmems); update_tasks_nodemask(cp, &oldmems);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册