io_uring_prep_writev(3)
β¨ io_uring_prep_writev(3) β¨
okay bestie, welcome to the liburing Manual π you're literally about to learn how to prep a vectored write request and honestly? iconic of you.
πΈ NAME πΈ
io_uring_prep_writev β prep a vector I/O write request, no cap π¦
π SYNOPSIS π
#include <sys/uio.h>
#include <liburing.h>
void io_uring_prep_writev(struct io_uring_sqe *sqe,
int fd,
const struct iovec *iovecs,
unsigned nr_vecs,
__u64 offset);
look at her. she's giving five arguments of pure power β¨
π DESCRIPTION π
so the way that io_uring_prep_writev(3) works is it preps a vectored IO write request. you hand it a submission queue entry sqe, and it sets that bad boy up to use the file descriptor fd to start writing nr_vecs from the iovecs array, all at the specified offset. periodt π
now on files that support seeking β listen up, this part matters β if the offset is set to -1, the write operation commences at the file offset, and then the file offset gets incremented by however many bytes were written. if you want the full lore, go read write(2). π«Ά
β οΈ but fr fr: for an async API, reading and updating the current file offset may result in unpredictable behavior, unless access to the file is serialized. it is not encouraged to use this feature if it's possible to provide the desired IO offset from the application or library. like, just pass the offset, bestie, it's right there π
on files that are not capable of seeking, the offset must be 0 or -1. no in-between. that's the rule. π
and once the write has been prepared, you can submit it with one of the submit functions. go off β¨
π RETURN VALUE π
None
literally nothing. she returns nothing. she's mysterious like that π
π₯ ERRORS π₯
the CQE res field will contain the result of the operation. see the related man page for the deets on possible values. π
and here's the thing that trips everyone up: where synchronous system calls will return-1on failure and seterrnoto the actual error value, io_uring never useserrno. instead it returns the negatederrnodirectly in the CQEresfield. so like, if you were waiting forerrnoto tell you what happened... she's not coming. checkres. π
π¦ NOTES π¦
okay so unless an application explicitly needs to pass in more than one iovec, it is more efficient to use io_uring_prep_write(3) rather than this function, because no state has to be maintained for a non-vectored IO request. lowkey just saying. save yourself the work π
and as with any request that passes in data in a struct, that data must remain valid until the request has been successfully submitted. it need not remain valid until completion. once a request has been submitted, the in-kernel state is stable. π
β οΈ very early kernels (5.4 and earlier) required state to be stable until the completion occurred. so if you're on ancient kernel energy, bestie, be careful π
applications can test for this behavior by inspecting the IORING_FEAT_SUBMIT_STABLE flag passed back from io_uring_queue_init_params(3). iykyk π
π SEE ALSO π
and that's the whole page, bestie π this one's from liburing-2.1, dated November 15, 2021. go prep those writes and slay π β¨π¦
π¦ where this page comes from
- alpine 3.22: liburing-doc 2.9-r0 Β· LGPL-2.1-or-later OR MIT
- alpine 3.23: liburing-doc 2.12-r0 Β· LGPL-2.1-or-later OR MIT
- alpine 3.24: liburing-doc 2.14-r0 Β· LGPL-2.1-or-later OR MIT
- centos-stream 10: liburing-devel 2.12-1.el10 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- centos-stream 9: liburing-devel 2.12-1.el9 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- centos-stream 9: liburing-devel 2.12-1.el9 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- debian trixie: liburing-dev 2.9-1
- fedora 43: liburing-devel 2.9-2.fc43 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 43: liburing-devel 2.9-2.fc43 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- nixpkgs unstable: liburing 2.14
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- ubuntu noble: liburing-dev 2.5-1build1
- ubuntu questing: liburing-dev 2.11-1
- ubuntu resolute: liburing-dev 2.14-1
- π the page's license: LGPL-2.0-or-later
- Copyright (C) 2021 Stefan Roesch <shr@fb.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms