io_uring_prep_readv_fixed(3)

πŸ“¦
version 2.15 Β· 2 versions
, in arch rolling, ubuntu stonking

✨ io_uring_prep_readv_fixed ✨

okay bestie, gather round, because today we're prepping a vectored read using fixed buffers and honestly? it's giving efficiency πŸ’…

🌸 SYNOPSIS 🌸

#include <liburing.h>

void io_uring_prep_readv_fixed(struct io_uring_sqe *sqe,
                               int fd,
                               const struct iovec *iovecs,
                               unsigned nr_vecs,
                               __u64 offset,
                               int flags,
                               int buf_index);

πŸ’– DESCRIPTION πŸ’–

so like. the io_uring_prep_readv_fixed(3) function gets a vectored read request all dressed and ready, and it does it using fixed (registered) buffers πŸŽ€. your submission queue entry, sqe, gets set up to use the file descriptor fd and start reading nr_vecs iovecs starting from the file position offset. no cap.

the iovecs argument points at an array of iovec structures that describe the read buffers πŸ¦‹. and here's the thing β€” all those buffers have to be part of the registered buffer set at index buf_index, the one you already registered earlier with io_uring_register_buffers(3). like, they gotta be in the club already, yk? πŸ”₯

the flags argument can hold any per-request flags, stuff like RWF_NOWAIT or any other flags that preadv2(2) supports ✨.

and the whole point of using fixed buffers? it skips the overhead of mapping your buffers for every single I/O operation, so apps that keep reusing the same buffers get a nice performance glow-up πŸ‘‘. iconic behavior, honestly.


🫢 RETURN VALUE 🫢

None. that's it, that's the whole section. it returns nothing. 😌


😭 ERRORS 😭

the CQE res field is where the actual result lives, bestie. on success it holds the number of bytes read ⭐. on error, you get a negative errno value back. so always check it, fr fr.


🧚 NOTES 🧚

ok so lowkey important detail here πŸ™ˆ: this function accepts an array of iovec's where each one has a size_t number of bytes, BUT the io_uring_cqe's result code is an __s32 value. so in theory, a short read with a big enough iov_len value could produce an ambiguous return πŸ‘€.

but plot twist β€” the number of bytes actually transferred has the same limit as read(2), so this cannot happen in practice πŸ’€. crisis averted, breathe.


🌈 SEE ALSO 🌈


and that's the whole page, bestie!! this one's from the liburing-2.10 era, dated January 18, 2025 β€” go forth and register those buffers, you absolute main character πŸ’œβœ¨

πŸ“¦ where this page comes from