Re: [PATCHv2 2/6] io_uring: create resource release callback

Pavel Begunkov
2025-02-13T01:30:10Z

On 2/11/25 00:56, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
>
> When a registered resource is about to be freed, check if it has
> registered a release function, and call it if so. This is preparing for
> resources that are related to an external component.
>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
> io_uring/rsrc.c | 2 ++
> io_uring/rsrc.h | 3 +++
> 2 files changed, 5 insertions(+)
>
> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
> index 4d0e1c06c8bc6..30f08cf13ef60 100644
> --- a/io_uring/rsrc.c
> +++ b/io_uring/rsrc.c
> @@ -455,6 +455,8 @@ void io_free_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
> case IORING_RSRC_BUFFER:
> if (node->buf)
> io_buffer_unmap(ctx, node);
> + if (node->release)
> + node->release(node->priv);
> break;
> default:
> WARN_ON_ONCE(1);
> diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h
> index abd0d5d42c3e1..a3826ab84e666 100644
> --- a/io_uring/rsrc.h
> +++ b/io_uring/rsrc.h
> @@ -24,6 +24,9 @@ struct io_rsrc_node {
> unsigned long file_ptr;
> struct io_mapped_ubuf *buf;
> };
> +
> + void (*release)(void *);
> + void *priv;

Nodes are more generic than buffers. Unless we want to reuse it
for files, and I very much doubt that, it should move into
io_mapped_ubuf.

> };
>
> struct io_mapped_ubuf {

--
Pavel Begunkov