Commit ecd5c9b2 authored by Jens Axboe's avatar Jens Axboe

io_uring/kbuf: add io_kbuf_commit() helper

Committing the selected ring buffer is currently done in three different
spots, combine it into a helper and just call that.
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 12044332
...@@ -171,9 +171,8 @@ static void __user *io_ring_buffer_select(struct io_kiocb *req, size_t *len, ...@@ -171,9 +171,8 @@ static void __user *io_ring_buffer_select(struct io_kiocb *req, size_t *len,
* the transfer completes (or if we get -EAGAIN and must poll of * the transfer completes (or if we get -EAGAIN and must poll of
* retry). * retry).
*/ */
req->flags &= ~REQ_F_BUFFERS_COMMIT; io_kbuf_commit(req, bl, 1);
req->buf_list = NULL; req->buf_list = NULL;
bl->head++;
} }
return u64_to_user_ptr(buf->addr); return u64_to_user_ptr(buf->addr);
} }
...@@ -297,8 +296,8 @@ int io_buffers_select(struct io_kiocb *req, struct buf_sel_arg *arg, ...@@ -297,8 +296,8 @@ int io_buffers_select(struct io_kiocb *req, struct buf_sel_arg *arg,
* committed them, they cannot be put back in the queue. * committed them, they cannot be put back in the queue.
*/ */
if (ret > 0) { if (ret > 0) {
req->flags |= REQ_F_BL_NO_RECYCLE; req->flags |= REQ_F_BUFFERS_COMMIT | REQ_F_BL_NO_RECYCLE;
bl->head += ret; io_kbuf_commit(req, bl, ret);
} }
} else { } else {
ret = io_provided_buffers_select(req, &arg->out_len, bl, arg->iovs); ret = io_provided_buffers_select(req, &arg->out_len, bl, arg->iovs);
......
...@@ -121,15 +121,21 @@ static inline bool io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags) ...@@ -121,15 +121,21 @@ static inline bool io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags)
return false; return false;
} }
static inline void io_kbuf_commit(struct io_kiocb *req,
struct io_buffer_list *bl, int nr)
{
if (unlikely(!(req->flags & REQ_F_BUFFERS_COMMIT)))
return;
bl->head += nr;
req->flags &= ~REQ_F_BUFFERS_COMMIT;
}
static inline void __io_put_kbuf_ring(struct io_kiocb *req, int nr) static inline void __io_put_kbuf_ring(struct io_kiocb *req, int nr)
{ {
struct io_buffer_list *bl = req->buf_list; struct io_buffer_list *bl = req->buf_list;
if (bl) { if (bl) {
if (req->flags & REQ_F_BUFFERS_COMMIT) { io_kbuf_commit(req, bl, nr);
bl->head += nr;
req->flags &= ~REQ_F_BUFFERS_COMMIT;
}
req->buf_index = bl->bgid; req->buf_index = bl->bgid;
} }
req->flags &= ~REQ_F_BUFFER_RING; req->flags &= ~REQ_F_BUFFER_RING;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment