Commit 0f4a0d53 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

proc: task_state: deuglify the max_fds calculation

1. The usage of fdt looks very ugly, it can't be NULL if ->files is
   not NULL. We can use "unsigned int max_fds" instead.

2. This also allows to move seq_printf(max_fds) outside of task_lock()
   and join it with the previous seq_printf(). See also the next patch.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Aaron Tomlin <atomlin@redhat.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
Cc: Sterling Alexander <stalexan@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roland McGrath <roland@hack.frob.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4af1036d
...@@ -157,9 +157,9 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns, ...@@ -157,9 +157,9 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
struct user_namespace *user_ns = seq_user_ns(m); struct user_namespace *user_ns = seq_user_ns(m);
struct group_info *group_info; struct group_info *group_info;
int g; int g;
struct fdtable *fdt = NULL;
const struct cred *cred; const struct cred *cred;
pid_t ppid, tpid; pid_t ppid, tpid;
unsigned int max_fds = 0;
rcu_read_lock(); rcu_read_lock();
ppid = pid_alive(p) ? ppid = pid_alive(p) ?
...@@ -171,6 +171,12 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns, ...@@ -171,6 +171,12 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
tpid = task_pid_nr_ns(tracer, ns); tpid = task_pid_nr_ns(tracer, ns);
} }
cred = get_task_cred(p); cred = get_task_cred(p);
task_lock(p);
if (p->files)
max_fds = files_fdtable(p->files)->max_fds;
task_unlock(p);
seq_printf(m, seq_printf(m,
"State:\t%s\n" "State:\t%s\n"
"Tgid:\t%d\n" "Tgid:\t%d\n"
...@@ -179,7 +185,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns, ...@@ -179,7 +185,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
"PPid:\t%d\n" "PPid:\t%d\n"
"TracerPid:\t%d\n" "TracerPid:\t%d\n"
"Uid:\t%d\t%d\t%d\t%d\n" "Uid:\t%d\t%d\t%d\t%d\n"
"Gid:\t%d\t%d\t%d\t%d\n", "Gid:\t%d\t%d\t%d\t%d\n"
"FDSize:\t%d\nGroups:\t",
get_task_state(p), get_task_state(p),
task_tgid_nr_ns(p, ns), task_tgid_nr_ns(p, ns),
task_numa_group_id(p), task_numa_group_id(p),
...@@ -192,16 +199,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns, ...@@ -192,16 +199,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
from_kgid_munged(user_ns, cred->gid), from_kgid_munged(user_ns, cred->gid),
from_kgid_munged(user_ns, cred->egid), from_kgid_munged(user_ns, cred->egid),
from_kgid_munged(user_ns, cred->sgid), from_kgid_munged(user_ns, cred->sgid),
from_kgid_munged(user_ns, cred->fsgid)); from_kgid_munged(user_ns, cred->fsgid),
max_fds);
task_lock(p);
if (p->files)
fdt = files_fdtable(p->files);
seq_printf(m,
"FDSize:\t%d\n"
"Groups:\t",
fdt ? fdt->max_fds : 0);
task_unlock(p);
rcu_read_unlock(); rcu_read_unlock();
group_info = cred->group_info; group_info = cred->group_info;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment