Merge branch 'bpf-task_group_seq_get_next-misc-cleanups'
Oleg Nesterov says: ==================== bpf: task_group_seq_get_next: misc cleanups Yonghong, I am resending 1-5 of 6 as you suggested with your acks included. The next (final) patch will change this code to use __next_thread when https://lore.kernel.org/all/20230824143142.GA31222@redhat.com/ is merged. Oleg. ==================== Link: https://lore.kernel.org/r/20230905154612.GA24872@redhat.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
commit
9bc869253d
@ -35,16 +35,13 @@ static struct task_struct *task_group_seq_get_next(struct bpf_iter_seq_task_comm
|
||||
u32 *tid,
|
||||
bool skip_if_dup_files)
|
||||
{
|
||||
struct task_struct *task, *next_task;
|
||||
struct task_struct *task;
|
||||
struct pid *pid;
|
||||
u32 saved_tid;
|
||||
u32 next_tid;
|
||||
|
||||
if (!*tid) {
|
||||
/* The first time, the iterator calls this function. */
|
||||
pid = find_pid_ns(common->pid, common->ns);
|
||||
if (!pid)
|
||||
return NULL;
|
||||
|
||||
task = get_pid_task(pid, PIDTYPE_TGID);
|
||||
if (!task)
|
||||
return NULL;
|
||||
@ -66,44 +63,27 @@ static struct task_struct *task_group_seq_get_next(struct bpf_iter_seq_task_comm
|
||||
return task;
|
||||
}
|
||||
|
||||
pid = find_pid_ns(common->pid_visiting, common->ns);
|
||||
if (!pid)
|
||||
return NULL;
|
||||
|
||||
task = get_pid_task(pid, PIDTYPE_PID);
|
||||
task = find_task_by_pid_ns(common->pid_visiting, common->ns);
|
||||
if (!task)
|
||||
return NULL;
|
||||
|
||||
retry:
|
||||
if (!pid_alive(task)) {
|
||||
put_task_struct(task);
|
||||
return NULL;
|
||||
}
|
||||
task = next_thread(task);
|
||||
|
||||
next_task = next_thread(task);
|
||||
put_task_struct(task);
|
||||
if (!next_task)
|
||||
return NULL;
|
||||
|
||||
saved_tid = *tid;
|
||||
*tid = __task_pid_nr_ns(next_task, PIDTYPE_PID, common->ns);
|
||||
if (!*tid || *tid == common->pid) {
|
||||
next_tid = __task_pid_nr_ns(task, PIDTYPE_PID, common->ns);
|
||||
if (!next_tid || next_tid == common->pid) {
|
||||
/* Run out of tasks of a process. The tasks of a
|
||||
* thread_group are linked as circular linked list.
|
||||
*/
|
||||
*tid = saved_tid;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
get_task_struct(next_task);
|
||||
common->pid_visiting = *tid;
|
||||
|
||||
if (skip_if_dup_files && task->files == task->group_leader->files) {
|
||||
task = next_task;
|
||||
if (skip_if_dup_files && task->files == task->group_leader->files)
|
||||
goto retry;
|
||||
}
|
||||
|
||||
return next_task;
|
||||
*tid = common->pid_visiting = next_tid;
|
||||
get_task_struct(task);
|
||||
return task;
|
||||
}
|
||||
|
||||
static struct task_struct *task_seq_get_next(struct bpf_iter_seq_task_common *common,
|
||||
|
Loading…
x
Reference in New Issue
Block a user