Skip to content

Commit ecd5c9b

Browse files
committed
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: Jens Axboe <[email protected]>
1 parent 1204433 commit ecd5c9b

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

io_uring/kbuf.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ static void __user *io_ring_buffer_select(struct io_kiocb *req, size_t *len,
171171
* the transfer completes (or if we get -EAGAIN and must poll of
172172
* retry).
173173
*/
174-
req->flags &= ~REQ_F_BUFFERS_COMMIT;
174+
io_kbuf_commit(req, bl, 1);
175175
req->buf_list = NULL;
176-
bl->head++;
177176
}
178177
return u64_to_user_ptr(buf->addr);
179178
}
@@ -297,8 +296,8 @@ int io_buffers_select(struct io_kiocb *req, struct buf_sel_arg *arg,
297296
* committed them, they cannot be put back in the queue.
298297
*/
299298
if (ret > 0) {
300-
req->flags |= REQ_F_BL_NO_RECYCLE;
301-
bl->head += ret;
299+
req->flags |= REQ_F_BUFFERS_COMMIT | REQ_F_BL_NO_RECYCLE;
300+
io_kbuf_commit(req, bl, ret);
302301
}
303302
} else {
304303
ret = io_provided_buffers_select(req, &arg->out_len, bl, arg->iovs);

io_uring/kbuf.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,21 @@ static inline bool io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags)
121121
return false;
122122
}
123123

124+
static inline void io_kbuf_commit(struct io_kiocb *req,
125+
struct io_buffer_list *bl, int nr)
126+
{
127+
if (unlikely(!(req->flags & REQ_F_BUFFERS_COMMIT)))
128+
return;
129+
bl->head += nr;
130+
req->flags &= ~REQ_F_BUFFERS_COMMIT;
131+
}
132+
124133
static inline void __io_put_kbuf_ring(struct io_kiocb *req, int nr)
125134
{
126135
struct io_buffer_list *bl = req->buf_list;
127136

128137
if (bl) {
129-
if (req->flags & REQ_F_BUFFERS_COMMIT) {
130-
bl->head += nr;
131-
req->flags &= ~REQ_F_BUFFERS_COMMIT;
132-
}
138+
io_kbuf_commit(req, bl, nr);
133139
req->buf_index = bl->bgid;
134140
}
135141
req->flags &= ~REQ_F_BUFFER_RING;

0 commit comments

Comments
 (0)