authorgravatar for joran@ronomon.comJoran Dirk Greef <joran@ronomon.com> 2020-09-17 20:29:56+02:00
committergravatar for joran@ronomon.comJoran Dirk Greef <joran@ronomon.com> 2020-09-17 20:29:56+02:00
log8b030a65994f7f71a71474c27636744a5aab3e08
tree9ec6a6601a50ba42e7852adc7217ae48b3c466f3
parente33c466dafce1d19014e5b9b9606f42b93d8f408

Use x.y for C-style x->y instead of x.*.y


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

lib/std/io_uring.zig+26-26
......@@ -85,13 +85,13 @@ pub const IO_Uring = struct {
8585 /// Matches the interface of io_uring_queue_init_params() in liburing.
8686 pub fn init_params(entries: u32, p: *io_uring_params) !IO_Uring {
8787 assert(entries >= 1 and entries <= 4096 and std.math.isPowerOfTwo(entries));
88 assert(p.*.sq_entries == 0);
89 assert(p.*.cq_entries == 0);
90 assert(p.*.features == 0);
91 assert(p.*.wq_fd == 0);
92 assert(p.*.resv[0] == 0);
93 assert(p.*.resv[1] == 0);
94 assert(p.*.resv[2] == 0);
88 assert(p.sq_entries == 0);
89 assert(p.cq_entries == 0);
90 assert(p.features == 0);
91 assert(p.wq_fd == 0);
92 assert(p.resv[0] == 0);
93 assert(p.resv[1] == 0);
94 assert(p.resv[2] == 0);
9595 if (!supported) return error.IO_UringKernelNotSupported;
9696
9797 const res = linux.io_uring_setup(entries, p);
......@@ -109,16 +109,16 @@ pub const IO_Uring = struct {
109109 // See https://patchwork.kernel.org/patch/11115257 for the kernel patch.
110110 // We do not support the double mmap() done before 5.4, because we want to keep the
111111 // init/deinit mmap paths simple and because io_uring has had many bug fixes even since 5.4.
112 if ((p.*.features & linux.IORING_FEAT_SINGLE_MMAP) == 0) {
112 if ((p.features & linux.IORING_FEAT_SINGLE_MMAP) == 0) {
113113 return error.IO_UringKernelNotSupported;
114114 }
115115
116116 // Check that the kernel has actually set params and that "impossible is nothing".
117 assert(p.*.sq_entries != 0);
118 assert(p.*.cq_entries != 0);
119 assert(p.*.cq_entries >= p.*.sq_entries);
117 assert(p.sq_entries != 0);
118 assert(p.cq_entries != 0);
119 assert(p.cq_entries >= p.sq_entries);
120120
121 // From here on, we only need to read from params, so pass `p` by value for convenience.
121 // From here on, we only need to read from params, so pass `p` by value as immutable.
122122 // The completion queue shares the mmap with the submission queue, so pass `sq` there too.
123123 var sq = try SubmissionQueue.init(fd, p.*);
124124 errdefer sq.deinit();
......@@ -128,25 +128,25 @@ pub const IO_Uring = struct {
128128 // Check that our starting state is as we expect.
129129 assert(sq.head.* == 0);
130130 assert(sq.tail.* == 0);
131 assert(sq.mask.* == p.*.sq_entries - 1);
131 assert(sq.mask.* == p.sq_entries - 1);
132132 // Allow flags.* to be non-zero, since the kernel may set IORING_SQ_NEED_WAKEUP at any time.
133133 assert(sq.dropped.* == 0);
134 assert(sq.array.len == p.*.sq_entries);
135 assert(sq.sqes.len == p.*.sq_entries);
134 assert(sq.array.len == p.sq_entries);
135 assert(sq.sqes.len == p.sq_entries);
136136 assert(sq.sqe_head == 0);
137137 assert(sq.sqe_tail == 0);
138138
139139 assert(cq.head.* == 0);
140140 assert(cq.tail.* == 0);
141 assert(cq.mask.* == p.*.cq_entries - 1);
141 assert(cq.mask.* == p.cq_entries - 1);
142142 assert(cq.overflow.* == 0);
143 assert(cq.cqes.len == p.*.cq_entries);
143 assert(cq.cqes.len == p.cq_entries);
144144
145145 return IO_Uring {
146146 .fd = fd,
147147 .sq = sq,
148148 .cq = cq,
149 .flags = p.*.flags
149 .flags = p.flags
150150 };
151151 }
152152
......@@ -491,7 +491,7 @@ pub const IO_Uring = struct {
491491 /// A chain will be broken if any SQE in the chain ends in error, where any unexpected result is
492492 /// considered an error. For example, a short read will terminate the remainder of the chain.
493493 pub fn link_with_next_sqe(self: *IO_Uring, sqe: *io_uring_sqe) void {
494 sqe.*.flags |= linux.IOSQE_IO_LINK;
494 sqe.flags |= linux.IOSQE_IO_LINK;
495495 }
496496
497497 /// Like `link_with_next_sqe()` but stronger.
......@@ -499,7 +499,7 @@ pub const IO_Uring = struct {
499499 /// For example, you may know that some commands will fail and may want the chain to continue.
500500 /// Hard links are resilient to completion results, but are not resilient to submission errors.
501501 pub fn hardlink_with_next_sqe(self: *IO_Uring, sqe: *io_uring_sqe) void {
502 sqe.*.flags |= linux.IOSQE_IO_HARDLINK;
502 sqe.flags |= linux.IOSQE_IO_HARDLINK;
503503 }
504504
505505 /// This creates a full pipeline barrier in the submission queue.
......@@ -508,7 +508,7 @@ pub const IO_Uring = struct {
508508 /// In other words, this stalls the entire submission queue.
509509 /// You should first consider using link_with_next_sqe() for more granular SQE sequence control.
510510 pub fn drain_previous_sqes(self: *IO_Uring, sqe: *io_uring_sqe) void {
511 sqe.*.flags |= linux.IOSQE_IO_DRAIN;
511 sqe.flags |= linux.IOSQE_IO_DRAIN;
512512 }
513513
514514 /// Registers an array of file descriptors.
......@@ -534,7 +534,7 @@ pub const IO_Uring = struct {
534534
535535 /// Changes the semantics of the SQE's `fd` to refer to a pre-registered file descriptor.
536536 pub fn use_registered_fd(self: *IO_Uring, sqe: *io_uring_sqe) void {
537 sqe.*.flags |= linux.IOSQE_FIXED_FILE;
537 sqe.flags |= linux.IOSQE_FIXED_FILE;
538538 }
539539
540540 /// Unregisters all registered file descriptors previously associated with the ring.
......@@ -719,7 +719,7 @@ test "queue_nop" {
719719
720720 var sqe_barrier = try ring.queue_nop(@intCast(u64, 0xbbbbbbbb));
721721 ring.drain_previous_sqes(sqe_barrier);
722 testing.expectEqual(@as(u8, linux.IOSQE_IO_DRAIN), sqe_barrier.*.flags);
722 testing.expectEqual(@as(u8, linux.IOSQE_IO_DRAIN), sqe_barrier.flags);
723723 testing.expectEqual(@as(u32, 1), try ring.submit());
724724 testing.expectEqual(io_uring_cqe {
725725 .user_data = 0xbbbbbbbb,
......@@ -750,7 +750,7 @@ test "queue_readv" {
750750 var iovecs = [_]os.iovec{ os.iovec { .iov_base = &buffer, .iov_len = buffer.len } };
751751 var sqe = try ring.queue_readv(0xcccccccc, fd_index, iovecs[0..], 0);
752752 ring.use_registered_fd(sqe);
753 testing.expectEqual(@as(u8, linux.IOSQE_FIXED_FILE), sqe.*.flags);
753 testing.expectEqual(@as(u8, linux.IOSQE_FIXED_FILE), sqe.flags);
754754
755755 testing.expectError(error.IO_UringSubmissionQueueFull, ring.queue_nop(0));
756756 testing.expectEqual(@as(u32, 1), try ring.submit());
......@@ -782,10 +782,10 @@ test "queue_writev/queue_fsync" {
782782 };
783783 var sqe_writev = try ring.queue_writev(0xdddddddd, fd, iovecs[0..], 0);
784784 ring.link_with_next_sqe(sqe_writev);
785 testing.expectEqual(@as(u8, linux.IOSQE_IO_LINK), sqe_writev.*.flags);
785 testing.expectEqual(@as(u8, linux.IOSQE_IO_LINK), sqe_writev.flags);
786786
787787 var sqe_fsync = try ring.queue_fsync(0xeeeeeeee, fd);
788 testing.expectEqual(fd, sqe_fsync.*.fd);
788 testing.expectEqual(fd, sqe_fsync.fd);
789789
790790 testing.expectEqual(@as(u32, 2), ring.sq_ready());
791791 testing.expectEqual(@as(u32, 2), try ring.submit_and_wait(2));