fix setpriority(PRIO_PGRP) thread iterator breakage

When user calls sys_setpriority(PRIO_PGRP ...) on a NPTL style multi-LWP
process, only the task leader of the process is affected, all other
sibling LWP threads didn't receive the setting.  The problem was that the
iterator used in sys_setpriority() only iteartes over one task for each
process, ignoring all other sibling thread.

Introduce a new macro do_each_pid_thread / while_each_pid_thread to walk
each thread of a process.  Convert 4 call sites in {set/get}priority and
ioprio_{set/get}.

Signed-off-by: Ken Chen <kenchen@google.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Roland McGrath <roland@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Ken Chen 2008-08-20 14:09:17 -07:00 committed by Linus Torvalds
parent 141d87e7de
commit 2d70b68d42
3 changed files with 17 additions and 8 deletions

View file

@ -115,11 +115,11 @@ asmlinkage long sys_ioprio_set(int which, int who, int ioprio)
pgrp = task_pgrp(current); pgrp = task_pgrp(current);
else else
pgrp = find_vpid(who); pgrp = find_vpid(who);
do_each_pid_task(pgrp, PIDTYPE_PGID, p) { do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
ret = set_task_ioprio(p, ioprio); ret = set_task_ioprio(p, ioprio);
if (ret) if (ret)
break; break;
} while_each_pid_task(pgrp, PIDTYPE_PGID, p); } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
break; break;
case IOPRIO_WHO_USER: case IOPRIO_WHO_USER:
if (!who) if (!who)
@ -204,7 +204,7 @@ asmlinkage long sys_ioprio_get(int which, int who)
pgrp = task_pgrp(current); pgrp = task_pgrp(current);
else else
pgrp = find_vpid(who); pgrp = find_vpid(who);
do_each_pid_task(pgrp, PIDTYPE_PGID, p) { do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
tmpio = get_task_ioprio(p); tmpio = get_task_ioprio(p);
if (tmpio < 0) if (tmpio < 0)
continue; continue;
@ -212,7 +212,7 @@ asmlinkage long sys_ioprio_get(int which, int who)
ret = tmpio; ret = tmpio;
else else
ret = ioprio_best(ret, tmpio); ret = ioprio_best(ret, tmpio);
} while_each_pid_task(pgrp, PIDTYPE_PGID, p); } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
break; break;
case IOPRIO_WHO_USER: case IOPRIO_WHO_USER:
if (!who) if (!who)

View file

@ -161,4 +161,13 @@ pid_t pid_vnr(struct pid *pid);
} \ } \
} while (0) } while (0)
#define do_each_pid_thread(pid, type, task) \
do_each_pid_task(pid, type, task) { \
struct task_struct *tg___ = task; \
do {
#define while_each_pid_thread(pid, type, task) \
} while_each_thread(tg___, task); \
task = tg___; \
} while_each_pid_task(pid, type, task)
#endif /* _LINUX_PID_H */ #endif /* _LINUX_PID_H */

View file

@ -169,9 +169,9 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
pgrp = find_vpid(who); pgrp = find_vpid(who);
else else
pgrp = task_pgrp(current); pgrp = task_pgrp(current);
do_each_pid_task(pgrp, PIDTYPE_PGID, p) { do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
error = set_one_prio(p, niceval, error); error = set_one_prio(p, niceval, error);
} while_each_pid_task(pgrp, PIDTYPE_PGID, p); } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
break; break;
case PRIO_USER: case PRIO_USER:
user = current->user; user = current->user;
@ -229,11 +229,11 @@ asmlinkage long sys_getpriority(int which, int who)
pgrp = find_vpid(who); pgrp = find_vpid(who);
else else
pgrp = task_pgrp(current); pgrp = task_pgrp(current);
do_each_pid_task(pgrp, PIDTYPE_PGID, p) { do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
niceval = 20 - task_nice(p); niceval = 20 - task_nice(p);
if (niceval > retval) if (niceval > retval)
retval = niceval; retval = niceval;
} while_each_pid_task(pgrp, PIDTYPE_PGID, p); } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
break; break;
case PRIO_USER: case PRIO_USER:
user = current->user; user = current->user;