提交 96e1429b 编写于 作者: J Jens Axboe 提交者: Xiaoguang Wang

io_uring: buffer registration infrastructure

to #28170604

commit 5a2e745d4d430c4dbeeeb448c3d5c0c3109e511e upstream

This just prepares the ring for having lists of buffers associated with
it, that the application can provide for SQEs to consume instead of
providing their own.

The buffers are organized by group ID.
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Acked-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
Signed-off-by: NXiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
上级 ab800df8
...@@ -195,6 +195,13 @@ struct fixed_file_data { ...@@ -195,6 +195,13 @@ struct fixed_file_data {
struct completion done; struct completion done;
}; };
struct io_buffer {
struct list_head list;
__u64 addr;
__s32 len;
__u16 bid;
};
struct io_ring_ctx { struct io_ring_ctx {
struct { struct {
struct percpu_ref refs; struct percpu_ref refs;
...@@ -272,6 +279,8 @@ struct io_ring_ctx { ...@@ -272,6 +279,8 @@ struct io_ring_ctx {
struct socket *ring_sock; struct socket *ring_sock;
#endif #endif
struct idr io_buffer_idr;
struct idr personality_idr; struct idr personality_idr;
struct { struct {
...@@ -877,6 +886,7 @@ static struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p) ...@@ -877,6 +886,7 @@ static struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
INIT_LIST_HEAD(&ctx->cq_overflow_list); INIT_LIST_HEAD(&ctx->cq_overflow_list);
init_completion(&ctx->completions[0]); init_completion(&ctx->completions[0]);
init_completion(&ctx->completions[1]); init_completion(&ctx->completions[1]);
idr_init(&ctx->io_buffer_idr);
idr_init(&ctx->personality_idr); idr_init(&ctx->personality_idr);
mutex_init(&ctx->uring_lock); mutex_init(&ctx->uring_lock);
init_waitqueue_head(&ctx->wait); init_waitqueue_head(&ctx->wait);
...@@ -6558,6 +6568,30 @@ static int io_eventfd_unregister(struct io_ring_ctx *ctx) ...@@ -6558,6 +6568,30 @@ static int io_eventfd_unregister(struct io_ring_ctx *ctx)
return -ENXIO; return -ENXIO;
} }
static int __io_destroy_buffers(int id, void *p, void *data)
{
struct io_ring_ctx *ctx = data;
struct io_buffer *buf = p;
/* the head kbuf is the list itself */
while (!list_empty(&buf->list)) {
struct io_buffer *nxt;
nxt = list_first_entry(&buf->list, struct io_buffer, list);
list_del(&nxt->list);
kfree(nxt);
}
kfree(buf);
idr_remove(&ctx->io_buffer_idr, id);
return 0;
}
static void io_destroy_buffers(struct io_ring_ctx *ctx)
{
idr_for_each(&ctx->io_buffer_idr, __io_destroy_buffers, ctx);
idr_destroy(&ctx->io_buffer_idr);
}
static void io_ring_ctx_free(struct io_ring_ctx *ctx) static void io_ring_ctx_free(struct io_ring_ctx *ctx)
{ {
io_finish_async(ctx); io_finish_async(ctx);
...@@ -6568,6 +6602,7 @@ static void io_ring_ctx_free(struct io_ring_ctx *ctx) ...@@ -6568,6 +6602,7 @@ static void io_ring_ctx_free(struct io_ring_ctx *ctx)
io_sqe_buffer_unregister(ctx); io_sqe_buffer_unregister(ctx);
io_sqe_files_unregister(ctx); io_sqe_files_unregister(ctx);
io_eventfd_unregister(ctx); io_eventfd_unregister(ctx);
io_destroy_buffers(ctx);
idr_destroy(&ctx->personality_idr); idr_destroy(&ctx->personality_idr);
#if defined(CONFIG_UNIX) #if defined(CONFIG_UNIX)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册