Commit 91b2db27 authored by Song Liu's avatar Song Liu Committed by Daniel Borkmann

bpf: Simplify task_file_seq_get_next()

Simplify task_file_seq_get_next() by removing two in/out arguments: task
and fstruct. Use info->task and info->files instead.
Signed-off-by: default avatarSong Liu <songliubraving@fb.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarYonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20201120002833.2481110-1-songliubraving@fb.com
parent 450d060e
...@@ -136,8 +136,7 @@ struct bpf_iter_seq_task_file_info { ...@@ -136,8 +136,7 @@ struct bpf_iter_seq_task_file_info {
}; };
static struct file * static struct file *
task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info, task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info)
struct task_struct **task, struct files_struct **fstruct)
{ {
struct pid_namespace *ns = info->common.ns; struct pid_namespace *ns = info->common.ns;
u32 curr_tid = info->tid, max_fds; u32 curr_tid = info->tid, max_fds;
...@@ -150,14 +149,17 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info, ...@@ -150,14 +149,17 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
* Otherwise, it does not hold any reference. * Otherwise, it does not hold any reference.
*/ */
again: again:
if (*task) { if (info->task) {
curr_task = *task; curr_task = info->task;
curr_files = *fstruct; curr_files = info->files;
curr_fd = info->fd; curr_fd = info->fd;
} else { } else {
curr_task = task_seq_get_next(ns, &curr_tid, true); curr_task = task_seq_get_next(ns, &curr_tid, true);
if (!curr_task) if (!curr_task) {
info->task = NULL;
info->files = NULL;
return NULL; return NULL;
}
curr_files = get_files_struct(curr_task); curr_files = get_files_struct(curr_task);
if (!curr_files) { if (!curr_files) {
...@@ -167,9 +169,8 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info, ...@@ -167,9 +169,8 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
goto again; goto again;
} }
/* set *fstruct, *task and info->tid */ info->files = curr_files;
*fstruct = curr_files; info->task = curr_task;
*task = curr_task;
if (curr_tid == info->tid) { if (curr_tid == info->tid) {
curr_fd = info->fd; curr_fd = info->fd;
} else { } else {
...@@ -199,8 +200,8 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info, ...@@ -199,8 +200,8 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
rcu_read_unlock(); rcu_read_unlock();
put_files_struct(curr_files); put_files_struct(curr_files);
put_task_struct(curr_task); put_task_struct(curr_task);
*task = NULL; info->task = NULL;
*fstruct = NULL; info->files = NULL;
info->fd = 0; info->fd = 0;
curr_tid = ++(info->tid); curr_tid = ++(info->tid);
goto again; goto again;
...@@ -209,21 +210,13 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info, ...@@ -209,21 +210,13 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
static void *task_file_seq_start(struct seq_file *seq, loff_t *pos) static void *task_file_seq_start(struct seq_file *seq, loff_t *pos)
{ {
struct bpf_iter_seq_task_file_info *info = seq->private; struct bpf_iter_seq_task_file_info *info = seq->private;
struct files_struct *files = NULL;
struct task_struct *task = NULL;
struct file *file; struct file *file;
file = task_file_seq_get_next(info, &task, &files);
if (!file) {
info->files = NULL;
info->task = NULL; info->task = NULL;
return NULL; info->files = NULL;
} file = task_file_seq_get_next(info);
if (file && *pos == 0)
if (*pos == 0)
++*pos; ++*pos;
info->task = task;
info->files = files;
return file; return file;
} }
...@@ -231,24 +224,11 @@ static void *task_file_seq_start(struct seq_file *seq, loff_t *pos) ...@@ -231,24 +224,11 @@ static void *task_file_seq_start(struct seq_file *seq, loff_t *pos)
static void *task_file_seq_next(struct seq_file *seq, void *v, loff_t *pos) static void *task_file_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{ {
struct bpf_iter_seq_task_file_info *info = seq->private; struct bpf_iter_seq_task_file_info *info = seq->private;
struct files_struct *files = info->files;
struct task_struct *task = info->task;
struct file *file;
++*pos; ++*pos;
++info->fd; ++info->fd;
fput((struct file *)v); fput((struct file *)v);
file = task_file_seq_get_next(info, &task, &files); return task_file_seq_get_next(info);
if (!file) {
info->files = NULL;
info->task = NULL;
return NULL;
}
info->task = task;
info->files = files;
return file;
} }
struct bpf_iter__task_file { struct bpf_iter__task_file {
......
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