polyphony 0.84 → 0.86
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +1 -1
- data/examples/core/multi_suspend.rb +39 -0
- data/examples/core/shutdown_all_children.rb +41 -0
- data/examples/io/gzip.rb +8 -0
- data/examples/io/splice_echo_server.rb +15 -0
- data/ext/polyphony/backend_io_uring.c +57 -31
- data/ext/polyphony/io_extensions.c +137 -26
- data/lib/polyphony/extensions/fiber.rb +3 -1
- data/lib/polyphony/extensions/io.rb +4 -0
- data/lib/polyphony/extensions/pipe.rb +4 -0
- data/lib/polyphony/extensions/socket.rb +4 -0
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +1 -1
- data/test/test_backend.rb +1 -1
- data/test/test_fiber.rb +5 -2
- data/test/test_signal.rb +3 -3
- data/vendor/liburing/.github/pull_request_template.md +86 -0
- data/vendor/liburing/.github/workflows/build.yml +85 -0
- data/vendor/liburing/.github/workflows/shellcheck.yml +20 -0
- data/vendor/liburing/.gitignore +149 -0
- data/vendor/liburing/COPYING +502 -0
- data/vendor/liburing/COPYING.GPL +339 -0
- data/vendor/liburing/LICENSE +7 -0
- data/vendor/liburing/Makefile +82 -0
- data/vendor/liburing/Makefile.common +5 -0
- data/vendor/liburing/Makefile.quiet +11 -0
- data/vendor/liburing/README +46 -0
- data/vendor/liburing/configure +486 -0
- data/vendor/liburing/debian/README.Debian +7 -0
- data/vendor/liburing/debian/changelog +27 -0
- data/vendor/liburing/debian/compat +1 -0
- data/vendor/liburing/debian/control +48 -0
- data/vendor/liburing/debian/copyright +49 -0
- data/vendor/liburing/debian/liburing-dev.install +4 -0
- data/vendor/liburing/debian/liburing-dev.manpages +6 -0
- data/vendor/liburing/debian/liburing1-udeb.install +1 -0
- data/vendor/liburing/debian/liburing1.install +1 -0
- data/vendor/liburing/debian/liburing1.symbols +32 -0
- data/vendor/liburing/debian/patches/series +1 -0
- data/vendor/liburing/debian/rules +81 -0
- data/vendor/liburing/debian/source/format +1 -0
- data/vendor/liburing/debian/source/local-options +2 -0
- data/vendor/liburing/debian/source/options +1 -0
- data/vendor/liburing/debian/watch +3 -0
- data/vendor/liburing/examples/Makefile +38 -0
- data/vendor/liburing/examples/io_uring-cp.c +282 -0
- data/vendor/liburing/examples/io_uring-test.c +112 -0
- data/vendor/liburing/examples/link-cp.c +193 -0
- data/vendor/liburing/examples/ucontext-cp.c +273 -0
- data/vendor/liburing/liburing.pc.in +12 -0
- data/vendor/liburing/liburing.spec +66 -0
- data/vendor/liburing/make-debs.sh +53 -0
- data/vendor/liburing/man/io_uring.7 +754 -0
- data/vendor/liburing/man/io_uring_cq_advance.3 +35 -0
- data/vendor/liburing/man/io_uring_cq_ready.3 +25 -0
- data/vendor/liburing/man/io_uring_cqe_get_data.3 +34 -0
- data/vendor/liburing/man/io_uring_cqe_seen.3 +32 -0
- data/vendor/liburing/man/io_uring_enter.2 +1483 -0
- data/vendor/liburing/man/io_uring_free_probe.3 +24 -0
- data/vendor/liburing/man/io_uring_get_probe.3 +29 -0
- data/vendor/liburing/man/io_uring_get_sqe.3 +38 -0
- data/vendor/liburing/man/io_uring_opcode_supported.3 +29 -0
- data/vendor/liburing/man/io_uring_prep_msg_ring.3 +58 -0
- data/vendor/liburing/man/io_uring_prep_read.3 +50 -0
- data/vendor/liburing/man/io_uring_prep_read_fixed.3 +54 -0
- data/vendor/liburing/man/io_uring_prep_readv.3 +51 -0
- data/vendor/liburing/man/io_uring_prep_readv2.3 +79 -0
- data/vendor/liburing/man/io_uring_prep_write.3 +50 -0
- data/vendor/liburing/man/io_uring_prep_write_fixed.3 +54 -0
- data/vendor/liburing/man/io_uring_prep_writev.3 +51 -0
- data/vendor/liburing/man/io_uring_prep_writev2.3 +78 -0
- data/vendor/liburing/man/io_uring_queue_exit.3 +27 -0
- data/vendor/liburing/man/io_uring_queue_init.3 +44 -0
- data/vendor/liburing/man/io_uring_register.2 +688 -0
- data/vendor/liburing/man/io_uring_register_buffers.3 +41 -0
- data/vendor/liburing/man/io_uring_register_files.3 +35 -0
- data/vendor/liburing/man/io_uring_setup.2 +534 -0
- data/vendor/liburing/man/io_uring_sq_ready.3 +25 -0
- data/vendor/liburing/man/io_uring_sq_space_left.3 +25 -0
- data/vendor/liburing/man/io_uring_sqe_set_data.3 +30 -0
- data/vendor/liburing/man/io_uring_sqe_set_flags.3 +60 -0
- data/vendor/liburing/man/io_uring_sqring_wait.3 +30 -0
- data/vendor/liburing/man/io_uring_submit.3 +29 -0
- data/vendor/liburing/man/io_uring_submit_and_wait.3 +34 -0
- data/vendor/liburing/man/io_uring_submit_and_wait_timeout.3 +49 -0
- data/vendor/liburing/man/io_uring_unregister_buffers.3 +26 -0
- data/vendor/liburing/man/io_uring_unregister_files.3 +26 -0
- data/vendor/liburing/man/io_uring_wait_cqe.3 +33 -0
- data/vendor/liburing/man/io_uring_wait_cqe_nr.3 +36 -0
- data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +39 -0
- data/vendor/liburing/man/io_uring_wait_cqes.3 +46 -0
- data/vendor/liburing/src/Makefile +89 -0
- data/vendor/liburing/src/arch/aarch64/syscall.h +95 -0
- data/vendor/liburing/src/arch/generic/lib.h +21 -0
- data/vendor/liburing/src/arch/generic/syscall.h +87 -0
- data/vendor/liburing/src/arch/syscall-defs.h +67 -0
- data/vendor/liburing/src/arch/x86/lib.h +32 -0
- data/vendor/liburing/src/arch/x86/syscall.h +160 -0
- data/vendor/liburing/src/include/liburing/barrier.h +81 -0
- data/vendor/liburing/src/include/liburing/io_uring.h +442 -0
- data/vendor/liburing/src/include/liburing.h +921 -0
- data/vendor/liburing/src/int_flags.h +8 -0
- data/vendor/liburing/src/lib.h +57 -0
- data/vendor/liburing/src/liburing.map +53 -0
- data/vendor/liburing/src/nolibc.c +48 -0
- data/vendor/liburing/src/queue.c +403 -0
- data/vendor/liburing/src/register.c +293 -0
- data/vendor/liburing/src/setup.c +332 -0
- data/vendor/liburing/src/syscall.c +47 -0
- data/vendor/liburing/src/syscall.h +103 -0
- data/vendor/liburing/test/232c93d07b74-test.c +306 -0
- data/vendor/liburing/test/35fa71a030ca-test.c +329 -0
- data/vendor/liburing/test/500f9fbadef8-test.c +89 -0
- data/vendor/liburing/test/7ad0e4b2f83c-test.c +93 -0
- data/vendor/liburing/test/8a9973408177-test.c +106 -0
- data/vendor/liburing/test/917257daa0fe-test.c +53 -0
- data/vendor/liburing/test/Makefile +244 -0
- data/vendor/liburing/test/a0908ae19763-test.c +58 -0
- data/vendor/liburing/test/a4c0b3decb33-test.c +180 -0
- data/vendor/liburing/test/accept-link.c +254 -0
- data/vendor/liburing/test/accept-reuse.c +164 -0
- data/vendor/liburing/test/accept-test.c +79 -0
- data/vendor/liburing/test/accept.c +477 -0
- data/vendor/liburing/test/across-fork.c +283 -0
- data/vendor/liburing/test/b19062a56726-test.c +53 -0
- data/vendor/liburing/test/b5837bd5311d-test.c +77 -0
- data/vendor/liburing/test/ce593a6c480a-test.c +136 -0
- data/vendor/liburing/test/close-opath.c +122 -0
- data/vendor/liburing/test/config +10 -0
- data/vendor/liburing/test/connect.c +398 -0
- data/vendor/liburing/test/cq-full.c +96 -0
- data/vendor/liburing/test/cq-overflow.c +294 -0
- data/vendor/liburing/test/cq-peek-batch.c +102 -0
- data/vendor/liburing/test/cq-ready.c +94 -0
- data/vendor/liburing/test/cq-size.c +64 -0
- data/vendor/liburing/test/d4ae271dfaae-test.c +96 -0
- data/vendor/liburing/test/d77a67ed5f27-test.c +65 -0
- data/vendor/liburing/test/defer.c +307 -0
- data/vendor/liburing/test/double-poll-crash.c +185 -0
- data/vendor/liburing/test/drop-submit.c +92 -0
- data/vendor/liburing/test/eeed8b54e0df-test.c +114 -0
- data/vendor/liburing/test/empty-eownerdead.c +45 -0
- data/vendor/liburing/test/eventfd-disable.c +151 -0
- data/vendor/liburing/test/eventfd-reg.c +76 -0
- data/vendor/liburing/test/eventfd-ring.c +97 -0
- data/vendor/liburing/test/eventfd.c +112 -0
- data/vendor/liburing/test/exec-target.c +6 -0
- data/vendor/liburing/test/exit-no-cleanup.c +117 -0
- data/vendor/liburing/test/fadvise.c +202 -0
- data/vendor/liburing/test/fallocate.c +249 -0
- data/vendor/liburing/test/fc2a85cb02ef-test.c +131 -0
- data/vendor/liburing/test/file-register.c +858 -0
- data/vendor/liburing/test/file-update.c +173 -0
- data/vendor/liburing/test/file-verify.c +629 -0
- data/vendor/liburing/test/files-exit-hang-poll.c +128 -0
- data/vendor/liburing/test/files-exit-hang-timeout.c +134 -0
- data/vendor/liburing/test/fixed-link.c +90 -0
- data/vendor/liburing/test/fpos.c +252 -0
- data/vendor/liburing/test/fsync.c +224 -0
- data/vendor/liburing/test/hardlink.c +136 -0
- data/vendor/liburing/test/helpers.c +135 -0
- data/vendor/liburing/test/helpers.h +67 -0
- data/vendor/liburing/test/io-cancel.c +550 -0
- data/vendor/liburing/test/io_uring_enter.c +296 -0
- data/vendor/liburing/test/io_uring_register.c +676 -0
- data/vendor/liburing/test/io_uring_setup.c +192 -0
- data/vendor/liburing/test/iopoll.c +372 -0
- data/vendor/liburing/test/lfs-openat-write.c +119 -0
- data/vendor/liburing/test/lfs-openat.c +275 -0
- data/vendor/liburing/test/link-timeout.c +1107 -0
- data/vendor/liburing/test/link.c +496 -0
- data/vendor/liburing/test/link_drain.c +229 -0
- data/vendor/liburing/test/madvise.c +195 -0
- data/vendor/liburing/test/mkdir.c +108 -0
- data/vendor/liburing/test/msg-ring.c +234 -0
- data/vendor/liburing/test/multicqes_drain.c +387 -0
- data/vendor/liburing/test/nop-all-sizes.c +99 -0
- data/vendor/liburing/test/nop.c +115 -0
- data/vendor/liburing/test/open-close.c +261 -0
- data/vendor/liburing/test/openat2.c +308 -0
- data/vendor/liburing/test/personality.c +204 -0
- data/vendor/liburing/test/pipe-eof.c +83 -0
- data/vendor/liburing/test/pipe-reuse.c +105 -0
- data/vendor/liburing/test/poll-cancel-ton.c +135 -0
- data/vendor/liburing/test/poll-cancel.c +228 -0
- data/vendor/liburing/test/poll-link.c +230 -0
- data/vendor/liburing/test/poll-many.c +208 -0
- data/vendor/liburing/test/poll-mshot-update.c +273 -0
- data/vendor/liburing/test/poll-ring.c +48 -0
- data/vendor/liburing/test/poll-v-poll.c +353 -0
- data/vendor/liburing/test/poll.c +109 -0
- data/vendor/liburing/test/pollfree.c +426 -0
- data/vendor/liburing/test/probe.c +135 -0
- data/vendor/liburing/test/read-write.c +876 -0
- data/vendor/liburing/test/register-restrictions.c +633 -0
- data/vendor/liburing/test/rename.c +135 -0
- data/vendor/liburing/test/ring-leak.c +173 -0
- data/vendor/liburing/test/ring-leak2.c +249 -0
- data/vendor/liburing/test/rsrc_tags.c +449 -0
- data/vendor/liburing/test/runtests-loop.sh +16 -0
- data/vendor/liburing/test/runtests.sh +170 -0
- data/vendor/liburing/test/rw_merge_test.c +97 -0
- data/vendor/liburing/test/self.c +91 -0
- data/vendor/liburing/test/send_recv.c +286 -0
- data/vendor/liburing/test/send_recvmsg.c +345 -0
- data/vendor/liburing/test/sendmsg_fs_cve.c +200 -0
- data/vendor/liburing/test/shared-wq.c +84 -0
- data/vendor/liburing/test/short-read.c +75 -0
- data/vendor/liburing/test/shutdown.c +165 -0
- data/vendor/liburing/test/sigfd-deadlock.c +74 -0
- data/vendor/liburing/test/skip-cqe.c +429 -0
- data/vendor/liburing/test/socket-rw-eagain.c +158 -0
- data/vendor/liburing/test/socket-rw-offset.c +157 -0
- data/vendor/liburing/test/socket-rw.c +145 -0
- data/vendor/liburing/test/splice.c +512 -0
- data/vendor/liburing/test/sq-full-cpp.cc +45 -0
- data/vendor/liburing/test/sq-full.c +45 -0
- data/vendor/liburing/test/sq-poll-dup.c +204 -0
- data/vendor/liburing/test/sq-poll-kthread.c +169 -0
- data/vendor/liburing/test/sq-poll-share.c +137 -0
- data/vendor/liburing/test/sq-space_left.c +159 -0
- data/vendor/liburing/test/sqpoll-cancel-hang.c +157 -0
- data/vendor/liburing/test/sqpoll-disable-exit.c +196 -0
- data/vendor/liburing/test/sqpoll-exit-hang.c +78 -0
- data/vendor/liburing/test/sqpoll-sleep.c +69 -0
- data/vendor/liburing/test/statx.c +172 -0
- data/vendor/liburing/test/stdout.c +232 -0
- data/vendor/liburing/test/submit-link-fail.c +154 -0
- data/vendor/liburing/test/submit-reuse.c +239 -0
- data/vendor/liburing/test/symlink.c +116 -0
- data/vendor/liburing/test/teardowns.c +58 -0
- data/vendor/liburing/test/thread-exit.c +143 -0
- data/vendor/liburing/test/timeout-new.c +252 -0
- data/vendor/liburing/test/timeout-overflow.c +204 -0
- data/vendor/liburing/test/timeout.c +1523 -0
- data/vendor/liburing/test/unlink.c +112 -0
- data/vendor/liburing/test/wakeup-hang.c +162 -0
- metadata +227 -2
@@ -0,0 +1,204 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: test if personalities work
|
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
|
+
#define FNAME "/tmp/.tmp.access"
|
16
|
+
#define USE_UID 1000
|
17
|
+
|
18
|
+
static int no_personality;
|
19
|
+
|
20
|
+
static int open_file(struct io_uring *ring, int cred_id, int with_link)
|
21
|
+
{
|
22
|
+
struct io_uring_cqe *cqe;
|
23
|
+
struct io_uring_sqe *sqe;
|
24
|
+
int ret, i, to_submit = 1;
|
25
|
+
|
26
|
+
if (with_link) {
|
27
|
+
sqe = io_uring_get_sqe(ring);
|
28
|
+
io_uring_prep_nop(sqe);
|
29
|
+
sqe->flags |= IOSQE_IO_LINK;
|
30
|
+
sqe->user_data = 1;
|
31
|
+
to_submit++;
|
32
|
+
}
|
33
|
+
|
34
|
+
sqe = io_uring_get_sqe(ring);
|
35
|
+
io_uring_prep_openat(sqe, -1, FNAME, O_RDONLY, 0);
|
36
|
+
sqe->user_data = 2;
|
37
|
+
|
38
|
+
if (cred_id != -1)
|
39
|
+
sqe->personality = cred_id;
|
40
|
+
|
41
|
+
ret = io_uring_submit(ring);
|
42
|
+
if (ret != to_submit) {
|
43
|
+
fprintf(stderr, "submit got: %d\n", ret);
|
44
|
+
goto err;
|
45
|
+
}
|
46
|
+
|
47
|
+
for (i = 0; i < to_submit; i++) {
|
48
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
49
|
+
if (ret < 0) {
|
50
|
+
fprintf(stderr, "wait completion %d\n", ret);
|
51
|
+
goto err;
|
52
|
+
}
|
53
|
+
|
54
|
+
ret = cqe->res;
|
55
|
+
io_uring_cqe_seen(ring, cqe);
|
56
|
+
}
|
57
|
+
err:
|
58
|
+
return ret;
|
59
|
+
}
|
60
|
+
|
61
|
+
static int test_personality(struct io_uring *ring)
|
62
|
+
{
|
63
|
+
int ret, cred_id;
|
64
|
+
|
65
|
+
ret = io_uring_register_personality(ring);
|
66
|
+
if (ret < 0) {
|
67
|
+
if (ret == -EINVAL) {
|
68
|
+
fprintf(stdout, "Personalities not supported, skipping\n");
|
69
|
+
no_personality = 1;
|
70
|
+
goto out;
|
71
|
+
}
|
72
|
+
fprintf(stderr, "register_personality: %d\n", ret);
|
73
|
+
goto err;
|
74
|
+
}
|
75
|
+
cred_id = ret;
|
76
|
+
|
77
|
+
/* create file only owner can open */
|
78
|
+
ret = open(FNAME, O_RDONLY | O_CREAT, 0600);
|
79
|
+
if (ret < 0) {
|
80
|
+
perror("open");
|
81
|
+
goto err;
|
82
|
+
}
|
83
|
+
close(ret);
|
84
|
+
|
85
|
+
/* verify we can open it */
|
86
|
+
ret = open_file(ring, -1, 0);
|
87
|
+
if (ret < 0) {
|
88
|
+
fprintf(stderr, "current open got: %d\n", ret);
|
89
|
+
goto err;
|
90
|
+
}
|
91
|
+
|
92
|
+
if (seteuid(USE_UID) < 0) {
|
93
|
+
fprintf(stdout, "Can't switch to UID %u, skipping\n", USE_UID);
|
94
|
+
goto out;
|
95
|
+
}
|
96
|
+
|
97
|
+
/* verify we can't open it with current credentials */
|
98
|
+
ret = open_file(ring, -1, 0);
|
99
|
+
if (ret != -EACCES) {
|
100
|
+
fprintf(stderr, "open got: %d\n", ret);
|
101
|
+
goto err;
|
102
|
+
}
|
103
|
+
|
104
|
+
/* verify we can open with registered credentials */
|
105
|
+
ret = open_file(ring, cred_id, 0);
|
106
|
+
if (ret < 0) {
|
107
|
+
fprintf(stderr, "credential open: %d\n", ret);
|
108
|
+
goto err;
|
109
|
+
}
|
110
|
+
close(ret);
|
111
|
+
|
112
|
+
/* verify we can open with registered credentials and as a link */
|
113
|
+
ret = open_file(ring, cred_id, 1);
|
114
|
+
if (ret < 0) {
|
115
|
+
fprintf(stderr, "credential open: %d\n", ret);
|
116
|
+
goto err;
|
117
|
+
}
|
118
|
+
|
119
|
+
if (seteuid(0))
|
120
|
+
perror("seteuid");
|
121
|
+
|
122
|
+
ret = io_uring_unregister_personality(ring, cred_id);
|
123
|
+
if (ret) {
|
124
|
+
fprintf(stderr, "register_personality: %d\n", ret);
|
125
|
+
goto err;
|
126
|
+
}
|
127
|
+
|
128
|
+
out:
|
129
|
+
unlink(FNAME);
|
130
|
+
return 0;
|
131
|
+
err:
|
132
|
+
unlink(FNAME);
|
133
|
+
return 1;
|
134
|
+
}
|
135
|
+
|
136
|
+
static int test_invalid_personality(struct io_uring *ring)
|
137
|
+
{
|
138
|
+
int ret;
|
139
|
+
|
140
|
+
ret = open_file(ring, 2, 0);
|
141
|
+
if (ret != -EINVAL) {
|
142
|
+
fprintf(stderr, "invalid personality got: %d\n", ret);
|
143
|
+
goto err;
|
144
|
+
}
|
145
|
+
return 0;
|
146
|
+
err:
|
147
|
+
return 1;
|
148
|
+
}
|
149
|
+
|
150
|
+
static int test_invalid_unregister(struct io_uring *ring)
|
151
|
+
{
|
152
|
+
int ret;
|
153
|
+
|
154
|
+
ret = io_uring_unregister_personality(ring, 2);
|
155
|
+
if (ret != -EINVAL) {
|
156
|
+
fprintf(stderr, "invalid personality unregister got: %d\n", ret);
|
157
|
+
goto err;
|
158
|
+
}
|
159
|
+
return 0;
|
160
|
+
err:
|
161
|
+
return 1;
|
162
|
+
}
|
163
|
+
|
164
|
+
int main(int argc, char *argv[])
|
165
|
+
{
|
166
|
+
struct io_uring ring;
|
167
|
+
int ret;
|
168
|
+
|
169
|
+
if (argc > 1)
|
170
|
+
return 0;
|
171
|
+
|
172
|
+
if (geteuid()) {
|
173
|
+
fprintf(stderr, "Not root, skipping\n");
|
174
|
+
return 0;
|
175
|
+
}
|
176
|
+
|
177
|
+
ret = io_uring_queue_init(8, &ring, 0);
|
178
|
+
if (ret) {
|
179
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
180
|
+
return 1;
|
181
|
+
}
|
182
|
+
|
183
|
+
ret = test_personality(&ring);
|
184
|
+
if (ret) {
|
185
|
+
fprintf(stderr, "test_personality failed\n");
|
186
|
+
return ret;
|
187
|
+
}
|
188
|
+
if (no_personality)
|
189
|
+
return 0;
|
190
|
+
|
191
|
+
ret = test_invalid_personality(&ring);
|
192
|
+
if (ret) {
|
193
|
+
fprintf(stderr, "test_invalid_personality failed\n");
|
194
|
+
return ret;
|
195
|
+
}
|
196
|
+
|
197
|
+
ret = test_invalid_unregister(&ring);
|
198
|
+
if (ret) {
|
199
|
+
fprintf(stderr, "test_invalid_unregister failed\n");
|
200
|
+
return ret;
|
201
|
+
}
|
202
|
+
|
203
|
+
return 0;
|
204
|
+
}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
|
3
|
+
/*
|
4
|
+
* Test that closed pipe reads returns 0, instead of waiting for more
|
5
|
+
* data.
|
6
|
+
*/
|
7
|
+
#include <errno.h>
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <string.h>
|
10
|
+
#include <unistd.h>
|
11
|
+
#include <pthread.h>
|
12
|
+
#include <string.h>
|
13
|
+
#include "liburing.h"
|
14
|
+
|
15
|
+
#define BUFSIZE 512
|
16
|
+
|
17
|
+
struct data {
|
18
|
+
char *str;
|
19
|
+
int fds[2];
|
20
|
+
};
|
21
|
+
|
22
|
+
static void *t(void *data)
|
23
|
+
{
|
24
|
+
struct data *d = data;
|
25
|
+
int ret;
|
26
|
+
|
27
|
+
strcpy(d->str, "This is a test string");
|
28
|
+
ret = write(d->fds[1], d->str, strlen(d->str));
|
29
|
+
close(d->fds[1]);
|
30
|
+
if (ret < 0)
|
31
|
+
perror("write");
|
32
|
+
|
33
|
+
return NULL;
|
34
|
+
}
|
35
|
+
|
36
|
+
int main(int argc, char *argv[])
|
37
|
+
{
|
38
|
+
static char buf[BUFSIZE];
|
39
|
+
struct io_uring ring;
|
40
|
+
pthread_t thread;
|
41
|
+
struct data d;
|
42
|
+
int ret;
|
43
|
+
|
44
|
+
if (pipe(d.fds) < 0) {
|
45
|
+
perror("pipe");
|
46
|
+
return 1;
|
47
|
+
}
|
48
|
+
d.str = buf;
|
49
|
+
|
50
|
+
io_uring_queue_init(8, &ring, 0);
|
51
|
+
|
52
|
+
pthread_create(&thread, NULL, t, &d);
|
53
|
+
|
54
|
+
while (1) {
|
55
|
+
struct io_uring_sqe *sqe;
|
56
|
+
struct io_uring_cqe *cqe;
|
57
|
+
|
58
|
+
sqe = io_uring_get_sqe(&ring);
|
59
|
+
io_uring_prep_read(sqe, d.fds[0], buf, BUFSIZE, 0);
|
60
|
+
ret = io_uring_submit(&ring);
|
61
|
+
if (ret != 1) {
|
62
|
+
fprintf(stderr, "submit: %d\n", ret);
|
63
|
+
return 1;
|
64
|
+
}
|
65
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
66
|
+
if (ret) {
|
67
|
+
fprintf(stderr, "wait: %d\n", ret);
|
68
|
+
return 1;
|
69
|
+
}
|
70
|
+
|
71
|
+
if (cqe->res < 0) {
|
72
|
+
fprintf(stderr, "Read error: %s\n", strerror(-cqe->res));
|
73
|
+
return 1;
|
74
|
+
}
|
75
|
+
if (cqe->res == 0)
|
76
|
+
break;
|
77
|
+
io_uring_cqe_seen(&ring, cqe);
|
78
|
+
}
|
79
|
+
|
80
|
+
pthread_join(thread, NULL);
|
81
|
+
io_uring_queue_exit(&ring);
|
82
|
+
return 0;
|
83
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Check split up read is handled correctly
|
4
|
+
*/
|
5
|
+
#include <errno.h>
|
6
|
+
#include <stdio.h>
|
7
|
+
#include <string.h>
|
8
|
+
#include <unistd.h>
|
9
|
+
#include <pthread.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include "liburing.h"
|
12
|
+
|
13
|
+
#define BUFSIZE 16384
|
14
|
+
#define BUFFERS 16
|
15
|
+
|
16
|
+
int main(int argc, char *argv[])
|
17
|
+
{
|
18
|
+
char buf[BUFSIZE], wbuf[BUFSIZE];
|
19
|
+
struct iovec iov[BUFFERS];
|
20
|
+
struct io_uring_params p = { };
|
21
|
+
struct io_uring ring;
|
22
|
+
struct io_uring_sqe *sqe;
|
23
|
+
struct io_uring_cqe *cqe;
|
24
|
+
int ret, i, fds[2];
|
25
|
+
void *ptr;
|
26
|
+
|
27
|
+
if (pipe(fds) < 0) {
|
28
|
+
perror("pipe");
|
29
|
+
return 1;
|
30
|
+
}
|
31
|
+
|
32
|
+
ptr = buf;
|
33
|
+
for (i = 0; i < BUFFERS; i++) {
|
34
|
+
unsigned bsize = BUFSIZE / BUFFERS;
|
35
|
+
|
36
|
+
iov[i].iov_base = ptr;
|
37
|
+
iov[i].iov_len = bsize;
|
38
|
+
ptr += bsize;
|
39
|
+
}
|
40
|
+
|
41
|
+
ret = io_uring_queue_init_params(8, &ring, &p);
|
42
|
+
if (ret) {
|
43
|
+
fprintf(stderr, "queue_init: %d\n", ret);
|
44
|
+
return 1;
|
45
|
+
}
|
46
|
+
if (!(p.features & IORING_FEAT_SUBMIT_STABLE)) {
|
47
|
+
fprintf(stdout, "FEAT_SUBMIT_STABLE not there, skipping\n");
|
48
|
+
return 0;
|
49
|
+
}
|
50
|
+
|
51
|
+
ptr = wbuf;
|
52
|
+
memset(ptr, 0x11, sizeof(wbuf) / 2);
|
53
|
+
ptr += sizeof(wbuf) / 2;
|
54
|
+
memset(ptr, 0x22, sizeof(wbuf) / 2);
|
55
|
+
|
56
|
+
ret = write(fds[1], wbuf, sizeof(wbuf) / 2);
|
57
|
+
if (ret != sizeof(wbuf) / 2) {
|
58
|
+
fprintf(stderr, "Bad write\n");
|
59
|
+
ret = 1;
|
60
|
+
goto err;
|
61
|
+
}
|
62
|
+
|
63
|
+
sqe = io_uring_get_sqe(&ring);
|
64
|
+
io_uring_prep_readv(sqe, fds[0], iov, BUFFERS, 0);
|
65
|
+
ret = io_uring_submit(&ring);
|
66
|
+
if (ret != 1) {
|
67
|
+
fprintf(stderr, "submit: %d\n", ret);
|
68
|
+
return 1;
|
69
|
+
}
|
70
|
+
|
71
|
+
for (i = 0; i < BUFFERS; i++) {
|
72
|
+
iov[i].iov_base = NULL;
|
73
|
+
iov[i].iov_len = 1000000;
|
74
|
+
}
|
75
|
+
|
76
|
+
ret = write(fds[1], ptr, sizeof(wbuf) / 2);
|
77
|
+
if (ret != sizeof(wbuf) / 2) {
|
78
|
+
fprintf(stderr, "Bad write\n");
|
79
|
+
ret = 1;
|
80
|
+
goto err;
|
81
|
+
}
|
82
|
+
|
83
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
84
|
+
if (ret) {
|
85
|
+
fprintf(stderr, "wait: %d\n", ret);
|
86
|
+
return 1;
|
87
|
+
}
|
88
|
+
|
89
|
+
if (cqe->res < 0) {
|
90
|
+
fprintf(stderr, "Read error: %s\n", strerror(-cqe->res));
|
91
|
+
return 1;
|
92
|
+
} else if (cqe->res != sizeof(wbuf)) {
|
93
|
+
/* ignore short read, not a failure */
|
94
|
+
goto err;
|
95
|
+
}
|
96
|
+
io_uring_cqe_seen(&ring, cqe);
|
97
|
+
|
98
|
+
ret = memcmp(wbuf, buf, sizeof(wbuf));
|
99
|
+
if (ret)
|
100
|
+
fprintf(stderr, "Read data mismatch\n");
|
101
|
+
|
102
|
+
err:
|
103
|
+
io_uring_queue_exit(&ring);
|
104
|
+
return ret;
|
105
|
+
}
|
@@ -0,0 +1,135 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: test massive amounts of poll with cancel
|
4
|
+
*
|
5
|
+
*/
|
6
|
+
#include <errno.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <unistd.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <inttypes.h>
|
12
|
+
#include <poll.h>
|
13
|
+
#include <sys/wait.h>
|
14
|
+
#include <signal.h>
|
15
|
+
|
16
|
+
#include "liburing.h"
|
17
|
+
|
18
|
+
#define POLL_COUNT 30000
|
19
|
+
|
20
|
+
static void *sqe_index[POLL_COUNT];
|
21
|
+
|
22
|
+
static int reap_events(struct io_uring *ring, unsigned nr_events, int nowait)
|
23
|
+
{
|
24
|
+
struct io_uring_cqe *cqe;
|
25
|
+
int i, ret = 0;
|
26
|
+
|
27
|
+
for (i = 0; i < nr_events; i++) {
|
28
|
+
if (!i && !nowait)
|
29
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
30
|
+
else
|
31
|
+
ret = io_uring_peek_cqe(ring, &cqe);
|
32
|
+
if (ret) {
|
33
|
+
if (ret != -EAGAIN)
|
34
|
+
fprintf(stderr, "cqe peek failed: %d\n", ret);
|
35
|
+
break;
|
36
|
+
}
|
37
|
+
io_uring_cqe_seen(ring, cqe);
|
38
|
+
}
|
39
|
+
|
40
|
+
return i ? i : ret;
|
41
|
+
}
|
42
|
+
|
43
|
+
static int del_polls(struct io_uring *ring, int fd, int nr)
|
44
|
+
{
|
45
|
+
int batch, i, ret;
|
46
|
+
struct io_uring_sqe *sqe;
|
47
|
+
|
48
|
+
while (nr) {
|
49
|
+
batch = 1024;
|
50
|
+
if (batch > nr)
|
51
|
+
batch = nr;
|
52
|
+
|
53
|
+
for (i = 0; i < batch; i++) {
|
54
|
+
void *data;
|
55
|
+
|
56
|
+
sqe = io_uring_get_sqe(ring);
|
57
|
+
data = sqe_index[lrand48() % nr];
|
58
|
+
io_uring_prep_poll_remove(sqe, (__u64)(uintptr_t)data);
|
59
|
+
}
|
60
|
+
|
61
|
+
ret = io_uring_submit(ring);
|
62
|
+
if (ret != batch) {
|
63
|
+
fprintf(stderr, "%s: failed submit, %d\n", __FUNCTION__, ret);
|
64
|
+
return 1;
|
65
|
+
}
|
66
|
+
nr -= batch;
|
67
|
+
ret = reap_events(ring, 2 * batch, 0);
|
68
|
+
}
|
69
|
+
return 0;
|
70
|
+
}
|
71
|
+
|
72
|
+
static int add_polls(struct io_uring *ring, int fd, int nr)
|
73
|
+
{
|
74
|
+
int batch, i, count, ret;
|
75
|
+
struct io_uring_sqe *sqe;
|
76
|
+
|
77
|
+
count = 0;
|
78
|
+
while (nr) {
|
79
|
+
batch = 1024;
|
80
|
+
if (batch > nr)
|
81
|
+
batch = nr;
|
82
|
+
|
83
|
+
for (i = 0; i < batch; i++) {
|
84
|
+
sqe = io_uring_get_sqe(ring);
|
85
|
+
io_uring_prep_poll_add(sqe, fd, POLLIN);
|
86
|
+
sqe_index[count++] = sqe;
|
87
|
+
sqe->user_data = (unsigned long) sqe;
|
88
|
+
}
|
89
|
+
|
90
|
+
ret = io_uring_submit(ring);
|
91
|
+
if (ret != batch) {
|
92
|
+
fprintf(stderr, "%s: failed submit, %d\n", __FUNCTION__, ret);
|
93
|
+
return 1;
|
94
|
+
}
|
95
|
+
nr -= batch;
|
96
|
+
reap_events(ring, batch, 1);
|
97
|
+
}
|
98
|
+
return 0;
|
99
|
+
}
|
100
|
+
|
101
|
+
int main(int argc, char *argv[])
|
102
|
+
{
|
103
|
+
struct io_uring ring;
|
104
|
+
struct io_uring_params p = { };
|
105
|
+
int pipe1[2];
|
106
|
+
int ret;
|
107
|
+
|
108
|
+
if (argc > 1)
|
109
|
+
return 0;
|
110
|
+
|
111
|
+
if (pipe(pipe1) != 0) {
|
112
|
+
perror("pipe");
|
113
|
+
return 1;
|
114
|
+
}
|
115
|
+
|
116
|
+
p.flags = IORING_SETUP_CQSIZE;
|
117
|
+
p.cq_entries = 16384;
|
118
|
+
ret = io_uring_queue_init_params(1024, &ring, &p);
|
119
|
+
if (ret) {
|
120
|
+
if (ret == -EINVAL) {
|
121
|
+
fprintf(stdout, "No CQSIZE, trying without\n");
|
122
|
+
ret = io_uring_queue_init(1024, &ring, 0);
|
123
|
+
if (ret) {
|
124
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
125
|
+
return 1;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
add_polls(&ring, pipe1[0], 30000);
|
131
|
+
del_polls(&ring, pipe1[0], 30000);
|
132
|
+
|
133
|
+
io_uring_queue_exit(&ring);
|
134
|
+
return 0;
|
135
|
+
}
|