Skip to content

Commit db0d9c2

Browse files
authored
Merge pull request #22857 from nikneym/master
linux(io_uring): port new functions from liburing
2 parents 6dc1a4d + 408c817 commit db0d9c2

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

lib/std/os/linux/IoUring.zig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
1190+
pub 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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

0 commit comments

Comments
 (0)