Message ID | 20241101135452.19359-4-erin.shepherd@e43.eu (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | pidfs: implement file handle support | expand |
On Fri, Nov 1, 2024 at 2:56 PM Erin Shepherd <erin.shepherd@e43.eu> wrote: > > In some situations it is useful to be able to atomically get a PID > from a specific PID namespace. > > Signed-off-by: Erin Shepherd <erin.shepherd@e43.eu> Reviewed-by: Amir Goldstein <amir73il@gmail.com> > --- > include/linux/pid.h | 1 + > kernel/pid.c | 10 ++++++++-- > 2 files changed, 9 insertions(+), 2 deletions(-) > > diff --git a/include/linux/pid.h b/include/linux/pid.h > index a3aad9b4074c..965f8b3ff9a8 100644 > --- a/include/linux/pid.h > +++ b/include/linux/pid.h > @@ -124,6 +124,7 @@ extern struct pid *find_vpid(int nr); > /* > * Lookup a PID in the hash table, and return with it's count elevated. > */ > +extern struct pid *find_get_pid_ns(int nr, struct pid_namespace *ns); > extern struct pid *find_get_pid(int nr); > extern struct pid *find_ge_pid(int nr, struct pid_namespace *); > > diff --git a/kernel/pid.c b/kernel/pid.c > index 2715afb77eab..2967f8a98330 100644 > --- a/kernel/pid.c > +++ b/kernel/pid.c > @@ -470,16 +470,22 @@ struct task_struct *get_pid_task(struct pid *pid, enum pid_type type) > } > EXPORT_SYMBOL_GPL(get_pid_task); > > -struct pid *find_get_pid(pid_t nr) > +struct pid *find_get_pid_ns(pid_t nr, struct pid_namespace *ns) > { > struct pid *pid; > > rcu_read_lock(); > - pid = get_pid(find_vpid(nr)); > + pid = get_pid(find_pid_ns(nr, ns)); > rcu_read_unlock(); > > return pid; > } > +EXPORT_SYMBOL_GPL(find_get_pid_ns); > + > +struct pid *find_get_pid(pid_t nr) > +{ > + return find_get_pid_ns(nr, task_active_pid_ns(current)); > +} > EXPORT_SYMBOL_GPL(find_get_pid); > > pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns) > -- > 2.46.1 > >
diff --git a/include/linux/pid.h b/include/linux/pid.h index a3aad9b4074c..965f8b3ff9a8 100644 --- a/include/linux/pid.h +++ b/include/linux/pid.h @@ -124,6 +124,7 @@ extern struct pid *find_vpid(int nr); /* * Lookup a PID in the hash table, and return with it's count elevated. */ +extern struct pid *find_get_pid_ns(int nr, struct pid_namespace *ns); extern struct pid *find_get_pid(int nr); extern struct pid *find_ge_pid(int nr, struct pid_namespace *); diff --git a/kernel/pid.c b/kernel/pid.c index 2715afb77eab..2967f8a98330 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -470,16 +470,22 @@ struct task_struct *get_pid_task(struct pid *pid, enum pid_type type) } EXPORT_SYMBOL_GPL(get_pid_task); -struct pid *find_get_pid(pid_t nr) +struct pid *find_get_pid_ns(pid_t nr, struct pid_namespace *ns) { struct pid *pid; rcu_read_lock(); - pid = get_pid(find_vpid(nr)); + pid = get_pid(find_pid_ns(nr, ns)); rcu_read_unlock(); return pid; } +EXPORT_SYMBOL_GPL(find_get_pid_ns); + +struct pid *find_get_pid(pid_t nr) +{ + return find_get_pid_ns(nr, task_active_pid_ns(current)); +} EXPORT_SYMBOL_GPL(find_get_pid); pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
In some situations it is useful to be able to atomically get a PID from a specific PID namespace. Signed-off-by: Erin Shepherd <erin.shepherd@e43.eu> --- include/linux/pid.h | 1 + kernel/pid.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)