From 331b8e892aa831d2825f3f006e508a6db46f1f2c Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 12 Dec 2021 16:55:51 +0100 Subject: [PATCH 1/7] os/linux: add more io_uring opcode --- lib/std/os/linux.zig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index fb43984773..e46761aa1c 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -3576,6 +3576,12 @@ pub const IORING_OP = enum(u8) { PROVIDE_BUFFERS, REMOVE_BUFFERS, TEE, + SHUTDOWN, + RENAMEAT, + UNLINKAT, + MKDIRAT, + SYMLINKAT, + LINKAT, _, }; From 0229fb7c62275c5a278e9d173919da6608dc4ae5 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 12 Dec 2021 17:27:32 +0100 Subject: [PATCH 2/7] os/linux/io_uring: implement shutdown --- lib/std/os/linux/io_uring.zig | 86 ++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index 55757f0cb5..63ff67b39c 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -731,6 +731,22 @@ pub const IO_Uring = struct { return sqe; } + /// Queues (but does not submit) an SQE to perform a `shutdown(2)`. + /// Returns a pointer to the SQE. + /// + /// The operation is identified by its `user_data`. + pub fn shutdown( + self: *IO_Uring, + user_data: u64, + sockfd: os.socket_t, + how: u32, + ) !*io_uring_sqe { + const sqe = try self.get_sqe(); + io_uring_prep_shutdown(sqe, sockfd, how); + sqe.user_data = user_data; + return sqe; + } + /// Registers an array of file descriptors. /// Every time a file descriptor is put in an SQE and submitted to the kernel, the kernel must /// retrieve a reference to the file, and once I/O has completed the file reference must be @@ -798,7 +814,7 @@ pub const IO_Uring = struct { } /// Registers the file descriptor for an eventfd that will be notified of completion events on - /// an io_uring instance. Notifications are only posted for events that complete in an async manner. + /// 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: *IO_Uring, fd: os.fd_t) !void { @@ -1279,6 +1295,14 @@ pub fn io_uring_prep_cancel( sqe.rw_flags = flags; } +pub fn io_uring_prep_shutdown( + sqe: *io_uring_sqe, + sockfd: os.socket_t, + how: u32, +) void { + io_uring_prep_rw(.SHUTDOWN, sqe, sockfd, 0, how, 0); +} + test "structs/offsets/entries" { if (builtin.os.tag != .linux) return error.SkipZigTest; @@ -2191,3 +2215,63 @@ test "register_files_update" { try ring.unregister_files(); } + +test "shutdown" { + if (builtin.os.tag != .linux) return error.SkipZigTest; + + var ring = IO_Uring.init(16, 0) catch |err| switch (err) { + error.SystemOutdated => return error.SkipZigTest, + error.PermissionDenied => return error.SkipZigTest, + else => return err, + }; + defer ring.deinit(); + + const address = try net.Address.parseIp4("127.0.0.1", 3131); + + // Socket bound, expect shutdown to work + { + const server = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); + defer os.close(server); + try os.setsockopt(server, os.SOL.SOCKET, os.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); + try os.bind(server, &address.any, address.getOsSockLen()); + try os.listen(server, 1); + + var shutdown_sqe = try ring.shutdown(0x445445445, server, os.linux.SHUT.RD); + try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode); + try testing.expectEqual(@as(i32, server), shutdown_sqe.fd); + + try testing.expectEqual(@as(u32, 1), try ring.submit()); + + const cqe = try ring.copy_cqe(); + switch (cqe.err()) { + .SUCCESS => {}, + // This kernel's io_uring does not yet implement shutdown (kernel version < 5.11) + .INVAL => return error.SkipZigTest, + else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), + } + + try testing.expectEqual(linux.io_uring_cqe{ + .user_data = 0x445445445, + .res = 0, + .flags = 0, + }, cqe); + } + + // Socket not bound, expect to fail with ENOTCONN + { + const server = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); + defer os.close(server); + + var shutdown_sqe = ring.shutdown(0x445445445, server, os.linux.SHUT.RD) catch |err| switch (err) { + else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), + }; + try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode); + try testing.expectEqual(@as(i32, server), shutdown_sqe.fd); + + try testing.expectEqual(@as(u32, 1), try ring.submit()); + + const cqe = try ring.copy_cqe(); + try testing.expectEqual(@as(u64, 0x445445445), cqe.user_data); + try testing.expectEqual(os.linux.E.NOTCONN, cqe.err()); + } +} From 088c1fab4d7463bf8d50cf23b7f7dbcbeb85fb32 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 12 Dec 2021 18:04:12 +0100 Subject: [PATCH 3/7] os/linux/io_uring: implement renameat --- lib/std/os/linux/io_uring.zig | 106 ++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index 63ff67b39c..19d1bea5ab 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -747,6 +747,23 @@ pub const IO_Uring = struct { return sqe; } + /// Queues (but does not submit) an SQE to perform a `renameat2(2)`. + /// Returns a pointer to the SQE. + pub fn renameat( + self: *IO_Uring, + user_data: u64, + old_dir_fd: os.fd_t, + old_path: [*:0]const u8, + new_dir_fd: os.fd_t, + new_path: [*:0]const u8, + flags: u32, + ) !*io_uring_sqe { + const sqe = try self.get_sqe(); + io_uring_prep_renameat(sqe, old_dir_fd, old_path, new_dir_fd, new_path, flags); + sqe.user_data = user_data; + return sqe; + } + /// Registers an array of file descriptors. /// Every time a file descriptor is put in an SQE and submitted to the kernel, the kernel must /// retrieve a reference to the file, and once I/O has completed the file reference must be @@ -1303,6 +1320,26 @@ pub fn io_uring_prep_shutdown( io_uring_prep_rw(.SHUTDOWN, sqe, sockfd, 0, how, 0); } +pub fn io_uring_prep_renameat( + sqe: *io_uring_sqe, + old_dir_fd: os.fd_t, + old_path: [*:0]const u8, + new_dir_fd: os.fd_t, + new_path: [*:0]const u8, + flags: u32, +) void { + io_uring_prep_rw( + .RENAMEAT, + sqe, + old_dir_fd, + @ptrToInt(old_path), + 0, + @ptrToInt(new_path), + ); + sqe.len = @bitCast(u32, new_dir_fd); + sqe.rw_flags = flags; +} + test "structs/offsets/entries" { if (builtin.os.tag != .linux) return error.SkipZigTest; @@ -2275,3 +2312,72 @@ test "shutdown" { try testing.expectEqual(os.linux.E.NOTCONN, cqe.err()); } } + +test "renameat" { + if (builtin.os.tag != .linux) return error.SkipZigTest; + + var ring = IO_Uring.init(1, 0) catch |err| switch (err) { + error.SystemOutdated => return error.SkipZigTest, + error.PermissionDenied => return error.SkipZigTest, + else => return err, + }; + defer ring.deinit(); + + const old_path = "test_io_uring_renameat_old"; + const new_path = "test_io_uring_renameat_new"; + + // Write old file with data + + const old_file = try std.fs.cwd().createFile(old_path, .{ .truncate = true, .mode = 0o666 }); + defer { + old_file.close(); + std.fs.cwd().deleteFile(new_path) catch {}; + } + try old_file.writeAll("hello"); + + // Submit renameat + + var sqe = try ring.renameat( + 0x12121212, + linux.AT.FDCWD, + old_path, + linux.AT.FDCWD, + new_path, + 0, + ); + try testing.expectEqual(linux.IORING_OP.RENAMEAT, sqe.opcode); + try testing.expectEqual(@as(i32, linux.AT.FDCWD), sqe.fd); + try testing.expectEqual(@as(i32, linux.AT.FDCWD), @bitCast(i32, sqe.len)); + try testing.expectEqual(@as(u32, 1), try ring.submit()); + + const cqe = try ring.copy_cqe(); + switch (cqe.err()) { + .SUCCESS => {}, + // This kernel's io_uring does not yet implement renameat (kernel version < 5.11) + .INVAL => return error.SkipZigTest, + else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), + } + try testing.expectEqual(linux.io_uring_cqe{ + .user_data = 0x12121212, + .res = 0, + .flags = 0, + }, cqe); + + // Validate that the old file doesn't exist anymore + { + _ = std.fs.cwd().openFile(old_path, .{}) catch |err| switch (err) { + error.FileNotFound => {}, + else => std.debug.panic("unexpected error: {}", .{err}), + }; + } + + // Validate that the new file exists with the proper content + { + const new_file = try std.fs.cwd().openFile(new_path, .{}); + defer new_file.close(); + + var new_file_data: [16]u8 = undefined; + const read = try new_file.readAll(&new_file_data); + try testing.expectEqualStrings("hello", new_file_data[0..read]); + } +} From 4e647dee9fc7a373bb88e9870e4a4b19e0dac5b9 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 12 Dec 2021 18:11:50 +0100 Subject: [PATCH 4/7] os/linux/io_uring: implement unlinkat --- lib/std/os/linux/io_uring.zig | 75 +++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index 19d1bea5ab..b254d91e08 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -764,6 +764,21 @@ pub const IO_Uring = struct { return sqe; } + /// Queues (but does not submit) an SQE to perform a `unlinkat(2)`. + /// Returns a pointer to the SQE. + pub fn unlinkat( + self: *IO_Uring, + user_data: u64, + dir_fd: os.fd_t, + path: [*:0]const u8, + flags: u32, + ) !*io_uring_sqe { + const sqe = try self.get_sqe(); + io_uring_prep_unlinkat(sqe, dir_fd, path, flags); + sqe.user_data = user_data; + return sqe; + } + /// Registers an array of file descriptors. /// Every time a file descriptor is put in an SQE and submitted to the kernel, the kernel must /// retrieve a reference to the file, and once I/O has completed the file reference must be @@ -1340,6 +1355,16 @@ pub fn io_uring_prep_renameat( sqe.rw_flags = flags; } +pub fn io_uring_prep_unlinkat( + sqe: *io_uring_sqe, + dir_fd: os.fd_t, + path: [*:0]const u8, + flags: u32, +) void { + io_uring_prep_rw(.UNLINKAT, sqe, dir_fd, @ptrToInt(path), 0, 0); + sqe.rw_flags = flags; +} + test "structs/offsets/entries" { if (builtin.os.tag != .linux) return error.SkipZigTest; @@ -2381,3 +2406,53 @@ test "renameat" { try testing.expectEqualStrings("hello", new_file_data[0..read]); } } + +test "unlinkat" { + if (builtin.os.tag != .linux) return error.SkipZigTest; + + var ring = IO_Uring.init(1, 0) catch |err| switch (err) { + error.SystemOutdated => return error.SkipZigTest, + error.PermissionDenied => return error.SkipZigTest, + else => return err, + }; + defer ring.deinit(); + + const path = "test_io_uring_unlinkat"; + + // Write old file with data + + const file = try std.fs.cwd().createFile(path, .{ .truncate = true, .mode = 0o666 }); + defer file.close(); + defer std.fs.cwd().deleteFile(path) catch {}; + + // Submit unlinkat + + var sqe = try ring.unlinkat( + 0x12121212, + linux.AT.FDCWD, + path, + 0, + ); + try testing.expectEqual(linux.IORING_OP.UNLINKAT, sqe.opcode); + try testing.expectEqual(@as(i32, linux.AT.FDCWD), sqe.fd); + try testing.expectEqual(@as(u32, 1), try ring.submit()); + + const cqe = try ring.copy_cqe(); + switch (cqe.err()) { + .SUCCESS => {}, + // This kernel's io_uring does not yet implement unlinkat (kernel version < 5.11) + .INVAL => return error.SkipZigTest, + else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), + } + try testing.expectEqual(linux.io_uring_cqe{ + .user_data = 0x12121212, + .res = 0, + .flags = 0, + }, cqe); + + // Validate that the file doesn't exist anymore + _ = std.fs.cwd().openFile(path, .{}) catch |err| switch (err) { + error.FileNotFound => {}, + else => std.debug.panic("unexpected error: {}", .{err}), + }; +} From 1fd0542bee467e3810b39c7d755a8152806c7818 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 12 Dec 2021 18:30:13 +0100 Subject: [PATCH 5/7] os/linux/io_uring: implement mkdirat --- lib/std/os/linux/io_uring.zig | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index b254d91e08..cb9f2a73f1 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -779,6 +779,21 @@ pub const IO_Uring = struct { return sqe; } + /// Queues (but does not submit) an SQE to perform a `mkdirat(2)`. + /// Returns a pointer to the SQE. + pub fn mkdirat( + self: *IO_Uring, + user_data: u64, + dir_fd: os.fd_t, + path: [*:0]const u8, + mode: os.mode_t, + ) !*io_uring_sqe { + const sqe = try self.get_sqe(); + io_uring_prep_mkdirat(sqe, dir_fd, path, mode); + sqe.user_data = user_data; + return sqe; + } + /// Registers an array of file descriptors. /// Every time a file descriptor is put in an SQE and submitted to the kernel, the kernel must /// retrieve a reference to the file, and once I/O has completed the file reference must be @@ -1365,6 +1380,15 @@ pub fn io_uring_prep_unlinkat( sqe.rw_flags = flags; } +pub fn io_uring_prep_mkdirat( + sqe: *io_uring_sqe, + dir_fd: os.fd_t, + path: [*:0]const u8, + mode: os.mode_t, +) void { + io_uring_prep_rw(.MKDIRAT, sqe, dir_fd, @ptrToInt(path), mode, 0); +} + test "structs/offsets/entries" { if (builtin.os.tag != .linux) return error.SkipZigTest; @@ -2456,3 +2480,46 @@ test "unlinkat" { else => std.debug.panic("unexpected error: {}", .{err}), }; } + +test "mkdirat" { + if (builtin.os.tag != .linux) return error.SkipZigTest; + + var ring = IO_Uring.init(1, 0) catch |err| switch (err) { + error.SystemOutdated => return error.SkipZigTest, + error.PermissionDenied => return error.SkipZigTest, + else => return err, + }; + defer ring.deinit(); + + const path = "test_io_uring_mkdirat"; + + defer std.fs.cwd().deleteDir(path) catch {}; + + // Submit mkdirat + + var sqe = try ring.mkdirat( + 0x12121212, + linux.AT.FDCWD, + path, + 0o0755, + ); + try testing.expectEqual(linux.IORING_OP.MKDIRAT, sqe.opcode); + try testing.expectEqual(@as(i32, linux.AT.FDCWD), sqe.fd); + try testing.expectEqual(@as(u32, 1), try ring.submit()); + + const cqe = try ring.copy_cqe(); + switch (cqe.err()) { + .SUCCESS => {}, + // This kernel's io_uring does not yet implement mkdirat (kernel version < 5.15) + .INVAL => return error.SkipZigTest, + else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), + } + try testing.expectEqual(linux.io_uring_cqe{ + .user_data = 0x12121212, + .res = 0, + .flags = 0, + }, cqe); + + // Validate that the directory exist + _ = try std.fs.cwd().openDir(path, .{}); +} From 5dd53c1986039ddf93d7eada8ceaa7ff2ad2b9bb Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 12 Dec 2021 18:43:31 +0100 Subject: [PATCH 6/7] os/linux/io_uring: implement symlinkat --- lib/std/os/linux/io_uring.zig | 80 +++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index cb9f2a73f1..d9a637b9f2 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -794,6 +794,21 @@ pub const IO_Uring = struct { return sqe; } + /// Queues (but does not submit) an SQE to perform a `symlinkat(2)`. + /// Returns a pointer to the SQE. + pub fn symlinkat( + self: *IO_Uring, + user_data: u64, + target: [*:0]const u8, + new_dir_fd: os.fd_t, + link_path: [*:0]const u8, + ) !*io_uring_sqe { + const sqe = try self.get_sqe(); + io_uring_prep_symlinkat(sqe, target, new_dir_fd, link_path); + sqe.user_data = user_data; + return sqe; + } + /// Registers an array of file descriptors. /// Every time a file descriptor is put in an SQE and submitted to the kernel, the kernel must /// retrieve a reference to the file, and once I/O has completed the file reference must be @@ -1389,6 +1404,22 @@ pub fn io_uring_prep_mkdirat( io_uring_prep_rw(.MKDIRAT, sqe, dir_fd, @ptrToInt(path), mode, 0); } +pub fn io_uring_prep_symlinkat( + sqe: *io_uring_sqe, + target: [*:0]const u8, + new_dir_fd: os.fd_t, + link_path: [*:0]const u8, +) void { + io_uring_prep_rw( + .SYMLINKAT, + sqe, + new_dir_fd, + @ptrToInt(target), + 0, + @ptrToInt(link_path), + ); +} + test "structs/offsets/entries" { if (builtin.os.tag != .linux) return error.SkipZigTest; @@ -2523,3 +2554,52 @@ test "mkdirat" { // Validate that the directory exist _ = try std.fs.cwd().openDir(path, .{}); } + +test "symlinkat" { + if (builtin.os.tag != .linux) return error.SkipZigTest; + + var ring = IO_Uring.init(1, 0) catch |err| switch (err) { + error.SystemOutdated => return error.SkipZigTest, + error.PermissionDenied => return error.SkipZigTest, + else => return err, + }; + defer ring.deinit(); + + const path = "test_io_uring_symlinkat"; + const link_path = "test_io_uring_symlinkat_link"; + + const file = try std.fs.cwd().createFile(path, .{ .truncate = true, .mode = 0o666 }); + defer { + file.close(); + std.fs.cwd().deleteFile(path) catch {}; + std.fs.cwd().deleteFile(link_path) catch {}; + } + + // Submit symlinkat + + var sqe = try ring.symlinkat( + 0x12121212, + path, + linux.AT.FDCWD, + link_path, + ); + try testing.expectEqual(linux.IORING_OP.SYMLINKAT, sqe.opcode); + try testing.expectEqual(@as(i32, linux.AT.FDCWD), sqe.fd); + try testing.expectEqual(@as(u32, 1), try ring.submit()); + + const cqe = try ring.copy_cqe(); + switch (cqe.err()) { + .SUCCESS => {}, + // This kernel's io_uring does not yet implement symlinkat (kernel version < 5.15) + .INVAL => return error.SkipZigTest, + else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), + } + try testing.expectEqual(linux.io_uring_cqe{ + .user_data = 0x12121212, + .res = 0, + .flags = 0, + }, cqe); + + // Validate that the symlink exist + _ = try std.fs.cwd().openFile(link_path, .{}); +} From f9b8808d7494757fc47dfd506264669270f4e573 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 12 Dec 2021 18:49:17 +0100 Subject: [PATCH 7/7] os/linux/io_uring: implement linkat --- lib/std/os/linux/io_uring.zig | 97 +++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index d9a637b9f2..ce87ab3aef 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -809,6 +809,23 @@ pub const IO_Uring = struct { return sqe; } + /// Queues (but does not submit) an SQE to perform a `linkat(2)`. + /// Returns a pointer to the SQE. + pub fn linkat( + self: *IO_Uring, + user_data: u64, + old_dir_fd: os.fd_t, + old_path: [*:0]const u8, + new_dir_fd: os.fd_t, + new_path: [*:0]const u8, + flags: u32, + ) !*io_uring_sqe { + const sqe = try self.get_sqe(); + io_uring_prep_linkat(sqe, old_dir_fd, old_path, new_dir_fd, new_path, flags); + sqe.user_data = user_data; + return sqe; + } + /// Registers an array of file descriptors. /// Every time a file descriptor is put in an SQE and submitted to the kernel, the kernel must /// retrieve a reference to the file, and once I/O has completed the file reference must be @@ -1420,6 +1437,26 @@ pub fn io_uring_prep_symlinkat( ); } +pub fn io_uring_prep_linkat( + sqe: *io_uring_sqe, + old_dir_fd: os.fd_t, + old_path: [*:0]const u8, + new_dir_fd: os.fd_t, + new_path: [*:0]const u8, + flags: u32, +) void { + io_uring_prep_rw( + .LINKAT, + sqe, + old_dir_fd, + @ptrToInt(old_path), + 0, + @ptrToInt(new_path), + ); + sqe.len = @bitCast(u32, new_dir_fd); + sqe.rw_flags = flags; +} + test "structs/offsets/entries" { if (builtin.os.tag != .linux) return error.SkipZigTest; @@ -2603,3 +2640,63 @@ test "symlinkat" { // Validate that the symlink exist _ = try std.fs.cwd().openFile(link_path, .{}); } + +test "linkat" { + if (builtin.os.tag != .linux) return error.SkipZigTest; + + var ring = IO_Uring.init(1, 0) catch |err| switch (err) { + error.SystemOutdated => return error.SkipZigTest, + error.PermissionDenied => return error.SkipZigTest, + else => return err, + }; + defer ring.deinit(); + + const first_path = "test_io_uring_linkat_first"; + const second_path = "test_io_uring_linkat_second"; + + // Write file with data + + const first_file = try std.fs.cwd().createFile(first_path, .{ .truncate = true, .mode = 0o666 }); + defer { + first_file.close(); + std.fs.cwd().deleteFile(first_path) catch {}; + std.fs.cwd().deleteFile(second_path) catch {}; + } + try first_file.writeAll("hello"); + + // Submit linkat + + var sqe = try ring.linkat( + 0x12121212, + linux.AT.FDCWD, + first_path, + linux.AT.FDCWD, + second_path, + 0, + ); + try testing.expectEqual(linux.IORING_OP.LINKAT, sqe.opcode); + try testing.expectEqual(@as(i32, linux.AT.FDCWD), sqe.fd); + try testing.expectEqual(@as(i32, linux.AT.FDCWD), @bitCast(i32, sqe.len)); + try testing.expectEqual(@as(u32, 1), try ring.submit()); + + const cqe = try ring.copy_cqe(); + switch (cqe.err()) { + .SUCCESS => {}, + // This kernel's io_uring does not yet implement linkat (kernel version < 5.15) + .INVAL => return error.SkipZigTest, + else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), + } + try testing.expectEqual(linux.io_uring_cqe{ + .user_data = 0x12121212, + .res = 0, + .flags = 0, + }, cqe); + + // Validate the second file + const second_file = try std.fs.cwd().openFile(second_path, .{}); + defer second_file.close(); + + var second_file_data: [16]u8 = undefined; + const read = try second_file.readAll(&second_file_data); + try testing.expectEqualStrings("hello", second_file_data[0..read]); +}