authorgravatar for kenta@lithdew.netKenta Iwasaki <kenta@lithdew.net> 2021-11-10 16:35:11+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-14 13:56:41-05:00
log09c17acf024ba43252cc516b13a4cf8c19fda057
treeb1b4ee2759f1d7e47eff8dc1e8a6e27a722f3779
parent1d55705fa42d83556346f8fcb3a8fce0d55f06ad

io_uring: add poll_update

Add method from liburing to queue (but not submit) a SQE to update the user data of an existing poll operation.

1 files changed, 38 insertions(+), 1 deletions(-)

lib/std/os/linux/io_uring.zig+38-1
......@@ -634,6 +634,22 @@ pub const IO_Uring = struct {
634634 return sqe;
635635 }
636636
637 /// Queues (but does not submit) an SQE to update the user data of an existing poll
638 /// operation. Returns a pointer to the SQE.
639 pub fn poll_update(
640 self: *IO_Uring,
641 user_data: u64,
642 old_user_data: u64,
643 new_user_data: u64,
644 poll_mask: u32,
645 flags: u32,
646 ) !*io_uring_sqe {
647 const sqe = try self.get_sqe();
648 io_uring_prep_poll_update(sqe, old_user_data, new_user_data, poll_mask, flags);
649 sqe.user_data = user_data;
650 return sqe;
651 }
652
637653 /// Queues (but does not submit) an SQE to perform an `fallocate(2)`.
638654 /// Returns a pointer to the SQE.
639655 pub fn fallocate(
......@@ -993,6 +1009,16 @@ pub fn io_uring_prep_write_fixed(sqe: *io_uring_sqe, fd: os.fd_t, buffer: *os.io
9931009 sqe.buf_index = buffer_index;
9941010}
9951011
1012/// Poll masks previously used to comprise of 16 bits in the flags union of
1013/// a SQE, but were then extended to comprise of 32 bits in order to make
1014/// room for additional option flags. To ensure that the correct bits of
1015/// poll masks are consistently and properly read across multiple kernel
1016/// versions, poll masks are enforced to be little-endian.
1017/// https://www.spinics.net/lists/io-uring/msg02848.html
1018pub inline fn __io_uring_prep_poll_mask(poll_mask: u32) u32 {
1019 return std.mem.nativeToLittle(u32, poll_mask);
1020}
1021
9961022pub fn io_uring_prep_accept(
9971023 sqe: *io_uring_sqe,
9981024 fd: os.fd_t,
......@@ -1099,7 +1125,7 @@ pub fn io_uring_prep_poll_add(
10991125 poll_mask: u32,
11001126) void {
11011127 io_uring_prep_rw(.POLL_ADD, sqe, fd, @ptrToInt(@as(?*c_void, null)), 0, 0);
1102 sqe.rw_flags = std.mem.nativeToLittle(u32, poll_mask);
1128 sqe.rw_flags = __io_uring_prep_poll_mask(poll_mask);
11031129}
11041130
11051131pub fn io_uring_prep_poll_remove(
......@@ -1109,6 +1135,17 @@ pub fn io_uring_prep_poll_remove(
11091135 io_uring_prep_rw(.POLL_REMOVE, sqe, -1, target_user_data, 0, 0);
11101136}
11111137
1138pub fn io_uring_prep_poll_update(
1139 sqe: *io_uring_sqe,
1140 old_user_data: u64,
1141 new_user_data: u64,
1142 poll_mask: u32,
1143 flags: u32,
1144) void {
1145 io_uring_prep_rw(.POLL_REMOVE, sqe, -1, old_user_data, flags, new_user_data);
1146 sqe.rw_flags = __io_uring_prep_poll_mask(poll_mask);
1147}
1148
11121149pub fn io_uring_prep_fallocate(
11131150 sqe: *io_uring_sqe,
11141151 fd: os.fd_t,