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>
Mon, 22 Apr 2024 17:26:01 +0000 (11:26 -0600)
commit35c8711c8fc4c16ad2749b8314da5829a493e28e
treefad9c7856c0244cd9b4fda79beb65b25b43bdb5f
parentac5f71a3d9d7eb540f6bf7e794eb4a3e4c3f11dd
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