diff options
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/os/linux/IoUring.zig | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index 5bcb4ec1a9..3b2f753a37 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -10,7 +10,7 @@ const testing = std.testing; const is_linux = builtin.os.tag == .linux; const page_size_min = std.heap.page_size_min; -fd: posix.fd_t = -1, +fd: linux.fd_t = -1, sq: SubmissionQueue, cq: CompletionQueue, flags: u32, @@ -62,7 +62,7 @@ pub fn init_params(entries: u16, p: *linux.io_uring_params) !IoUring { .NOSYS => return error.SystemOutdated, else => |errno| return posix.unexpectedErrno(errno), } - const fd = @as(posix.fd_t, @intCast(res)); + const fd = @as(linux.fd_t, @intCast(res)); assert(fd >= 0); errdefer posix.close(fd); @@ -341,7 +341,7 @@ pub fn cq_advance(self: *IoUring, count: u32) void { /// apply to the write, since the fsync may complete before the write is issued to the disk. /// You should preferably use `link_with_next_sqe()` on a write's SQE to link it with an fsync, /// or else insert a full write barrier using `drain_previous_sqes()` when queueing an fsync. -pub fn fsync(self: *IoUring, user_data: u64, fd: posix.fd_t, flags: u32) !*linux.io_uring_sqe { +pub fn fsync(self: *IoUring, user_data: u64, fd: linux.fd_t, flags: u32) !*linux.io_uring_sqe { const sqe = try self.get_sqe(); sqe.prep_fsync(fd, flags); sqe.user_data = user_data; @@ -386,7 +386,7 @@ pub const ReadBuffer = union(enum) { pub fn read( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, buffer: ReadBuffer, offset: u64, ) !*linux.io_uring_sqe { @@ -409,7 +409,7 @@ pub fn read( pub fn write( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, buffer: []const u8, offset: u64, ) !*linux.io_uring_sqe { @@ -433,7 +433,7 @@ pub fn write( /// See https://github.com/axboe/liburing/issues/291 /// /// Returns a pointer to the SQE so that you can further modify the SQE for advanced use cases. -pub fn splice(self: *IoUring, user_data: u64, fd_in: posix.fd_t, off_in: u64, fd_out: posix.fd_t, off_out: u64, len: usize) !*linux.io_uring_sqe { +pub fn splice(self: *IoUring, user_data: u64, fd_in: linux.fd_t, off_in: u64, fd_out: linux.fd_t, off_out: u64, len: usize) !*linux.io_uring_sqe { const sqe = try self.get_sqe(); sqe.prep_splice(fd_in, off_in, fd_out, off_out, len); sqe.user_data = user_data; @@ -448,7 +448,7 @@ pub fn splice(self: *IoUring, user_data: u64, fd_in: posix.fd_t, off_in: u64, fd pub fn read_fixed( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, buffer: *posix.iovec, offset: u64, buffer_index: u16, @@ -466,7 +466,7 @@ pub fn read_fixed( pub fn writev( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, iovecs: []const posix.iovec_const, offset: u64, ) !*linux.io_uring_sqe { @@ -484,7 +484,7 @@ pub fn writev( pub fn write_fixed( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, buffer: *posix.iovec, offset: u64, buffer_index: u16, @@ -501,7 +501,7 @@ pub fn write_fixed( pub fn accept( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, addr: ?*posix.sockaddr, addrlen: ?*posix.socklen_t, flags: u32, @@ -523,7 +523,7 @@ pub fn accept( pub fn accept_multishot( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, addr: ?*posix.sockaddr, addrlen: ?*posix.socklen_t, flags: u32, @@ -548,7 +548,7 @@ pub fn accept_multishot( pub fn accept_direct( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, addr: ?*posix.sockaddr, addrlen: ?*posix.socklen_t, flags: u32, @@ -564,7 +564,7 @@ pub fn accept_direct( pub fn accept_multishot_direct( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, addr: ?*posix.sockaddr, addrlen: ?*posix.socklen_t, flags: u32, @@ -580,7 +580,7 @@ pub fn accept_multishot_direct( pub fn connect( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, addr: *const posix.sockaddr, addrlen: posix.socklen_t, ) !*linux.io_uring_sqe { @@ -595,8 +595,8 @@ pub fn connect( pub fn epoll_ctl( self: *IoUring, user_data: u64, - epfd: posix.fd_t, - fd: posix.fd_t, + epfd: linux.fd_t, + fd: linux.fd_t, op: u32, ev: ?*linux.epoll_event, ) !*linux.io_uring_sqe { @@ -626,7 +626,7 @@ pub const RecvBuffer = union(enum) { pub fn recv( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, buffer: RecvBuffer, flags: u32, ) !*linux.io_uring_sqe { @@ -650,7 +650,7 @@ pub fn recv( pub fn send( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, buffer: []const u8, flags: u32, ) !*linux.io_uring_sqe { @@ -678,7 +678,7 @@ pub fn send( pub fn send_zc( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, buffer: []const u8, send_flags: u32, zc_flags: u16, @@ -695,7 +695,7 @@ pub fn send_zc( pub fn send_zc_fixed( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, buffer: []const u8, send_flags: u32, zc_flags: u16, @@ -713,8 +713,8 @@ pub fn send_zc_fixed( pub fn recvmsg( self: *IoUring, user_data: u64, - fd: posix.fd_t, - msg: *posix.msghdr, + fd: linux.fd_t, + msg: *linux.msghdr, flags: u32, ) !*linux.io_uring_sqe { const sqe = try self.get_sqe(); @@ -729,8 +729,8 @@ pub fn recvmsg( pub fn sendmsg( self: *IoUring, user_data: u64, - fd: posix.fd_t, - msg: *const posix.msghdr_const, + fd: linux.fd_t, + msg: *const linux.msghdr_const, flags: u32, ) !*linux.io_uring_sqe { const sqe = try self.get_sqe(); @@ -745,8 +745,8 @@ pub fn sendmsg( pub fn sendmsg_zc( self: *IoUring, user_data: u64, - fd: posix.fd_t, - msg: *const posix.msghdr_const, + fd: linux.fd_t, + msg: *const linux.msghdr_const, flags: u32, ) !*linux.io_uring_sqe { const sqe = try self.get_sqe(); @@ -761,7 +761,7 @@ pub fn sendmsg_zc( pub fn openat( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, path: [*:0]const u8, flags: linux.O, mode: posix.mode_t, @@ -786,7 +786,7 @@ pub fn openat( pub fn openat_direct( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, path: [*:0]const u8, flags: linux.O, mode: posix.mode_t, @@ -801,7 +801,7 @@ pub fn openat_direct( /// Queues (but does not submit) an SQE to perform a `close(2)`. /// Returns a pointer to the SQE. /// Available since 5.6. -pub fn close(self: *IoUring, user_data: u64, fd: posix.fd_t) !*linux.io_uring_sqe { +pub fn close(self: *IoUring, user_data: u64, fd: linux.fd_t) !*linux.io_uring_sqe { const sqe = try self.get_sqe(); sqe.prep_close(fd); sqe.user_data = user_data; @@ -896,7 +896,7 @@ pub fn link_timeout( pub fn poll_add( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, poll_mask: u32, ) !*linux.io_uring_sqe { const sqe = try self.get_sqe(); @@ -939,7 +939,7 @@ pub fn poll_update( pub fn fallocate( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, mode: i32, offset: u64, len: u64, @@ -955,7 +955,7 @@ pub fn fallocate( pub fn statx( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, path: [:0]const u8, flags: u32, mask: u32, @@ -1008,9 +1008,9 @@ pub fn shutdown( pub fn renameat( self: *IoUring, user_data: u64, - old_dir_fd: posix.fd_t, + old_dir_fd: linux.fd_t, old_path: [*:0]const u8, - new_dir_fd: posix.fd_t, + new_dir_fd: linux.fd_t, new_path: [*:0]const u8, flags: u32, ) !*linux.io_uring_sqe { @@ -1025,7 +1025,7 @@ pub fn renameat( pub fn unlinkat( self: *IoUring, user_data: u64, - dir_fd: posix.fd_t, + dir_fd: linux.fd_t, path: [*:0]const u8, flags: u32, ) !*linux.io_uring_sqe { @@ -1040,7 +1040,7 @@ pub fn unlinkat( pub fn mkdirat( self: *IoUring, user_data: u64, - dir_fd: posix.fd_t, + dir_fd: linux.fd_t, path: [*:0]const u8, mode: posix.mode_t, ) !*linux.io_uring_sqe { @@ -1056,7 +1056,7 @@ pub fn symlinkat( self: *IoUring, user_data: u64, target: [*:0]const u8, - new_dir_fd: posix.fd_t, + new_dir_fd: linux.fd_t, link_path: [*:0]const u8, ) !*linux.io_uring_sqe { const sqe = try self.get_sqe(); @@ -1070,9 +1070,9 @@ pub fn symlinkat( pub fn linkat( self: *IoUring, user_data: u64, - old_dir_fd: posix.fd_t, + old_dir_fd: linux.fd_t, old_path: [*:0]const u8, - new_dir_fd: posix.fd_t, + new_dir_fd: linux.fd_t, new_path: [*:0]const u8, flags: u32, ) !*linux.io_uring_sqe { @@ -1144,7 +1144,7 @@ pub fn waitid( /// Registering file descriptors will wait for the ring to idle. /// Files are automatically unregistered by the kernel when the ring is torn down. /// An application need unregister only if it wants to register a new array of file descriptors. -pub fn register_files(self: *IoUring, fds: []const posix.fd_t) !void { +pub fn register_files(self: *IoUring, fds: []const linux.fd_t) !void { assert(self.fd >= 0); const res = linux.io_uring_register( self.fd, @@ -1163,7 +1163,7 @@ pub fn register_files(self: *IoUring, fds: []const posix.fd_t) !void { /// * removing an existing entry (set the fd to -1) /// * replacing an existing entry with a new fd /// Adding new file descriptors must be done with `register_files`. -pub fn register_files_update(self: *IoUring, offset: u32, fds: []const posix.fd_t) !void { +pub fn register_files_update(self: *IoUring, offset: u32, fds: []const linux.fd_t) !void { assert(self.fd >= 0); const FilesUpdate = extern struct { @@ -1232,7 +1232,7 @@ pub fn register_file_alloc_range(self: *IoUring, offset: u32, len: u32) !void { /// 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. -pub fn register_eventfd(self: *IoUring, fd: posix.fd_t) !void { +pub fn register_eventfd(self: *IoUring, fd: linux.fd_t) !void { assert(self.fd >= 0); const res = linux.io_uring_register( self.fd, @@ -1247,7 +1247,7 @@ pub fn register_eventfd(self: *IoUring, fd: posix.fd_t) !void { /// an io_uring instance. Notifications are only posted for events that complete in an async manner. /// This means that events that complete inline while being submitted do not trigger a notification event. /// Only a single eventfd can be registered at any given point in time. -pub fn register_eventfd_async(self: *IoUring, fd: posix.fd_t) !void { +pub fn register_eventfd_async(self: *IoUring, fd: linux.fd_t) !void { assert(self.fd >= 0); const res = linux.io_uring_register( self.fd, @@ -1405,7 +1405,7 @@ pub fn socket_direct_alloc( pub fn bind( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, addr: *const posix.sockaddr, addrlen: posix.socklen_t, flags: u32, @@ -1422,7 +1422,7 @@ pub fn bind( pub fn listen( self: *IoUring, user_data: u64, - fd: posix.fd_t, + fd: linux.fd_t, backlog: usize, flags: u32, ) !*linux.io_uring_sqe { @@ -1513,7 +1513,7 @@ pub const SubmissionQueue = struct { sqe_head: u32 = 0, sqe_tail: u32 = 0, - pub fn init(fd: posix.fd_t, p: linux.io_uring_params) !SubmissionQueue { + pub fn init(fd: linux.fd_t, p: linux.io_uring_params) !SubmissionQueue { assert(fd >= 0); assert((p.features & linux.IORING_FEAT_SINGLE_MMAP) != 0); const size = @max( @@ -1576,7 +1576,7 @@ pub const CompletionQueue = struct { overflow: *u32, cqes: []linux.io_uring_cqe, - pub fn init(fd: posix.fd_t, p: linux.io_uring_params, sq: SubmissionQueue) !CompletionQueue { + pub fn init(fd: linux.fd_t, p: linux.io_uring_params, sq: SubmissionQueue) !CompletionQueue { assert(fd >= 0); assert((p.features & linux.IORING_FEAT_SINGLE_MMAP) != 0); const mmap = sq.mmap; @@ -1677,7 +1677,7 @@ pub const BufferGroup = struct { } // Prepare recv operation which will select buffer from this group. - pub fn recv(self: *BufferGroup, user_data: u64, fd: posix.fd_t, flags: u32) !*linux.io_uring_sqe { + pub fn recv(self: *BufferGroup, user_data: u64, fd: linux.fd_t, flags: u32) !*linux.io_uring_sqe { var sqe = try self.ring.get_sqe(); sqe.prep_rw(.RECV, fd, 0, 0, 0); sqe.rw_flags = flags; @@ -1688,7 +1688,7 @@ pub const BufferGroup = struct { } // Prepare multishot recv operation which will select buffer from this group. - pub fn recv_multishot(self: *BufferGroup, user_data: u64, fd: posix.fd_t, flags: u32) !*linux.io_uring_sqe { + pub fn recv_multishot(self: *BufferGroup, user_data: u64, fd: linux.fd_t, flags: u32) !*linux.io_uring_sqe { var sqe = try self.recv(user_data, fd, flags); sqe.ioprio |= linux.IORING_RECV_MULTISHOT; return sqe; @@ -1732,7 +1732,7 @@ pub const BufferGroup = struct { /// `entries` is the number of entries requested in the buffer ring, must be power of 2. /// `group_id` is the chosen buffer group ID, unique in IO_Uring. pub fn setup_buf_ring( - fd: posix.fd_t, + fd: linux.fd_t, entries: u16, group_id: u16, flags: linux.io_uring_buf_reg.Flags, @@ -1758,7 +1758,7 @@ pub fn setup_buf_ring( } fn register_buf_ring( - fd: posix.fd_t, + fd: linux.fd_t, addr: u64, entries: u32, group_id: u16, @@ -1780,7 +1780,7 @@ fn register_buf_ring( try handle_register_buf_ring_result(res); } -fn unregister_buf_ring(fd: posix.fd_t, group_id: u16) !void { +fn unregister_buf_ring(fd: linux.fd_t, group_id: u16) !void { var reg = mem.zeroInit(linux.io_uring_buf_reg, .{ .bgid = group_id, }); @@ -1802,7 +1802,7 @@ fn handle_register_buf_ring_result(res: usize) !void { } // Unregisters a previously registered shared buffer ring, returned from io_uring_setup_buf_ring. -pub fn free_buf_ring(fd: posix.fd_t, br: *align(page_size_min) linux.io_uring_buf_ring, entries: u32, group_id: u16) void { +pub fn free_buf_ring(fd: linux.fd_t, br: *align(page_size_min) linux.io_uring_buf_ring, entries: u32, group_id: u16) void { unregister_buf_ring(fd, group_id) catch {}; var mmap: []align(page_size_min) u8 = undefined; mmap.ptr = @ptrCast(br); @@ -1873,7 +1873,7 @@ test "nop" { }; defer { ring.deinit(); - testing.expectEqual(@as(posix.fd_t, -1), ring.fd) catch @panic("test failed"); + testing.expectEqual(@as(linux.fd_t, -1), ring.fd) catch @panic("test failed"); } const sqe = try ring.nop(0xaaaaaaaa); @@ -1949,7 +1949,7 @@ test "readv" { // https://github.com/torvalds/linux/blob/v5.4/fs/io_uring.c#L3119-L3124 vs // https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L6687-L6691 // We therefore avoid stressing sparse fd sets here: - var registered_fds = [_]posix.fd_t{0} ** 1; + var registered_fds = [_]linux.fd_t{0} ** 1; const fd_index = 0; registered_fds[fd_index] = fd; try ring.register_files(registered_fds[0..]); @@ -2383,7 +2383,7 @@ test "sendmsg/recvmsg" { const iovecs_send = [_]posix.iovec_const{ posix.iovec_const{ .base = &buffer_send, .len = buffer_send.len }, }; - const msg_send: posix.msghdr_const = .{ + const msg_send: linux.msghdr_const = .{ .name = addrAny(&address_server), .namelen = @sizeOf(linux.sockaddr.in), .iov = &iovecs_send, @@ -2405,7 +2405,7 @@ test "sendmsg/recvmsg" { .port = 0, .addr = 0, }; - var msg_recv: posix.msghdr = .{ + var msg_recv: linux.msghdr = .{ .name = addrAny(&address_recv), .namelen = @sizeOf(linux.sockaddr.in), .iov = &iovecs_recv, @@ -2785,7 +2785,7 @@ test "register_files_update" { const fd = try posix.openZ("/dev/zero", .{ .ACCMODE = .RDONLY, .CLOEXEC = true }, 0); defer posix.close(fd); - var registered_fds = [_]posix.fd_t{0} ** 2; + var registered_fds = [_]linux.fd_t{0} ** 2; const fd_index = 0; const fd_index2 = 1; registered_fds[fd_index] = fd; @@ -3764,7 +3764,7 @@ test "accept_direct" { }; // register direct file descriptors - var registered_fds = [_]posix.fd_t{-1} ** 2; + var registered_fds = [_]linux.fd_t{-1} ** 2; try ring.register_files(registered_fds[0..]); const listener_socket = try createListenerSocket(&address); @@ -3847,7 +3847,7 @@ test "accept_multishot_direct" { .addr = @bitCast([4]u8{ 127, 0, 0, 1 }), }; - var registered_fds = [_]posix.fd_t{-1} ** 2; + var registered_fds = [_]linux.fd_t{-1} ** 2; try ring.register_files(registered_fds[0..]); const listener_socket = try createListenerSocket(&address); @@ -3910,7 +3910,7 @@ test "socket" { // test completion var cqe = try ring.copy_cqe(); try testing.expectEqual(posix.E.SUCCESS, cqe.err()); - const fd: posix.fd_t = @intCast(cqe.res); + const fd: linux.fd_t = @intCast(cqe.res); try testing.expect(fd > 2); posix.close(fd); @@ -3926,7 +3926,7 @@ test "socket_direct/socket_direct_alloc/close_direct" { }; defer ring.deinit(); - var registered_fds = [_]posix.fd_t{-1} ** 3; + var registered_fds = [_]linux.fd_t{-1} ** 3; try ring.register_files(registered_fds[0..]); // create socket in registered file descriptor at index 0 (last param) @@ -4007,7 +4007,7 @@ test "openat_direct/close_direct" { }; defer ring.deinit(); - var registered_fds = [_]posix.fd_t{-1} ** 3; + var registered_fds = [_]linux.fd_t{-1} ** 3; try ring.register_files(registered_fds[0..]); var tmp = std.testing.tmpDir(.{}); @@ -4394,7 +4394,7 @@ test "ring mapped buffers multishot recv" { fn buf_grp_recv_submit_get_cqe( ring: *IoUring, buf_grp: *BufferGroup, - fd: posix.fd_t, + fd: linux.fd_t, user_data: u64, ) !linux.io_uring_cqe { // prepare and submit recv @@ -4507,7 +4507,7 @@ test "bind/listen/connect" { var cqe = try ring.copy_cqe(); try testing.expectEqual(1, cqe.user_data); try testing.expectEqual(posix.E.SUCCESS, cqe.err()); - const listen_fd: posix.fd_t = @intCast(cqe.res); + const listen_fd: linux.fd_t = @intCast(cqe.res); try testing.expect(listen_fd > 2); // Prepare: set socket option * 2, bind, listen @@ -4549,7 +4549,7 @@ test "bind/listen/connect" { try testing.expectEqual(6, cqe.user_data); try testing.expectEqual(posix.E.SUCCESS, cqe.err()); // Get connect socket fd - const connect_fd: posix.fd_t = @intCast(cqe.res); + const connect_fd: linux.fd_t = @intCast(cqe.res); try testing.expect(connect_fd > 2 and connect_fd != listen_fd); break :brk connect_fd; }; |
