Merge pull request #22857 from nikneym/master

linux(io_uring): port new functions from liburing
This commit is contained in:
Alex Rønne Petersen 2025-02-12 07:57:10 +01:00 committed by GitHub
commit db0d9c2126
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 0 deletions

View File

@ -1186,6 +1186,28 @@ pub fn register_files_update(self: *IoUring, offset: u32, fds: []const posix.fd_
try handle_registration_result(res);
}
/// Registers an empty (-1) file table of `nr_files` number of file descriptors.
pub fn register_files_sparse(self: *IoUring, nr_files: u32) !void {
assert(self.fd >= 0);
const reg = &linux.io_uring_rsrc_register{
.nr = nr_files,
.flags = linux.IORING_RSRC_REGISTER_SPARSE,
.resv2 = 0,
.data = 0,
.tags = 0,
};
const res = linux.io_uring_register(
self.fd,
.REGISTER_FILES2,
@ptrCast(reg),
@as(u32, @sizeOf(linux.io_uring_rsrc_register)),
);
return handle_registration_result(res);
}
/// Registers the file descriptor for an eventfd that will be notified of completion events on
/// an io_uring instance.
/// Only a single a eventfd can be registered at any given point in time.

View File

@ -436,6 +436,15 @@ pub const io_uring_sqe = extern struct {
sqe.rw_flags = flags;
}
pub fn prep_cancel_fd(
sqe: *linux.io_uring_sqe,
fd: linux.fd_t,
flags: u32,
) void {
sqe.prep_rw(.ASYNC_CANCEL, fd, 0, 0, 0);
sqe.rw_flags = flags | linux.IORING_ASYNC_CANCEL_FD;
}
pub fn prep_shutdown(
sqe: *linux.io_uring_sqe,
sockfd: linux.socket_t,
@ -516,6 +525,21 @@ pub const io_uring_sqe = extern struct {
sqe.rw_flags = flags;
}
pub fn prep_files_update(
sqe: *linux.io_uring_sqe,
fds: []const linux.fd_t,
offset: u32,
) void {
sqe.prep_rw(.FILES_UPDATE, -1, @intFromPtr(fds.ptr), fds.len, @intCast(offset));
}
pub fn prep_files_update_alloc(
sqe: *linux.io_uring_sqe,
fds: []linux.fd_t,
) void {
sqe.prep_rw(.FILES_UPDATE, -1, @intFromPtr(fds.ptr), fds.len, linux.IORING_FILE_INDEX_ALLOC);
}
pub fn prep_provide_buffers(
sqe: *linux.io_uring_sqe,
buffers: [*]u8,