[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241210-elastisch-flamingo-9271dc82c3a0@brauner>
Date: Tue, 10 Dec 2024 15:28:46 +0100
From: Christian Brauner <brauner@...nel.org>
To: Juntong Deng <juntong.deng@...look.com>
Cc: ast@...nel.org, daniel@...earbox.net, john.fastabend@...il.com,
andrii@...nel.org, martin.lau@...ux.dev, eddyz87@...il.com, song@...nel.org,
yonghong.song@...ux.dev, kpsingh@...nel.org, sdf@...ichev.me, haoluo@...gle.com,
jolsa@...nel.org, memxor@...il.com, snorcht@...il.com, bpf@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH bpf-next v5 3/5] bpf: Add bpf_fget_task() kfunc
On Tue, Dec 10, 2024 at 02:03:52PM +0000, Juntong Deng wrote:
> This patch adds bpf_fget_task() kfunc.
>
> bpf_fget_task() is used to get a pointer to the struct file
> corresponding to the task file descriptor. Note that this function
> acquires a reference to struct file.
>
> Signed-off-by: Juntong Deng <juntong.deng@...look.com>
> ---
> fs/bpf_fs_kfuncs.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
> index 3fe9f59ef867..19a9d45c47f9 100644
> --- a/fs/bpf_fs_kfuncs.c
> +++ b/fs/bpf_fs_kfuncs.c
> @@ -152,6 +152,26 @@ __bpf_kfunc int bpf_get_file_xattr(struct file *file, const char *name__str,
> return bpf_get_dentry_xattr(dentry, name__str, value_p);
> }
>
> +/**
> + * bpf_fget_task() - Get a pointer to the struct file corresponding to
> + * the task file descriptor
> + *
> + * Note that this function acquires a reference to struct file.
> + *
> + * @task: the specified struct task_struct
> + * @fd: the file descriptor
> + *
> + * @returns the corresponding struct file pointer if found,
> + * otherwise returns NULL
> + */
> +__bpf_kfunc struct file *bpf_fget_task(struct task_struct *task, unsigned int fd)
> +{
> + struct file *file;
> +
> + file = fget_task(task, fd);
> + return file;
Why the local variable?
Powered by blists - more mailing lists