polyphony 0.94 → 0.95

Sign up to get free protection for your applications and to get access to all the features.
Files changed (306) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +2 -2
  3. data/.gitignore +3 -3
  4. data/CHANGELOG.md +14 -0
  5. data/docs/api-reference/fiber.md +2 -2
  6. data/docs/api-reference/object.md +3 -3
  7. data/docs/main-concepts/exception-handling.md +2 -2
  8. data/ext/polyphony/backend_common.c +3 -3
  9. data/ext/polyphony/backend_io_uring.c +18 -16
  10. data/ext/polyphony/event.c +1 -1
  11. data/ext/polyphony/extconf.rb +5 -3
  12. data/ext/polyphony/fiber.c +5 -13
  13. data/ext/polyphony/io_extensions.c +1 -1
  14. data/ext/polyphony/pipe.c +1 -1
  15. data/ext/polyphony/polyphony.c +1 -1
  16. data/ext/polyphony/polyphony_ext.c +1 -1
  17. data/ext/polyphony/queue.c +1 -1
  18. data/ext/polyphony/ring_buffer.c +1 -0
  19. data/ext/polyphony/socket_extensions.c +1 -1
  20. data/ext/polyphony/thread.c +1 -1
  21. data/lib/polyphony/extensions/enumerator.rb +16 -0
  22. data/lib/polyphony/extensions/socket.rb +2 -0
  23. data/lib/polyphony/extensions.rb +1 -0
  24. data/lib/polyphony/version.rb +1 -1
  25. data/polyphony.gemspec +2 -2
  26. data/test/test_backend.rb +5 -1
  27. data/test/test_enumerator.rb +46 -0
  28. data/test/test_io.rb +241 -216
  29. data/test/test_socket.rb +1 -1
  30. data/test/test_thread_pool.rb +3 -3
  31. data/vendor/liburing/.github/workflows/build.yml +51 -5
  32. data/vendor/liburing/.github/workflows/shellcheck.yml +1 -1
  33. data/vendor/liburing/.gitignore +6 -123
  34. data/vendor/liburing/CHANGELOG +35 -0
  35. data/vendor/liburing/CITATION.cff +11 -0
  36. data/vendor/liburing/LICENSE +16 -3
  37. data/vendor/liburing/Makefile +3 -1
  38. data/vendor/liburing/Makefile.common +1 -0
  39. data/vendor/liburing/README +14 -2
  40. data/vendor/liburing/SECURITY.md +6 -0
  41. data/vendor/liburing/configure +16 -15
  42. data/vendor/liburing/examples/Makefile +4 -1
  43. data/vendor/liburing/examples/io_uring-udp.c +395 -0
  44. data/vendor/liburing/examples/poll-bench.c +101 -0
  45. data/vendor/liburing/examples/send-zerocopy.c +339 -0
  46. data/vendor/liburing/liburing.spec +1 -1
  47. data/vendor/liburing/man/io_uring.7 +38 -11
  48. data/vendor/liburing/man/io_uring_buf_ring_add.3 +53 -0
  49. data/vendor/liburing/man/io_uring_buf_ring_advance.3 +31 -0
  50. data/vendor/liburing/man/io_uring_buf_ring_cq_advance.3 +41 -0
  51. data/vendor/liburing/man/io_uring_buf_ring_init.3 +30 -0
  52. data/vendor/liburing/man/io_uring_buf_ring_mask.3 +27 -0
  53. data/vendor/liburing/man/io_uring_cq_advance.3 +29 -15
  54. data/vendor/liburing/man/io_uring_cq_has_overflow.3 +25 -0
  55. data/vendor/liburing/man/io_uring_cq_ready.3 +9 -8
  56. data/vendor/liburing/man/io_uring_cqe_get_data.3 +32 -13
  57. data/vendor/liburing/man/io_uring_cqe_get_data64.3 +1 -0
  58. data/vendor/liburing/man/io_uring_cqe_seen.3 +22 -12
  59. data/vendor/liburing/man/io_uring_enter.2 +249 -32
  60. data/vendor/liburing/man/io_uring_enter2.2 +1 -0
  61. data/vendor/liburing/man/io_uring_free_probe.3 +11 -8
  62. data/vendor/liburing/man/io_uring_get_events.3 +33 -0
  63. data/vendor/liburing/man/io_uring_get_probe.3 +9 -8
  64. data/vendor/liburing/man/io_uring_get_sqe.3 +29 -10
  65. data/vendor/liburing/man/io_uring_opcode_supported.3 +11 -10
  66. data/vendor/liburing/man/io_uring_peek_cqe.3 +38 -0
  67. data/vendor/liburing/man/io_uring_prep_accept.3 +197 -0
  68. data/vendor/liburing/man/io_uring_prep_accept_direct.3 +1 -0
  69. data/vendor/liburing/man/io_uring_prep_cancel.3 +118 -0
  70. data/vendor/liburing/man/io_uring_prep_cancel64.3 +1 -0
  71. data/vendor/liburing/man/io_uring_prep_close.3 +59 -0
  72. data/vendor/liburing/man/io_uring_prep_close_direct.3 +1 -0
  73. data/vendor/liburing/man/io_uring_prep_connect.3 +66 -0
  74. data/vendor/liburing/man/io_uring_prep_fadvise.3 +59 -0
  75. data/vendor/liburing/man/io_uring_prep_fallocate.3 +59 -0
  76. data/vendor/liburing/man/io_uring_prep_files_update.3 +92 -0
  77. data/vendor/liburing/man/io_uring_prep_fsync.3 +70 -0
  78. data/vendor/liburing/man/io_uring_prep_link.3 +1 -0
  79. data/vendor/liburing/man/io_uring_prep_linkat.3 +91 -0
  80. data/vendor/liburing/man/io_uring_prep_madvise.3 +56 -0
  81. data/vendor/liburing/man/io_uring_prep_mkdir.3 +1 -0
  82. data/vendor/liburing/man/io_uring_prep_mkdirat.3 +83 -0
  83. data/vendor/liburing/man/io_uring_prep_msg_ring.3 +39 -25
  84. data/vendor/liburing/man/io_uring_prep_multishot_accept.3 +1 -0
  85. data/vendor/liburing/man/io_uring_prep_multishot_accept_direct.3 +1 -0
  86. data/vendor/liburing/man/io_uring_prep_nop.3 +28 -0
  87. data/vendor/liburing/man/io_uring_prep_openat.3 +117 -0
  88. data/vendor/liburing/man/io_uring_prep_openat2.3 +117 -0
  89. data/vendor/liburing/man/io_uring_prep_openat2_direct.3 +1 -0
  90. data/vendor/liburing/man/io_uring_prep_openat_direct.3 +1 -0
  91. data/vendor/liburing/man/io_uring_prep_poll_add.3 +72 -0
  92. data/vendor/liburing/man/io_uring_prep_poll_multishot.3 +1 -0
  93. data/vendor/liburing/man/io_uring_prep_poll_remove.3 +55 -0
  94. data/vendor/liburing/man/io_uring_prep_poll_update.3 +89 -0
  95. data/vendor/liburing/man/io_uring_prep_provide_buffers.3 +131 -0
  96. data/vendor/liburing/man/io_uring_prep_read.3 +33 -14
  97. data/vendor/liburing/man/io_uring_prep_read_fixed.3 +39 -21
  98. data/vendor/liburing/man/io_uring_prep_readv.3 +49 -15
  99. data/vendor/liburing/man/io_uring_prep_readv2.3 +49 -17
  100. data/vendor/liburing/man/io_uring_prep_recv.3 +105 -0
  101. data/vendor/liburing/man/io_uring_prep_recv_multishot.3 +1 -0
  102. data/vendor/liburing/man/io_uring_prep_recvmsg.3 +124 -0
  103. data/vendor/liburing/man/io_uring_prep_recvmsg_multishot.3 +1 -0
  104. data/vendor/liburing/man/io_uring_prep_remove_buffers.3 +52 -0
  105. data/vendor/liburing/man/io_uring_prep_rename.3 +1 -0
  106. data/vendor/liburing/man/io_uring_prep_renameat.3 +96 -0
  107. data/vendor/liburing/man/io_uring_prep_send.3 +57 -0
  108. data/vendor/liburing/man/io_uring_prep_send_zc.3 +64 -0
  109. data/vendor/liburing/man/io_uring_prep_sendmsg.3 +69 -0
  110. data/vendor/liburing/man/io_uring_prep_shutdown.3 +53 -0
  111. data/vendor/liburing/man/io_uring_prep_socket.3 +118 -0
  112. data/vendor/liburing/man/io_uring_prep_socket_direct.3 +1 -0
  113. data/vendor/liburing/man/io_uring_prep_socket_direct_alloc.3 +1 -0
  114. data/vendor/liburing/man/io_uring_prep_splice.3 +80 -0
  115. data/vendor/liburing/man/io_uring_prep_statx.3 +74 -0
  116. data/vendor/liburing/man/io_uring_prep_symlink.3 +1 -0
  117. data/vendor/liburing/man/io_uring_prep_symlinkat.3 +85 -0
  118. data/vendor/liburing/man/io_uring_prep_sync_file_range.3 +59 -0
  119. data/vendor/liburing/man/io_uring_prep_tee.3 +74 -0
  120. data/vendor/liburing/man/io_uring_prep_timeout.3 +95 -0
  121. data/vendor/liburing/man/io_uring_prep_timeout_remove.3 +1 -0
  122. data/vendor/liburing/man/io_uring_prep_timeout_update.3 +98 -0
  123. data/vendor/liburing/man/io_uring_prep_unlink.3 +1 -0
  124. data/vendor/liburing/man/io_uring_prep_unlinkat.3 +82 -0
  125. data/vendor/liburing/man/io_uring_prep_write.3 +32 -15
  126. data/vendor/liburing/man/io_uring_prep_write_fixed.3 +39 -21
  127. data/vendor/liburing/man/io_uring_prep_writev.3 +50 -16
  128. data/vendor/liburing/man/io_uring_prep_writev2.3 +50 -17
  129. data/vendor/liburing/man/io_uring_queue_exit.3 +3 -4
  130. data/vendor/liburing/man/io_uring_queue_init.3 +58 -13
  131. data/vendor/liburing/man/io_uring_queue_init_params.3 +1 -0
  132. data/vendor/liburing/man/io_uring_recvmsg_cmsg_firsthdr.3 +1 -0
  133. data/vendor/liburing/man/io_uring_recvmsg_cmsg_nexthdr.3 +1 -0
  134. data/vendor/liburing/man/io_uring_recvmsg_name.3 +1 -0
  135. data/vendor/liburing/man/io_uring_recvmsg_out.3 +78 -0
  136. data/vendor/liburing/man/io_uring_recvmsg_payload.3 +1 -0
  137. data/vendor/liburing/man/io_uring_recvmsg_payload_length.3 +1 -0
  138. data/vendor/liburing/man/io_uring_recvmsg_validate.3 +1 -0
  139. data/vendor/liburing/man/io_uring_register.2 +153 -13
  140. data/vendor/liburing/man/io_uring_register_buf_ring.3 +140 -0
  141. data/vendor/liburing/man/io_uring_register_buffers.3 +32 -12
  142. data/vendor/liburing/man/io_uring_register_eventfd.3 +51 -0
  143. data/vendor/liburing/man/io_uring_register_eventfd_async.3 +1 -0
  144. data/vendor/liburing/man/io_uring_register_file_alloc_range.3 +52 -0
  145. data/vendor/liburing/man/io_uring_register_files.3 +33 -11
  146. data/vendor/liburing/man/io_uring_register_files_sparse.3 +1 -0
  147. data/vendor/liburing/man/io_uring_register_iowq_aff.3 +61 -0
  148. data/vendor/liburing/man/io_uring_register_iowq_max_workers.3 +71 -0
  149. data/vendor/liburing/man/io_uring_register_ring_fd.3 +49 -0
  150. data/vendor/liburing/man/io_uring_register_sync_cancel.3 +71 -0
  151. data/vendor/liburing/man/io_uring_setup.2 +119 -13
  152. data/vendor/liburing/man/io_uring_sq_ready.3 +14 -8
  153. data/vendor/liburing/man/io_uring_sq_space_left.3 +9 -9
  154. data/vendor/liburing/man/io_uring_sqe_set_data.3 +29 -11
  155. data/vendor/liburing/man/io_uring_sqe_set_data64.3 +1 -0
  156. data/vendor/liburing/man/io_uring_sqe_set_flags.3 +38 -11
  157. data/vendor/liburing/man/io_uring_sqring_wait.3 +13 -9
  158. data/vendor/liburing/man/io_uring_submit.3 +29 -12
  159. data/vendor/liburing/man/io_uring_submit_and_get_events.3 +31 -0
  160. data/vendor/liburing/man/io_uring_submit_and_wait.3 +16 -12
  161. data/vendor/liburing/man/io_uring_submit_and_wait_timeout.3 +30 -23
  162. data/vendor/liburing/man/io_uring_unregister_buf_ring.3 +30 -0
  163. data/vendor/liburing/man/io_uring_unregister_buffers.3 +11 -10
  164. data/vendor/liburing/man/io_uring_unregister_eventfd.3 +1 -0
  165. data/vendor/liburing/man/io_uring_unregister_files.3 +11 -10
  166. data/vendor/liburing/man/io_uring_unregister_iowq_aff.3 +1 -0
  167. data/vendor/liburing/man/io_uring_unregister_ring_fd.3 +32 -0
  168. data/vendor/liburing/man/io_uring_wait_cqe.3 +19 -12
  169. data/vendor/liburing/man/io_uring_wait_cqe_nr.3 +21 -14
  170. data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +27 -13
  171. data/vendor/liburing/man/io_uring_wait_cqes.3 +24 -14
  172. data/vendor/liburing/src/Makefile +8 -7
  173. data/vendor/liburing/src/arch/aarch64/lib.h +48 -0
  174. data/vendor/liburing/src/arch/aarch64/syscall.h +0 -4
  175. data/vendor/liburing/src/arch/generic/lib.h +0 -4
  176. data/vendor/liburing/src/arch/generic/syscall.h +29 -16
  177. data/vendor/liburing/src/arch/syscall-defs.h +41 -14
  178. data/vendor/liburing/src/arch/x86/lib.h +0 -21
  179. data/vendor/liburing/src/arch/x86/syscall.h +146 -10
  180. data/vendor/liburing/src/include/liburing/io_uring.h +245 -5
  181. data/vendor/liburing/src/include/liburing.h +468 -35
  182. data/vendor/liburing/src/int_flags.h +1 -0
  183. data/vendor/liburing/src/lib.h +20 -16
  184. data/vendor/liburing/src/liburing.map +16 -0
  185. data/vendor/liburing/src/nolibc.c +1 -1
  186. data/vendor/liburing/src/queue.c +87 -55
  187. data/vendor/liburing/src/register.c +129 -53
  188. data/vendor/liburing/src/setup.c +65 -28
  189. data/vendor/liburing/src/syscall.c +14 -32
  190. data/vendor/liburing/src/syscall.h +12 -64
  191. data/vendor/liburing/test/{232c93d07b74-test.c → 232c93d07b74.c} +8 -9
  192. data/vendor/liburing/test/{35fa71a030ca-test.c → 35fa71a030ca.c} +4 -4
  193. data/vendor/liburing/test/{500f9fbadef8-test.c → 500f9fbadef8.c} +7 -7
  194. data/vendor/liburing/test/{7ad0e4b2f83c-test.c → 7ad0e4b2f83c.c} +8 -7
  195. data/vendor/liburing/test/{8a9973408177-test.c → 8a9973408177.c} +4 -3
  196. data/vendor/liburing/test/{917257daa0fe-test.c → 917257daa0fe.c} +3 -2
  197. data/vendor/liburing/test/Makefile +60 -62
  198. data/vendor/liburing/test/{a0908ae19763-test.c → a0908ae19763.c} +3 -2
  199. data/vendor/liburing/test/{a4c0b3decb33-test.c → a4c0b3decb33.c} +3 -2
  200. data/vendor/liburing/test/accept-link.c +5 -4
  201. data/vendor/liburing/test/accept-reuse.c +17 -16
  202. data/vendor/liburing/test/accept-test.c +14 -10
  203. data/vendor/liburing/test/accept.c +529 -107
  204. data/vendor/liburing/test/across-fork.c +7 -6
  205. data/vendor/liburing/test/{b19062a56726-test.c → b19062a56726.c} +3 -2
  206. data/vendor/liburing/test/{b5837bd5311d-test.c → b5837bd5311d.c} +10 -9
  207. data/vendor/liburing/test/buf-ring.c +420 -0
  208. data/vendor/liburing/test/{ce593a6c480a-test.c → ce593a6c480a.c} +15 -12
  209. data/vendor/liburing/test/connect.c +8 -7
  210. data/vendor/liburing/test/cq-full.c +5 -4
  211. data/vendor/liburing/test/cq-overflow.c +242 -12
  212. data/vendor/liburing/test/cq-peek-batch.c +5 -4
  213. data/vendor/liburing/test/cq-ready.c +5 -4
  214. data/vendor/liburing/test/cq-size.c +5 -4
  215. data/vendor/liburing/test/{d4ae271dfaae-test.c → d4ae271dfaae.c} +2 -2
  216. data/vendor/liburing/test/{d77a67ed5f27-test.c → d77a67ed5f27.c} +6 -6
  217. data/vendor/liburing/test/defer-taskrun.c +336 -0
  218. data/vendor/liburing/test/defer.c +26 -14
  219. data/vendor/liburing/test/double-poll-crash.c +15 -5
  220. data/vendor/liburing/test/drop-submit.c +5 -3
  221. data/vendor/liburing/test/{eeed8b54e0df-test.c → eeed8b54e0df.c} +7 -6
  222. data/vendor/liburing/test/empty-eownerdead.c +4 -4
  223. data/vendor/liburing/test/eventfd-disable.c +48 -20
  224. data/vendor/liburing/test/eventfd-reg.c +10 -9
  225. data/vendor/liburing/test/eventfd-ring.c +13 -12
  226. data/vendor/liburing/test/eventfd.c +13 -12
  227. data/vendor/liburing/test/exit-no-cleanup.c +1 -1
  228. data/vendor/liburing/test/fadvise.c +3 -3
  229. data/vendor/liburing/test/fallocate.c +16 -9
  230. data/vendor/liburing/test/{fc2a85cb02ef-test.c → fc2a85cb02ef.c} +4 -3
  231. data/vendor/liburing/test/fd-pass.c +187 -0
  232. data/vendor/liburing/test/file-register.c +302 -36
  233. data/vendor/liburing/test/file-update.c +62 -4
  234. data/vendor/liburing/test/file-verify.c +6 -2
  235. data/vendor/liburing/test/files-exit-hang-poll.c +11 -25
  236. data/vendor/liburing/test/files-exit-hang-timeout.c +13 -10
  237. data/vendor/liburing/test/fixed-buf-iter.c +115 -0
  238. data/vendor/liburing/test/fixed-link.c +10 -10
  239. data/vendor/liburing/test/fixed-reuse.c +160 -0
  240. data/vendor/liburing/test/fpos.c +6 -3
  241. data/vendor/liburing/test/fsync.c +3 -3
  242. data/vendor/liburing/test/hardlink.c +10 -6
  243. data/vendor/liburing/test/helpers.c +137 -4
  244. data/vendor/liburing/test/helpers.h +27 -0
  245. data/vendor/liburing/test/io-cancel.c +16 -11
  246. data/vendor/liburing/test/io_uring_enter.c +46 -81
  247. data/vendor/liburing/test/io_uring_passthrough.c +451 -0
  248. data/vendor/liburing/test/io_uring_register.c +59 -229
  249. data/vendor/liburing/test/io_uring_setup.c +24 -29
  250. data/vendor/liburing/test/iopoll-leak.c +85 -0
  251. data/vendor/liburing/test/iopoll.c +16 -9
  252. data/vendor/liburing/test/lfs-openat-write.c +3 -1
  253. data/vendor/liburing/test/link-timeout.c +4 -3
  254. data/vendor/liburing/test/link.c +8 -7
  255. data/vendor/liburing/test/madvise.c +2 -2
  256. data/vendor/liburing/test/mkdir.c +9 -5
  257. data/vendor/liburing/test/msg-ring.c +46 -20
  258. data/vendor/liburing/test/multicqes_drain.c +51 -12
  259. data/vendor/liburing/test/nolibc.c +60 -0
  260. data/vendor/liburing/test/nop.c +78 -16
  261. data/vendor/liburing/test/nvme.h +168 -0
  262. data/vendor/liburing/test/open-direct-link.c +188 -0
  263. data/vendor/liburing/test/open-direct-pick.c +180 -0
  264. data/vendor/liburing/test/openat2.c +3 -3
  265. data/vendor/liburing/test/poll-cancel-all.c +472 -0
  266. data/vendor/liburing/test/poll-link.c +9 -18
  267. data/vendor/liburing/test/poll-mshot-overflow.c +162 -0
  268. data/vendor/liburing/test/poll-mshot-update.c +83 -33
  269. data/vendor/liburing/test/pollfree.c +2 -2
  270. data/vendor/liburing/test/read-before-exit.c +112 -0
  271. data/vendor/liburing/test/read-write.c +83 -1
  272. data/vendor/liburing/test/recv-msgall-stream.c +398 -0
  273. data/vendor/liburing/test/recv-msgall.c +265 -0
  274. data/vendor/liburing/test/recv-multishot.c +505 -0
  275. data/vendor/liburing/test/rename.c +2 -5
  276. data/vendor/liburing/test/ring-leak.c +97 -0
  277. data/vendor/liburing/test/ringbuf-read.c +200 -0
  278. data/vendor/liburing/test/rsrc_tags.c +25 -13
  279. data/vendor/liburing/test/runtests-quiet.sh +11 -0
  280. data/vendor/liburing/test/runtests.sh +18 -20
  281. data/vendor/liburing/test/rw_merge_test.c +3 -2
  282. data/vendor/liburing/test/send-zerocopy.c +684 -0
  283. data/vendor/liburing/test/send_recv.c +49 -2
  284. data/vendor/liburing/test/send_recvmsg.c +165 -55
  285. data/vendor/liburing/test/shutdown.c +3 -4
  286. data/vendor/liburing/test/sigfd-deadlock.c +22 -8
  287. data/vendor/liburing/test/single-issuer.c +171 -0
  288. data/vendor/liburing/test/socket-rw-eagain.c +2 -12
  289. data/vendor/liburing/test/socket-rw-offset.c +2 -11
  290. data/vendor/liburing/test/socket-rw.c +2 -11
  291. data/vendor/liburing/test/socket.c +409 -0
  292. data/vendor/liburing/test/sq-poll-dup.c +1 -1
  293. data/vendor/liburing/test/sq-poll-share.c +1 -1
  294. data/vendor/liburing/test/statx.c +2 -2
  295. data/vendor/liburing/test/submit-and-wait.c +108 -0
  296. data/vendor/liburing/test/submit-link-fail.c +5 -3
  297. data/vendor/liburing/test/submit-reuse.c +0 -2
  298. data/vendor/liburing/test/sync-cancel.c +235 -0
  299. data/vendor/liburing/test/test.h +35 -0
  300. data/vendor/liburing/test/timeout-overflow.c +11 -11
  301. data/vendor/liburing/test/timeout.c +7 -7
  302. data/vendor/liburing/test/tty-write-dpoll.c +60 -0
  303. data/vendor/liburing/test/unlink.c +1 -1
  304. data/vendor/liburing/test/xattr.c +425 -0
  305. metadata +143 -22
  306. data/Gemfile.lock +0 -78
@@ -11,12 +11,16 @@
11
11
  #include <fcntl.h>
12
12
 
13
13
  #include "liburing.h"
14
+ #include "test.h"
14
15
 
15
- static int test_single_nop(struct io_uring *ring)
16
+ static int seq;
17
+
18
+ static int test_single_nop(struct io_uring *ring, unsigned req_flags)
16
19
  {
17
20
  struct io_uring_cqe *cqe;
18
21
  struct io_uring_sqe *sqe;
19
22
  int ret;
23
+ bool cqe32 = (ring->flags & IORING_SETUP_CQE32);
20
24
 
21
25
  sqe = io_uring_get_sqe(ring);
22
26
  if (!sqe) {
@@ -25,6 +29,8 @@ static int test_single_nop(struct io_uring *ring)
25
29
  }
26
30
 
27
31
  io_uring_prep_nop(sqe);
32
+ sqe->user_data = ++seq;
33
+ sqe->flags |= req_flags;
28
34
 
29
35
  ret = io_uring_submit(ring);
30
36
  if (ret <= 0) {
@@ -37,18 +43,33 @@ static int test_single_nop(struct io_uring *ring)
37
43
  fprintf(stderr, "wait completion %d\n", ret);
38
44
  goto err;
39
45
  }
46
+ if (!cqe->user_data) {
47
+ fprintf(stderr, "Unexpected 0 user_data\n");
48
+ goto err;
49
+ }
50
+ if (cqe32) {
51
+ if (cqe->big_cqe[0] != 0) {
52
+ fprintf(stderr, "Unexpected extra1\n");
53
+ goto err;
40
54
 
55
+ }
56
+ if (cqe->big_cqe[1] != 0) {
57
+ fprintf(stderr, "Unexpected extra2\n");
58
+ goto err;
59
+ }
60
+ }
41
61
  io_uring_cqe_seen(ring, cqe);
42
62
  return 0;
43
63
  err:
44
64
  return 1;
45
65
  }
46
66
 
47
- static int test_barrier_nop(struct io_uring *ring)
67
+ static int test_barrier_nop(struct io_uring *ring, unsigned req_flags)
48
68
  {
49
69
  struct io_uring_cqe *cqe;
50
70
  struct io_uring_sqe *sqe;
51
71
  int ret, i;
72
+ bool cqe32 = (ring->flags & IORING_SETUP_CQE32);
52
73
 
53
74
  for (i = 0; i < 8; i++) {
54
75
  sqe = io_uring_get_sqe(ring);
@@ -60,6 +81,8 @@ static int test_barrier_nop(struct io_uring *ring)
60
81
  io_uring_prep_nop(sqe);
61
82
  if (i == 4)
62
83
  sqe->flags = IOSQE_IO_DRAIN;
84
+ sqe->user_data = ++seq;
85
+ sqe->flags |= req_flags;
63
86
  }
64
87
 
65
88
  ret = io_uring_submit(ring);
@@ -77,6 +100,20 @@ static int test_barrier_nop(struct io_uring *ring)
77
100
  fprintf(stderr, "wait completion %d\n", ret);
78
101
  goto err;
79
102
  }
103
+ if (!cqe->user_data) {
104
+ fprintf(stderr, "Unexpected 0 user_data\n");
105
+ goto err;
106
+ }
107
+ if (cqe32) {
108
+ if (cqe->big_cqe[0] != 0) {
109
+ fprintf(stderr, "Unexpected extra1\n");
110
+ goto err;
111
+ }
112
+ if (cqe->big_cqe[1] != 0) {
113
+ fprintf(stderr, "Unexpected extra2\n");
114
+ goto err;
115
+ }
116
+ }
80
117
  io_uring_cqe_seen(ring, cqe);
81
118
  }
82
119
 
@@ -85,30 +122,55 @@ err:
85
122
  return 1;
86
123
  }
87
124
 
88
- int main(int argc, char *argv[])
125
+ static int test_ring(unsigned flags)
89
126
  {
90
127
  struct io_uring ring;
91
- int ret;
92
-
93
- if (argc > 1)
94
- return 0;
128
+ struct io_uring_params p = { };
129
+ int ret, i;
95
130
 
96
- ret = io_uring_queue_init(8, &ring, 0);
131
+ p.flags = flags;
132
+ ret = io_uring_queue_init_params(8, &ring, &p);
97
133
  if (ret) {
134
+ if (ret == -EINVAL)
135
+ return 0;
98
136
  fprintf(stderr, "ring setup failed: %d\n", ret);
99
137
  return 1;
100
138
  }
101
139
 
102
- ret = test_single_nop(&ring);
103
- if (ret) {
104
- fprintf(stderr, "test_single_nop failed\n");
105
- return ret;
140
+ for (i = 0; i < 1000; i++) {
141
+ unsigned req_flags = (i & 1) ? IOSQE_ASYNC : 0;
142
+
143
+ ret = test_single_nop(&ring, req_flags);
144
+ if (ret) {
145
+ fprintf(stderr, "test_single_nop failed\n");
146
+ goto err;
147
+ }
148
+
149
+ ret = test_barrier_nop(&ring, req_flags);
150
+ if (ret) {
151
+ fprintf(stderr, "test_barrier_nop failed\n");
152
+ goto err;
153
+ }
106
154
  }
155
+ err:
156
+ io_uring_queue_exit(&ring);
157
+ return ret;
158
+ }
107
159
 
108
- ret = test_barrier_nop(&ring);
109
- if (ret) {
110
- fprintf(stderr, "test_barrier_nop failed\n");
111
- return ret;
160
+ int main(int argc, char *argv[])
161
+ {
162
+ int ret;
163
+
164
+ if (argc > 1)
165
+ return 0;
166
+
167
+ FOR_ALL_TEST_CONFIGS {
168
+ ret = test_ring(IORING_GET_TEST_CONFIG_FLAGS());
169
+ if (ret) {
170
+ fprintf(stderr, "Normal ring test failed: %s\n",
171
+ IORING_GET_TEST_CONFIG_DESCRIPTION());
172
+ return ret;
173
+ }
112
174
  }
113
175
 
114
176
  return 0;
@@ -0,0 +1,168 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: Helpers for NVMe uring passthrough commands
4
+ */
5
+ #ifndef LIBURING_NVME_H
6
+ #define LIBURING_NVME_H
7
+
8
+ #ifdef __cplusplus
9
+ extern "C" {
10
+ #endif
11
+
12
+ #include <sys/ioctl.h>
13
+ #include <linux/nvme_ioctl.h>
14
+
15
+ /*
16
+ * If the uapi headers installed on the system lacks nvme uring command
17
+ * support, use the local version to prevent compilation issues.
18
+ */
19
+ #ifndef CONFIG_HAVE_NVME_URING
20
+ struct nvme_uring_cmd {
21
+ __u8 opcode;
22
+ __u8 flags;
23
+ __u16 rsvd1;
24
+ __u32 nsid;
25
+ __u32 cdw2;
26
+ __u32 cdw3;
27
+ __u64 metadata;
28
+ __u64 addr;
29
+ __u32 metadata_len;
30
+ __u32 data_len;
31
+ __u32 cdw10;
32
+ __u32 cdw11;
33
+ __u32 cdw12;
34
+ __u32 cdw13;
35
+ __u32 cdw14;
36
+ __u32 cdw15;
37
+ __u32 timeout_ms;
38
+ __u32 rsvd2;
39
+ };
40
+
41
+ #define NVME_URING_CMD_IO _IOWR('N', 0x80, struct nvme_uring_cmd)
42
+ #define NVME_URING_CMD_IO_VEC _IOWR('N', 0x81, struct nvme_uring_cmd)
43
+ #endif /* CONFIG_HAVE_NVME_URING */
44
+
45
+ #define NVME_DEFAULT_IOCTL_TIMEOUT 0
46
+ #define NVME_IDENTIFY_DATA_SIZE 4096
47
+ #define NVME_IDENTIFY_CSI_SHIFT 24
48
+ #define NVME_IDENTIFY_CNS_NS 0
49
+ #define NVME_CSI_NVM 0
50
+
51
+ enum nvme_admin_opcode {
52
+ nvme_admin_identify = 0x06,
53
+ };
54
+
55
+ enum nvme_io_opcode {
56
+ nvme_cmd_write = 0x01,
57
+ nvme_cmd_read = 0x02,
58
+ };
59
+
60
+ int nsid;
61
+ __u32 lba_shift;
62
+
63
+ struct nvme_lbaf {
64
+ __le16 ms;
65
+ __u8 ds;
66
+ __u8 rp;
67
+ };
68
+
69
+ struct nvme_id_ns {
70
+ __le64 nsze;
71
+ __le64 ncap;
72
+ __le64 nuse;
73
+ __u8 nsfeat;
74
+ __u8 nlbaf;
75
+ __u8 flbas;
76
+ __u8 mc;
77
+ __u8 dpc;
78
+ __u8 dps;
79
+ __u8 nmic;
80
+ __u8 rescap;
81
+ __u8 fpi;
82
+ __u8 dlfeat;
83
+ __le16 nawun;
84
+ __le16 nawupf;
85
+ __le16 nacwu;
86
+ __le16 nabsn;
87
+ __le16 nabo;
88
+ __le16 nabspf;
89
+ __le16 noiob;
90
+ __u8 nvmcap[16];
91
+ __le16 npwg;
92
+ __le16 npwa;
93
+ __le16 npdg;
94
+ __le16 npda;
95
+ __le16 nows;
96
+ __le16 mssrl;
97
+ __le32 mcl;
98
+ __u8 msrc;
99
+ __u8 rsvd81[11];
100
+ __le32 anagrpid;
101
+ __u8 rsvd96[3];
102
+ __u8 nsattr;
103
+ __le16 nvmsetid;
104
+ __le16 endgid;
105
+ __u8 nguid[16];
106
+ __u8 eui64[8];
107
+ struct nvme_lbaf lbaf[16];
108
+ __u8 rsvd192[192];
109
+ __u8 vs[3712];
110
+ };
111
+
112
+ static inline int ilog2(uint32_t i)
113
+ {
114
+ int log = -1;
115
+
116
+ while (i) {
117
+ i >>= 1;
118
+ log++;
119
+ }
120
+ return log;
121
+ }
122
+
123
+ int nvme_get_info(const char *file)
124
+ {
125
+ struct nvme_id_ns ns;
126
+ int fd, err;
127
+ __u32 lba_size;
128
+
129
+ fd = open(file, O_RDONLY);
130
+ if (fd < 0) {
131
+ perror("file open");
132
+ return -errno;
133
+ }
134
+
135
+ nsid = ioctl(fd, NVME_IOCTL_ID);
136
+ if (nsid < 0) {
137
+ close(fd);
138
+ return -errno;
139
+ }
140
+
141
+ struct nvme_passthru_cmd cmd = {
142
+ .opcode = nvme_admin_identify,
143
+ .nsid = nsid,
144
+ .addr = (__u64)(uintptr_t)&ns,
145
+ .data_len = NVME_IDENTIFY_DATA_SIZE,
146
+ .cdw10 = NVME_IDENTIFY_CNS_NS,
147
+ .cdw11 = NVME_CSI_NVM << NVME_IDENTIFY_CSI_SHIFT,
148
+ .timeout_ms = NVME_DEFAULT_IOCTL_TIMEOUT,
149
+ };
150
+
151
+ err = ioctl(fd, NVME_IOCTL_ADMIN_CMD, &cmd);
152
+ if (err) {
153
+ close(fd);
154
+ return err;
155
+ }
156
+
157
+ lba_size = 1 << ns.lbaf[(ns.flbas & 0x0f)].ds;
158
+ lba_shift = ilog2(lba_size);
159
+
160
+ close(fd);
161
+ return 0;
162
+ }
163
+
164
+ #ifdef __cplusplus
165
+ }
166
+ #endif
167
+
168
+ #endif
@@ -0,0 +1,188 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: link <open file><read from file><close file>
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
+ #include "helpers.h"
15
+
16
+ #define MAX_FILES 8
17
+ #define FNAME ".link.direct"
18
+
19
+ static int test(struct io_uring *ring, int skip_success, int drain, int async)
20
+ {
21
+ struct io_uring_cqe *cqe;
22
+ struct io_uring_sqe *sqe;
23
+ char buf[4096];
24
+ int ret, i;
25
+
26
+ /* drain and cqe skip are mutually exclusive */
27
+ if (skip_success && drain)
28
+ return 1;
29
+
30
+ sqe = io_uring_get_sqe(ring);
31
+ io_uring_prep_openat_direct(sqe, AT_FDCWD, FNAME, O_RDONLY, 0, 0);
32
+ if (!drain)
33
+ sqe->flags |= IOSQE_IO_LINK;
34
+ if (skip_success)
35
+ sqe->flags |= IOSQE_CQE_SKIP_SUCCESS;
36
+ if (async)
37
+ sqe->flags |= IOSQE_ASYNC;
38
+ sqe->user_data = 1;
39
+
40
+ sqe = io_uring_get_sqe(ring);
41
+ io_uring_prep_read(sqe, 0, buf, sizeof(buf), 0);
42
+ sqe->flags |= IOSQE_FIXED_FILE;
43
+ if (drain)
44
+ sqe->flags |= IOSQE_IO_DRAIN;
45
+ else
46
+ sqe->flags |= IOSQE_IO_LINK;
47
+ if (async)
48
+ sqe->flags |= IOSQE_ASYNC;
49
+ sqe->user_data = 2;
50
+
51
+ sqe = io_uring_get_sqe(ring);
52
+ io_uring_prep_close_direct(sqe, 0);
53
+ sqe->user_data = 3;
54
+ if (skip_success)
55
+ sqe->flags |= IOSQE_CQE_SKIP_SUCCESS;
56
+ if (drain)
57
+ sqe->flags |= IOSQE_IO_DRAIN;
58
+ if (async)
59
+ sqe->flags |= IOSQE_ASYNC;
60
+
61
+ ret = io_uring_submit(ring);
62
+ if (ret != 3) {
63
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
64
+ goto err;
65
+ }
66
+
67
+ if (skip_success) {
68
+ ret = io_uring_wait_cqe(ring, &cqe);
69
+ if (ret < 0) {
70
+ fprintf(stderr, "wait completion %d\n", ret);
71
+ goto err;
72
+ }
73
+ if (cqe->user_data != 2) {
74
+ fprintf(stderr, "Unexpected cqe %lu/%d\n",
75
+ (unsigned long) cqe->user_data,
76
+ cqe->res);
77
+ goto err;
78
+ }
79
+ if (cqe->res != sizeof(buf)) {
80
+ fprintf(stderr, "bad read %d\n", cqe->res);
81
+ goto err;
82
+ }
83
+ io_uring_cqe_seen(ring, cqe);
84
+ return 0;
85
+ }
86
+
87
+ for (i = 0; i < 3; i++) {
88
+ ret = io_uring_wait_cqe(ring, &cqe);
89
+ if (ret < 0) {
90
+ fprintf(stderr, "wait completion %d\n", ret);
91
+ goto err;
92
+ }
93
+ switch (cqe->user_data) {
94
+ case 1:
95
+ if (cqe->res) {
96
+ fprintf(stderr, "bad open %d\n", cqe->res);
97
+ goto err;
98
+ }
99
+ break;
100
+ case 2:
101
+ if (cqe->res != sizeof(buf)) {
102
+ fprintf(stderr, "bad read %d\n", cqe->res);
103
+ goto err;
104
+ }
105
+ break;
106
+ case 3:
107
+ if (cqe->res) {
108
+ fprintf(stderr, "bad close %d\n", cqe->res);
109
+ goto err;
110
+ }
111
+ break;
112
+ }
113
+ io_uring_cqe_seen(ring, cqe);
114
+ }
115
+
116
+ return 0;
117
+ err:
118
+ return 1;
119
+ }
120
+
121
+ int main(int argc, char *argv[])
122
+ {
123
+ struct io_uring ring;
124
+ struct io_uring_params p = { };
125
+ int ret, files[MAX_FILES];
126
+
127
+ if (argc > 1)
128
+ return 0;
129
+
130
+ ret = io_uring_queue_init_params(8, &ring, &p);
131
+ if (ret) {
132
+ fprintf(stderr, "ring setup failed: %d\n", ret);
133
+ return 1;
134
+ }
135
+ if (!(p.features & IORING_FEAT_CQE_SKIP))
136
+ return 0;
137
+
138
+ memset(files, -1, sizeof(files));
139
+ ret = io_uring_register_files(&ring, files, ARRAY_SIZE(files));
140
+ if (ret) {
141
+ fprintf(stderr, "Failed registering files\n");
142
+ return 1;
143
+ }
144
+
145
+ t_create_file(FNAME, 4096);
146
+
147
+ ret = test(&ring, 0, 0, 0);
148
+ if (ret) {
149
+ fprintf(stderr, "test 0 0 0 failed\n");
150
+ goto err;
151
+ }
152
+
153
+ ret = test(&ring, 0, 1, 0);
154
+ if (ret) {
155
+ fprintf(stderr, "test 0 1 0 failed\n");
156
+ goto err;
157
+ }
158
+
159
+ ret = test(&ring, 0, 0, 1);
160
+ if (ret) {
161
+ fprintf(stderr, "test 0 0 1 failed\n");
162
+ goto err;
163
+ }
164
+
165
+ ret = test(&ring, 0, 1, 1);
166
+ if (ret) {
167
+ fprintf(stderr, "test 0 1 1 failed\n");
168
+ goto err;
169
+ }
170
+
171
+ ret = test(&ring, 1, 0, 0);
172
+ if (ret) {
173
+ fprintf(stderr, "test 1 0 0 failed\n");
174
+ goto err;
175
+ }
176
+
177
+ ret = test(&ring, 1, 0, 1);
178
+ if (ret) {
179
+ fprintf(stderr, "test 1 0 1 failed\n");
180
+ goto err;
181
+ }
182
+
183
+ unlink(FNAME);
184
+ return 0;
185
+ err:
186
+ unlink(FNAME);
187
+ return 1;
188
+ }
@@ -0,0 +1,180 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: run various openat(2) 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
+ #include <limits.h>
13
+
14
+ #include "helpers.h"
15
+ #include "liburing.h"
16
+
17
+ #define FDS 800
18
+
19
+ static int no_direct_pick;
20
+
21
+ static int submit_wait(struct io_uring *ring)
22
+ {
23
+ struct io_uring_cqe *cqe;
24
+ int ret;
25
+
26
+ ret = io_uring_submit(ring);
27
+ if (ret <= 0) {
28
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
29
+ return 1;
30
+ }
31
+ ret = io_uring_wait_cqe(ring, &cqe);
32
+ if (ret < 0) {
33
+ fprintf(stderr, "wait completion %d\n", ret);
34
+ return 1;
35
+ }
36
+
37
+ ret = cqe->res;
38
+ io_uring_cqe_seen(ring, cqe);
39
+ return ret;
40
+ }
41
+
42
+ static inline int try_close(struct io_uring *ring, int slot)
43
+ {
44
+ struct io_uring_sqe *sqe;
45
+
46
+ sqe = io_uring_get_sqe(ring);
47
+ io_uring_prep_close_direct(sqe, slot);
48
+ return submit_wait(ring);
49
+ }
50
+
51
+ static int do_opens(struct io_uring *ring, const char *path, int nr,
52
+ int expect_enfile)
53
+ {
54
+ struct io_uring_cqe *cqe;
55
+ struct io_uring_sqe *sqe;
56
+ int i, ret;
57
+
58
+ for (i = 0; i < nr; i++) {
59
+ sqe = io_uring_get_sqe(ring);
60
+ if (!sqe) {
61
+ fprintf(stderr, "get sqe failed\n");
62
+ goto err;
63
+ }
64
+ io_uring_prep_openat_direct(sqe, -1, path, O_RDONLY, 0, 0);
65
+ sqe->file_index = UINT_MAX;
66
+
67
+ ret = io_uring_submit(ring);
68
+ if (ret <= 0) {
69
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
70
+ goto err;
71
+ }
72
+ }
73
+
74
+ for (i = 0; i < nr; i++) {
75
+ ret = io_uring_wait_cqe(ring, &cqe);
76
+ if (ret < 0) {
77
+ fprintf(stderr, "wait completion %d\n", ret);
78
+ goto err;
79
+ }
80
+ ret = cqe->res;
81
+ if (ret < 0) {
82
+ if (!expect_enfile || ret != -ENFILE) {
83
+ printf("open=%d, %d\n", cqe->res, i);
84
+ goto err;
85
+ }
86
+ if (!i && ret == -EINVAL) {
87
+ no_direct_pick = 1;
88
+ return 0;
89
+ }
90
+ }
91
+ io_uring_cqe_seen(ring, cqe);
92
+ }
93
+ return 0;
94
+ err:
95
+ return 1;
96
+ }
97
+
98
+ static int test_openat(struct io_uring *ring, const char *path)
99
+ {
100
+ int ret, i;
101
+
102
+ /* open all */
103
+ ret = do_opens(ring, path, FDS, 0);
104
+ if (ret)
105
+ goto err;
106
+ if (no_direct_pick)
107
+ return 0;
108
+
109
+ /* now close 100 randomly */
110
+ for (i = 0; i < 100; i++) {
111
+ do {
112
+ int slot = rand() % FDS;
113
+ ret = try_close(ring, slot);
114
+ if (ret == -EBADF)
115
+ continue;
116
+ break;
117
+ } while (1);
118
+ }
119
+
120
+ /* opening 100 should work, we closed 100 */
121
+ ret = do_opens(ring, path, 100, 0);
122
+ if (ret)
123
+ goto err;
124
+
125
+ /* we should be full now, expect -ENFILE */
126
+ ret = do_opens(ring, path, 1, 1);
127
+ if (ret)
128
+ goto err;
129
+
130
+ return ret;
131
+ err:
132
+ fprintf(stderr,"%s: err=%d\n", __FUNCTION__, ret);
133
+ return -1;
134
+ }
135
+
136
+ int main(int argc, char *argv[])
137
+ {
138
+ struct io_uring ring;
139
+ const char *path;
140
+ int ret;
141
+
142
+ if (argc > 1)
143
+ return 0;
144
+
145
+ ret = io_uring_queue_init(8, &ring, 0);
146
+ if (ret) {
147
+ fprintf(stderr, "ring setup failed\n");
148
+ return 1;
149
+ }
150
+
151
+ ret = io_uring_register_files_sparse(&ring, FDS);
152
+ if (ret ) {
153
+ if (ret != -EINVAL) {
154
+ fprintf(stderr, "Sparse file registration failed\n");
155
+ return 1;
156
+ }
157
+ /* skip, kernel doesn't support sparse file array */
158
+ return 0;
159
+ }
160
+
161
+ path = "/tmp/.open.direct.pick";
162
+ t_create_file(path, 4096);
163
+
164
+ ret = test_openat(&ring, path);
165
+ if (ret < 0) {
166
+ if (ret == -EINVAL) {
167
+ fprintf(stdout, "Open not supported, skipping\n");
168
+ goto done;
169
+ }
170
+ fprintf(stderr, "test_openat absolute failed: %d\n", ret);
171
+ goto err;
172
+ }
173
+
174
+ done:
175
+ unlink(path);
176
+ return 0;
177
+ err:
178
+ unlink(path);
179
+ return 1;
180
+ }
@@ -246,12 +246,12 @@ int main(int argc, char *argv[])
246
246
  }
247
247
 
248
248
  if (argc > 1) {
249
- path = "/tmp/.open.close";
249
+ path = "/tmp/.open.at2";
250
250
  path_rel = argv[1];
251
251
  do_unlink = 0;
252
252
  } else {
253
- path = "/tmp/.open.close";
254
- path_rel = ".open.close";
253
+ path = "/tmp/.open.at2";
254
+ path_rel = ".open.at2";
255
255
  do_unlink = 1;
256
256
  }
257
257