polyphony 0.85 → 0.86

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile.lock +1 -1
  4. data/ext/polyphony/io_extensions.c +2 -3
  5. data/lib/polyphony/version.rb +1 -1
  6. data/polyphony.gemspec +1 -1
  7. data/test/test_backend.rb +1 -1
  8. data/test/test_signal.rb +3 -3
  9. data/vendor/liburing/.github/pull_request_template.md +86 -0
  10. data/vendor/liburing/.github/workflows/build.yml +85 -0
  11. data/vendor/liburing/.github/workflows/shellcheck.yml +20 -0
  12. data/vendor/liburing/.gitignore +149 -0
  13. data/vendor/liburing/COPYING +502 -0
  14. data/vendor/liburing/COPYING.GPL +339 -0
  15. data/vendor/liburing/LICENSE +7 -0
  16. data/vendor/liburing/Makefile +82 -0
  17. data/vendor/liburing/Makefile.common +5 -0
  18. data/vendor/liburing/Makefile.quiet +11 -0
  19. data/vendor/liburing/README +46 -0
  20. data/vendor/liburing/configure +486 -0
  21. data/vendor/liburing/debian/README.Debian +7 -0
  22. data/vendor/liburing/debian/changelog +27 -0
  23. data/vendor/liburing/debian/compat +1 -0
  24. data/vendor/liburing/debian/control +48 -0
  25. data/vendor/liburing/debian/copyright +49 -0
  26. data/vendor/liburing/debian/liburing-dev.install +4 -0
  27. data/vendor/liburing/debian/liburing-dev.manpages +6 -0
  28. data/vendor/liburing/debian/liburing1-udeb.install +1 -0
  29. data/vendor/liburing/debian/liburing1.install +1 -0
  30. data/vendor/liburing/debian/liburing1.symbols +32 -0
  31. data/vendor/liburing/debian/patches/series +1 -0
  32. data/vendor/liburing/debian/rules +81 -0
  33. data/vendor/liburing/debian/source/format +1 -0
  34. data/vendor/liburing/debian/source/local-options +2 -0
  35. data/vendor/liburing/debian/source/options +1 -0
  36. data/vendor/liburing/debian/watch +3 -0
  37. data/vendor/liburing/examples/Makefile +38 -0
  38. data/vendor/liburing/examples/io_uring-cp.c +282 -0
  39. data/vendor/liburing/examples/io_uring-test.c +112 -0
  40. data/vendor/liburing/examples/link-cp.c +193 -0
  41. data/vendor/liburing/examples/ucontext-cp.c +273 -0
  42. data/vendor/liburing/liburing.pc.in +12 -0
  43. data/vendor/liburing/liburing.spec +66 -0
  44. data/vendor/liburing/make-debs.sh +53 -0
  45. data/vendor/liburing/man/io_uring.7 +754 -0
  46. data/vendor/liburing/man/io_uring_cq_advance.3 +35 -0
  47. data/vendor/liburing/man/io_uring_cq_ready.3 +25 -0
  48. data/vendor/liburing/man/io_uring_cqe_get_data.3 +34 -0
  49. data/vendor/liburing/man/io_uring_cqe_seen.3 +32 -0
  50. data/vendor/liburing/man/io_uring_enter.2 +1483 -0
  51. data/vendor/liburing/man/io_uring_free_probe.3 +24 -0
  52. data/vendor/liburing/man/io_uring_get_probe.3 +29 -0
  53. data/vendor/liburing/man/io_uring_get_sqe.3 +38 -0
  54. data/vendor/liburing/man/io_uring_opcode_supported.3 +29 -0
  55. data/vendor/liburing/man/io_uring_prep_msg_ring.3 +58 -0
  56. data/vendor/liburing/man/io_uring_prep_read.3 +50 -0
  57. data/vendor/liburing/man/io_uring_prep_read_fixed.3 +54 -0
  58. data/vendor/liburing/man/io_uring_prep_readv.3 +51 -0
  59. data/vendor/liburing/man/io_uring_prep_readv2.3 +79 -0
  60. data/vendor/liburing/man/io_uring_prep_write.3 +50 -0
  61. data/vendor/liburing/man/io_uring_prep_write_fixed.3 +54 -0
  62. data/vendor/liburing/man/io_uring_prep_writev.3 +51 -0
  63. data/vendor/liburing/man/io_uring_prep_writev2.3 +78 -0
  64. data/vendor/liburing/man/io_uring_queue_exit.3 +27 -0
  65. data/vendor/liburing/man/io_uring_queue_init.3 +44 -0
  66. data/vendor/liburing/man/io_uring_register.2 +688 -0
  67. data/vendor/liburing/man/io_uring_register_buffers.3 +41 -0
  68. data/vendor/liburing/man/io_uring_register_files.3 +35 -0
  69. data/vendor/liburing/man/io_uring_setup.2 +534 -0
  70. data/vendor/liburing/man/io_uring_sq_ready.3 +25 -0
  71. data/vendor/liburing/man/io_uring_sq_space_left.3 +25 -0
  72. data/vendor/liburing/man/io_uring_sqe_set_data.3 +30 -0
  73. data/vendor/liburing/man/io_uring_sqe_set_flags.3 +60 -0
  74. data/vendor/liburing/man/io_uring_sqring_wait.3 +30 -0
  75. data/vendor/liburing/man/io_uring_submit.3 +29 -0
  76. data/vendor/liburing/man/io_uring_submit_and_wait.3 +34 -0
  77. data/vendor/liburing/man/io_uring_submit_and_wait_timeout.3 +49 -0
  78. data/vendor/liburing/man/io_uring_unregister_buffers.3 +26 -0
  79. data/vendor/liburing/man/io_uring_unregister_files.3 +26 -0
  80. data/vendor/liburing/man/io_uring_wait_cqe.3 +33 -0
  81. data/vendor/liburing/man/io_uring_wait_cqe_nr.3 +36 -0
  82. data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +39 -0
  83. data/vendor/liburing/man/io_uring_wait_cqes.3 +46 -0
  84. data/vendor/liburing/src/Makefile +89 -0
  85. data/vendor/liburing/src/arch/aarch64/syscall.h +95 -0
  86. data/vendor/liburing/src/arch/generic/lib.h +21 -0
  87. data/vendor/liburing/src/arch/generic/syscall.h +87 -0
  88. data/vendor/liburing/src/arch/syscall-defs.h +67 -0
  89. data/vendor/liburing/src/arch/x86/lib.h +32 -0
  90. data/vendor/liburing/src/arch/x86/syscall.h +160 -0
  91. data/vendor/liburing/src/include/liburing/barrier.h +81 -0
  92. data/vendor/liburing/src/include/liburing/io_uring.h +442 -0
  93. data/vendor/liburing/src/include/liburing.h +921 -0
  94. data/vendor/liburing/src/int_flags.h +8 -0
  95. data/vendor/liburing/src/lib.h +57 -0
  96. data/vendor/liburing/src/liburing.map +53 -0
  97. data/vendor/liburing/src/nolibc.c +48 -0
  98. data/vendor/liburing/src/queue.c +403 -0
  99. data/vendor/liburing/src/register.c +293 -0
  100. data/vendor/liburing/src/setup.c +332 -0
  101. data/vendor/liburing/src/syscall.c +47 -0
  102. data/vendor/liburing/src/syscall.h +103 -0
  103. data/vendor/liburing/test/232c93d07b74-test.c +306 -0
  104. data/vendor/liburing/test/35fa71a030ca-test.c +329 -0
  105. data/vendor/liburing/test/500f9fbadef8-test.c +89 -0
  106. data/vendor/liburing/test/7ad0e4b2f83c-test.c +93 -0
  107. data/vendor/liburing/test/8a9973408177-test.c +106 -0
  108. data/vendor/liburing/test/917257daa0fe-test.c +53 -0
  109. data/vendor/liburing/test/Makefile +244 -0
  110. data/vendor/liburing/test/a0908ae19763-test.c +58 -0
  111. data/vendor/liburing/test/a4c0b3decb33-test.c +180 -0
  112. data/vendor/liburing/test/accept-link.c +254 -0
  113. data/vendor/liburing/test/accept-reuse.c +164 -0
  114. data/vendor/liburing/test/accept-test.c +79 -0
  115. data/vendor/liburing/test/accept.c +477 -0
  116. data/vendor/liburing/test/across-fork.c +283 -0
  117. data/vendor/liburing/test/b19062a56726-test.c +53 -0
  118. data/vendor/liburing/test/b5837bd5311d-test.c +77 -0
  119. data/vendor/liburing/test/ce593a6c480a-test.c +136 -0
  120. data/vendor/liburing/test/close-opath.c +122 -0
  121. data/vendor/liburing/test/config +10 -0
  122. data/vendor/liburing/test/connect.c +398 -0
  123. data/vendor/liburing/test/cq-full.c +96 -0
  124. data/vendor/liburing/test/cq-overflow.c +294 -0
  125. data/vendor/liburing/test/cq-peek-batch.c +102 -0
  126. data/vendor/liburing/test/cq-ready.c +94 -0
  127. data/vendor/liburing/test/cq-size.c +64 -0
  128. data/vendor/liburing/test/d4ae271dfaae-test.c +96 -0
  129. data/vendor/liburing/test/d77a67ed5f27-test.c +65 -0
  130. data/vendor/liburing/test/defer.c +307 -0
  131. data/vendor/liburing/test/double-poll-crash.c +185 -0
  132. data/vendor/liburing/test/drop-submit.c +92 -0
  133. data/vendor/liburing/test/eeed8b54e0df-test.c +114 -0
  134. data/vendor/liburing/test/empty-eownerdead.c +45 -0
  135. data/vendor/liburing/test/eventfd-disable.c +151 -0
  136. data/vendor/liburing/test/eventfd-reg.c +76 -0
  137. data/vendor/liburing/test/eventfd-ring.c +97 -0
  138. data/vendor/liburing/test/eventfd.c +112 -0
  139. data/vendor/liburing/test/exec-target.c +6 -0
  140. data/vendor/liburing/test/exit-no-cleanup.c +117 -0
  141. data/vendor/liburing/test/fadvise.c +202 -0
  142. data/vendor/liburing/test/fallocate.c +249 -0
  143. data/vendor/liburing/test/fc2a85cb02ef-test.c +131 -0
  144. data/vendor/liburing/test/file-register.c +858 -0
  145. data/vendor/liburing/test/file-update.c +173 -0
  146. data/vendor/liburing/test/file-verify.c +629 -0
  147. data/vendor/liburing/test/files-exit-hang-poll.c +128 -0
  148. data/vendor/liburing/test/files-exit-hang-timeout.c +134 -0
  149. data/vendor/liburing/test/fixed-link.c +90 -0
  150. data/vendor/liburing/test/fpos.c +252 -0
  151. data/vendor/liburing/test/fsync.c +224 -0
  152. data/vendor/liburing/test/hardlink.c +136 -0
  153. data/vendor/liburing/test/helpers.c +135 -0
  154. data/vendor/liburing/test/helpers.h +67 -0
  155. data/vendor/liburing/test/io-cancel.c +550 -0
  156. data/vendor/liburing/test/io_uring_enter.c +296 -0
  157. data/vendor/liburing/test/io_uring_register.c +676 -0
  158. data/vendor/liburing/test/io_uring_setup.c +192 -0
  159. data/vendor/liburing/test/iopoll.c +372 -0
  160. data/vendor/liburing/test/lfs-openat-write.c +119 -0
  161. data/vendor/liburing/test/lfs-openat.c +275 -0
  162. data/vendor/liburing/test/link-timeout.c +1107 -0
  163. data/vendor/liburing/test/link.c +496 -0
  164. data/vendor/liburing/test/link_drain.c +229 -0
  165. data/vendor/liburing/test/madvise.c +195 -0
  166. data/vendor/liburing/test/mkdir.c +108 -0
  167. data/vendor/liburing/test/msg-ring.c +234 -0
  168. data/vendor/liburing/test/multicqes_drain.c +387 -0
  169. data/vendor/liburing/test/nop-all-sizes.c +99 -0
  170. data/vendor/liburing/test/nop.c +115 -0
  171. data/vendor/liburing/test/open-close.c +261 -0
  172. data/vendor/liburing/test/openat2.c +308 -0
  173. data/vendor/liburing/test/personality.c +204 -0
  174. data/vendor/liburing/test/pipe-eof.c +83 -0
  175. data/vendor/liburing/test/pipe-reuse.c +105 -0
  176. data/vendor/liburing/test/poll-cancel-ton.c +135 -0
  177. data/vendor/liburing/test/poll-cancel.c +228 -0
  178. data/vendor/liburing/test/poll-link.c +230 -0
  179. data/vendor/liburing/test/poll-many.c +208 -0
  180. data/vendor/liburing/test/poll-mshot-update.c +273 -0
  181. data/vendor/liburing/test/poll-ring.c +48 -0
  182. data/vendor/liburing/test/poll-v-poll.c +353 -0
  183. data/vendor/liburing/test/poll.c +109 -0
  184. data/vendor/liburing/test/pollfree.c +426 -0
  185. data/vendor/liburing/test/probe.c +135 -0
  186. data/vendor/liburing/test/read-write.c +876 -0
  187. data/vendor/liburing/test/register-restrictions.c +633 -0
  188. data/vendor/liburing/test/rename.c +135 -0
  189. data/vendor/liburing/test/ring-leak.c +173 -0
  190. data/vendor/liburing/test/ring-leak2.c +249 -0
  191. data/vendor/liburing/test/rsrc_tags.c +449 -0
  192. data/vendor/liburing/test/runtests-loop.sh +16 -0
  193. data/vendor/liburing/test/runtests.sh +170 -0
  194. data/vendor/liburing/test/rw_merge_test.c +97 -0
  195. data/vendor/liburing/test/self.c +91 -0
  196. data/vendor/liburing/test/send_recv.c +286 -0
  197. data/vendor/liburing/test/send_recvmsg.c +345 -0
  198. data/vendor/liburing/test/sendmsg_fs_cve.c +200 -0
  199. data/vendor/liburing/test/shared-wq.c +84 -0
  200. data/vendor/liburing/test/short-read.c +75 -0
  201. data/vendor/liburing/test/shutdown.c +165 -0
  202. data/vendor/liburing/test/sigfd-deadlock.c +74 -0
  203. data/vendor/liburing/test/skip-cqe.c +429 -0
  204. data/vendor/liburing/test/socket-rw-eagain.c +158 -0
  205. data/vendor/liburing/test/socket-rw-offset.c +157 -0
  206. data/vendor/liburing/test/socket-rw.c +145 -0
  207. data/vendor/liburing/test/splice.c +512 -0
  208. data/vendor/liburing/test/sq-full-cpp.cc +45 -0
  209. data/vendor/liburing/test/sq-full.c +45 -0
  210. data/vendor/liburing/test/sq-poll-dup.c +204 -0
  211. data/vendor/liburing/test/sq-poll-kthread.c +169 -0
  212. data/vendor/liburing/test/sq-poll-share.c +137 -0
  213. data/vendor/liburing/test/sq-space_left.c +159 -0
  214. data/vendor/liburing/test/sqpoll-cancel-hang.c +157 -0
  215. data/vendor/liburing/test/sqpoll-disable-exit.c +196 -0
  216. data/vendor/liburing/test/sqpoll-exit-hang.c +78 -0
  217. data/vendor/liburing/test/sqpoll-sleep.c +69 -0
  218. data/vendor/liburing/test/statx.c +172 -0
  219. data/vendor/liburing/test/stdout.c +232 -0
  220. data/vendor/liburing/test/submit-link-fail.c +154 -0
  221. data/vendor/liburing/test/submit-reuse.c +239 -0
  222. data/vendor/liburing/test/symlink.c +116 -0
  223. data/vendor/liburing/test/teardowns.c +58 -0
  224. data/vendor/liburing/test/thread-exit.c +143 -0
  225. data/vendor/liburing/test/timeout-new.c +252 -0
  226. data/vendor/liburing/test/timeout-overflow.c +204 -0
  227. data/vendor/liburing/test/timeout.c +1523 -0
  228. data/vendor/liburing/test/unlink.c +112 -0
  229. data/vendor/liburing/test/wakeup-hang.c +162 -0
  230. metadata +223 -2
@@ -0,0 +1,496 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: run various linked sqe tests
4
+ *
5
+ */
6
+ #include <errno.h>
7
+ #include <stdio.h>
8
+ #include <unistd.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+ #include <fcntl.h>
12
+
13
+ #include "liburing.h"
14
+
15
+ static int no_hardlink;
16
+
17
+ /*
18
+ * Timer with single nop
19
+ */
20
+ static int test_single_hardlink(struct io_uring *ring)
21
+ {
22
+ struct __kernel_timespec ts;
23
+ struct io_uring_cqe *cqe;
24
+ struct io_uring_sqe *sqe;
25
+ int ret, i;
26
+
27
+ sqe = io_uring_get_sqe(ring);
28
+ if (!sqe) {
29
+ fprintf(stderr, "get sqe failed\n");
30
+ goto err;
31
+ }
32
+ ts.tv_sec = 0;
33
+ ts.tv_nsec = 10000000ULL;
34
+ io_uring_prep_timeout(sqe, &ts, 0, 0);
35
+ sqe->flags |= IOSQE_IO_LINK | IOSQE_IO_HARDLINK;
36
+ sqe->user_data = 1;
37
+
38
+ sqe = io_uring_get_sqe(ring);
39
+ if (!sqe) {
40
+ fprintf(stderr, "get sqe failed\n");
41
+ goto err;
42
+ }
43
+ io_uring_prep_nop(sqe);
44
+ sqe->user_data = 2;
45
+
46
+ ret = io_uring_submit(ring);
47
+ if (ret <= 0) {
48
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
49
+ goto err;
50
+ }
51
+
52
+ for (i = 0; i < 2; i++) {
53
+ ret = io_uring_wait_cqe(ring, &cqe);
54
+ if (ret < 0) {
55
+ fprintf(stderr, "wait completion %d\n", ret);
56
+ goto err;
57
+ }
58
+ if (!cqe) {
59
+ fprintf(stderr, "failed to get cqe\n");
60
+ goto err;
61
+ }
62
+ if (no_hardlink)
63
+ goto next;
64
+ if (cqe->user_data == 1 && cqe->res == -EINVAL) {
65
+ fprintf(stdout, "Hard links not supported, skipping\n");
66
+ no_hardlink = 1;
67
+ goto next;
68
+ }
69
+ if (cqe->user_data == 1 && cqe->res != -ETIME) {
70
+ fprintf(stderr, "timeout failed with %d\n", cqe->res);
71
+ goto err;
72
+ }
73
+ if (cqe->user_data == 2 && cqe->res) {
74
+ fprintf(stderr, "nop failed with %d\n", cqe->res);
75
+ goto err;
76
+ }
77
+ next:
78
+ io_uring_cqe_seen(ring, cqe);
79
+ }
80
+
81
+ return 0;
82
+ err:
83
+ return 1;
84
+ }
85
+
86
+ /*
87
+ * Timer -> timer -> nop
88
+ */
89
+ static int test_double_hardlink(struct io_uring *ring)
90
+ {
91
+ struct __kernel_timespec ts1, ts2;
92
+ struct io_uring_cqe *cqe;
93
+ struct io_uring_sqe *sqe;
94
+ int ret, i;
95
+
96
+ if (no_hardlink)
97
+ return 0;
98
+
99
+ sqe = io_uring_get_sqe(ring);
100
+ if (!sqe) {
101
+ fprintf(stderr, "get sqe failed\n");
102
+ goto err;
103
+ }
104
+ ts1.tv_sec = 0;
105
+ ts1.tv_nsec = 10000000ULL;
106
+ io_uring_prep_timeout(sqe, &ts1, 0, 0);
107
+ sqe->flags |= IOSQE_IO_LINK | IOSQE_IO_HARDLINK;
108
+ sqe->user_data = 1;
109
+
110
+ sqe = io_uring_get_sqe(ring);
111
+ if (!sqe) {
112
+ fprintf(stderr, "get sqe failed\n");
113
+ goto err;
114
+ }
115
+ ts2.tv_sec = 0;
116
+ ts2.tv_nsec = 15000000ULL;
117
+ io_uring_prep_timeout(sqe, &ts2, 0, 0);
118
+ sqe->flags |= IOSQE_IO_LINK | IOSQE_IO_HARDLINK;
119
+ sqe->user_data = 2;
120
+
121
+ sqe = io_uring_get_sqe(ring);
122
+ if (!sqe) {
123
+ fprintf(stderr, "get sqe failed\n");
124
+ goto err;
125
+ }
126
+ io_uring_prep_nop(sqe);
127
+ sqe->user_data = 3;
128
+
129
+ ret = io_uring_submit(ring);
130
+ if (ret <= 0) {
131
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
132
+ goto err;
133
+ }
134
+
135
+ for (i = 0; i < 3; i++) {
136
+ ret = io_uring_wait_cqe(ring, &cqe);
137
+ if (ret < 0) {
138
+ fprintf(stderr, "wait completion %d\n", ret);
139
+ goto err;
140
+ }
141
+ if (!cqe) {
142
+ fprintf(stderr, "failed to get cqe\n");
143
+ goto err;
144
+ }
145
+ if (cqe->user_data == 1 && cqe->res != -ETIME) {
146
+ fprintf(stderr, "timeout failed with %d\n", cqe->res);
147
+ goto err;
148
+ }
149
+ if (cqe->user_data == 2 && cqe->res != -ETIME) {
150
+ fprintf(stderr, "timeout failed with %d\n", cqe->res);
151
+ goto err;
152
+ }
153
+ if (cqe->user_data == 3 && cqe->res) {
154
+ fprintf(stderr, "nop failed with %d\n", cqe->res);
155
+ goto err;
156
+ }
157
+ io_uring_cqe_seen(ring, cqe);
158
+ }
159
+
160
+ return 0;
161
+ err:
162
+ return 1;
163
+
164
+ }
165
+
166
+ /*
167
+ * Test failing head of chain, and dependent getting -ECANCELED
168
+ */
169
+ static int test_single_link_fail(struct io_uring *ring)
170
+ {
171
+ struct io_uring_cqe *cqe;
172
+ struct io_uring_sqe *sqe;
173
+ int ret, i;
174
+
175
+ sqe = io_uring_get_sqe(ring);
176
+ if (!sqe) {
177
+ printf("get sqe failed\n");
178
+ goto err;
179
+ }
180
+
181
+ io_uring_prep_nop(sqe);
182
+ sqe->flags |= IOSQE_IO_LINK;
183
+
184
+ sqe = io_uring_get_sqe(ring);
185
+ if (!sqe) {
186
+ printf("get sqe failed\n");
187
+ goto err;
188
+ }
189
+
190
+ io_uring_prep_nop(sqe);
191
+
192
+ ret = io_uring_submit(ring);
193
+ if (ret <= 0) {
194
+ printf("sqe submit failed: %d\n", ret);
195
+ goto err;
196
+ }
197
+
198
+ for (i = 0; i < 2; i++) {
199
+ ret = io_uring_peek_cqe(ring, &cqe);
200
+ if (ret < 0) {
201
+ printf("wait completion %d\n", ret);
202
+ goto err;
203
+ }
204
+ if (!cqe) {
205
+ printf("failed to get cqe\n");
206
+ goto err;
207
+ }
208
+ if (i == 0 && cqe->res != -EINVAL) {
209
+ printf("sqe0 failed with %d, wanted -EINVAL\n", cqe->res);
210
+ goto err;
211
+ }
212
+ if (i == 1 && cqe->res != -ECANCELED) {
213
+ printf("sqe1 failed with %d, wanted -ECANCELED\n", cqe->res);
214
+ goto err;
215
+ }
216
+ io_uring_cqe_seen(ring, cqe);
217
+ }
218
+
219
+ return 0;
220
+ err:
221
+ return 1;
222
+ }
223
+
224
+ /*
225
+ * Test two independent chains
226
+ */
227
+ static int test_double_chain(struct io_uring *ring)
228
+ {
229
+ struct io_uring_cqe *cqe;
230
+ struct io_uring_sqe *sqe;
231
+ int ret, i;
232
+
233
+ sqe = io_uring_get_sqe(ring);
234
+ if (!sqe) {
235
+ printf("get sqe failed\n");
236
+ goto err;
237
+ }
238
+
239
+ io_uring_prep_nop(sqe);
240
+ sqe->flags |= IOSQE_IO_LINK;
241
+
242
+ sqe = io_uring_get_sqe(ring);
243
+ if (!sqe) {
244
+ printf("get sqe failed\n");
245
+ goto err;
246
+ }
247
+
248
+ io_uring_prep_nop(sqe);
249
+
250
+ sqe = io_uring_get_sqe(ring);
251
+ if (!sqe) {
252
+ printf("get sqe failed\n");
253
+ goto err;
254
+ }
255
+
256
+ io_uring_prep_nop(sqe);
257
+ sqe->flags |= IOSQE_IO_LINK;
258
+
259
+ sqe = io_uring_get_sqe(ring);
260
+ if (!sqe) {
261
+ printf("get sqe failed\n");
262
+ goto err;
263
+ }
264
+
265
+ io_uring_prep_nop(sqe);
266
+
267
+ ret = io_uring_submit(ring);
268
+ if (ret <= 0) {
269
+ printf("sqe submit failed: %d\n", ret);
270
+ goto err;
271
+ }
272
+
273
+ for (i = 0; i < 4; i++) {
274
+ ret = io_uring_wait_cqe(ring, &cqe);
275
+ if (ret < 0) {
276
+ printf("wait completion %d\n", ret);
277
+ goto err;
278
+ }
279
+ io_uring_cqe_seen(ring, cqe);
280
+ }
281
+
282
+ return 0;
283
+ err:
284
+ return 1;
285
+ }
286
+
287
+ /*
288
+ * Test multiple dependents
289
+ */
290
+ static int test_double_link(struct io_uring *ring)
291
+ {
292
+ struct io_uring_cqe *cqe;
293
+ struct io_uring_sqe *sqe;
294
+ int ret, i;
295
+
296
+ sqe = io_uring_get_sqe(ring);
297
+ if (!sqe) {
298
+ printf("get sqe failed\n");
299
+ goto err;
300
+ }
301
+
302
+ io_uring_prep_nop(sqe);
303
+ sqe->flags |= IOSQE_IO_LINK;
304
+
305
+ sqe = io_uring_get_sqe(ring);
306
+ if (!sqe) {
307
+ printf("get sqe failed\n");
308
+ goto err;
309
+ }
310
+
311
+ io_uring_prep_nop(sqe);
312
+ sqe->flags |= IOSQE_IO_LINK;
313
+
314
+ sqe = io_uring_get_sqe(ring);
315
+ if (!sqe) {
316
+ printf("get sqe failed\n");
317
+ goto err;
318
+ }
319
+
320
+ io_uring_prep_nop(sqe);
321
+
322
+ ret = io_uring_submit(ring);
323
+ if (ret <= 0) {
324
+ printf("sqe submit failed: %d\n", ret);
325
+ goto err;
326
+ }
327
+
328
+ for (i = 0; i < 3; i++) {
329
+ ret = io_uring_wait_cqe(ring, &cqe);
330
+ if (ret < 0) {
331
+ printf("wait completion %d\n", ret);
332
+ goto err;
333
+ }
334
+ io_uring_cqe_seen(ring, cqe);
335
+ }
336
+
337
+ return 0;
338
+ err:
339
+ return 1;
340
+ }
341
+
342
+ /*
343
+ * Test single dependency
344
+ */
345
+ static int test_single_link(struct io_uring *ring)
346
+ {
347
+ struct io_uring_cqe *cqe;
348
+ struct io_uring_sqe *sqe;
349
+ int ret, i;
350
+
351
+ sqe = io_uring_get_sqe(ring);
352
+ if (!sqe) {
353
+ printf("get sqe failed\n");
354
+ goto err;
355
+ }
356
+
357
+ io_uring_prep_nop(sqe);
358
+ sqe->flags |= IOSQE_IO_LINK;
359
+
360
+ sqe = io_uring_get_sqe(ring);
361
+ if (!sqe) {
362
+ printf("get sqe failed\n");
363
+ goto err;
364
+ }
365
+
366
+ io_uring_prep_nop(sqe);
367
+
368
+ ret = io_uring_submit(ring);
369
+ if (ret <= 0) {
370
+ printf("sqe submit failed: %d\n", ret);
371
+ goto err;
372
+ }
373
+
374
+ for (i = 0; i < 2; i++) {
375
+ ret = io_uring_wait_cqe(ring, &cqe);
376
+ if (ret < 0) {
377
+ printf("wait completion %d\n", ret);
378
+ goto err;
379
+ }
380
+ io_uring_cqe_seen(ring, cqe);
381
+ }
382
+
383
+ return 0;
384
+ err:
385
+ return 1;
386
+ }
387
+
388
+ static int test_early_fail_and_wait(void)
389
+ {
390
+ struct io_uring ring;
391
+ struct io_uring_sqe *sqe;
392
+ int ret, invalid_fd = 42;
393
+ struct iovec iov = { .iov_base = NULL, .iov_len = 0 };
394
+
395
+ /* create a new ring as it leaves it dirty */
396
+ ret = io_uring_queue_init(8, &ring, 0);
397
+ if (ret) {
398
+ printf("ring setup failed\n");
399
+ return 1;
400
+ }
401
+
402
+ sqe = io_uring_get_sqe(&ring);
403
+ if (!sqe) {
404
+ printf("get sqe failed\n");
405
+ goto err;
406
+ }
407
+
408
+ io_uring_prep_readv(sqe, invalid_fd, &iov, 1, 0);
409
+ sqe->flags |= IOSQE_IO_LINK;
410
+
411
+ sqe = io_uring_get_sqe(&ring);
412
+ if (!sqe) {
413
+ printf("get sqe failed\n");
414
+ goto err;
415
+ }
416
+
417
+ io_uring_prep_nop(sqe);
418
+
419
+ ret = io_uring_submit_and_wait(&ring, 2);
420
+ if (ret <= 0 && ret != -EAGAIN) {
421
+ printf("sqe submit failed: %d\n", ret);
422
+ goto err;
423
+ }
424
+
425
+ io_uring_queue_exit(&ring);
426
+ return 0;
427
+ err:
428
+ io_uring_queue_exit(&ring);
429
+ return 1;
430
+ }
431
+
432
+ int main(int argc, char *argv[])
433
+ {
434
+ struct io_uring ring, poll_ring;
435
+ int ret;
436
+
437
+ if (argc > 1)
438
+ return 0;
439
+
440
+ ret = io_uring_queue_init(8, &ring, 0);
441
+ if (ret) {
442
+ printf("ring setup failed\n");
443
+ return 1;
444
+
445
+ }
446
+
447
+ ret = io_uring_queue_init(8, &poll_ring, IORING_SETUP_IOPOLL);
448
+ if (ret) {
449
+ printf("poll_ring setup failed\n");
450
+ return 1;
451
+ }
452
+
453
+ ret = test_single_link(&ring);
454
+ if (ret) {
455
+ printf("test_single_link failed\n");
456
+ return ret;
457
+ }
458
+
459
+ ret = test_double_link(&ring);
460
+ if (ret) {
461
+ printf("test_double_link failed\n");
462
+ return ret;
463
+ }
464
+
465
+ ret = test_double_chain(&ring);
466
+ if (ret) {
467
+ printf("test_double_chain failed\n");
468
+ return ret;
469
+ }
470
+
471
+ ret = test_single_link_fail(&poll_ring);
472
+ if (ret) {
473
+ printf("test_single_link_fail failed\n");
474
+ return ret;
475
+ }
476
+
477
+ ret = test_single_hardlink(&ring);
478
+ if (ret) {
479
+ fprintf(stderr, "test_single_hardlink\n");
480
+ return ret;
481
+ }
482
+
483
+ ret = test_double_hardlink(&ring);
484
+ if (ret) {
485
+ fprintf(stderr, "test_double_hardlink\n");
486
+ return ret;
487
+ }
488
+
489
+ ret = test_early_fail_and_wait();
490
+ if (ret) {
491
+ fprintf(stderr, "test_early_fail_and_wait\n");
492
+ return ret;
493
+ }
494
+
495
+ return 0;
496
+ }
@@ -0,0 +1,229 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: test io_uring link io with drain io
4
+ *
5
+ */
6
+ #include <errno.h>
7
+ #include <stdio.h>
8
+ #include <unistd.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+ #include <fcntl.h>
12
+
13
+ #include "helpers.h"
14
+ #include "liburing.h"
15
+
16
+ static int test_link_drain_one(struct io_uring *ring)
17
+ {
18
+ struct io_uring_cqe *cqe;
19
+ struct io_uring_sqe *sqe[5];
20
+ struct iovec iovecs;
21
+ int i, fd, ret;
22
+ off_t off = 0;
23
+ char data[5] = {0};
24
+ char expect[5] = {0, 1, 2, 3, 4};
25
+
26
+ fd = open("testfile", O_WRONLY | O_CREAT, 0644);
27
+ if (fd < 0) {
28
+ perror("open");
29
+ return 1;
30
+ }
31
+
32
+ iovecs.iov_base = t_malloc(4096);
33
+ iovecs.iov_len = 4096;
34
+
35
+ for (i = 0; i < 5; i++) {
36
+ sqe[i] = io_uring_get_sqe(ring);
37
+ if (!sqe[i]) {
38
+ printf("get sqe failed\n");
39
+ goto err;
40
+ }
41
+ }
42
+
43
+ /* normal heavy io */
44
+ io_uring_prep_writev(sqe[0], fd, &iovecs, 1, off);
45
+ sqe[0]->user_data = 0;
46
+
47
+ /* link io */
48
+ io_uring_prep_nop(sqe[1]);
49
+ sqe[1]->flags |= IOSQE_IO_LINK;
50
+ sqe[1]->user_data = 1;
51
+
52
+ /* link drain io */
53
+ io_uring_prep_nop(sqe[2]);
54
+ sqe[2]->flags |= (IOSQE_IO_LINK | IOSQE_IO_DRAIN);
55
+ sqe[2]->user_data = 2;
56
+
57
+ /* link io */
58
+ io_uring_prep_nop(sqe[3]);
59
+ sqe[3]->user_data = 3;
60
+
61
+ /* normal nop io */
62
+ io_uring_prep_nop(sqe[4]);
63
+ sqe[4]->user_data = 4;
64
+
65
+ ret = io_uring_submit(ring);
66
+ if (ret < 0) {
67
+ printf("sqe submit failed\n");
68
+ goto err;
69
+ } else if (ret < 5) {
70
+ printf("Submitted only %d\n", ret);
71
+ goto err;
72
+ }
73
+
74
+ for (i = 0; i < 5; i++) {
75
+ ret = io_uring_wait_cqe(ring, &cqe);
76
+ if (ret < 0) {
77
+ printf("child: wait completion %d\n", ret);
78
+ goto err;
79
+ }
80
+
81
+ data[i] = cqe->user_data;
82
+ io_uring_cqe_seen(ring, cqe);
83
+ }
84
+
85
+ if (memcmp(data, expect, 5) != 0)
86
+ goto err;
87
+
88
+ free(iovecs.iov_base);
89
+ close(fd);
90
+ unlink("testfile");
91
+ return 0;
92
+ err:
93
+ free(iovecs.iov_base);
94
+ close(fd);
95
+ unlink("testfile");
96
+ return 1;
97
+ }
98
+
99
+ int test_link_drain_multi(struct io_uring *ring)
100
+ {
101
+ struct io_uring_cqe *cqe;
102
+ struct io_uring_sqe *sqe[9];
103
+ struct iovec iovecs;
104
+ int i, fd, ret;
105
+ off_t off = 0;
106
+ char data[9] = {0};
107
+ char expect[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
108
+
109
+ fd = open("testfile", O_WRONLY | O_CREAT, 0644);
110
+ if (fd < 0) {
111
+ perror("open");
112
+ return 1;
113
+ }
114
+ unlink("testfile");
115
+
116
+ iovecs.iov_base = t_malloc(4096);
117
+ iovecs.iov_len = 4096;
118
+
119
+ for (i = 0; i < 9; i++) {
120
+ sqe[i] = io_uring_get_sqe(ring);
121
+ if (!sqe[i]) {
122
+ printf("get sqe failed\n");
123
+ goto err;
124
+ }
125
+ }
126
+
127
+ /* normal heavy io */
128
+ io_uring_prep_writev(sqe[0], fd, &iovecs, 1, off);
129
+ sqe[0]->user_data = 0;
130
+
131
+ /* link1 io head */
132
+ io_uring_prep_nop(sqe[1]);
133
+ sqe[1]->flags |= IOSQE_IO_LINK;
134
+ sqe[1]->user_data = 1;
135
+
136
+ /* link1 drain io */
137
+ io_uring_prep_nop(sqe[2]);
138
+ sqe[2]->flags |= (IOSQE_IO_LINK | IOSQE_IO_DRAIN);
139
+ sqe[2]->user_data = 2;
140
+
141
+ /* link1 io end*/
142
+ io_uring_prep_nop(sqe[3]);
143
+ sqe[3]->user_data = 3;
144
+
145
+ /* link2 io head */
146
+ io_uring_prep_nop(sqe[4]);
147
+ sqe[4]->flags |= IOSQE_IO_LINK;
148
+ sqe[4]->user_data = 4;
149
+
150
+ /* link2 io */
151
+ io_uring_prep_nop(sqe[5]);
152
+ sqe[5]->flags |= IOSQE_IO_LINK;
153
+ sqe[5]->user_data = 5;
154
+
155
+ /* link2 drain io */
156
+ io_uring_prep_writev(sqe[6], fd, &iovecs, 1, off);
157
+ sqe[6]->flags |= (IOSQE_IO_LINK | IOSQE_IO_DRAIN);
158
+ sqe[6]->user_data = 6;
159
+
160
+ /* link2 io end */
161
+ io_uring_prep_nop(sqe[7]);
162
+ sqe[7]->user_data = 7;
163
+
164
+ /* normal io */
165
+ io_uring_prep_nop(sqe[8]);
166
+ sqe[8]->user_data = 8;
167
+
168
+ ret = io_uring_submit(ring);
169
+ if (ret < 0) {
170
+ printf("sqe submit failed\n");
171
+ goto err;
172
+ } else if (ret < 9) {
173
+ printf("Submitted only %d\n", ret);
174
+ goto err;
175
+ }
176
+
177
+ for (i = 0; i < 9; i++) {
178
+ ret = io_uring_wait_cqe(ring, &cqe);
179
+ if (ret < 0) {
180
+ printf("child: wait completion %d\n", ret);
181
+ goto err;
182
+ }
183
+
184
+ data[i] = cqe->user_data;
185
+ io_uring_cqe_seen(ring, cqe);
186
+ }
187
+
188
+ if (memcmp(data, expect, 9) != 0)
189
+ goto err;
190
+
191
+ free(iovecs.iov_base);
192
+ close(fd);
193
+ return 0;
194
+ err:
195
+ free(iovecs.iov_base);
196
+ close(fd);
197
+ return 1;
198
+
199
+ }
200
+
201
+ int main(int argc, char *argv[])
202
+ {
203
+ struct io_uring ring;
204
+ int i, ret;
205
+
206
+ if (argc > 1)
207
+ return 0;
208
+
209
+ ret = io_uring_queue_init(100, &ring, 0);
210
+ if (ret) {
211
+ printf("ring setup failed\n");
212
+ return 1;
213
+ }
214
+
215
+ for (i = 0; i < 1000; i++) {
216
+ ret = test_link_drain_one(&ring);
217
+ if (ret) {
218
+ fprintf(stderr, "test_link_drain_one failed\n");
219
+ break;
220
+ }
221
+ ret = test_link_drain_multi(&ring);
222
+ if (ret) {
223
+ fprintf(stderr, "test_link_drain_multi failed\n");
224
+ break;
225
+ }
226
+ }
227
+
228
+ return ret;
229
+ }