Skip to content

Commit 1aa92cd

Browse files
minchanktorvalds
authored andcommitted
pid: move pidfd_get_pid() to pid.c
process_madvise syscall needs pidfd_get_pid function to translate pidfd to pid so this patch move the function to kernel/pid.c. Suggested-by: Alexander Duyck <alexander.h.duyck@linux.intel.com> Signed-off-by: Minchan Kim <minchan@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Suren Baghdasaryan <surenb@google.com> Reviewed-by: Alexander Duyck <alexander.h.duyck@linux.intel.com> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Christian Brauner <christian.brauner@ubuntu.com> Acked-by: David Rientjes <rientjes@google.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Jann Horn <jannh@google.com> Cc: Brian Geffon <bgeffon@google.com> Cc: Daniel Colascione <dancol@google.com> Cc: Joel Fernandes <joel@joelfernandes.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: John Dias <joaodias@google.com> Cc: Kirill Tkhai <ktkhai@virtuozzo.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Oleksandr Natalenko <oleksandr@redhat.com> Cc: Sandeep Patil <sspatil@google.com> Cc: SeongJae Park <sj38.park@gmail.com> Cc: SeongJae Park <sjpark@amazon.de> Cc: Shakeel Butt <shakeelb@google.com> Cc: Sonny Rao <sonnyrao@google.com> Cc: Tim Murray <timmurray@google.com> Cc: Christian Brauner <christian.brauner@ubuntu.com> Cc: Florian Weimer <fw@deneb.enyo.de> Cc: <linux-man@vger.kernel.org> Link: http://lkml.kernel.org/r/20200302193630.68771-5-minchan@kernel.org Link: http://lkml.kernel.org/r/20200622192900.22757-3-minchan@kernel.org Link: https://lkml.kernel.org/r/20200901000633.1920247-3-minchan@kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0726b01 commit 1aa92cd

3 files changed

Lines changed: 20 additions & 19 deletions

File tree

‎include/linux/pid.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ extern const struct file_operations pidfd_fops;
7777
struct file;
7878

7979
extern struct pid *pidfd_pid(const struct file *file);
80+
struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags);
8081

8182
static inline struct pid *get_pid(struct pid *pid)
8283
{

‎kernel/exit.c‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,25 +1474,6 @@ static long do_wait(struct wait_opts *wo)
14741474
return retval;
14751475
}
14761476

1477-
static struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags)
1478-
{
1479-
struct fd f;
1480-
struct pid *pid;
1481-
1482-
f = fdget(fd);
1483-
if (!f.file)
1484-
return ERR_PTR(-EBADF);
1485-
1486-
pid = pidfd_pid(f.file);
1487-
if (!IS_ERR(pid)) {
1488-
get_pid(pid);
1489-
*flags = f.file->f_flags;
1490-
}
1491-
1492-
fdput(f);
1493-
return pid;
1494-
}
1495-
14961477
static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop,
14971478
int options, struct rusage *ru)
14981479
{

‎kernel/pid.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,25 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *ns)
520520
return idr_get_next(&ns->idr, &nr);
521521
}
522522

523+
struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags)
524+
{
525+
struct fd f;
526+
struct pid *pid;
527+
528+
f = fdget(fd);
529+
if (!f.file)
530+
return ERR_PTR(-EBADF);
531+
532+
pid = pidfd_pid(f.file);
533+
if (!IS_ERR(pid)) {
534+
get_pid(pid);
535+
*flags = f.file->f_flags;
536+
}
537+
538+
fdput(f);
539+
return pid;
540+
}
541+
523542
/**
524543
* pidfd_create() - Create a new pid file descriptor.
525544
*

0 commit comments

Comments
 (0)