* [PATCH bpf-next] bpf: simplify task_file_seq_get_next()
@ 2020-11-20 0:28 Song Liu
2020-11-20 16:57 ` Yonghong Song
2020-11-20 22:19 ` Daniel Borkmann
0 siblings, 2 replies; 3+ messages in thread
From: Song Liu @ 2020-11-20 0:28 UTC (permalink / raw)
To: bpf, netdev
Cc: kernel-team, ast, daniel, andrii, kpsingh, john.fastabend,
Song Liu, Yonghong Song
Simplify task_file_seq_get_next() by removing two in/out arguments: task
and fstruct. Use info->task and info->files instead.
Cc: Yonghong Song <yhs@fb.com>
Signed-off-by: Song Liu <songliubraving@fb.com>
---
kernel/bpf/task_iter.c | 53 ++++++++++++++----------------------------
1 file changed, 17 insertions(+), 36 deletions(-)
diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
index 1fdb2fc196cd9..7e15ca802988a 100644
--- a/kernel/bpf/task_iter.c
+++ b/kernel/bpf/task_iter.c
@@ -136,8 +136,7 @@ struct bpf_iter_seq_task_file_info {
};
static struct file *
-task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
- struct task_struct **task, struct files_struct **fstruct)
+task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info)
{
struct pid_namespace *ns = info->common.ns;
u32 curr_tid = info->tid, max_fds;
@@ -150,14 +149,17 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
* Otherwise, it does not hold any reference.
*/
again:
- if (*task) {
- curr_task = *task;
- curr_files = *fstruct;
+ if (info->task) {
+ curr_task = info->task;
+ curr_files = info->files;
curr_fd = info->fd;
} else {
curr_task = task_seq_get_next(ns, &curr_tid, true);
- if (!curr_task)
+ if (!curr_task) {
+ info->task = NULL;
+ info->files = NULL;
return NULL;
+ }
curr_files = get_files_struct(curr_task);
if (!curr_files) {
@@ -168,8 +170,8 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
}
/* set *fstruct, *task and info->tid */
- *fstruct = curr_files;
- *task = curr_task;
+ info->files = curr_files;
+ info->task = curr_task;
if (curr_tid == info->tid) {
curr_fd = info->fd;
} else {
@@ -199,8 +201,8 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
rcu_read_unlock();
put_files_struct(curr_files);
put_task_struct(curr_task);
- *task = NULL;
- *fstruct = NULL;
+ info->task = NULL;
+ info->files = NULL;
info->fd = 0;
curr_tid = ++(info->tid);
goto again;
@@ -209,21 +211,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)
{
struct bpf_iter_seq_task_file_info *info = seq->private;
- struct files_struct *files = NULL;
- struct task_struct *task = NULL;
struct file *file;
- file = task_file_seq_get_next(info, &task, &files);
- if (!file) {
- info->files = NULL;
- info->task = NULL;
- return NULL;
- }
-
- if (*pos == 0)
+ info->task = NULL;
+ info->files = NULL;
+ file = task_file_seq_get_next(info);
+ if (file && *pos == 0)
++*pos;
- info->task = task;
- info->files = files;
return file;
}
@@ -231,24 +225,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)
{
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;
++info->fd;
fput((struct file *)v);
- file = task_file_seq_get_next(info, &task, &files);
- if (!file) {
- info->files = NULL;
- info->task = NULL;
- return NULL;
- }
-
- info->task = task;
- info->files = files;
-
- return file;
+ return task_file_seq_get_next(info);
}
struct bpf_iter__task_file {
--
2.24.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpf: simplify task_file_seq_get_next()
2020-11-20 0:28 [PATCH bpf-next] bpf: simplify task_file_seq_get_next() Song Liu
@ 2020-11-20 16:57 ` Yonghong Song
2020-11-20 22:19 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Yonghong Song @ 2020-11-20 16:57 UTC (permalink / raw)
To: Song Liu, bpf, netdev
Cc: kernel-team, ast, daniel, andrii, kpsingh, john.fastabend
On 11/19/20 4:28 PM, Song Liu wrote:
> Simplify task_file_seq_get_next() by removing two in/out arguments: task
> and fstruct. Use info->task and info->files instead.
>
> Cc: Yonghong Song <yhs@fb.com>
> Signed-off-by: Song Liu <songliubraving@fb.com>
Thanks for the refactor. The new code is shorter and cleaner.
Acked-by: Yonghong Song <yhs@fb.com>
> ---
> kernel/bpf/task_iter.c | 53 ++++++++++++++----------------------------
> 1 file changed, 17 insertions(+), 36 deletions(-)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpf: simplify task_file_seq_get_next()
2020-11-20 0:28 [PATCH bpf-next] bpf: simplify task_file_seq_get_next() Song Liu
2020-11-20 16:57 ` Yonghong Song
@ 2020-11-20 22:19 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2020-11-20 22:19 UTC (permalink / raw)
To: Song Liu, bpf, netdev
Cc: kernel-team, ast, andrii, kpsingh, john.fastabend, Yonghong Song
On 11/20/20 1:28 AM, Song Liu wrote:
> Simplify task_file_seq_get_next() by removing two in/out arguments: task
> and fstruct. Use info->task and info->files instead.
>
> Cc: Yonghong Song <yhs@fb.com>
> Signed-off-by: Song Liu <songliubraving@fb.com>
Applied, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-20 22:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20 0:28 [PATCH bpf-next] bpf: simplify task_file_seq_get_next() Song Liu
2020-11-20 16:57 ` Yonghong Song
2020-11-20 22:19 ` Daniel Borkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).