Skip to content

Commit 2894d65

Browse files
Sukadev BhattiproluLinus Torvalds
authored andcommitted
pid namespaces: define and use task_active_pid_ns() wrapper
With multiple pid namespaces, a process is known by some pid_t in every ancestor pid namespace. Every time the process forks, the child process also gets a pid_t in every ancestor pid namespace. While a process is visible in >=1 pid namespaces, it can see pid_t's in only one pid namespace. We call this pid namespace it's "active pid namespace", and it is always the youngest pid namespace in which the process is known. This patch defines and uses a wrapper to find the active pid namespace of a process. The implementation of the wrapper will be changed in when support for multiple pid namespaces are added. Changelog: 2.6.22-rc4-mm2-pidns1: - [Pavel Emelianov, Alexey Dobriyan] Back out the change to use task_active_pid_ns() in child_reaper() since task->nsproxy can be NULL during task exit (so child_reaper() continues to use init_pid_ns). to implement child_reaper() since init_pid_ns.child_reaper to implement child_reaper() since tsk->nsproxy can be NULL during exit. 2.6.21-rc6-mm1: - Rename task_pid_ns() to task_active_pid_ns() to reflect that a process can have multiple pid namespaces. Signed-off-by: Sukadev Bhattiprolu <sukadev@us.ibm.com> Acked-by: Pavel Emelianov <xemul@openvz.org> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Cedric Le Goater <clg@fr.ibm.com> Cc: Dave Hansen <haveblue@us.ibm.com> Cc: Serge Hallyn <serue@us.ibm.com> Cc: Herbert Poetzel <herbert@13thfloor.at> Cc: Kirill Korotaev <dev@sw.ru> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent baf8f0f commit 2894d65

5 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎fs/exec.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ static int de_thread(struct task_struct *tsk)
776776
* so it is safe to do it under read_lock.
777777
*/
778778
if (unlikely(tsk->group_leader == child_reaper(tsk)))
779-
tsk->nsproxy->pid_ns->child_reaper = tsk;
779+
task_active_pid_ns(tsk)->child_reaper = tsk;
780780

781781
zap_other_threads(tsk);
782782
read_unlock(&tasklist_lock);

‎fs/proc/proc_misc.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ static int loadavg_read_proc(char *page, char **start, off_t off,
9191
LOAD_INT(a), LOAD_FRAC(a),
9292
LOAD_INT(b), LOAD_FRAC(b),
9393
LOAD_INT(c), LOAD_FRAC(c),
94-
nr_running(), nr_threads, current->nsproxy->pid_ns->last_pid);
94+
nr_running(), nr_threads,
95+
task_active_pid_ns(current)->last_pid);
9596
return proc_calc_metrics(page, start, off, count, eof, len);
9697
}
9798

‎include/linux/pid_namespace.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ static inline void put_pid_ns(struct pid_namespace *ns)
3939
kref_put(&ns->kref, free_pid_ns);
4040
}
4141

42+
static inline struct pid_namespace *task_active_pid_ns(struct task_struct *tsk)
43+
{
44+
return tsk->nsproxy->pid_ns;
45+
}
46+
4247
static inline struct task_struct *child_reaper(struct task_struct *tsk)
4348
{
4449
return init_pid_ns.child_reaper;

‎kernel/nsproxy.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
8787
goto out_ipc;
8888
}
8989

90-
new_nsp->pid_ns = copy_pid_ns(flags, tsk->nsproxy->pid_ns);
90+
new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
9191
if (IS_ERR(new_nsp->pid_ns)) {
9292
err = PTR_ERR(new_nsp->pid_ns);
9393
goto out_pid;

‎kernel/pid.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ struct pid *alloc_pid(void)
214214
int nr = -1;
215215
struct pid_namespace *ns;
216216

217-
ns = current->nsproxy->pid_ns;
217+
ns = task_active_pid_ns(current);
218218
pid = kmem_cache_alloc(ns->pid_cachep, GFP_KERNEL);
219219
if (!pid)
220220
goto out;
@@ -364,7 +364,7 @@ struct pid *find_ge_pid(int nr)
364364
pid = find_pid(nr);
365365
if (pid)
366366
break;
367-
nr = next_pidmap(current->nsproxy->pid_ns, nr);
367+
nr = next_pidmap(task_active_pid_ns(current), nr);
368368
} while (nr > 0);
369369

370370
return pid;

0 commit comments

Comments
 (0)