io_uring/kbuf: add helpers for getting/peeking multiple buffers
authorJens Axboe <axboe@kernel.dk>
Tue, 5 Mar 2024 14:31:52 +0000 (07:31 -0700)
committerJens Axboe <axboe@kernel.dk>
Sat, 20 Apr 2024 15:47:51 +0000 (09:47 -0600)
commit3aff40d4066ea52eb76cce240574ff09b310d9ef
treefad9c7856c0244cd9b4fda79beb65b25b43bdb5f
parent1763c80061f36bc9a16e432c70509cabf27ed212
io_uring/kbuf: add helpers for getting/peeking multiple buffers

Our provided buffer interface only allows selection of a single buffer.
Add an API that allows getting/peeking multiple buffers at the same time.

This is only implemented for the ring provided buffers. It could be added
for the legacy provided buffers as well, but since it's strongly
encouraged to use the new interface, let's keep it simpler and just
provide it for the new API. The legacy interface will always just select
a single buffer.

There are two new main functions:

io_buffers_select(), which selects up as many buffers as it can. The
caller supplies the iovec array, and io_buffers_select() may allocate a
bigger array if the 'out_len' being passed in is non-zero and bigger
than what fits in the provided iovec. Buffers grabbed with this helper
are permanently assigned.

io_buffers_peek(), which works like io_buffers_select(), except they can
be recycled, if needed. Callers using either of these functions should
call io_put_kbufs() rather than io_put_kbuf() at completion time. The
peek interface must be called with the ctx locked from peek to
completion.

This add a bit state for the request:

- REQ_F_BUFFERS_COMMIT, which means that the the buffers have been
  peeked and should be committed to the buffer ring head when they are
  put as part of completion. Prior to this, req->buf_list was cleared to
  NULL when committed.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/io_uring_types.h
io_uring/kbuf.c
io_uring/kbuf.h