polyphony 0.85 → 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 +4 -0
- data/Gemfile.lock +1 -1
- data/ext/polyphony/io_extensions.c +2 -3
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +1 -1
- data/test/test_backend.rb +1 -1
- 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 +223 -2
@@ -0,0 +1,283 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: test sharing a ring across a fork
|
4
|
+
*/
|
5
|
+
#include <fcntl.h>
|
6
|
+
#include <pthread.h>
|
7
|
+
#include <signal.h>
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <sys/mman.h>
|
12
|
+
#include <sys/stat.h>
|
13
|
+
#include <sys/types.h>
|
14
|
+
#include <sys/wait.h>
|
15
|
+
#include <unistd.h>
|
16
|
+
|
17
|
+
#include "liburing.h"
|
18
|
+
|
19
|
+
|
20
|
+
struct forktestmem
|
21
|
+
{
|
22
|
+
struct io_uring ring;
|
23
|
+
pthread_barrier_t barrier;
|
24
|
+
pthread_barrierattr_t barrierattr;
|
25
|
+
};
|
26
|
+
|
27
|
+
static int open_tempfile(const char *dir, const char *fname)
|
28
|
+
{
|
29
|
+
int fd;
|
30
|
+
char buf[32];
|
31
|
+
|
32
|
+
snprintf(buf, sizeof(buf), "%s/%s",
|
33
|
+
dir, fname);
|
34
|
+
fd = open(buf, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
|
35
|
+
if (fd < 0) {
|
36
|
+
perror("open");
|
37
|
+
exit(1);
|
38
|
+
}
|
39
|
+
|
40
|
+
return fd;
|
41
|
+
}
|
42
|
+
|
43
|
+
static int submit_write(struct io_uring *ring, int fd, const char *str,
|
44
|
+
int wait)
|
45
|
+
{
|
46
|
+
struct io_uring_sqe *sqe;
|
47
|
+
struct iovec iovec;
|
48
|
+
int ret;
|
49
|
+
|
50
|
+
sqe = io_uring_get_sqe(ring);
|
51
|
+
if (!sqe) {
|
52
|
+
fprintf(stderr, "could not get sqe\n");
|
53
|
+
return 1;
|
54
|
+
}
|
55
|
+
|
56
|
+
iovec.iov_base = (char *) str;
|
57
|
+
iovec.iov_len = strlen(str);
|
58
|
+
io_uring_prep_writev(sqe, fd, &iovec, 1, 0);
|
59
|
+
ret = io_uring_submit_and_wait(ring, wait);
|
60
|
+
if (ret < 0) {
|
61
|
+
fprintf(stderr, "submit failed: %s\n", strerror(-ret));
|
62
|
+
return 1;
|
63
|
+
}
|
64
|
+
|
65
|
+
return 0;
|
66
|
+
}
|
67
|
+
|
68
|
+
static int wait_cqe(struct io_uring *ring, const char *stage)
|
69
|
+
{
|
70
|
+
struct io_uring_cqe *cqe;
|
71
|
+
int ret;
|
72
|
+
|
73
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
74
|
+
if (ret) {
|
75
|
+
fprintf(stderr, "%s wait_cqe failed %d\n", stage, ret);
|
76
|
+
return 1;
|
77
|
+
}
|
78
|
+
if (cqe->res < 0) {
|
79
|
+
fprintf(stderr, "%s cqe failed %d\n", stage, cqe->res);
|
80
|
+
return 1;
|
81
|
+
}
|
82
|
+
|
83
|
+
io_uring_cqe_seen(ring, cqe);
|
84
|
+
return 0;
|
85
|
+
}
|
86
|
+
|
87
|
+
static int verify_file(const char *tmpdir, const char *fname, const char* expect)
|
88
|
+
{
|
89
|
+
int fd;
|
90
|
+
char buf[512];
|
91
|
+
int err = 0;
|
92
|
+
|
93
|
+
memset(buf, 0, sizeof(buf));
|
94
|
+
|
95
|
+
fd = open_tempfile(tmpdir, fname);
|
96
|
+
if (fd < 0)
|
97
|
+
return 1;
|
98
|
+
|
99
|
+
if (read(fd, buf, sizeof(buf) - 1) < 0)
|
100
|
+
return 1;
|
101
|
+
|
102
|
+
if (strcmp(buf, expect) != 0) {
|
103
|
+
fprintf(stderr, "content mismatch for %s\n"
|
104
|
+
"got:\n%s\n"
|
105
|
+
"expected:\n%s\n",
|
106
|
+
fname, buf, expect);
|
107
|
+
err = 1;
|
108
|
+
}
|
109
|
+
|
110
|
+
close(fd);
|
111
|
+
return err;
|
112
|
+
}
|
113
|
+
|
114
|
+
static void cleanup(const char *tmpdir)
|
115
|
+
{
|
116
|
+
char buf[32];
|
117
|
+
|
118
|
+
/* don't check errors, called during partial runs */
|
119
|
+
|
120
|
+
snprintf(buf, sizeof(buf), "%s/%s", tmpdir, "shared");
|
121
|
+
unlink(buf);
|
122
|
+
|
123
|
+
snprintf(buf, sizeof(buf), "%s/%s", tmpdir, "parent1");
|
124
|
+
unlink(buf);
|
125
|
+
|
126
|
+
snprintf(buf, sizeof(buf), "%s/%s", tmpdir, "parent2");
|
127
|
+
unlink(buf);
|
128
|
+
|
129
|
+
snprintf(buf, sizeof(buf), "%s/%s", tmpdir, "child");
|
130
|
+
unlink(buf);
|
131
|
+
|
132
|
+
rmdir(tmpdir);
|
133
|
+
}
|
134
|
+
|
135
|
+
int main(int argc, char *argv[])
|
136
|
+
{
|
137
|
+
struct forktestmem *shmem;
|
138
|
+
char tmpdir[] = "forktmpXXXXXX";
|
139
|
+
int shared_fd;
|
140
|
+
int ret;
|
141
|
+
pid_t p;
|
142
|
+
|
143
|
+
if (argc > 1)
|
144
|
+
return 0;
|
145
|
+
|
146
|
+
shmem = mmap(0, sizeof(struct forktestmem), PROT_READ|PROT_WRITE,
|
147
|
+
MAP_SHARED | MAP_ANONYMOUS, 0, 0);
|
148
|
+
if (!shmem) {
|
149
|
+
fprintf(stderr, "mmap failed\n");
|
150
|
+
exit(1);
|
151
|
+
}
|
152
|
+
|
153
|
+
pthread_barrierattr_init(&shmem->barrierattr);
|
154
|
+
pthread_barrierattr_setpshared(&shmem->barrierattr, 1);
|
155
|
+
pthread_barrier_init(&shmem->barrier, &shmem->barrierattr, 2);
|
156
|
+
|
157
|
+
ret = io_uring_queue_init(10, &shmem->ring, 0);
|
158
|
+
if (ret < 0) {
|
159
|
+
fprintf(stderr, "queue init failed\n");
|
160
|
+
exit(1);
|
161
|
+
}
|
162
|
+
|
163
|
+
if (mkdtemp(tmpdir) == NULL) {
|
164
|
+
fprintf(stderr, "temp directory creation failed\n");
|
165
|
+
exit(1);
|
166
|
+
}
|
167
|
+
|
168
|
+
shared_fd = open_tempfile(tmpdir, "shared");
|
169
|
+
|
170
|
+
/*
|
171
|
+
* First do a write before the fork, to test whether child can
|
172
|
+
* reap that
|
173
|
+
*/
|
174
|
+
if (submit_write(&shmem->ring, shared_fd, "before fork: write shared fd\n", 0))
|
175
|
+
goto errcleanup;
|
176
|
+
|
177
|
+
p = fork();
|
178
|
+
switch (p) {
|
179
|
+
case -1:
|
180
|
+
fprintf(stderr, "fork failed\n");
|
181
|
+
goto errcleanup;
|
182
|
+
|
183
|
+
default: {
|
184
|
+
/* parent */
|
185
|
+
int parent_fd1;
|
186
|
+
int parent_fd2;
|
187
|
+
int wstatus;
|
188
|
+
|
189
|
+
/* wait till fork is started up */
|
190
|
+
pthread_barrier_wait(&shmem->barrier);
|
191
|
+
|
192
|
+
parent_fd1 = open_tempfile(tmpdir, "parent1");
|
193
|
+
parent_fd2 = open_tempfile(tmpdir, "parent2");
|
194
|
+
|
195
|
+
/* do a parent write to the shared fd */
|
196
|
+
if (submit_write(&shmem->ring, shared_fd, "parent: write shared fd\n", 0))
|
197
|
+
goto errcleanup;
|
198
|
+
|
199
|
+
/* do a parent write to an fd where same numbered fd exists in child */
|
200
|
+
if (submit_write(&shmem->ring, parent_fd1, "parent: write parent fd 1\n", 0))
|
201
|
+
goto errcleanup;
|
202
|
+
|
203
|
+
/* do a parent write to an fd where no same numbered fd exists in child */
|
204
|
+
if (submit_write(&shmem->ring, parent_fd2, "parent: write parent fd 2\n", 0))
|
205
|
+
goto errcleanup;
|
206
|
+
|
207
|
+
/* wait to switch read/writ roles with child */
|
208
|
+
pthread_barrier_wait(&shmem->barrier);
|
209
|
+
|
210
|
+
/* now wait for child to exit, to ensure we still can read completion */
|
211
|
+
waitpid(p, &wstatus, 0);
|
212
|
+
if (WEXITSTATUS(wstatus) != 0) {
|
213
|
+
fprintf(stderr, "child failed\n");
|
214
|
+
goto errcleanup;
|
215
|
+
}
|
216
|
+
|
217
|
+
if (wait_cqe(&shmem->ring, "p cqe 1"))
|
218
|
+
goto errcleanup;
|
219
|
+
|
220
|
+
if (wait_cqe(&shmem->ring, "p cqe 2"))
|
221
|
+
goto errcleanup;
|
222
|
+
|
223
|
+
/* check that IO can still be submitted after child exited */
|
224
|
+
if (submit_write(&shmem->ring, shared_fd, "parent: write shared fd after child exit\n", 0))
|
225
|
+
goto errcleanup;
|
226
|
+
|
227
|
+
if (wait_cqe(&shmem->ring, "p cqe 3"))
|
228
|
+
goto errcleanup;
|
229
|
+
|
230
|
+
break;
|
231
|
+
}
|
232
|
+
case 0: {
|
233
|
+
/* child */
|
234
|
+
int child_fd;
|
235
|
+
|
236
|
+
/* wait till fork is started up */
|
237
|
+
pthread_barrier_wait(&shmem->barrier);
|
238
|
+
|
239
|
+
child_fd = open_tempfile(tmpdir, "child");
|
240
|
+
|
241
|
+
if (wait_cqe(&shmem->ring, "c cqe shared"))
|
242
|
+
exit(1);
|
243
|
+
|
244
|
+
if (wait_cqe(&shmem->ring, "c cqe parent 1"))
|
245
|
+
exit(1);
|
246
|
+
|
247
|
+
if (wait_cqe(&shmem->ring, "c cqe parent 2"))
|
248
|
+
exit(1);
|
249
|
+
|
250
|
+
if (wait_cqe(&shmem->ring, "c cqe parent 3"))
|
251
|
+
exit(1);
|
252
|
+
|
253
|
+
/* wait to switch read/writ roles with parent */
|
254
|
+
pthread_barrier_wait(&shmem->barrier);
|
255
|
+
|
256
|
+
if (submit_write(&shmem->ring, child_fd, "child: write child fd\n", 0))
|
257
|
+
exit(1);
|
258
|
+
|
259
|
+
/* ensure both writes have finished before child exits */
|
260
|
+
if (submit_write(&shmem->ring, shared_fd, "child: write shared fd\n", 2))
|
261
|
+
exit(1);
|
262
|
+
|
263
|
+
exit(0);
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
if (verify_file(tmpdir, "shared",
|
268
|
+
"before fork: write shared fd\n"
|
269
|
+
"parent: write shared fd\n"
|
270
|
+
"child: write shared fd\n"
|
271
|
+
"parent: write shared fd after child exit\n") ||
|
272
|
+
verify_file(tmpdir, "parent1", "parent: write parent fd 1\n") ||
|
273
|
+
verify_file(tmpdir, "parent2", "parent: write parent fd 2\n") ||
|
274
|
+
verify_file(tmpdir, "child", "child: write child fd\n"))
|
275
|
+
goto errcleanup;
|
276
|
+
|
277
|
+
cleanup(tmpdir);
|
278
|
+
exit(0);
|
279
|
+
|
280
|
+
errcleanup:
|
281
|
+
cleanup(tmpdir);
|
282
|
+
exit(1);
|
283
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
// autogenerated by syzkaller (https://github.com/google/syzkaller)
|
3
|
+
|
4
|
+
#include <endian.h>
|
5
|
+
#include <stdint.h>
|
6
|
+
#include <stdio.h>
|
7
|
+
#include <stdlib.h>
|
8
|
+
#include <string.h>
|
9
|
+
#include <sys/types.h>
|
10
|
+
#include <sys/mman.h>
|
11
|
+
#include <unistd.h>
|
12
|
+
|
13
|
+
#include "liburing.h"
|
14
|
+
#include "../src/syscall.h"
|
15
|
+
|
16
|
+
int main(int argc, char *argv[])
|
17
|
+
{
|
18
|
+
if (argc > 1)
|
19
|
+
return 0;
|
20
|
+
|
21
|
+
mmap((void *) 0x20000000, 0x1000000, 3, 0x32, -1, 0);
|
22
|
+
|
23
|
+
*(uint32_t*)0x20000200 = 0;
|
24
|
+
*(uint32_t*)0x20000204 = 0;
|
25
|
+
*(uint32_t*)0x20000208 = 5;
|
26
|
+
*(uint32_t*)0x2000020c = 0x400;
|
27
|
+
*(uint32_t*)0x20000210 = 0;
|
28
|
+
*(uint32_t*)0x20000214 = 0;
|
29
|
+
*(uint32_t*)0x20000218 = 0;
|
30
|
+
*(uint32_t*)0x2000021c = 0;
|
31
|
+
*(uint32_t*)0x20000220 = 0;
|
32
|
+
*(uint32_t*)0x20000224 = 0;
|
33
|
+
*(uint32_t*)0x20000228 = 0;
|
34
|
+
*(uint32_t*)0x2000022c = 0;
|
35
|
+
*(uint32_t*)0x20000230 = 0;
|
36
|
+
*(uint32_t*)0x20000234 = 0;
|
37
|
+
*(uint32_t*)0x20000238 = 0;
|
38
|
+
*(uint32_t*)0x2000023c = 0;
|
39
|
+
*(uint32_t*)0x20000240 = 0;
|
40
|
+
*(uint32_t*)0x20000244 = 0;
|
41
|
+
*(uint64_t*)0x20000248 = 0;
|
42
|
+
*(uint32_t*)0x20000250 = 0;
|
43
|
+
*(uint32_t*)0x20000254 = 0;
|
44
|
+
*(uint32_t*)0x20000258 = 0;
|
45
|
+
*(uint32_t*)0x2000025c = 0;
|
46
|
+
*(uint32_t*)0x20000260 = 0;
|
47
|
+
*(uint32_t*)0x20000264 = 0;
|
48
|
+
*(uint32_t*)0x20000268 = 0;
|
49
|
+
*(uint32_t*)0x2000026c = 0;
|
50
|
+
*(uint64_t*)0x20000270 = 0;
|
51
|
+
__sys_io_uring_setup(0xc9f, (struct io_uring_params *) 0x20000200);
|
52
|
+
return 0;
|
53
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: Check to see if wait_nr is being honored.
|
4
|
+
*/
|
5
|
+
#include <stdio.h>
|
6
|
+
#include "liburing.h"
|
7
|
+
|
8
|
+
int main(int argc, char *argv[])
|
9
|
+
{
|
10
|
+
struct io_uring_sqe *sqe;
|
11
|
+
struct io_uring_cqe *cqe;
|
12
|
+
struct io_uring ring;
|
13
|
+
int ret;
|
14
|
+
struct __kernel_timespec ts = {
|
15
|
+
.tv_sec = 0,
|
16
|
+
.tv_nsec = 10000000
|
17
|
+
};
|
18
|
+
|
19
|
+
if (argc > 1)
|
20
|
+
return 0;
|
21
|
+
|
22
|
+
if (io_uring_queue_init(4, &ring, 0) != 0) {
|
23
|
+
fprintf(stderr, "ring setup failed\n");
|
24
|
+
return 1;
|
25
|
+
}
|
26
|
+
|
27
|
+
/*
|
28
|
+
* First, submit the timeout sqe so we can actually finish the test
|
29
|
+
* if everything is in working order.
|
30
|
+
*/
|
31
|
+
sqe = io_uring_get_sqe(&ring);
|
32
|
+
if (!sqe) {
|
33
|
+
fprintf(stderr, "get sqe failed\n");
|
34
|
+
return 1;
|
35
|
+
}
|
36
|
+
io_uring_prep_timeout(sqe, &ts, (unsigned)-1, 0);
|
37
|
+
|
38
|
+
ret = io_uring_submit(&ring);
|
39
|
+
if (ret != 1) {
|
40
|
+
fprintf(stderr, "Got submit %d, expected 1\n", ret);
|
41
|
+
return 1;
|
42
|
+
}
|
43
|
+
|
44
|
+
/*
|
45
|
+
* Next, submit a nop and wait for two events. If everything is working
|
46
|
+
* as it should, we should be waiting for more than a millisecond and we
|
47
|
+
* should see two cqes. Otherwise, execution continues immediately
|
48
|
+
* and we see only one cqe.
|
49
|
+
*/
|
50
|
+
sqe = io_uring_get_sqe(&ring);
|
51
|
+
if (!sqe) {
|
52
|
+
fprintf(stderr, "get sqe failed\n");
|
53
|
+
return 1;
|
54
|
+
}
|
55
|
+
io_uring_prep_nop(sqe);
|
56
|
+
|
57
|
+
ret = io_uring_submit_and_wait(&ring, 2);
|
58
|
+
if (ret != 1) {
|
59
|
+
fprintf(stderr, "Got submit %d, expected 1\n", ret);
|
60
|
+
return 1;
|
61
|
+
}
|
62
|
+
|
63
|
+
if (io_uring_peek_cqe(&ring, &cqe) != 0) {
|
64
|
+
fprintf(stderr, "Unable to peek cqe!\n");
|
65
|
+
return 1;
|
66
|
+
}
|
67
|
+
|
68
|
+
io_uring_cqe_seen(&ring, cqe);
|
69
|
+
|
70
|
+
if (io_uring_peek_cqe(&ring, &cqe) != 0) {
|
71
|
+
fprintf(stderr, "Unable to peek cqe!\n");
|
72
|
+
return 1;
|
73
|
+
}
|
74
|
+
|
75
|
+
io_uring_queue_exit(&ring);
|
76
|
+
return 0;
|
77
|
+
}
|
@@ -0,0 +1,136 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Test 5.7 regression with task_work not being run while a task is
|
4
|
+
* waiting on another event in the kernel.
|
5
|
+
*/
|
6
|
+
#include <errno.h>
|
7
|
+
#include <poll.h>
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <sys/eventfd.h>
|
11
|
+
#include <unistd.h>
|
12
|
+
#include <pthread.h>
|
13
|
+
#include "liburing.h"
|
14
|
+
#include "helpers.h"
|
15
|
+
|
16
|
+
static int use_sqpoll = 0;
|
17
|
+
|
18
|
+
void notify_fd(int fd)
|
19
|
+
{
|
20
|
+
char buf[8] = {0, 0, 0, 0, 0, 0, 1};
|
21
|
+
int ret;
|
22
|
+
|
23
|
+
ret = write(fd, &buf, 8);
|
24
|
+
if (ret < 0)
|
25
|
+
perror("write");
|
26
|
+
}
|
27
|
+
|
28
|
+
void *delay_set_fd_from_thread(void *data)
|
29
|
+
{
|
30
|
+
int fd = (intptr_t) data;
|
31
|
+
|
32
|
+
sleep(1);
|
33
|
+
notify_fd(fd);
|
34
|
+
return NULL;
|
35
|
+
}
|
36
|
+
|
37
|
+
int main(int argc, char *argv[])
|
38
|
+
{
|
39
|
+
struct io_uring_params p = {};
|
40
|
+
struct io_uring ring;
|
41
|
+
int loop_fd, other_fd;
|
42
|
+
struct io_uring_sqe *sqe;
|
43
|
+
struct io_uring_cqe *cqe = NULL;
|
44
|
+
int ret, use_fd;
|
45
|
+
char buf[8] = {0, 0, 0, 0, 0, 0, 1};
|
46
|
+
pthread_t tid;
|
47
|
+
|
48
|
+
if (argc > 1)
|
49
|
+
return 0;
|
50
|
+
|
51
|
+
/* Create an eventfd to be registered with the loop to be
|
52
|
+
* notified of events being ready
|
53
|
+
*/
|
54
|
+
loop_fd = eventfd(0, EFD_CLOEXEC);
|
55
|
+
if (loop_fd == -1) {
|
56
|
+
fprintf(stderr, "eventfd errno=%d\n", errno);
|
57
|
+
return 1;
|
58
|
+
}
|
59
|
+
|
60
|
+
/* Create an eventfd that can create events */
|
61
|
+
use_fd = other_fd = eventfd(0, EFD_CLOEXEC);
|
62
|
+
if (other_fd == -1) {
|
63
|
+
fprintf(stderr, "eventfd errno=%d\n", errno);
|
64
|
+
return 1;
|
65
|
+
}
|
66
|
+
|
67
|
+
if (use_sqpoll)
|
68
|
+
p.flags = IORING_SETUP_SQPOLL;
|
69
|
+
|
70
|
+
/* Setup the ring with a registered event fd to be notified on events */
|
71
|
+
ret = t_create_ring_params(8, &ring, &p);
|
72
|
+
if (ret == T_SETUP_SKIP)
|
73
|
+
return 0;
|
74
|
+
else if (ret < 0)
|
75
|
+
return ret;
|
76
|
+
|
77
|
+
ret = io_uring_register_eventfd(&ring, loop_fd);
|
78
|
+
if (ret < 0) {
|
79
|
+
fprintf(stderr, "register_eventfd=%d\n", ret);
|
80
|
+
return 1;
|
81
|
+
}
|
82
|
+
|
83
|
+
if (use_sqpoll) {
|
84
|
+
ret = io_uring_register_files(&ring, &other_fd, 1);
|
85
|
+
if (ret < 0) {
|
86
|
+
fprintf(stderr, "register_files=%d\n", ret);
|
87
|
+
return 1;
|
88
|
+
}
|
89
|
+
use_fd = 0;
|
90
|
+
}
|
91
|
+
|
92
|
+
/* Submit a poll operation to wait on an event in other_fd */
|
93
|
+
sqe = io_uring_get_sqe(&ring);
|
94
|
+
io_uring_prep_poll_add(sqe, use_fd, POLLIN);
|
95
|
+
sqe->user_data = 1;
|
96
|
+
if (use_sqpoll)
|
97
|
+
sqe->flags |= IOSQE_FIXED_FILE;
|
98
|
+
ret = io_uring_submit(&ring);
|
99
|
+
if (ret != 1) {
|
100
|
+
fprintf(stderr, "submit=%d\n", ret);
|
101
|
+
return 1;
|
102
|
+
}
|
103
|
+
|
104
|
+
/*
|
105
|
+
* CASE 3: Hangs forever in Linux 5.7.5; Works in Linux 5.6.0 When this
|
106
|
+
* code is uncommented, we don't se a notification on other_fd until
|
107
|
+
* _after_ we have started the read on loop_fd. In that case, the read() on
|
108
|
+
* loop_fd seems to hang forever.
|
109
|
+
*/
|
110
|
+
pthread_create(&tid, NULL, delay_set_fd_from_thread,
|
111
|
+
(void*) (intptr_t) other_fd);
|
112
|
+
|
113
|
+
/* Wait on the event fd for an event to be ready */
|
114
|
+
ret = read(loop_fd, buf, 8);
|
115
|
+
if (ret < 0) {
|
116
|
+
perror("read");
|
117
|
+
return 1;
|
118
|
+
} else if (ret != 8) {
|
119
|
+
fprintf(stderr, "Odd-sized eventfd read: %d\n", ret);
|
120
|
+
return 1;
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
125
|
+
if (ret) {
|
126
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
127
|
+
return ret;
|
128
|
+
}
|
129
|
+
if (cqe->res < 0) {
|
130
|
+
fprintf(stderr, "cqe->res=%d\n", cqe->res);
|
131
|
+
return 1;
|
132
|
+
}
|
133
|
+
|
134
|
+
io_uring_cqe_seen(&ring, cqe);
|
135
|
+
return 0;
|
136
|
+
}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
|
3
|
+
#define _GNU_SOURCE 1
|
4
|
+
#define _FILE_OFFSET_BITS 64
|
5
|
+
|
6
|
+
// Test program for io_uring IORING_OP_CLOSE with O_PATH file.
|
7
|
+
// Author: Clayton Harris <bugs@claycon.org>, 2020-06-07
|
8
|
+
|
9
|
+
// linux 5.6.14-300.fc32.x86_64
|
10
|
+
// gcc 10.1.1-1.fc32
|
11
|
+
// liburing.x86_64 0.5-1.fc32
|
12
|
+
|
13
|
+
// gcc -O2 -Wall -Wextra -std=c11 -o close_opath close_opath.c -luring
|
14
|
+
// ./close_opath testfilepath
|
15
|
+
|
16
|
+
#include <errno.h>
|
17
|
+
#include <fcntl.h>
|
18
|
+
#include <liburing.h>
|
19
|
+
#include <sys/stat.h>
|
20
|
+
#include <stdio.h>
|
21
|
+
#include <string.h>
|
22
|
+
#include <unistd.h>
|
23
|
+
|
24
|
+
typedef struct
|
25
|
+
{
|
26
|
+
const char *const flnames;
|
27
|
+
const int oflags;
|
28
|
+
} oflgs_t;
|
29
|
+
|
30
|
+
static int test_io_uring_close(struct io_uring *ring, int fd)
|
31
|
+
{
|
32
|
+
struct io_uring_sqe *sqe;
|
33
|
+
struct io_uring_cqe *cqe;
|
34
|
+
int ret;
|
35
|
+
|
36
|
+
sqe = io_uring_get_sqe(ring);
|
37
|
+
if (!sqe) {
|
38
|
+
fprintf(stderr, "io_uring_get_sqe() failed\n");
|
39
|
+
return -ENOENT;
|
40
|
+
}
|
41
|
+
|
42
|
+
io_uring_prep_close(sqe, fd);
|
43
|
+
|
44
|
+
ret = io_uring_submit(ring);
|
45
|
+
if (ret < 0) {
|
46
|
+
fprintf(stderr, "io_uring_submit() failed, errno %d: %s\n",
|
47
|
+
-ret, strerror(-ret));
|
48
|
+
return ret;
|
49
|
+
}
|
50
|
+
|
51
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
52
|
+
if (ret < 0) {
|
53
|
+
fprintf(stderr, "io_uring_wait_cqe() failed, errno %d: %s\n",
|
54
|
+
-ret, strerror(-ret));
|
55
|
+
return ret;
|
56
|
+
}
|
57
|
+
|
58
|
+
ret = cqe->res;
|
59
|
+
io_uring_cqe_seen(ring, cqe);
|
60
|
+
|
61
|
+
if (ret < 0 && ret != -EOPNOTSUPP && ret != -EINVAL && ret != -EBADF) {
|
62
|
+
fprintf(stderr, "io_uring close() failed, errno %d: %s\n",
|
63
|
+
-ret, strerror(-ret));
|
64
|
+
return ret;
|
65
|
+
}
|
66
|
+
|
67
|
+
return 0;
|
68
|
+
}
|
69
|
+
|
70
|
+
static int open_file(const char *path, const oflgs_t *oflgs)
|
71
|
+
{
|
72
|
+
int fd;
|
73
|
+
|
74
|
+
fd = openat(AT_FDCWD, path, oflgs->oflags, 0);
|
75
|
+
if (fd < 0) {
|
76
|
+
int err = errno;
|
77
|
+
fprintf(stderr, "openat(%s, %s) failed, errno %d: %s\n",
|
78
|
+
path, oflgs->flnames, err, strerror(err));
|
79
|
+
return -err;
|
80
|
+
}
|
81
|
+
|
82
|
+
return fd;
|
83
|
+
}
|
84
|
+
|
85
|
+
int main(int argc, char *argv[])
|
86
|
+
{
|
87
|
+
const char *fname = ".";
|
88
|
+
struct io_uring ring;
|
89
|
+
int ret, i;
|
90
|
+
static const oflgs_t oflgs[] = {
|
91
|
+
{ "O_RDONLY", O_RDONLY },
|
92
|
+
{ "O_PATH", O_PATH }
|
93
|
+
};
|
94
|
+
|
95
|
+
ret = io_uring_queue_init(2, &ring, 0);
|
96
|
+
if (ret < 0) {
|
97
|
+
fprintf(stderr, "io_uring_queue_init() failed, errno %d: %s\n",
|
98
|
+
-ret, strerror(-ret));
|
99
|
+
return 0x02;
|
100
|
+
}
|
101
|
+
|
102
|
+
#define OFLGS_SIZE (sizeof(oflgs) / sizeof(oflgs[0]))
|
103
|
+
|
104
|
+
ret = 0;
|
105
|
+
for (i = 0; i < OFLGS_SIZE; i++) {
|
106
|
+
int fd;
|
107
|
+
|
108
|
+
fd = open_file(fname, &oflgs[i]);
|
109
|
+
if (fd < 0) {
|
110
|
+
ret |= 0x02;
|
111
|
+
break;
|
112
|
+
}
|
113
|
+
|
114
|
+
/* Should always succeed */
|
115
|
+
if (test_io_uring_close(&ring, fd) < 0)
|
116
|
+
ret |= 0x04 << i;
|
117
|
+
}
|
118
|
+
#undef OFLGS_SIZE
|
119
|
+
|
120
|
+
io_uring_queue_exit(&ring);
|
121
|
+
return ret;
|
122
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Copy this to config.local, uncomment and define values
|
2
|
+
#
|
3
|
+
# Define tests to exclude from running
|
4
|
+
# TEST_EXCLUDE=""
|
5
|
+
#
|
6
|
+
# Define raw test devices (or files) for test cases, if any
|
7
|
+
# declare -A TEST_MAP=()
|
8
|
+
#
|
9
|
+
# If no TEST_MAP entry exists for a test, use the ones given in TEST_FILES
|
10
|
+
# TEST_FILES="/dev/somedevice /data/somefile"
|