io_uring: abstract out provided buffer list selection
In preparation for providing another way to select a buffer, move the existing logic into a helper. Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
b66e65f414
commit
149c69b04a
1 changed files with 23 additions and 11 deletions
|
@ -3448,29 +3448,41 @@ static int io_buffer_add_list(struct io_ring_ctx *ctx,
|
||||||
return xa_err(xa_store(&ctx->io_bl_xa, bgid, bl, GFP_KERNEL));
|
return xa_err(xa_store(&ctx->io_bl_xa, bgid, bl, GFP_KERNEL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void __user *io_provided_buffer_select(struct io_kiocb *req, size_t *len,
|
||||||
|
struct io_buffer_list *bl,
|
||||||
|
unsigned int issue_flags)
|
||||||
|
{
|
||||||
|
struct io_buffer *kbuf;
|
||||||
|
|
||||||
|
if (list_empty(&bl->buf_list))
|
||||||
|
return ERR_PTR(-ENOBUFS);
|
||||||
|
|
||||||
|
kbuf = list_first_entry(&bl->buf_list, struct io_buffer, list);
|
||||||
|
list_del(&kbuf->list);
|
||||||
|
if (*len > kbuf->len)
|
||||||
|
*len = kbuf->len;
|
||||||
|
req->flags |= REQ_F_BUFFER_SELECTED;
|
||||||
|
req->kbuf = kbuf;
|
||||||
|
io_ring_submit_unlock(req->ctx, issue_flags);
|
||||||
|
return u64_to_user_ptr(kbuf->addr);
|
||||||
|
}
|
||||||
|
|
||||||
static void __user *io_buffer_select(struct io_kiocb *req, size_t *len,
|
static void __user *io_buffer_select(struct io_kiocb *req, size_t *len,
|
||||||
unsigned int issue_flags)
|
unsigned int issue_flags)
|
||||||
{
|
{
|
||||||
struct io_buffer *kbuf = req->kbuf;
|
|
||||||
struct io_ring_ctx *ctx = req->ctx;
|
struct io_ring_ctx *ctx = req->ctx;
|
||||||
struct io_buffer_list *bl;
|
struct io_buffer_list *bl;
|
||||||
|
|
||||||
io_ring_submit_lock(req->ctx, issue_flags);
|
io_ring_submit_lock(req->ctx, issue_flags);
|
||||||
|
|
||||||
bl = io_buffer_get_list(ctx, req->buf_index);
|
bl = io_buffer_get_list(ctx, req->buf_index);
|
||||||
if (bl && !list_empty(&bl->buf_list)) {
|
if (unlikely(!bl)) {
|
||||||
kbuf = list_first_entry(&bl->buf_list, struct io_buffer, list);
|
|
||||||
list_del(&kbuf->list);
|
|
||||||
if (*len > kbuf->len)
|
|
||||||
*len = kbuf->len;
|
|
||||||
req->flags |= REQ_F_BUFFER_SELECTED;
|
|
||||||
req->kbuf = kbuf;
|
|
||||||
io_ring_submit_unlock(req->ctx, issue_flags);
|
io_ring_submit_unlock(req->ctx, issue_flags);
|
||||||
return u64_to_user_ptr(kbuf->addr);
|
return ERR_PTR(-ENOBUFS);
|
||||||
}
|
}
|
||||||
|
|
||||||
io_ring_submit_unlock(req->ctx, issue_flags);
|
/* selection helpers drop the submit lock again, if needed */
|
||||||
return ERR_PTR(-ENOBUFS);
|
return io_provided_buffer_select(req, len, bl, issue_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_COMPAT
|
#ifdef CONFIG_COMPAT
|
||||||
|
|
Loading…
Add table
Reference in a new issue