@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.
- package/binding.cc +66 -91
- package/deps/liburing/liburing/COPYING +502 -0
- package/deps/liburing/liburing/COPYING.GPL +339 -0
- package/deps/liburing/liburing/LICENSE +7 -0
- package/deps/liburing/liburing/Makefile +84 -0
- package/deps/liburing/liburing/Makefile.quiet +11 -0
- package/deps/liburing/liburing/README +46 -0
- package/deps/liburing/liburing/configure +420 -0
- package/deps/liburing/liburing/debian/README.Debian +7 -0
- package/deps/liburing/liburing/debian/changelog +27 -0
- package/deps/liburing/liburing/debian/compat +1 -0
- package/deps/liburing/liburing/debian/control +48 -0
- package/deps/liburing/liburing/debian/copyright +49 -0
- package/deps/liburing/liburing/debian/liburing-dev.install +4 -0
- package/deps/liburing/liburing/debian/liburing-dev.manpages +6 -0
- package/deps/liburing/liburing/debian/liburing1-udeb.install +1 -0
- package/deps/liburing/liburing/debian/liburing1.install +1 -0
- package/deps/liburing/liburing/debian/liburing1.symbols +32 -0
- package/deps/liburing/liburing/debian/patches/series +1 -0
- package/deps/liburing/liburing/debian/rules +81 -0
- package/deps/liburing/liburing/debian/source/format +1 -0
- package/deps/liburing/liburing/debian/source/local-options +2 -0
- package/deps/liburing/liburing/debian/source/options +1 -0
- package/deps/liburing/liburing/debian/watch +3 -0
- package/deps/liburing/liburing/examples/Makefile +29 -0
- package/deps/liburing/liburing/examples/io_uring-cp.c +279 -0
- package/deps/liburing/liburing/examples/io_uring-test.c +112 -0
- package/deps/liburing/liburing/examples/link-cp.c +193 -0
- package/deps/liburing/liburing/examples/ucontext-cp.c +273 -0
- package/deps/liburing/liburing/liburing.pc.in +12 -0
- package/deps/liburing/liburing/liburing.spec +66 -0
- package/deps/liburing/liburing/make-debs.sh +53 -0
- package/deps/liburing/liburing/man/io_uring.7 +736 -0
- package/deps/liburing/liburing/man/io_uring_enter.2 +1403 -0
- package/deps/liburing/liburing/man/io_uring_get_sqe.3 +37 -0
- package/deps/liburing/liburing/man/io_uring_queue_exit.3 +27 -0
- package/deps/liburing/liburing/man/io_uring_queue_init.3 +44 -0
- package/deps/liburing/liburing/man/io_uring_register.2 +605 -0
- package/deps/liburing/liburing/man/io_uring_setup.2 +515 -0
- package/deps/liburing/liburing/src/Makefile +76 -0
- package/deps/liburing/liburing/src/include/liburing/barrier.h +73 -0
- package/deps/liburing/liburing/src/include/liburing/io_uring.h +422 -0
- package/deps/liburing/liburing/src/include/liburing.h +775 -0
- package/deps/liburing/liburing/src/liburing.map +46 -0
- package/deps/liburing/liburing/src/queue.c +403 -0
- package/deps/liburing/liburing/src/register.c +299 -0
- package/deps/liburing/liburing/src/setup.c +356 -0
- package/deps/liburing/liburing/src/syscall.c +73 -0
- package/deps/liburing/liburing/src/syscall.h +20 -0
- package/deps/liburing/liburing/test/232c93d07b74-test.c +305 -0
- package/deps/liburing/liburing/test/35fa71a030ca-test.c +329 -0
- package/deps/liburing/liburing/test/500f9fbadef8-test.c +89 -0
- package/deps/liburing/liburing/test/7ad0e4b2f83c-test.c +93 -0
- package/deps/liburing/liburing/test/8a9973408177-test.c +106 -0
- package/deps/liburing/liburing/test/917257daa0fe-test.c +53 -0
- package/deps/liburing/liburing/test/Makefile +312 -0
- package/deps/liburing/liburing/test/a0908ae19763-test.c +58 -0
- package/deps/liburing/liburing/test/a4c0b3decb33-test.c +180 -0
- package/deps/liburing/liburing/test/accept-link.c +251 -0
- package/deps/liburing/liburing/test/accept-reuse.c +164 -0
- package/deps/liburing/liburing/test/accept-test.c +79 -0
- package/deps/liburing/liburing/test/accept.c +476 -0
- package/deps/liburing/liburing/test/across-fork.c +283 -0
- package/deps/liburing/liburing/test/b19062a56726-test.c +53 -0
- package/deps/liburing/liburing/test/b5837bd5311d-test.c +77 -0
- package/deps/liburing/liburing/test/ce593a6c480a-test.c +135 -0
- package/deps/liburing/liburing/test/close-opath.c +122 -0
- package/deps/liburing/liburing/test/config +10 -0
- package/deps/liburing/liburing/test/connect.c +398 -0
- package/deps/liburing/liburing/test/cq-full.c +96 -0
- package/deps/liburing/liburing/test/cq-overflow.c +294 -0
- package/deps/liburing/liburing/test/cq-peek-batch.c +102 -0
- package/deps/liburing/liburing/test/cq-ready.c +94 -0
- package/deps/liburing/liburing/test/cq-size.c +58 -0
- package/deps/liburing/liburing/test/d4ae271dfaae-test.c +96 -0
- package/deps/liburing/liburing/test/d77a67ed5f27-test.c +65 -0
- package/deps/liburing/liburing/test/defer.c +307 -0
- package/deps/liburing/liburing/test/double-poll-crash.c +186 -0
- package/deps/liburing/liburing/test/eeed8b54e0df-test.c +114 -0
- package/deps/liburing/liburing/test/empty-eownerdead.c +42 -0
- package/deps/liburing/liburing/test/eventfd-disable.c +151 -0
- package/deps/liburing/liburing/test/eventfd-ring.c +97 -0
- package/deps/liburing/liburing/test/eventfd.c +112 -0
- package/deps/liburing/liburing/test/fadvise.c +202 -0
- package/deps/liburing/liburing/test/fallocate.c +249 -0
- package/deps/liburing/liburing/test/fc2a85cb02ef-test.c +138 -0
- package/deps/liburing/liburing/test/file-register.c +843 -0
- package/deps/liburing/liburing/test/file-update.c +173 -0
- package/deps/liburing/liburing/test/files-exit-hang-poll.c +128 -0
- package/deps/liburing/liburing/test/files-exit-hang-timeout.c +134 -0
- package/deps/liburing/liburing/test/fixed-link.c +90 -0
- package/deps/liburing/liburing/test/fsync.c +224 -0
- package/deps/liburing/liburing/test/hardlink.c +136 -0
- package/deps/liburing/liburing/test/helpers.c +135 -0
- package/deps/liburing/liburing/test/helpers.h +67 -0
- package/deps/liburing/liburing/test/io-cancel.c +537 -0
- package/deps/liburing/liburing/test/io_uring_enter.c +296 -0
- package/deps/liburing/liburing/test/io_uring_register.c +664 -0
- package/deps/liburing/liburing/test/io_uring_setup.c +192 -0
- package/deps/liburing/liburing/test/iopoll.c +366 -0
- package/deps/liburing/liburing/test/lfs-openat-write.c +117 -0
- package/deps/liburing/liburing/test/lfs-openat.c +273 -0
- package/deps/liburing/liburing/test/link-timeout.c +1107 -0
- package/deps/liburing/liburing/test/link.c +496 -0
- package/deps/liburing/liburing/test/link_drain.c +229 -0
- package/deps/liburing/liburing/test/madvise.c +195 -0
- package/deps/liburing/liburing/test/mkdir.c +108 -0
- package/deps/liburing/liburing/test/multicqes_drain.c +383 -0
- package/deps/liburing/liburing/test/nop-all-sizes.c +107 -0
- package/deps/liburing/liburing/test/nop.c +115 -0
- package/deps/liburing/liburing/test/open-close.c +146 -0
- package/deps/liburing/liburing/test/openat2.c +240 -0
- package/deps/liburing/liburing/test/personality.c +204 -0
- package/deps/liburing/liburing/test/pipe-eof.c +81 -0
- package/deps/liburing/liburing/test/pipe-reuse.c +105 -0
- package/deps/liburing/liburing/test/poll-cancel-ton.c +139 -0
- package/deps/liburing/liburing/test/poll-cancel.c +135 -0
- package/deps/liburing/liburing/test/poll-link.c +227 -0
- package/deps/liburing/liburing/test/poll-many.c +208 -0
- package/deps/liburing/liburing/test/poll-mshot-update.c +273 -0
- package/deps/liburing/liburing/test/poll-ring.c +48 -0
- package/deps/liburing/liburing/test/poll-v-poll.c +353 -0
- package/deps/liburing/liburing/test/poll.c +109 -0
- package/deps/liburing/liburing/test/probe.c +137 -0
- package/deps/liburing/liburing/test/read-write.c +876 -0
- package/deps/liburing/liburing/test/register-restrictions.c +633 -0
- package/deps/liburing/liburing/test/rename.c +134 -0
- package/deps/liburing/liburing/test/ring-leak.c +173 -0
- package/deps/liburing/liburing/test/ring-leak2.c +249 -0
- package/deps/liburing/liburing/test/rsrc_tags.c +449 -0
- package/deps/liburing/liburing/test/runtests-loop.sh +16 -0
- package/deps/liburing/liburing/test/runtests.sh +170 -0
- package/deps/liburing/liburing/test/rw_merge_test.c +97 -0
- package/deps/liburing/liburing/test/self.c +91 -0
- package/deps/liburing/liburing/test/send_recv.c +291 -0
- package/deps/liburing/liburing/test/send_recvmsg.c +345 -0
- package/deps/liburing/liburing/test/sendmsg_fs_cve.c +198 -0
- package/deps/liburing/liburing/test/shared-wq.c +84 -0
- package/deps/liburing/liburing/test/short-read.c +75 -0
- package/deps/liburing/liburing/test/shutdown.c +163 -0
- package/deps/liburing/liburing/test/sigfd-deadlock.c +74 -0
- package/deps/liburing/liburing/test/socket-rw-eagain.c +156 -0
- package/deps/liburing/liburing/test/socket-rw.c +147 -0
- package/deps/liburing/liburing/test/splice.c +511 -0
- package/deps/liburing/liburing/test/sq-full-cpp.cc +45 -0
- package/deps/liburing/liburing/test/sq-full.c +45 -0
- package/deps/liburing/liburing/test/sq-poll-dup.c +200 -0
- package/deps/liburing/liburing/test/sq-poll-kthread.c +168 -0
- package/deps/liburing/liburing/test/sq-poll-share.c +137 -0
- package/deps/liburing/liburing/test/sq-space_left.c +159 -0
- package/deps/liburing/liburing/test/sqpoll-cancel-hang.c +159 -0
- package/deps/liburing/liburing/test/sqpoll-disable-exit.c +195 -0
- package/deps/liburing/liburing/test/sqpoll-exit-hang.c +77 -0
- package/deps/liburing/liburing/test/sqpoll-sleep.c +68 -0
- package/deps/liburing/liburing/test/statx.c +172 -0
- package/deps/liburing/liburing/test/stdout.c +232 -0
- package/deps/liburing/liburing/test/submit-link-fail.c +154 -0
- package/deps/liburing/liburing/test/submit-reuse.c +239 -0
- package/deps/liburing/liburing/test/symlink.c +116 -0
- package/deps/liburing/liburing/test/teardowns.c +58 -0
- package/deps/liburing/liburing/test/thread-exit.c +131 -0
- package/deps/liburing/liburing/test/timeout-new.c +246 -0
- package/deps/liburing/liburing/test/timeout-overflow.c +204 -0
- package/deps/liburing/liburing/test/timeout.c +1354 -0
- package/deps/liburing/liburing/test/unlink.c +111 -0
- package/deps/liburing/liburing/test/wakeup-hang.c +162 -0
- package/deps/liburing/liburing.gyp +20 -0
- package/deps/rocksdb/rocksdb/db/corruption_test.cc +62 -0
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +7 -62
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +25 -11
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +74 -155
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +1 -2
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.h +2 -2
- package/deps/rocksdb/rocksdb/env/fs_posix.cc +13 -0
- package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +4 -2
- package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +22 -4
- package/deps/rocksdb/rocksdb/file/prefetch_test.cc +5 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +15 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +5 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/version.h +1 -1
- package/deps/rocksdb/rocksdb/monitoring/statistics.cc +3 -0
- package/deps/rocksdb/rocksdb/monitoring/stats_history_test.cc +3 -7
- package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +2 -1
- package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +44 -29
- package/deps/rocksdb/rocksdb.gyp +4 -3
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
- package/prebuilds/darwin-x64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
- package/prebuilds/prebuilds/linux-x64/node.napi.node +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/*
|
|
3
|
+
* Regression test for incorrect async_list io_should_merge() logic
|
|
4
|
+
* Bug was fixed in 5.5 by (commit: 561fb04 io_uring: replace workqueue usage with io-wq")
|
|
5
|
+
* Affects 5.4 lts branch, at least 5.4.106 is affected.
|
|
6
|
+
*/
|
|
7
|
+
#include <stdio.h>
|
|
8
|
+
#include <errno.h>
|
|
9
|
+
#include <sys/socket.h>
|
|
10
|
+
#include <sys/un.h>
|
|
11
|
+
#include <assert.h>
|
|
12
|
+
#include <fcntl.h>
|
|
13
|
+
#include <unistd.h>
|
|
14
|
+
|
|
15
|
+
#include "liburing.h"
|
|
16
|
+
#include "helpers.h"
|
|
17
|
+
|
|
18
|
+
int main(int argc, char *argv[])
|
|
19
|
+
{
|
|
20
|
+
struct io_uring_sqe *sqe;
|
|
21
|
+
struct io_uring_cqe *cqe;
|
|
22
|
+
struct io_uring ring;
|
|
23
|
+
int ret, fd, pipe1[2];
|
|
24
|
+
char buf[4096];
|
|
25
|
+
struct iovec vec = {
|
|
26
|
+
.iov_base = buf,
|
|
27
|
+
.iov_len = sizeof(buf)
|
|
28
|
+
};
|
|
29
|
+
struct __kernel_timespec ts = {.tv_sec = 3, .tv_nsec = 0};
|
|
30
|
+
|
|
31
|
+
if (argc > 1)
|
|
32
|
+
return 0;
|
|
33
|
+
|
|
34
|
+
ret = pipe(pipe1);
|
|
35
|
+
assert(!ret);
|
|
36
|
+
|
|
37
|
+
fd = open("testfile", O_RDWR | O_CREAT, 0644);
|
|
38
|
+
assert(ret >= 0);
|
|
39
|
+
ret = ftruncate(fd, 4096);
|
|
40
|
+
assert(!ret);
|
|
41
|
+
|
|
42
|
+
ret = t_create_ring(4, &ring, 0);
|
|
43
|
+
if (ret == T_SETUP_SKIP)
|
|
44
|
+
return 0;
|
|
45
|
+
else if (ret < 0)
|
|
46
|
+
return 1;
|
|
47
|
+
|
|
48
|
+
/* REQ1 */
|
|
49
|
+
sqe = io_uring_get_sqe(&ring);
|
|
50
|
+
io_uring_prep_readv(sqe, pipe1[0], &vec, 1, 0);
|
|
51
|
+
sqe->user_data = 1;
|
|
52
|
+
|
|
53
|
+
/* REQ2 */
|
|
54
|
+
sqe = io_uring_get_sqe(&ring);
|
|
55
|
+
io_uring_prep_readv(sqe, fd, &vec, 1, 4096);
|
|
56
|
+
sqe->user_data = 2;
|
|
57
|
+
|
|
58
|
+
ret = io_uring_submit(&ring);
|
|
59
|
+
assert(ret == 2);
|
|
60
|
+
|
|
61
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
|
62
|
+
assert(!ret);
|
|
63
|
+
assert(cqe->res == 0);
|
|
64
|
+
assert(cqe->user_data == 2);
|
|
65
|
+
io_uring_cqe_seen(&ring, cqe);
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* REQ3
|
|
69
|
+
* Prepare request adjacent to previous one, so merge logic may want to
|
|
70
|
+
* link it to previous request, but because of a bug in merge logic
|
|
71
|
+
* it may be merged with <REQ1> request
|
|
72
|
+
*/
|
|
73
|
+
sqe = io_uring_get_sqe(&ring);
|
|
74
|
+
io_uring_prep_readv(sqe, fd, &vec, 1, 2048);
|
|
75
|
+
sqe->user_data = 3;
|
|
76
|
+
|
|
77
|
+
ret = io_uring_submit(&ring);
|
|
78
|
+
assert(ret == 1);
|
|
79
|
+
|
|
80
|
+
/*
|
|
81
|
+
* Read may stuck because of bug there request was be incorrecly
|
|
82
|
+
* merged with <REQ1> request
|
|
83
|
+
*/
|
|
84
|
+
ret = io_uring_wait_cqe_timeout(&ring, &cqe, &ts);
|
|
85
|
+
if (ret == -ETIME) {
|
|
86
|
+
printf("TEST_FAIL: readv req3 stuck\n");
|
|
87
|
+
return 1;
|
|
88
|
+
}
|
|
89
|
+
assert(!ret);
|
|
90
|
+
|
|
91
|
+
assert(cqe->res == 2048);
|
|
92
|
+
assert(cqe->user_data == 3);
|
|
93
|
+
|
|
94
|
+
io_uring_cqe_seen(&ring, cqe);
|
|
95
|
+
io_uring_queue_exit(&ring);
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/*
|
|
3
|
+
* Description: test that pathname resolution works from async context when
|
|
4
|
+
* using /proc/self/ which should be the original submitting task, not the
|
|
5
|
+
* async worker.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
#include <errno.h>
|
|
9
|
+
#include <stdio.h>
|
|
10
|
+
#include <unistd.h>
|
|
11
|
+
#include <stdlib.h>
|
|
12
|
+
#include <string.h>
|
|
13
|
+
#include <fcntl.h>
|
|
14
|
+
|
|
15
|
+
#include "liburing.h"
|
|
16
|
+
|
|
17
|
+
static int io_openat2(struct io_uring *ring, const char *path, int dfd)
|
|
18
|
+
{
|
|
19
|
+
struct io_uring_cqe *cqe;
|
|
20
|
+
struct io_uring_sqe *sqe;
|
|
21
|
+
struct open_how how;
|
|
22
|
+
int ret;
|
|
23
|
+
|
|
24
|
+
sqe = io_uring_get_sqe(ring);
|
|
25
|
+
if (!sqe) {
|
|
26
|
+
fprintf(stderr, "get sqe failed\n");
|
|
27
|
+
goto err;
|
|
28
|
+
}
|
|
29
|
+
memset(&how, 0, sizeof(how));
|
|
30
|
+
how.flags = O_RDONLY;
|
|
31
|
+
io_uring_prep_openat2(sqe, dfd, path, &how);
|
|
32
|
+
|
|
33
|
+
ret = io_uring_submit(ring);
|
|
34
|
+
if (ret <= 0) {
|
|
35
|
+
fprintf(stderr, "sqe submit failed: %d\n", ret);
|
|
36
|
+
goto err;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
|
40
|
+
if (ret < 0) {
|
|
41
|
+
fprintf(stderr, "wait completion %d\n", ret);
|
|
42
|
+
goto err;
|
|
43
|
+
}
|
|
44
|
+
ret = cqe->res;
|
|
45
|
+
io_uring_cqe_seen(ring, cqe);
|
|
46
|
+
return ret;
|
|
47
|
+
err:
|
|
48
|
+
return -1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
int main(int argc, char *argv[])
|
|
52
|
+
{
|
|
53
|
+
struct io_uring ring;
|
|
54
|
+
char buf[64];
|
|
55
|
+
int ret;
|
|
56
|
+
|
|
57
|
+
if (argc > 1)
|
|
58
|
+
return 0;
|
|
59
|
+
|
|
60
|
+
ret = io_uring_queue_init(1, &ring, 0);
|
|
61
|
+
if (ret) {
|
|
62
|
+
fprintf(stderr, "ring setup failed\n");
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
ret = io_openat2(&ring, "/proc/self/comm", -1);
|
|
67
|
+
if (ret < 0) {
|
|
68
|
+
if (ret == -EOPNOTSUPP)
|
|
69
|
+
return 0;
|
|
70
|
+
if (ret == -EINVAL) {
|
|
71
|
+
fprintf(stdout, "openat2 not supported, skipping\n");
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
fprintf(stderr, "openat2 failed: %s\n", strerror(-ret));
|
|
75
|
+
return 1;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
memset(buf, 0, sizeof(buf));
|
|
79
|
+
ret = read(ret, buf, sizeof(buf));
|
|
80
|
+
if (ret < 0) {
|
|
81
|
+
perror("read");
|
|
82
|
+
return 1;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (strncmp(buf, "self", 4)) {
|
|
86
|
+
fprintf(stderr, "got comm=<%s>, wanted <self>\n", buf);
|
|
87
|
+
return 1;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/*
|
|
3
|
+
* Simple test case showing using send and recv through io_uring
|
|
4
|
+
*/
|
|
5
|
+
#include <errno.h>
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
#include <unistd.h>
|
|
10
|
+
#include <arpa/inet.h>
|
|
11
|
+
#include <sys/types.h>
|
|
12
|
+
#include <sys/socket.h>
|
|
13
|
+
#include <pthread.h>
|
|
14
|
+
|
|
15
|
+
#include "liburing.h"
|
|
16
|
+
#include "helpers.h"
|
|
17
|
+
|
|
18
|
+
static char str[] = "This is a test of send and recv over io_uring!";
|
|
19
|
+
|
|
20
|
+
#define MAX_MSG 128
|
|
21
|
+
|
|
22
|
+
#define PORT 10200
|
|
23
|
+
#define HOST "127.0.0.1"
|
|
24
|
+
|
|
25
|
+
#if 0
|
|
26
|
+
# define io_uring_prep_send io_uring_prep_write
|
|
27
|
+
# define io_uring_prep_recv io_uring_prep_read
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
static int recv_prep(struct io_uring *ring, struct iovec *iov, int *sock,
|
|
31
|
+
int registerfiles)
|
|
32
|
+
{
|
|
33
|
+
struct sockaddr_in saddr;
|
|
34
|
+
struct io_uring_sqe *sqe;
|
|
35
|
+
int sockfd, ret, val, use_fd;
|
|
36
|
+
|
|
37
|
+
memset(&saddr, 0, sizeof(saddr));
|
|
38
|
+
saddr.sin_family = AF_INET;
|
|
39
|
+
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
40
|
+
saddr.sin_port = htons(PORT);
|
|
41
|
+
|
|
42
|
+
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
43
|
+
if (sockfd < 0) {
|
|
44
|
+
perror("socket");
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
val = 1;
|
|
49
|
+
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
|
|
50
|
+
|
|
51
|
+
ret = bind(sockfd, (struct sockaddr *)&saddr, sizeof(saddr));
|
|
52
|
+
if (ret < 0) {
|
|
53
|
+
perror("bind");
|
|
54
|
+
goto err;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (registerfiles) {
|
|
58
|
+
ret = io_uring_register_files(ring, &sockfd, 1);
|
|
59
|
+
if (ret) {
|
|
60
|
+
fprintf(stderr, "file reg failed\n");
|
|
61
|
+
goto err;
|
|
62
|
+
}
|
|
63
|
+
use_fd = 0;
|
|
64
|
+
} else {
|
|
65
|
+
use_fd = sockfd;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
sqe = io_uring_get_sqe(ring);
|
|
69
|
+
io_uring_prep_recv(sqe, use_fd, iov->iov_base, iov->iov_len, 0);
|
|
70
|
+
if (registerfiles)
|
|
71
|
+
sqe->flags |= IOSQE_FIXED_FILE;
|
|
72
|
+
sqe->user_data = 2;
|
|
73
|
+
|
|
74
|
+
ret = io_uring_submit(ring);
|
|
75
|
+
if (ret <= 0) {
|
|
76
|
+
fprintf(stderr, "submit failed: %d\n", ret);
|
|
77
|
+
goto err;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
*sock = sockfd;
|
|
81
|
+
return 0;
|
|
82
|
+
err:
|
|
83
|
+
close(sockfd);
|
|
84
|
+
return 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static int do_recv(struct io_uring *ring, struct iovec *iov)
|
|
88
|
+
{
|
|
89
|
+
struct io_uring_cqe *cqe;
|
|
90
|
+
int ret;
|
|
91
|
+
|
|
92
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
|
93
|
+
if (ret) {
|
|
94
|
+
fprintf(stdout, "wait_cqe: %d\n", ret);
|
|
95
|
+
goto err;
|
|
96
|
+
}
|
|
97
|
+
if (cqe->res == -EINVAL) {
|
|
98
|
+
fprintf(stdout, "recv not supported, skipping\n");
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
if (cqe->res < 0) {
|
|
102
|
+
fprintf(stderr, "failed cqe: %d\n", cqe->res);
|
|
103
|
+
goto err;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (cqe->res -1 != strlen(str)) {
|
|
107
|
+
fprintf(stderr, "got wrong length: %d/%d\n", cqe->res,
|
|
108
|
+
(int) strlen(str) + 1);
|
|
109
|
+
goto err;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (strcmp(str, iov->iov_base)) {
|
|
113
|
+
fprintf(stderr, "string mismatch\n");
|
|
114
|
+
goto err;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return 0;
|
|
118
|
+
err:
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
struct recv_data {
|
|
123
|
+
pthread_mutex_t mutex;
|
|
124
|
+
int use_sqthread;
|
|
125
|
+
int registerfiles;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
static void *recv_fn(void *data)
|
|
129
|
+
{
|
|
130
|
+
struct recv_data *rd = data;
|
|
131
|
+
char buf[MAX_MSG + 1];
|
|
132
|
+
struct iovec iov = {
|
|
133
|
+
.iov_base = buf,
|
|
134
|
+
.iov_len = sizeof(buf) - 1,
|
|
135
|
+
};
|
|
136
|
+
struct io_uring_params p = { };
|
|
137
|
+
struct io_uring ring;
|
|
138
|
+
int ret, sock;
|
|
139
|
+
|
|
140
|
+
if (rd->use_sqthread)
|
|
141
|
+
p.flags = IORING_SETUP_SQPOLL;
|
|
142
|
+
ret = t_create_ring_params(1, &ring, &p);
|
|
143
|
+
if (ret == T_SETUP_SKIP) {
|
|
144
|
+
pthread_mutex_unlock(&rd->mutex);
|
|
145
|
+
ret = 0;
|
|
146
|
+
goto err;
|
|
147
|
+
} else if (ret < 0) {
|
|
148
|
+
pthread_mutex_unlock(&rd->mutex);
|
|
149
|
+
goto err;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (rd->use_sqthread && !rd->registerfiles) {
|
|
153
|
+
if (!(p.features & IORING_FEAT_SQPOLL_NONFIXED)) {
|
|
154
|
+
fprintf(stdout, "Non-registered SQPOLL not available, skipping\n");
|
|
155
|
+
pthread_mutex_unlock(&rd->mutex);
|
|
156
|
+
goto err;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
ret = recv_prep(&ring, &iov, &sock, rd->registerfiles);
|
|
161
|
+
if (ret) {
|
|
162
|
+
fprintf(stderr, "recv_prep failed: %d\n", ret);
|
|
163
|
+
goto err;
|
|
164
|
+
}
|
|
165
|
+
pthread_mutex_unlock(&rd->mutex);
|
|
166
|
+
ret = do_recv(&ring, &iov);
|
|
167
|
+
|
|
168
|
+
close(sock);
|
|
169
|
+
io_uring_queue_exit(&ring);
|
|
170
|
+
err:
|
|
171
|
+
return (void *)(intptr_t)ret;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static int do_send(void)
|
|
175
|
+
{
|
|
176
|
+
struct sockaddr_in saddr;
|
|
177
|
+
struct iovec iov = {
|
|
178
|
+
.iov_base = str,
|
|
179
|
+
.iov_len = sizeof(str),
|
|
180
|
+
};
|
|
181
|
+
struct io_uring ring;
|
|
182
|
+
struct io_uring_cqe *cqe;
|
|
183
|
+
struct io_uring_sqe *sqe;
|
|
184
|
+
int sockfd, ret;
|
|
185
|
+
|
|
186
|
+
ret = io_uring_queue_init(1, &ring, 0);
|
|
187
|
+
if (ret) {
|
|
188
|
+
fprintf(stderr, "queue init failed: %d\n", ret);
|
|
189
|
+
return 1;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
memset(&saddr, 0, sizeof(saddr));
|
|
193
|
+
saddr.sin_family = AF_INET;
|
|
194
|
+
saddr.sin_port = htons(PORT);
|
|
195
|
+
inet_pton(AF_INET, HOST, &saddr.sin_addr);
|
|
196
|
+
|
|
197
|
+
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
198
|
+
if (sockfd < 0) {
|
|
199
|
+
perror("socket");
|
|
200
|
+
return 1;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
ret = connect(sockfd, &saddr, sizeof(saddr));
|
|
204
|
+
if (ret < 0) {
|
|
205
|
+
perror("connect");
|
|
206
|
+
return 1;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
sqe = io_uring_get_sqe(&ring);
|
|
210
|
+
io_uring_prep_send(sqe, sockfd, iov.iov_base, iov.iov_len, 0);
|
|
211
|
+
sqe->user_data = 1;
|
|
212
|
+
|
|
213
|
+
ret = io_uring_submit(&ring);
|
|
214
|
+
if (ret <= 0) {
|
|
215
|
+
fprintf(stderr, "submit failed: %d\n", ret);
|
|
216
|
+
goto err;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
|
220
|
+
if (cqe->res == -EINVAL) {
|
|
221
|
+
fprintf(stdout, "send not supported, skipping\n");
|
|
222
|
+
close(sockfd);
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
if (cqe->res != iov.iov_len) {
|
|
226
|
+
fprintf(stderr, "failed cqe: %d\n", cqe->res);
|
|
227
|
+
goto err;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
close(sockfd);
|
|
231
|
+
return 0;
|
|
232
|
+
err:
|
|
233
|
+
close(sockfd);
|
|
234
|
+
return 1;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
static int test(int use_sqthread, int regfiles)
|
|
238
|
+
{
|
|
239
|
+
pthread_mutexattr_t attr;
|
|
240
|
+
pthread_t recv_thread;
|
|
241
|
+
struct recv_data rd;
|
|
242
|
+
int ret;
|
|
243
|
+
void *retval;
|
|
244
|
+
|
|
245
|
+
pthread_mutexattr_init(&attr);
|
|
246
|
+
pthread_mutexattr_setpshared(&attr, 1);
|
|
247
|
+
pthread_mutex_init(&rd.mutex, &attr);
|
|
248
|
+
pthread_mutex_lock(&rd.mutex);
|
|
249
|
+
rd.use_sqthread = use_sqthread;
|
|
250
|
+
rd.registerfiles = regfiles;
|
|
251
|
+
|
|
252
|
+
ret = pthread_create(&recv_thread, NULL, recv_fn, &rd);
|
|
253
|
+
if (ret) {
|
|
254
|
+
fprintf(stderr, "Thread create failed: %d\n", ret);
|
|
255
|
+
pthread_mutex_unlock(&rd.mutex);
|
|
256
|
+
return 1;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
pthread_mutex_lock(&rd.mutex);
|
|
260
|
+
do_send();
|
|
261
|
+
pthread_join(recv_thread, &retval);
|
|
262
|
+
return (int)(intptr_t)retval;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
int main(int argc, char *argv[])
|
|
266
|
+
{
|
|
267
|
+
int ret;
|
|
268
|
+
|
|
269
|
+
if (argc > 1)
|
|
270
|
+
return 0;
|
|
271
|
+
|
|
272
|
+
ret = test(0, 0);
|
|
273
|
+
if (ret) {
|
|
274
|
+
fprintf(stderr, "test sqthread=0 failed\n");
|
|
275
|
+
return ret;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
ret = test(1, 1);
|
|
279
|
+
if (ret) {
|
|
280
|
+
fprintf(stderr, "test sqthread=1 reg=1 failed\n");
|
|
281
|
+
return ret;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
ret = test(1, 0);
|
|
285
|
+
if (ret) {
|
|
286
|
+
fprintf(stderr, "test sqthread=1 reg=0 failed\n");
|
|
287
|
+
return ret;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return 0;
|
|
291
|
+
}
|