authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-02-12 07:57:10+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-02-12 07:57:10+01:00
logdb0d9c21267dd6e482c96be1fc532a5f4eef9219
treeec7d264c7356e55599a99b525ce272d8bc884fde
parent6dc1a4db7f9561dd2b84a99159b3ad7b55958717
parent408c817e1e9b4f68f2d0c6b4cc1c6673c591bb2f
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #22857 from nikneym/master

linux(io_uring): port new functions from liburing

2 files changed, 46 insertions(+), 0 deletions(-)

lib/std/os/linux/IoUring.zig+22
......@@ -1186,6 +1186,28 @@ pub fn register_files_update(self: *IoUring, offset: u32, fds: []const posix.fd_
11861186 try handle_registration_result(res);
11871187}
11881188
1189/// Registers an empty (-1) file table of `nr_files` number of file descriptors.
1190pub fn register_files_sparse(self: *IoUring, nr_files: u32) !void {
1191 assert(self.fd >= 0);
1192
1193 const reg = &linux.io_uring_rsrc_register{
1194 .nr = nr_files,
1195 .flags = linux.IORING_RSRC_REGISTER_SPARSE,
1196 .resv2 = 0,
1197 .data = 0,
1198 .tags = 0,
1199 };
1200
1201 const res = linux.io_uring_register(
1202 self.fd,
1203 .REGISTER_FILES2,
1204 @ptrCast(reg),
1205 @as(u32, @sizeOf(linux.io_uring_rsrc_register)),
1206 );
1207
1208 return handle_registration_result(res);
1209}
1210
11891211/// Registers the file descriptor for an eventfd that will be notified of completion events on
11901212/// an io_uring instance.
11911213/// Only a single a eventfd can be registered at any given point in time.
lib/std/os/linux/io_uring_sqe.zig+24
......@@ -436,6 +436,15 @@ pub const io_uring_sqe = extern struct {
436436 sqe.rw_flags = flags;
437437 }
438438
439 pub fn prep_cancel_fd(
440 sqe: *linux.io_uring_sqe,
441 fd: linux.fd_t,
442 flags: u32,
443 ) void {
444 sqe.prep_rw(.ASYNC_CANCEL, fd, 0, 0, 0);
445 sqe.rw_flags = flags | linux.IORING_ASYNC_CANCEL_FD;
446 }
447
439448 pub fn prep_shutdown(
440449 sqe: *linux.io_uring_sqe,
441450 sockfd: linux.socket_t,
......@@ -516,6 +525,21 @@ pub const io_uring_sqe = extern struct {
516525 sqe.rw_flags = flags;
517526 }
518527
528 pub fn prep_files_update(
529 sqe: *linux.io_uring_sqe,
530 fds: []const linux.fd_t,
531 offset: u32,
532 ) void {
533 sqe.prep_rw(.FILES_UPDATE, -1, @intFromPtr(fds.ptr), fds.len, @intCast(offset));
534 }
535
536 pub fn prep_files_update_alloc(
537 sqe: *linux.io_uring_sqe,
538 fds: []linux.fd_t,
539 ) void {
540 sqe.prep_rw(.FILES_UPDATE, -1, @intFromPtr(fds.ptr), fds.len, linux.IORING_FILE_INDEX_ALLOC);
541 }
542
519543 pub fn prep_provide_buffers(
520544 sqe: *linux.io_uring_sqe,
521545 buffers: [*]u8,