| author | |
| committer | |
| log | d98c0893b0a565507af955d4f47e63393ac8e464 |
| tree | 8d62241f3d8b7fed7964beb50ebae5eca0179789 |
| parent | 85e20748785880555f9db3bb3061edbd1bae10e7 |
ring.get_probe returns io_uring_probe which can be use to probe
capabilities of the current running kernel.
Ref:
https://unixism.net/loti/ref-liburing/supported_caps.html
https://github.com/axboe/liburing/blob/e1003e496e66f9b0ae06674869795edf772d5500/src/setup.c#L4542 files changed, 29 insertions(+), 15 deletions(-)
lib/std/os/linux.zig+14-12| ... | ... | @@ -6138,26 +6138,28 @@ pub const IO_URING_OP_SUPPORTED = 1 << 0; |
| 6138 | 6138 | |
| 6139 | 6139 | pub const io_uring_probe_op = extern struct { |
| 6140 | 6140 | op: IORING_OP, |
| 6141 | ||
| 6142 | 6141 | resv: u8, |
| 6143 | ||
| 6144 | /// IO_URING_OP_* flags | |
| 6145 | flags: u16, | |
| 6146 | ||
| 6142 | flags: u16, // IO_URING_OP_* flags | |
| 6147 | 6143 | resv2: u32, |
| 6144 | ||
| 6145 | pub fn is_supported(self: @This()) bool { | |
| 6146 | return self.flags & IO_URING_OP_SUPPORTED != 0; | |
| 6147 | } | |
| 6148 | 6148 | }; |
| 6149 | 6149 | |
| 6150 | 6150 | pub const io_uring_probe = extern struct { |
| 6151 | /// last opcode supported | |
| 6152 | last_op: IORING_OP, | |
| 6153 | ||
| 6154 | /// Number of io_uring_probe_op following | |
| 6155 | ops_len: u8, | |
| 6156 | ||
| 6151 | last_op: IORING_OP, // last opcode supported | |
| 6152 | ops_len: u8, // length of ops[] array below | |
| 6157 | 6153 | resv: u16, |
| 6158 | 6154 | resv2: [3]u32, |
| 6155 | ops: [256]io_uring_probe_op, | |
| 6159 | 6156 | |
| 6160 | // Followed by up to `ops_len` io_uring_probe_op structures | |
| 6157 | pub fn is_supported(self: @This(), op: IORING_OP) bool { | |
| 6158 | const i = @intFromEnum(op); | |
| 6159 | if (i > @intFromEnum(self.last_op) or i >= self.ops_len) | |
| 6160 | return false; | |
| 6161 | return self.ops[i].is_supported(); | |
| 6162 | } | |
| 6161 | 6163 | }; |
| 6162 | 6164 | |
| 6163 | 6165 | pub const io_uring_restriction = extern struct { |
lib/std/os/linux/IoUring.zig+15-3| ... | ... | @@ -1272,6 +1272,16 @@ pub fn unregister_buffers(self: *IoUring) !void { |
| 1272 | 1272 | } |
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | /// Returns a io_uring_probe which is used to probe the capabilities of the | |
| 1276 | /// io_uring subsystem of the running kernel. The io_uring_probe contains the | |
| 1277 | /// list of supported operations. | |
| 1278 | pub fn get_probe(self: *IoUring) !linux.io_uring_probe { | |
| 1279 | var probe = mem.zeroInit(linux.io_uring_probe, .{}); | |
| 1280 | const res = linux.io_uring_register(self.fd, .REGISTER_PROBE, &probe, probe.ops.len); | |
| 1281 | try handle_register_buf_ring_result(res); | |
| 1282 | return probe; | |
| 1283 | } | |
| 1284 | ||
| 1275 | 1285 | fn handle_registration_result(res: usize) !void { |
| 1276 | 1286 | switch (linux.E.init(res)) { |
| 1277 | 1287 | .SUCCESS => {}, |
| ... | ... | @@ -4355,9 +4365,7 @@ test "copy_cqes with wrapping sq.cqes buffer" { |
| 4355 | 4365 | } |
| 4356 | 4366 | } |
| 4357 | 4367 | |
| 4358 | test "bind" { | |
| 4359 | try skipKernelLessThan(.{ .major = 6, .minor = 11, .patch = 0 }); | |
| 4360 | ||
| 4368 | test "bind/listen/connect" { | |
| 4361 | 4369 | var ring = IoUring.init(4, 0) catch |err| switch (err) { |
| 4362 | 4370 | error.SystemOutdated => return error.SkipZigTest, |
| 4363 | 4371 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -4365,6 +4373,10 @@ test "bind" { |
| 4365 | 4373 | }; |
| 4366 | 4374 | defer ring.deinit(); |
| 4367 | 4375 | |
| 4376 | const probe = ring.get_probe() catch return error.SkipZigTest; | |
| 4377 | // LISTEN is higher required operation | |
| 4378 | if (!probe.is_supported(.LISTEN)) return error.SkipZigTest; | |
| 4379 | ||
| 4368 | 4380 | var addr = net.Address.initIp4([4]u8{ 127, 0, 0, 1 }, 0); |
| 4369 | 4381 | const proto: u32 = if (addr.any.family == linux.AF.UNIX) 0 else linux.IPPROTO.TCP; |
| 4370 | 4382 |