@nxtedition/rocksdb 5.2.36 → 5.2.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/binding.cc +66 -91
  2. package/deps/liburing/liburing/COPYING +502 -0
  3. package/deps/liburing/liburing/COPYING.GPL +339 -0
  4. package/deps/liburing/liburing/LICENSE +7 -0
  5. package/deps/liburing/liburing/Makefile +84 -0
  6. package/deps/liburing/liburing/Makefile.quiet +11 -0
  7. package/deps/liburing/liburing/README +46 -0
  8. package/deps/liburing/liburing/configure +420 -0
  9. package/deps/liburing/liburing/debian/README.Debian +7 -0
  10. package/deps/liburing/liburing/debian/changelog +27 -0
  11. package/deps/liburing/liburing/debian/compat +1 -0
  12. package/deps/liburing/liburing/debian/control +48 -0
  13. package/deps/liburing/liburing/debian/copyright +49 -0
  14. package/deps/liburing/liburing/debian/liburing-dev.install +4 -0
  15. package/deps/liburing/liburing/debian/liburing-dev.manpages +6 -0
  16. package/deps/liburing/liburing/debian/liburing1-udeb.install +1 -0
  17. package/deps/liburing/liburing/debian/liburing1.install +1 -0
  18. package/deps/liburing/liburing/debian/liburing1.symbols +32 -0
  19. package/deps/liburing/liburing/debian/patches/series +1 -0
  20. package/deps/liburing/liburing/debian/rules +81 -0
  21. package/deps/liburing/liburing/debian/source/format +1 -0
  22. package/deps/liburing/liburing/debian/source/local-options +2 -0
  23. package/deps/liburing/liburing/debian/source/options +1 -0
  24. package/deps/liburing/liburing/debian/watch +3 -0
  25. package/deps/liburing/liburing/examples/Makefile +29 -0
  26. package/deps/liburing/liburing/examples/io_uring-cp.c +279 -0
  27. package/deps/liburing/liburing/examples/io_uring-test.c +112 -0
  28. package/deps/liburing/liburing/examples/link-cp.c +193 -0
  29. package/deps/liburing/liburing/examples/ucontext-cp.c +273 -0
  30. package/deps/liburing/liburing/liburing.pc.in +12 -0
  31. package/deps/liburing/liburing/liburing.spec +66 -0
  32. package/deps/liburing/liburing/make-debs.sh +53 -0
  33. package/deps/liburing/liburing/man/io_uring.7 +736 -0
  34. package/deps/liburing/liburing/man/io_uring_enter.2 +1403 -0
  35. package/deps/liburing/liburing/man/io_uring_get_sqe.3 +37 -0
  36. package/deps/liburing/liburing/man/io_uring_queue_exit.3 +27 -0
  37. package/deps/liburing/liburing/man/io_uring_queue_init.3 +44 -0
  38. package/deps/liburing/liburing/man/io_uring_register.2 +605 -0
  39. package/deps/liburing/liburing/man/io_uring_setup.2 +515 -0
  40. package/deps/liburing/liburing/src/Makefile +76 -0
  41. package/deps/liburing/liburing/src/include/liburing/barrier.h +73 -0
  42. package/deps/liburing/liburing/src/include/liburing/io_uring.h +422 -0
  43. package/deps/liburing/liburing/src/include/liburing.h +775 -0
  44. package/deps/liburing/liburing/src/liburing.map +46 -0
  45. package/deps/liburing/liburing/src/queue.c +403 -0
  46. package/deps/liburing/liburing/src/register.c +299 -0
  47. package/deps/liburing/liburing/src/setup.c +356 -0
  48. package/deps/liburing/liburing/src/syscall.c +73 -0
  49. package/deps/liburing/liburing/src/syscall.h +20 -0
  50. package/deps/liburing/liburing/test/232c93d07b74-test.c +305 -0
  51. package/deps/liburing/liburing/test/35fa71a030ca-test.c +329 -0
  52. package/deps/liburing/liburing/test/500f9fbadef8-test.c +89 -0
  53. package/deps/liburing/liburing/test/7ad0e4b2f83c-test.c +93 -0
  54. package/deps/liburing/liburing/test/8a9973408177-test.c +106 -0
  55. package/deps/liburing/liburing/test/917257daa0fe-test.c +53 -0
  56. package/deps/liburing/liburing/test/Makefile +312 -0
  57. package/deps/liburing/liburing/test/a0908ae19763-test.c +58 -0
  58. package/deps/liburing/liburing/test/a4c0b3decb33-test.c +180 -0
  59. package/deps/liburing/liburing/test/accept-link.c +251 -0
  60. package/deps/liburing/liburing/test/accept-reuse.c +164 -0
  61. package/deps/liburing/liburing/test/accept-test.c +79 -0
  62. package/deps/liburing/liburing/test/accept.c +476 -0
  63. package/deps/liburing/liburing/test/across-fork.c +283 -0
  64. package/deps/liburing/liburing/test/b19062a56726-test.c +53 -0
  65. package/deps/liburing/liburing/test/b5837bd5311d-test.c +77 -0
  66. package/deps/liburing/liburing/test/ce593a6c480a-test.c +135 -0
  67. package/deps/liburing/liburing/test/close-opath.c +122 -0
  68. package/deps/liburing/liburing/test/config +10 -0
  69. package/deps/liburing/liburing/test/connect.c +398 -0
  70. package/deps/liburing/liburing/test/cq-full.c +96 -0
  71. package/deps/liburing/liburing/test/cq-overflow.c +294 -0
  72. package/deps/liburing/liburing/test/cq-peek-batch.c +102 -0
  73. package/deps/liburing/liburing/test/cq-ready.c +94 -0
  74. package/deps/liburing/liburing/test/cq-size.c +58 -0
  75. package/deps/liburing/liburing/test/d4ae271dfaae-test.c +96 -0
  76. package/deps/liburing/liburing/test/d77a67ed5f27-test.c +65 -0
  77. package/deps/liburing/liburing/test/defer.c +307 -0
  78. package/deps/liburing/liburing/test/double-poll-crash.c +186 -0
  79. package/deps/liburing/liburing/test/eeed8b54e0df-test.c +114 -0
  80. package/deps/liburing/liburing/test/empty-eownerdead.c +42 -0
  81. package/deps/liburing/liburing/test/eventfd-disable.c +151 -0
  82. package/deps/liburing/liburing/test/eventfd-ring.c +97 -0
  83. package/deps/liburing/liburing/test/eventfd.c +112 -0
  84. package/deps/liburing/liburing/test/fadvise.c +202 -0
  85. package/deps/liburing/liburing/test/fallocate.c +249 -0
  86. package/deps/liburing/liburing/test/fc2a85cb02ef-test.c +138 -0
  87. package/deps/liburing/liburing/test/file-register.c +843 -0
  88. package/deps/liburing/liburing/test/file-update.c +173 -0
  89. package/deps/liburing/liburing/test/files-exit-hang-poll.c +128 -0
  90. package/deps/liburing/liburing/test/files-exit-hang-timeout.c +134 -0
  91. package/deps/liburing/liburing/test/fixed-link.c +90 -0
  92. package/deps/liburing/liburing/test/fsync.c +224 -0
  93. package/deps/liburing/liburing/test/hardlink.c +136 -0
  94. package/deps/liburing/liburing/test/helpers.c +135 -0
  95. package/deps/liburing/liburing/test/helpers.h +67 -0
  96. package/deps/liburing/liburing/test/io-cancel.c +537 -0
  97. package/deps/liburing/liburing/test/io_uring_enter.c +296 -0
  98. package/deps/liburing/liburing/test/io_uring_register.c +664 -0
  99. package/deps/liburing/liburing/test/io_uring_setup.c +192 -0
  100. package/deps/liburing/liburing/test/iopoll.c +366 -0
  101. package/deps/liburing/liburing/test/lfs-openat-write.c +117 -0
  102. package/deps/liburing/liburing/test/lfs-openat.c +273 -0
  103. package/deps/liburing/liburing/test/link-timeout.c +1107 -0
  104. package/deps/liburing/liburing/test/link.c +496 -0
  105. package/deps/liburing/liburing/test/link_drain.c +229 -0
  106. package/deps/liburing/liburing/test/madvise.c +195 -0
  107. package/deps/liburing/liburing/test/mkdir.c +108 -0
  108. package/deps/liburing/liburing/test/multicqes_drain.c +383 -0
  109. package/deps/liburing/liburing/test/nop-all-sizes.c +107 -0
  110. package/deps/liburing/liburing/test/nop.c +115 -0
  111. package/deps/liburing/liburing/test/open-close.c +146 -0
  112. package/deps/liburing/liburing/test/openat2.c +240 -0
  113. package/deps/liburing/liburing/test/personality.c +204 -0
  114. package/deps/liburing/liburing/test/pipe-eof.c +81 -0
  115. package/deps/liburing/liburing/test/pipe-reuse.c +105 -0
  116. package/deps/liburing/liburing/test/poll-cancel-ton.c +139 -0
  117. package/deps/liburing/liburing/test/poll-cancel.c +135 -0
  118. package/deps/liburing/liburing/test/poll-link.c +227 -0
  119. package/deps/liburing/liburing/test/poll-many.c +208 -0
  120. package/deps/liburing/liburing/test/poll-mshot-update.c +273 -0
  121. package/deps/liburing/liburing/test/poll-ring.c +48 -0
  122. package/deps/liburing/liburing/test/poll-v-poll.c +353 -0
  123. package/deps/liburing/liburing/test/poll.c +109 -0
  124. package/deps/liburing/liburing/test/probe.c +137 -0
  125. package/deps/liburing/liburing/test/read-write.c +876 -0
  126. package/deps/liburing/liburing/test/register-restrictions.c +633 -0
  127. package/deps/liburing/liburing/test/rename.c +134 -0
  128. package/deps/liburing/liburing/test/ring-leak.c +173 -0
  129. package/deps/liburing/liburing/test/ring-leak2.c +249 -0
  130. package/deps/liburing/liburing/test/rsrc_tags.c +449 -0
  131. package/deps/liburing/liburing/test/runtests-loop.sh +16 -0
  132. package/deps/liburing/liburing/test/runtests.sh +170 -0
  133. package/deps/liburing/liburing/test/rw_merge_test.c +97 -0
  134. package/deps/liburing/liburing/test/self.c +91 -0
  135. package/deps/liburing/liburing/test/send_recv.c +291 -0
  136. package/deps/liburing/liburing/test/send_recvmsg.c +345 -0
  137. package/deps/liburing/liburing/test/sendmsg_fs_cve.c +198 -0
  138. package/deps/liburing/liburing/test/shared-wq.c +84 -0
  139. package/deps/liburing/liburing/test/short-read.c +75 -0
  140. package/deps/liburing/liburing/test/shutdown.c +163 -0
  141. package/deps/liburing/liburing/test/sigfd-deadlock.c +74 -0
  142. package/deps/liburing/liburing/test/socket-rw-eagain.c +156 -0
  143. package/deps/liburing/liburing/test/socket-rw.c +147 -0
  144. package/deps/liburing/liburing/test/splice.c +511 -0
  145. package/deps/liburing/liburing/test/sq-full-cpp.cc +45 -0
  146. package/deps/liburing/liburing/test/sq-full.c +45 -0
  147. package/deps/liburing/liburing/test/sq-poll-dup.c +200 -0
  148. package/deps/liburing/liburing/test/sq-poll-kthread.c +168 -0
  149. package/deps/liburing/liburing/test/sq-poll-share.c +137 -0
  150. package/deps/liburing/liburing/test/sq-space_left.c +159 -0
  151. package/deps/liburing/liburing/test/sqpoll-cancel-hang.c +159 -0
  152. package/deps/liburing/liburing/test/sqpoll-disable-exit.c +195 -0
  153. package/deps/liburing/liburing/test/sqpoll-exit-hang.c +77 -0
  154. package/deps/liburing/liburing/test/sqpoll-sleep.c +68 -0
  155. package/deps/liburing/liburing/test/statx.c +172 -0
  156. package/deps/liburing/liburing/test/stdout.c +232 -0
  157. package/deps/liburing/liburing/test/submit-link-fail.c +154 -0
  158. package/deps/liburing/liburing/test/submit-reuse.c +239 -0
  159. package/deps/liburing/liburing/test/symlink.c +116 -0
  160. package/deps/liburing/liburing/test/teardowns.c +58 -0
  161. package/deps/liburing/liburing/test/thread-exit.c +131 -0
  162. package/deps/liburing/liburing/test/timeout-new.c +246 -0
  163. package/deps/liburing/liburing/test/timeout-overflow.c +204 -0
  164. package/deps/liburing/liburing/test/timeout.c +1354 -0
  165. package/deps/liburing/liburing/test/unlink.c +111 -0
  166. package/deps/liburing/liburing/test/wakeup-hang.c +162 -0
  167. package/deps/liburing/liburing.gyp +20 -0
  168. package/deps/rocksdb/rocksdb/db/corruption_test.cc +62 -0
  169. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +7 -62
  170. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +25 -11
  171. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +74 -155
  172. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +1 -2
  173. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.h +2 -2
  174. package/deps/rocksdb/rocksdb/env/fs_posix.cc +13 -0
  175. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +4 -2
  176. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +22 -4
  177. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +5 -0
  178. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +15 -0
  179. package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +5 -0
  180. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +1 -1
  181. package/deps/rocksdb/rocksdb/monitoring/statistics.cc +3 -0
  182. package/deps/rocksdb/rocksdb/monitoring/stats_history_test.cc +3 -7
  183. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +2 -1
  184. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +44 -29
  185. package/deps/rocksdb/rocksdb.gyp +4 -3
  186. package/package.json +1 -1
  187. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  188. package/prebuilds/darwin-x64/node.napi.node +0 -0
  189. package/prebuilds/linux-x64/node.napi.node +0 -0
  190. package/prebuilds/prebuilds/linux-x64/node.napi.node +0 -0
@@ -0,0 +1,192 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * io_uring_setup.c
4
+ *
5
+ * Description: Unit tests for the io_uring_setup system call.
6
+ *
7
+ * Copyright 2019, Red Hat, Inc.
8
+ * Author: Jeff Moyer <jmoyer@redhat.com>
9
+ */
10
+ #include <stdio.h>
11
+ #include <fcntl.h>
12
+ #include <string.h>
13
+ #include <stdlib.h>
14
+ #include <unistd.h>
15
+ #include <errno.h>
16
+ #include <sys/sysinfo.h>
17
+ #include "liburing.h"
18
+
19
+ #include "../syscall.h"
20
+
21
+ char *features_string(struct io_uring_params *p)
22
+ {
23
+ static char flagstr[64];
24
+
25
+ if (!p || !p->features)
26
+ return "none";
27
+
28
+ if (p->features & ~IORING_FEAT_SINGLE_MMAP) {
29
+ snprintf(flagstr, 64, "0x%.8x", p->features);
30
+ return flagstr;
31
+ }
32
+
33
+ if (p->features & IORING_FEAT_SINGLE_MMAP)
34
+ strncat(flagstr, "IORING_FEAT_SINGLE_MMAP", 64 - strlen(flagstr));
35
+
36
+ return flagstr;
37
+ }
38
+
39
+ /*
40
+ * Attempt the call with the given args. Return 0 when expect matches
41
+ * the return value of the system call, 1 otherwise.
42
+ */
43
+ char *
44
+ flags_string(struct io_uring_params *p)
45
+ {
46
+ static char flagstr[64];
47
+ int add_pipe = 0;
48
+
49
+ memset(flagstr, 0, sizeof(flagstr));
50
+
51
+ if (!p || p->flags == 0)
52
+ return "none";
53
+
54
+ /*
55
+ * If unsupported flags are present, just print the bitmask.
56
+ */
57
+ if (p->flags & ~(IORING_SETUP_IOPOLL | IORING_SETUP_SQPOLL |
58
+ IORING_SETUP_SQ_AFF)) {
59
+ snprintf(flagstr, 64, "0x%.8x", p->flags);
60
+ return flagstr;
61
+ }
62
+
63
+ if (p->flags & IORING_SETUP_IOPOLL) {
64
+ strncat(flagstr, "IORING_SETUP_IOPOLL", 64 - strlen(flagstr));
65
+ add_pipe = 1;
66
+ }
67
+ if (p->flags & IORING_SETUP_SQPOLL) {
68
+ if (add_pipe)
69
+ strncat(flagstr, "|", 64 - strlen(flagstr));
70
+ else
71
+ add_pipe = 1;
72
+ strncat(flagstr, "IORING_SETUP_SQPOLL", 64 - strlen(flagstr));
73
+ }
74
+ if (p->flags & IORING_SETUP_SQ_AFF) {
75
+ if (add_pipe)
76
+ strncat(flagstr, "|", 64 - strlen(flagstr));
77
+ strncat(flagstr, "IORING_SETUP_SQ_AFF", 64 - strlen(flagstr));
78
+ }
79
+
80
+ return flagstr;
81
+ }
82
+
83
+ char *
84
+ dump_resv(struct io_uring_params *p)
85
+ {
86
+ static char resvstr[4096];
87
+
88
+ if (!p)
89
+ return "";
90
+
91
+ sprintf(resvstr, "0x%.8x 0x%.8x 0x%.8x", p->resv[0],
92
+ p->resv[1], p->resv[2]);
93
+
94
+ return resvstr;
95
+ }
96
+
97
+ /* bogus: setup returns a valid fd on success... expect can't predict the
98
+ fd we'll get, so this really only takes 1 parameter: error */
99
+ int
100
+ try_io_uring_setup(unsigned entries, struct io_uring_params *p, int expect, int error)
101
+ {
102
+ int ret, __errno;
103
+
104
+ printf("io_uring_setup(%u, %p), flags: %s, feat: %s, resv: %s, sq_thread_cpu: %u\n",
105
+ entries, p, flags_string(p), features_string(p), dump_resv(p),
106
+ p ? p->sq_thread_cpu : 0);
107
+
108
+ ret = __sys_io_uring_setup(entries, p);
109
+ if (ret != expect) {
110
+ printf("expected %d, got %d\n", expect, ret);
111
+ /* if we got a valid uring, close it */
112
+ if (ret > 0)
113
+ close(ret);
114
+ return 1;
115
+ }
116
+ __errno = errno;
117
+ if (expect == -1 && error != __errno) {
118
+ if (__errno == EPERM && geteuid() != 0) {
119
+ printf("Needs root, not flagging as an error\n");
120
+ return 0;
121
+ }
122
+ printf("expected errno %d, got %d\n", error, __errno);
123
+ return 1;
124
+ }
125
+
126
+ return 0;
127
+ }
128
+
129
+ int
130
+ main(int argc, char **argv)
131
+ {
132
+ int fd;
133
+ unsigned int status = 0;
134
+ struct io_uring_params p;
135
+
136
+ if (argc > 1)
137
+ return 0;
138
+
139
+ memset(&p, 0, sizeof(p));
140
+ status |= try_io_uring_setup(0, &p, -1, EINVAL);
141
+ status |= try_io_uring_setup(1, NULL, -1, EFAULT);
142
+
143
+ /* resv array is non-zero */
144
+ memset(&p, 0, sizeof(p));
145
+ p.resv[0] = p.resv[1] = p.resv[2] = 1;
146
+ status |= try_io_uring_setup(1, &p, -1, EINVAL);
147
+
148
+ /* invalid flags */
149
+ memset(&p, 0, sizeof(p));
150
+ p.flags = ~0U;
151
+ status |= try_io_uring_setup(1, &p, -1, EINVAL);
152
+
153
+ /* IORING_SETUP_SQ_AFF set but not IORING_SETUP_SQPOLL */
154
+ memset(&p, 0, sizeof(p));
155
+ p.flags = IORING_SETUP_SQ_AFF;
156
+ status |= try_io_uring_setup(1, &p, -1, EINVAL);
157
+
158
+ /* attempt to bind to invalid cpu */
159
+ memset(&p, 0, sizeof(p));
160
+ p.flags = IORING_SETUP_SQPOLL | IORING_SETUP_SQ_AFF;
161
+ p.sq_thread_cpu = get_nprocs_conf();
162
+ status |= try_io_uring_setup(1, &p, -1, EINVAL);
163
+
164
+ /* I think we can limit a process to a set of cpus. I assume
165
+ * we shouldn't be able to setup a kernel thread outside of that.
166
+ * try to do that. (task->cpus_allowed) */
167
+
168
+ /* read/write on io_uring_fd */
169
+ memset(&p, 0, sizeof(p));
170
+ fd = __sys_io_uring_setup(1, &p);
171
+ if (fd < 0) {
172
+ printf("io_uring_setup failed with %d, expected success\n",
173
+ errno);
174
+ status = 1;
175
+ } else {
176
+ char buf[4096];
177
+ int ret;
178
+ ret = read(fd, buf, 4096);
179
+ if (ret >= 0) {
180
+ printf("read from io_uring fd succeeded. expected fail\n");
181
+ status = 1;
182
+ }
183
+ }
184
+
185
+ if (!status) {
186
+ printf("PASS\n");
187
+ return 0;
188
+ }
189
+
190
+ printf("FAIL\n");
191
+ return -1;
192
+ }
@@ -0,0 +1,366 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: basic read/write tests with polled IO
4
+ */
5
+ #include <errno.h>
6
+ #include <stdio.h>
7
+ #include <unistd.h>
8
+ #include <stdlib.h>
9
+ #include <string.h>
10
+ #include <fcntl.h>
11
+ #include <sys/types.h>
12
+ #include <sys/poll.h>
13
+ #include <sys/eventfd.h>
14
+ #include <sys/resource.h>
15
+ #include "helpers.h"
16
+ #include "liburing.h"
17
+ #include "../src/syscall.h"
18
+
19
+ #define FILE_SIZE (128 * 1024)
20
+ #define BS 4096
21
+ #define BUFFERS (FILE_SIZE / BS)
22
+
23
+ static struct iovec *vecs;
24
+ static int no_buf_select;
25
+ static int no_iopoll;
26
+
27
+ static int provide_buffers(struct io_uring *ring)
28
+ {
29
+ struct io_uring_sqe *sqe;
30
+ struct io_uring_cqe *cqe;
31
+ int ret, i;
32
+
33
+ for (i = 0; i < BUFFERS; i++) {
34
+ sqe = io_uring_get_sqe(ring);
35
+ io_uring_prep_provide_buffers(sqe, vecs[i].iov_base,
36
+ vecs[i].iov_len, 1, 1, i);
37
+ }
38
+
39
+ ret = io_uring_submit(ring);
40
+ if (ret != BUFFERS) {
41
+ fprintf(stderr, "submit: %d\n", ret);
42
+ return 1;
43
+ }
44
+
45
+ for (i = 0; i < BUFFERS; i++) {
46
+ ret = io_uring_wait_cqe(ring, &cqe);
47
+ if (cqe->res < 0) {
48
+ fprintf(stderr, "cqe->res=%d\n", cqe->res);
49
+ return 1;
50
+ }
51
+ io_uring_cqe_seen(ring, cqe);
52
+ }
53
+
54
+ return 0;
55
+ }
56
+
57
+ static int __test_io(const char *file, struct io_uring *ring, int write, int sqthread,
58
+ int fixed, int buf_select)
59
+ {
60
+ struct io_uring_sqe *sqe;
61
+ struct io_uring_cqe *cqe;
62
+ int open_flags;
63
+ int i, fd = -1, ret;
64
+ off_t offset;
65
+
66
+ if (buf_select) {
67
+ write = 0;
68
+ fixed = 0;
69
+ }
70
+ if (buf_select && provide_buffers(ring))
71
+ return 1;
72
+
73
+ if (write)
74
+ open_flags = O_WRONLY;
75
+ else
76
+ open_flags = O_RDONLY;
77
+ open_flags |= O_DIRECT;
78
+
79
+ if (fixed) {
80
+ ret = t_register_buffers(ring, vecs, BUFFERS);
81
+ if (ret == T_SETUP_SKIP)
82
+ return 0;
83
+ if (ret != T_SETUP_OK) {
84
+ fprintf(stderr, "buffer reg failed: %d\n", ret);
85
+ goto err;
86
+ }
87
+ }
88
+ fd = open(file, open_flags);
89
+ if (fd < 0) {
90
+ perror("file open");
91
+ goto err;
92
+ }
93
+ if (sqthread) {
94
+ ret = io_uring_register_files(ring, &fd, 1);
95
+ if (ret) {
96
+ fprintf(stderr, "file reg failed: %d\n", ret);
97
+ goto err;
98
+ }
99
+ }
100
+
101
+ offset = 0;
102
+ for (i = 0; i < BUFFERS; i++) {
103
+ sqe = io_uring_get_sqe(ring);
104
+ if (!sqe) {
105
+ fprintf(stderr, "sqe get failed\n");
106
+ goto err;
107
+ }
108
+ offset = BS * (rand() % BUFFERS);
109
+ if (write) {
110
+ int do_fixed = fixed;
111
+ int use_fd = fd;
112
+
113
+ if (sqthread)
114
+ use_fd = 0;
115
+ if (fixed && (i & 1))
116
+ do_fixed = 0;
117
+ if (do_fixed) {
118
+ io_uring_prep_write_fixed(sqe, use_fd, vecs[i].iov_base,
119
+ vecs[i].iov_len,
120
+ offset, i);
121
+ } else {
122
+ io_uring_prep_writev(sqe, use_fd, &vecs[i], 1,
123
+ offset);
124
+ }
125
+ } else {
126
+ int do_fixed = fixed;
127
+ int use_fd = fd;
128
+
129
+ if (sqthread)
130
+ use_fd = 0;
131
+ if (fixed && (i & 1))
132
+ do_fixed = 0;
133
+ if (do_fixed) {
134
+ io_uring_prep_read_fixed(sqe, use_fd, vecs[i].iov_base,
135
+ vecs[i].iov_len,
136
+ offset, i);
137
+ } else {
138
+ io_uring_prep_readv(sqe, use_fd, &vecs[i], 1,
139
+ offset);
140
+ }
141
+
142
+ }
143
+ if (sqthread)
144
+ sqe->flags |= IOSQE_FIXED_FILE;
145
+ if (buf_select) {
146
+ sqe->flags |= IOSQE_BUFFER_SELECT;
147
+ sqe->buf_group = buf_select;
148
+ sqe->user_data = i;
149
+ }
150
+ }
151
+
152
+ ret = io_uring_submit(ring);
153
+ if (ret != BUFFERS) {
154
+ fprintf(stderr, "submit got %d, wanted %d\n", ret, BUFFERS);
155
+ goto err;
156
+ }
157
+
158
+ for (i = 0; i < BUFFERS; i++) {
159
+ ret = io_uring_wait_cqe(ring, &cqe);
160
+ if (ret) {
161
+ fprintf(stderr, "wait_cqe=%d\n", ret);
162
+ goto err;
163
+ } else if (cqe->res == -EOPNOTSUPP) {
164
+ fprintf(stdout, "File/device/fs doesn't support polled IO\n");
165
+ no_iopoll = 1;
166
+ goto out;
167
+ } else if (cqe->res != BS) {
168
+ fprintf(stderr, "cqe res %d, wanted %d\n", cqe->res, BS);
169
+ goto err;
170
+ }
171
+ io_uring_cqe_seen(ring, cqe);
172
+ }
173
+
174
+ if (fixed) {
175
+ ret = io_uring_unregister_buffers(ring);
176
+ if (ret) {
177
+ fprintf(stderr, "buffer unreg failed: %d\n", ret);
178
+ goto err;
179
+ }
180
+ }
181
+ if (sqthread) {
182
+ ret = io_uring_unregister_files(ring);
183
+ if (ret) {
184
+ fprintf(stderr, "file unreg failed: %d\n", ret);
185
+ goto err;
186
+ }
187
+ }
188
+
189
+ out:
190
+ close(fd);
191
+ return 0;
192
+ err:
193
+ if (fd != -1)
194
+ close(fd);
195
+ return 1;
196
+ }
197
+
198
+ extern int __io_uring_flush_sq(struct io_uring *ring);
199
+
200
+ /*
201
+ * if we are polling io_uring_submit needs to always enter the
202
+ * kernel to fetch events
203
+ */
204
+ static int test_io_uring_submit_enters(const char *file)
205
+ {
206
+ struct io_uring ring;
207
+ int fd, i, ret, ring_flags, open_flags;
208
+ unsigned head;
209
+ struct io_uring_cqe *cqe;
210
+
211
+ if (no_iopoll)
212
+ return 0;
213
+
214
+ ring_flags = IORING_SETUP_IOPOLL;
215
+ ret = io_uring_queue_init(64, &ring, ring_flags);
216
+ if (ret) {
217
+ fprintf(stderr, "ring create failed: %d\n", ret);
218
+ return 1;
219
+ }
220
+
221
+ open_flags = O_WRONLY | O_DIRECT;
222
+ fd = open(file, open_flags);
223
+ if (fd < 0) {
224
+ perror("file open");
225
+ goto err;
226
+ }
227
+
228
+ for (i = 0; i < BUFFERS; i++) {
229
+ struct io_uring_sqe *sqe;
230
+ off_t offset = BS * (rand() % BUFFERS);
231
+
232
+ sqe = io_uring_get_sqe(&ring);
233
+ io_uring_prep_writev(sqe, fd, &vecs[i], 1, offset);
234
+ sqe->user_data = 1;
235
+ }
236
+
237
+ /* submit manually to avoid adding IORING_ENTER_GETEVENTS */
238
+ ret = __sys_io_uring_enter(ring.ring_fd, __io_uring_flush_sq(&ring), 0,
239
+ 0, NULL);
240
+ if (ret < 0)
241
+ goto err;
242
+
243
+ for (i = 0; i < 500; i++) {
244
+ ret = io_uring_submit(&ring);
245
+ if (ret != 0) {
246
+ fprintf(stderr, "still had %d sqes to submit, this is unexpected", ret);
247
+ goto err;
248
+ }
249
+
250
+ io_uring_for_each_cqe(&ring, head, cqe) {
251
+ /* runs after test_io so should not have happened */
252
+ if (cqe->res == -EOPNOTSUPP) {
253
+ fprintf(stdout, "File/device/fs doesn't support polled IO\n");
254
+ goto err;
255
+ }
256
+ goto ok;
257
+ }
258
+ usleep(10000);
259
+ }
260
+ err:
261
+ ret = 1;
262
+ if (fd != -1)
263
+ close(fd);
264
+
265
+ ok:
266
+ io_uring_queue_exit(&ring);
267
+ return ret;
268
+ }
269
+
270
+ static int test_io(const char *file, int write, int sqthread, int fixed,
271
+ int buf_select)
272
+ {
273
+ struct io_uring ring;
274
+ int ret, ring_flags = IORING_SETUP_IOPOLL;
275
+
276
+ if (no_iopoll)
277
+ return 0;
278
+
279
+ ret = t_create_ring(64, &ring, ring_flags);
280
+ if (ret == T_SETUP_SKIP)
281
+ return 0;
282
+ if (ret != T_SETUP_OK) {
283
+ fprintf(stderr, "ring create failed: %d\n", ret);
284
+ return 1;
285
+ }
286
+ ret = __test_io(file, &ring, write, sqthread, fixed, buf_select);
287
+ io_uring_queue_exit(&ring);
288
+ return ret;
289
+ }
290
+
291
+ static int probe_buf_select(void)
292
+ {
293
+ struct io_uring_probe *p;
294
+ struct io_uring ring;
295
+ int ret;
296
+
297
+ ret = io_uring_queue_init(1, &ring, 0);
298
+ if (ret) {
299
+ fprintf(stderr, "ring create failed: %d\n", ret);
300
+ return 1;
301
+ }
302
+
303
+ p = io_uring_get_probe_ring(&ring);
304
+ if (!p || !io_uring_opcode_supported(p, IORING_OP_PROVIDE_BUFFERS)) {
305
+ no_buf_select = 1;
306
+ fprintf(stdout, "Buffer select not supported, skipping\n");
307
+ return 0;
308
+ }
309
+ free(p);
310
+ return 0;
311
+ }
312
+
313
+ int main(int argc, char *argv[])
314
+ {
315
+ int i, ret, nr;
316
+ char buf[256];
317
+ char *fname;
318
+
319
+ if (probe_buf_select())
320
+ return 1;
321
+
322
+ if (argc > 1) {
323
+ fname = argv[1];
324
+ } else {
325
+ srand((unsigned)time(NULL));
326
+ snprintf(buf, sizeof(buf), ".basic-rw-%u-%u",
327
+ (unsigned)rand(), (unsigned)getpid());
328
+ fname = buf;
329
+ t_create_file(fname, FILE_SIZE);
330
+ }
331
+
332
+ vecs = t_create_buffers(BUFFERS, BS);
333
+
334
+ nr = 16;
335
+ if (no_buf_select)
336
+ nr = 8;
337
+ for (i = 0; i < nr; i++) {
338
+ int write = (i & 1) != 0;
339
+ int sqthread = (i & 2) != 0;
340
+ int fixed = (i & 4) != 0;
341
+ int buf_select = (i & 8) != 0;
342
+
343
+ ret = test_io(fname, write, sqthread, fixed, buf_select);
344
+ if (ret) {
345
+ fprintf(stderr, "test_io failed %d/%d/%d/%d\n",
346
+ write, sqthread, fixed, buf_select);
347
+ goto err;
348
+ }
349
+ if (no_iopoll)
350
+ break;
351
+ }
352
+
353
+ ret = test_io_uring_submit_enters(fname);
354
+ if (ret) {
355
+ fprintf(stderr, "test_io_uring_submit_enters failed\n");
356
+ goto err;
357
+ }
358
+
359
+ if (fname != argv[1])
360
+ unlink(fname);
361
+ return 0;
362
+ err:
363
+ if (fname != argv[1])
364
+ unlink(fname);
365
+ return 1;
366
+ }
@@ -0,0 +1,117 @@
1
+ #define _LARGEFILE_SOURCE
2
+ #define _FILE_OFFSET_BITS 64
3
+
4
+ #include <liburing.h>
5
+ #include <string.h>
6
+ #include <stdio.h>
7
+ #include <stdlib.h>
8
+ #include <sys/types.h>
9
+ #include <sys/stat.h>
10
+ #include <fcntl.h>
11
+ #include <errno.h>
12
+ #include <sys/resource.h>
13
+ #include <unistd.h>
14
+
15
+ static const int RSIZE = 2;
16
+ static const int OPEN_FLAGS = O_RDWR | O_CREAT;
17
+ static const mode_t OPEN_MODE = S_IRUSR | S_IWUSR;
18
+
19
+ #define DIE(...) do {\
20
+ fprintf(stderr, __VA_ARGS__);\
21
+ abort();\
22
+ } while(0);
23
+
24
+ static int do_write(struct io_uring *ring, int fd, off_t offset)
25
+ {
26
+ char buf[] = "some test write buf";
27
+ struct io_uring_sqe *sqe;
28
+ struct io_uring_cqe *cqe;
29
+ int res, ret;
30
+
31
+ sqe = io_uring_get_sqe(ring);
32
+ if (!sqe) {
33
+ fprintf(stderr, "failed to get sqe\n");
34
+ return 1;
35
+ }
36
+ io_uring_prep_write(sqe, fd, buf, sizeof(buf), offset);
37
+
38
+ ret = io_uring_submit(ring);
39
+ if (ret < 0) {
40
+ fprintf(stderr, "failed to submit write: %s\n", strerror(-ret));
41
+ return 1;
42
+ }
43
+
44
+ ret = io_uring_wait_cqe(ring, &cqe);
45
+ if (ret < 0) {
46
+ fprintf(stderr, "wait_cqe failed: %s\n", strerror(-ret));
47
+ return 1;
48
+ }
49
+
50
+ res = cqe->res;
51
+ io_uring_cqe_seen(ring, cqe);
52
+ if (res < 0) {
53
+ fprintf(stderr, "write failed: %s\n", strerror(-res));
54
+ return 1;
55
+ }
56
+
57
+ return 0;
58
+ }
59
+
60
+ static int test_open_write(struct io_uring *ring, int dfd, const char *fn)
61
+ {
62
+ struct io_uring_sqe *sqe;
63
+ struct io_uring_cqe *cqe;
64
+ int ret, fd = -1;
65
+
66
+ sqe = io_uring_get_sqe(ring);
67
+ if (!sqe) {
68
+ fprintf(stderr, "failed to get sqe\n");
69
+ return 1;
70
+ }
71
+ io_uring_prep_openat(sqe, dfd, fn, OPEN_FLAGS, OPEN_MODE);
72
+
73
+ ret = io_uring_submit(ring);
74
+ if (ret < 0) {
75
+ fprintf(stderr, "failed to submit openat: %s\n", strerror(-ret));
76
+ return 1;
77
+ }
78
+
79
+ ret = io_uring_wait_cqe(ring, &cqe);
80
+ if (ret < 0) {
81
+ fprintf(stderr, "wait_cqe failed: %s\n", strerror(-ret));
82
+ return 1;
83
+ }
84
+
85
+ fd = cqe->res;
86
+ io_uring_cqe_seen(ring, cqe);
87
+ if (fd < 0) {
88
+ fprintf(stderr, "openat failed: %s\n", strerror(-fd));
89
+ return 1;
90
+ }
91
+
92
+ return do_write(ring, fd, 1ULL << 32);
93
+ }
94
+
95
+ int main(int argc, char *argv[])
96
+ {
97
+ struct io_uring ring;
98
+ int dfd, ret;
99
+
100
+ if (argc > 1)
101
+ return 0;
102
+
103
+ dfd = open("/tmp", O_RDONLY | O_DIRECTORY);
104
+ if (dfd < 0)
105
+ DIE("open /tmp: %s\n", strerror(errno));
106
+
107
+ ret = io_uring_queue_init(RSIZE, &ring, 0);
108
+ if (ret < 0)
109
+ DIE("failed to init io_uring: %s\n", strerror(-ret));
110
+
111
+ ret = test_open_write(&ring, dfd, "io_uring_openat_write_test1");
112
+
113
+ io_uring_queue_exit(&ring);
114
+ close(dfd);
115
+ unlink("/tmp/io_uring_openat_write_test1");
116
+ return ret;
117
+ }