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 {...@@ -634,6 +634,22 @@ pub const IO_Uring = struct {
634 return sqe;634 return sqe;
635 }635 }
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
637 /// Queues (but does not submit) an SQE to perform an `fallocate(2)`.653 /// Queues (but does not submit) an SQE to perform an `fallocate(2)`.
638 /// Returns a pointer to the SQE.654 /// Returns a pointer to the SQE.
639 pub fn fallocate(655 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...@@ -993,6 +1009,16 @@ pub fn io_uring_prep_write_fixed(sqe: *io_uring_sqe, fd: os.fd_t, buffer: *os.io
993 sqe.buf_index = buffer_index;1009 sqe.buf_index = buffer_index;
994}1010}
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
996pub fn io_uring_prep_accept(1022pub fn io_uring_prep_accept(
997 sqe: *io_uring_sqe,1023 sqe: *io_uring_sqe,
998 fd: os.fd_t,1024 fd: os.fd_t,
...@@ -1099,7 +1125,7 @@ pub fn io_uring_prep_poll_add(...@@ -1099,7 +1125,7 @@ pub fn io_uring_prep_poll_add(
1099 poll_mask: u32,1125 poll_mask: u32,
1100) void {1126) void {
1101 io_uring_prep_rw(.POLL_ADD, sqe, fd, @ptrToInt(@as(?*c_void, null)), 0, 0);1127 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);
1103}1129}
11041130
1105pub fn io_uring_prep_poll_remove(1131pub fn io_uring_prep_poll_remove(
...@@ -1109,6 +1135,17 @@ pub fn io_uring_prep_poll_remove(...@@ -1109,6 +1135,17 @@ pub fn io_uring_prep_poll_remove(
1109 io_uring_prep_rw(.POLL_REMOVE, sqe, -1, target_user_data, 0, 0);1135 io_uring_prep_rw(.POLL_REMOVE, sqe, -1, target_user_data, 0, 0);
1110}1136}
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
1112pub fn io_uring_prep_fallocate(1149pub fn io_uring_prep_fallocate(
1113 sqe: *io_uring_sqe,1150 sqe: *io_uring_sqe,
1114 fd: os.fd_t,1151 fd: os.fd_t,