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,293 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
#define _POSIX_C_SOURCE 200112L
|
3
|
+
|
4
|
+
#include "lib.h"
|
5
|
+
#include "syscall.h"
|
6
|
+
#include "liburing.h"
|
7
|
+
#include "int_flags.h"
|
8
|
+
#include "liburing/compat.h"
|
9
|
+
#include "liburing/io_uring.h"
|
10
|
+
|
11
|
+
|
12
|
+
int io_uring_register_buffers_update_tag(struct io_uring *ring, unsigned off,
|
13
|
+
const struct iovec *iovecs,
|
14
|
+
const __u64 *tags,
|
15
|
+
unsigned nr)
|
16
|
+
{
|
17
|
+
struct io_uring_rsrc_update2 up = {
|
18
|
+
.offset = off,
|
19
|
+
.data = (unsigned long)iovecs,
|
20
|
+
.tags = (unsigned long)tags,
|
21
|
+
.nr = nr,
|
22
|
+
};
|
23
|
+
|
24
|
+
return ____sys_io_uring_register(ring->ring_fd,
|
25
|
+
IORING_REGISTER_BUFFERS_UPDATE, &up,
|
26
|
+
sizeof(up));
|
27
|
+
}
|
28
|
+
|
29
|
+
int io_uring_register_buffers_tags(struct io_uring *ring,
|
30
|
+
const struct iovec *iovecs,
|
31
|
+
const __u64 *tags,
|
32
|
+
unsigned nr)
|
33
|
+
{
|
34
|
+
struct io_uring_rsrc_register reg = {
|
35
|
+
.nr = nr,
|
36
|
+
.data = (unsigned long)iovecs,
|
37
|
+
.tags = (unsigned long)tags,
|
38
|
+
};
|
39
|
+
|
40
|
+
return ____sys_io_uring_register(ring->ring_fd, IORING_REGISTER_BUFFERS2,
|
41
|
+
®, sizeof(reg));
|
42
|
+
}
|
43
|
+
|
44
|
+
int io_uring_register_buffers(struct io_uring *ring, const struct iovec *iovecs,
|
45
|
+
unsigned nr_iovecs)
|
46
|
+
{
|
47
|
+
int ret;
|
48
|
+
|
49
|
+
ret = ____sys_io_uring_register(ring->ring_fd, IORING_REGISTER_BUFFERS,
|
50
|
+
iovecs, nr_iovecs);
|
51
|
+
return (ret < 0) ? ret : 0;
|
52
|
+
}
|
53
|
+
|
54
|
+
int io_uring_unregister_buffers(struct io_uring *ring)
|
55
|
+
{
|
56
|
+
int ret;
|
57
|
+
|
58
|
+
ret = ____sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_BUFFERS,
|
59
|
+
NULL, 0);
|
60
|
+
return (ret < 0) ? ret : 0;
|
61
|
+
}
|
62
|
+
|
63
|
+
int io_uring_register_files_update_tag(struct io_uring *ring, unsigned off,
|
64
|
+
const int *files, const __u64 *tags,
|
65
|
+
unsigned nr_files)
|
66
|
+
{
|
67
|
+
struct io_uring_rsrc_update2 up = {
|
68
|
+
.offset = off,
|
69
|
+
.data = (unsigned long)files,
|
70
|
+
.tags = (unsigned long)tags,
|
71
|
+
.nr = nr_files,
|
72
|
+
};
|
73
|
+
|
74
|
+
return ____sys_io_uring_register(ring->ring_fd,
|
75
|
+
IORING_REGISTER_FILES_UPDATE2, &up,
|
76
|
+
sizeof(up));
|
77
|
+
}
|
78
|
+
|
79
|
+
/*
|
80
|
+
* Register an update for an existing file set. The updates will start at
|
81
|
+
* 'off' in the original array, and 'nr_files' is the number of files we'll
|
82
|
+
* update.
|
83
|
+
*
|
84
|
+
* Returns number of files updated on success, -ERROR on failure.
|
85
|
+
*/
|
86
|
+
int io_uring_register_files_update(struct io_uring *ring, unsigned off,
|
87
|
+
int *files, unsigned nr_files)
|
88
|
+
{
|
89
|
+
struct io_uring_files_update up = {
|
90
|
+
.offset = off,
|
91
|
+
.fds = (unsigned long) files,
|
92
|
+
};
|
93
|
+
|
94
|
+
return ____sys_io_uring_register(ring->ring_fd,
|
95
|
+
IORING_REGISTER_FILES_UPDATE, &up,
|
96
|
+
nr_files);
|
97
|
+
}
|
98
|
+
|
99
|
+
static int increase_rlimit_nofile(unsigned nr)
|
100
|
+
{
|
101
|
+
int ret;
|
102
|
+
struct rlimit rlim;
|
103
|
+
|
104
|
+
ret = __sys_getrlimit(RLIMIT_NOFILE, &rlim);
|
105
|
+
if (ret < 0)
|
106
|
+
return ret;
|
107
|
+
|
108
|
+
if (rlim.rlim_cur < nr) {
|
109
|
+
rlim.rlim_cur += nr;
|
110
|
+
__sys_setrlimit(RLIMIT_NOFILE, &rlim);
|
111
|
+
}
|
112
|
+
|
113
|
+
return 0;
|
114
|
+
}
|
115
|
+
|
116
|
+
int io_uring_register_files_tags(struct io_uring *ring, const int *files,
|
117
|
+
const __u64 *tags, unsigned nr)
|
118
|
+
{
|
119
|
+
struct io_uring_rsrc_register reg = {
|
120
|
+
.nr = nr,
|
121
|
+
.data = (unsigned long)files,
|
122
|
+
.tags = (unsigned long)tags,
|
123
|
+
};
|
124
|
+
int ret, did_increase = 0;
|
125
|
+
|
126
|
+
do {
|
127
|
+
ret = ____sys_io_uring_register(ring->ring_fd,
|
128
|
+
IORING_REGISTER_FILES2, ®,
|
129
|
+
sizeof(reg));
|
130
|
+
if (ret >= 0)
|
131
|
+
break;
|
132
|
+
if (ret == -EMFILE && !did_increase) {
|
133
|
+
did_increase = 1;
|
134
|
+
increase_rlimit_nofile(nr);
|
135
|
+
continue;
|
136
|
+
}
|
137
|
+
break;
|
138
|
+
} while (1);
|
139
|
+
|
140
|
+
return ret;
|
141
|
+
}
|
142
|
+
|
143
|
+
int io_uring_register_files(struct io_uring *ring, const int *files,
|
144
|
+
unsigned nr_files)
|
145
|
+
{
|
146
|
+
int ret, did_increase = 0;
|
147
|
+
|
148
|
+
do {
|
149
|
+
ret = ____sys_io_uring_register(ring->ring_fd,
|
150
|
+
IORING_REGISTER_FILES, files,
|
151
|
+
nr_files);
|
152
|
+
if (ret >= 0)
|
153
|
+
break;
|
154
|
+
if (ret == -EMFILE && !did_increase) {
|
155
|
+
did_increase = 1;
|
156
|
+
increase_rlimit_nofile(nr_files);
|
157
|
+
continue;
|
158
|
+
}
|
159
|
+
break;
|
160
|
+
} while (1);
|
161
|
+
|
162
|
+
return ret;
|
163
|
+
}
|
164
|
+
|
165
|
+
int io_uring_unregister_files(struct io_uring *ring)
|
166
|
+
{
|
167
|
+
int ret;
|
168
|
+
|
169
|
+
ret = ____sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_FILES,
|
170
|
+
NULL, 0);
|
171
|
+
return (ret < 0) ? ret : 0;
|
172
|
+
}
|
173
|
+
|
174
|
+
int io_uring_register_eventfd(struct io_uring *ring, int event_fd)
|
175
|
+
{
|
176
|
+
int ret;
|
177
|
+
|
178
|
+
ret = ____sys_io_uring_register(ring->ring_fd, IORING_REGISTER_EVENTFD,
|
179
|
+
&event_fd, 1);
|
180
|
+
return (ret < 0) ? ret : 0;
|
181
|
+
}
|
182
|
+
|
183
|
+
int io_uring_unregister_eventfd(struct io_uring *ring)
|
184
|
+
{
|
185
|
+
int ret;
|
186
|
+
|
187
|
+
ret = ____sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_EVENTFD,
|
188
|
+
NULL, 0);
|
189
|
+
return (ret < 0) ? ret : 0;
|
190
|
+
}
|
191
|
+
|
192
|
+
int io_uring_register_eventfd_async(struct io_uring *ring, int event_fd)
|
193
|
+
{
|
194
|
+
int ret;
|
195
|
+
|
196
|
+
ret = ____sys_io_uring_register(ring->ring_fd,
|
197
|
+
IORING_REGISTER_EVENTFD_ASYNC,
|
198
|
+
&event_fd, 1);
|
199
|
+
return (ret < 0) ? ret : 0;
|
200
|
+
}
|
201
|
+
|
202
|
+
int io_uring_register_probe(struct io_uring *ring, struct io_uring_probe *p,
|
203
|
+
unsigned int nr_ops)
|
204
|
+
{
|
205
|
+
int ret;
|
206
|
+
|
207
|
+
ret = ____sys_io_uring_register(ring->ring_fd, IORING_REGISTER_PROBE, p,
|
208
|
+
nr_ops);
|
209
|
+
return (ret < 0) ? ret : 0;
|
210
|
+
}
|
211
|
+
|
212
|
+
int io_uring_register_personality(struct io_uring *ring)
|
213
|
+
{
|
214
|
+
return ____sys_io_uring_register(ring->ring_fd,
|
215
|
+
IORING_REGISTER_PERSONALITY, NULL, 0);
|
216
|
+
}
|
217
|
+
|
218
|
+
int io_uring_unregister_personality(struct io_uring *ring, int id)
|
219
|
+
{
|
220
|
+
return ____sys_io_uring_register(ring->ring_fd,
|
221
|
+
IORING_UNREGISTER_PERSONALITY, NULL, id);
|
222
|
+
}
|
223
|
+
|
224
|
+
int io_uring_register_restrictions(struct io_uring *ring,
|
225
|
+
struct io_uring_restriction *res,
|
226
|
+
unsigned int nr_res)
|
227
|
+
{
|
228
|
+
int ret;
|
229
|
+
|
230
|
+
ret = ____sys_io_uring_register(ring->ring_fd,
|
231
|
+
IORING_REGISTER_RESTRICTIONS, res,
|
232
|
+
nr_res);
|
233
|
+
return (ret < 0) ? ret : 0;
|
234
|
+
}
|
235
|
+
|
236
|
+
int io_uring_enable_rings(struct io_uring *ring)
|
237
|
+
{
|
238
|
+
return ____sys_io_uring_register(ring->ring_fd,
|
239
|
+
IORING_REGISTER_ENABLE_RINGS, NULL, 0);
|
240
|
+
}
|
241
|
+
|
242
|
+
int io_uring_register_iowq_aff(struct io_uring *ring, size_t cpusz,
|
243
|
+
const cpu_set_t *mask)
|
244
|
+
{
|
245
|
+
return ____sys_io_uring_register(ring->ring_fd, IORING_REGISTER_IOWQ_AFF,
|
246
|
+
mask, cpusz);
|
247
|
+
}
|
248
|
+
|
249
|
+
int io_uring_unregister_iowq_aff(struct io_uring *ring)
|
250
|
+
{
|
251
|
+
return ____sys_io_uring_register(ring->ring_fd,
|
252
|
+
IORING_UNREGISTER_IOWQ_AFF, NULL, 0);
|
253
|
+
}
|
254
|
+
|
255
|
+
int io_uring_register_iowq_max_workers(struct io_uring *ring, unsigned int *val)
|
256
|
+
{
|
257
|
+
return ____sys_io_uring_register(ring->ring_fd,
|
258
|
+
IORING_REGISTER_IOWQ_MAX_WORKERS, val,
|
259
|
+
2);
|
260
|
+
}
|
261
|
+
|
262
|
+
int io_uring_register_ring_fd(struct io_uring *ring)
|
263
|
+
{
|
264
|
+
struct io_uring_rsrc_update up = {
|
265
|
+
.data = ring->ring_fd,
|
266
|
+
.offset = -1U,
|
267
|
+
};
|
268
|
+
int ret;
|
269
|
+
|
270
|
+
ret = ____sys_io_uring_register(ring->ring_fd, IORING_REGISTER_RING_FDS,
|
271
|
+
&up, 1);
|
272
|
+
if (ret == 1) {
|
273
|
+
ring->enter_ring_fd = up.offset;
|
274
|
+
ring->int_flags |= INT_FLAG_REG_RING;
|
275
|
+
}
|
276
|
+
return ret;
|
277
|
+
}
|
278
|
+
|
279
|
+
int io_uring_unregister_ring_fd(struct io_uring *ring)
|
280
|
+
{
|
281
|
+
struct io_uring_rsrc_update up = {
|
282
|
+
.offset = ring->enter_ring_fd,
|
283
|
+
};
|
284
|
+
int ret;
|
285
|
+
|
286
|
+
ret = ____sys_io_uring_register(ring->ring_fd,
|
287
|
+
IORING_UNREGISTER_RING_FDS, &up, 1);
|
288
|
+
if (ret == 1) {
|
289
|
+
ring->enter_ring_fd = ring->ring_fd;
|
290
|
+
ring->int_flags &= ~INT_FLAG_REG_RING;
|
291
|
+
}
|
292
|
+
return ret;
|
293
|
+
}
|
@@ -0,0 +1,332 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
#define _DEFAULT_SOURCE
|
3
|
+
|
4
|
+
#include "lib.h"
|
5
|
+
#include "syscall.h"
|
6
|
+
#include "liburing.h"
|
7
|
+
#include "int_flags.h"
|
8
|
+
#include "liburing/compat.h"
|
9
|
+
#include "liburing/io_uring.h"
|
10
|
+
|
11
|
+
|
12
|
+
static void io_uring_unmap_rings(struct io_uring_sq *sq, struct io_uring_cq *cq)
|
13
|
+
{
|
14
|
+
__sys_munmap(sq->ring_ptr, sq->ring_sz);
|
15
|
+
if (cq->ring_ptr && cq->ring_ptr != sq->ring_ptr)
|
16
|
+
__sys_munmap(cq->ring_ptr, cq->ring_sz);
|
17
|
+
}
|
18
|
+
|
19
|
+
static int io_uring_mmap(int fd, struct io_uring_params *p,
|
20
|
+
struct io_uring_sq *sq, struct io_uring_cq *cq)
|
21
|
+
{
|
22
|
+
size_t size;
|
23
|
+
int ret;
|
24
|
+
|
25
|
+
sq->ring_sz = p->sq_off.array + p->sq_entries * sizeof(unsigned);
|
26
|
+
cq->ring_sz = p->cq_off.cqes + p->cq_entries * sizeof(struct io_uring_cqe);
|
27
|
+
|
28
|
+
if (p->features & IORING_FEAT_SINGLE_MMAP) {
|
29
|
+
if (cq->ring_sz > sq->ring_sz)
|
30
|
+
sq->ring_sz = cq->ring_sz;
|
31
|
+
cq->ring_sz = sq->ring_sz;
|
32
|
+
}
|
33
|
+
sq->ring_ptr = __sys_mmap(0, sq->ring_sz, PROT_READ | PROT_WRITE,
|
34
|
+
MAP_SHARED | MAP_POPULATE, fd,
|
35
|
+
IORING_OFF_SQ_RING);
|
36
|
+
if (IS_ERR(sq->ring_ptr))
|
37
|
+
return PTR_ERR(sq->ring_ptr);
|
38
|
+
|
39
|
+
if (p->features & IORING_FEAT_SINGLE_MMAP) {
|
40
|
+
cq->ring_ptr = sq->ring_ptr;
|
41
|
+
} else {
|
42
|
+
cq->ring_ptr = __sys_mmap(0, cq->ring_sz, PROT_READ | PROT_WRITE,
|
43
|
+
MAP_SHARED | MAP_POPULATE, fd,
|
44
|
+
IORING_OFF_CQ_RING);
|
45
|
+
if (IS_ERR(cq->ring_ptr)) {
|
46
|
+
ret = PTR_ERR(cq->ring_ptr);
|
47
|
+
cq->ring_ptr = NULL;
|
48
|
+
goto err;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
sq->khead = sq->ring_ptr + p->sq_off.head;
|
53
|
+
sq->ktail = sq->ring_ptr + p->sq_off.tail;
|
54
|
+
sq->kring_mask = sq->ring_ptr + p->sq_off.ring_mask;
|
55
|
+
sq->kring_entries = sq->ring_ptr + p->sq_off.ring_entries;
|
56
|
+
sq->kflags = sq->ring_ptr + p->sq_off.flags;
|
57
|
+
sq->kdropped = sq->ring_ptr + p->sq_off.dropped;
|
58
|
+
sq->array = sq->ring_ptr + p->sq_off.array;
|
59
|
+
|
60
|
+
size = p->sq_entries * sizeof(struct io_uring_sqe);
|
61
|
+
sq->sqes = __sys_mmap(0, size, PROT_READ | PROT_WRITE,
|
62
|
+
MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_SQES);
|
63
|
+
if (IS_ERR(sq->sqes)) {
|
64
|
+
ret = PTR_ERR(sq->sqes);
|
65
|
+
err:
|
66
|
+
io_uring_unmap_rings(sq, cq);
|
67
|
+
return ret;
|
68
|
+
}
|
69
|
+
|
70
|
+
cq->khead = cq->ring_ptr + p->cq_off.head;
|
71
|
+
cq->ktail = cq->ring_ptr + p->cq_off.tail;
|
72
|
+
cq->kring_mask = cq->ring_ptr + p->cq_off.ring_mask;
|
73
|
+
cq->kring_entries = cq->ring_ptr + p->cq_off.ring_entries;
|
74
|
+
cq->koverflow = cq->ring_ptr + p->cq_off.overflow;
|
75
|
+
cq->cqes = cq->ring_ptr + p->cq_off.cqes;
|
76
|
+
if (p->cq_off.flags)
|
77
|
+
cq->kflags = cq->ring_ptr + p->cq_off.flags;
|
78
|
+
return 0;
|
79
|
+
}
|
80
|
+
|
81
|
+
/*
|
82
|
+
* For users that want to specify sq_thread_cpu or sq_thread_idle, this
|
83
|
+
* interface is a convenient helper for mmap()ing the rings.
|
84
|
+
* Returns -errno on error, or zero on success. On success, 'ring'
|
85
|
+
* contains the necessary information to read/write to the rings.
|
86
|
+
*/
|
87
|
+
int io_uring_queue_mmap(int fd, struct io_uring_params *p, struct io_uring *ring)
|
88
|
+
{
|
89
|
+
int ret;
|
90
|
+
|
91
|
+
memset(ring, 0, sizeof(*ring));
|
92
|
+
ret = io_uring_mmap(fd, p, &ring->sq, &ring->cq);
|
93
|
+
if (!ret) {
|
94
|
+
ring->flags = p->flags;
|
95
|
+
ring->ring_fd = ring->enter_ring_fd = fd;
|
96
|
+
ring->int_flags = 0;
|
97
|
+
}
|
98
|
+
return ret;
|
99
|
+
}
|
100
|
+
|
101
|
+
/*
|
102
|
+
* Ensure that the mmap'ed rings aren't available to a child after a fork(2).
|
103
|
+
* This uses madvise(..., MADV_DONTFORK) on the mmap'ed ranges.
|
104
|
+
*/
|
105
|
+
int io_uring_ring_dontfork(struct io_uring *ring)
|
106
|
+
{
|
107
|
+
size_t len;
|
108
|
+
int ret;
|
109
|
+
|
110
|
+
if (!ring->sq.ring_ptr || !ring->sq.sqes || !ring->cq.ring_ptr)
|
111
|
+
return -EINVAL;
|
112
|
+
|
113
|
+
len = *ring->sq.kring_entries * sizeof(struct io_uring_sqe);
|
114
|
+
ret = __sys_madvise(ring->sq.sqes, len, MADV_DONTFORK);
|
115
|
+
if (ret < 0)
|
116
|
+
return ret;
|
117
|
+
|
118
|
+
len = ring->sq.ring_sz;
|
119
|
+
ret = __sys_madvise(ring->sq.ring_ptr, len, MADV_DONTFORK);
|
120
|
+
if (ret < 0)
|
121
|
+
return ret;
|
122
|
+
|
123
|
+
if (ring->cq.ring_ptr != ring->sq.ring_ptr) {
|
124
|
+
len = ring->cq.ring_sz;
|
125
|
+
ret = __sys_madvise(ring->cq.ring_ptr, len, MADV_DONTFORK);
|
126
|
+
if (ret < 0)
|
127
|
+
return ret;
|
128
|
+
}
|
129
|
+
|
130
|
+
return 0;
|
131
|
+
}
|
132
|
+
|
133
|
+
int io_uring_queue_init_params(unsigned entries, struct io_uring *ring,
|
134
|
+
struct io_uring_params *p)
|
135
|
+
{
|
136
|
+
int fd, ret;
|
137
|
+
|
138
|
+
fd = ____sys_io_uring_setup(entries, p);
|
139
|
+
if (fd < 0)
|
140
|
+
return fd;
|
141
|
+
|
142
|
+
ret = io_uring_queue_mmap(fd, p, ring);
|
143
|
+
if (ret) {
|
144
|
+
__sys_close(fd);
|
145
|
+
return ret;
|
146
|
+
}
|
147
|
+
|
148
|
+
ring->features = p->features;
|
149
|
+
return 0;
|
150
|
+
}
|
151
|
+
|
152
|
+
/*
|
153
|
+
* Returns -errno on error, or zero on success. On success, 'ring'
|
154
|
+
* contains the necessary information to read/write to the rings.
|
155
|
+
*/
|
156
|
+
int io_uring_queue_init(unsigned entries, struct io_uring *ring, unsigned flags)
|
157
|
+
{
|
158
|
+
struct io_uring_params p;
|
159
|
+
|
160
|
+
memset(&p, 0, sizeof(p));
|
161
|
+
p.flags = flags;
|
162
|
+
|
163
|
+
return io_uring_queue_init_params(entries, ring, &p);
|
164
|
+
}
|
165
|
+
|
166
|
+
void io_uring_queue_exit(struct io_uring *ring)
|
167
|
+
{
|
168
|
+
struct io_uring_sq *sq = &ring->sq;
|
169
|
+
struct io_uring_cq *cq = &ring->cq;
|
170
|
+
|
171
|
+
__sys_munmap(sq->sqes, *sq->kring_entries * sizeof(struct io_uring_sqe));
|
172
|
+
io_uring_unmap_rings(sq, cq);
|
173
|
+
/*
|
174
|
+
* Not strictly required, but frees up the slot we used now rather
|
175
|
+
* than at process exit time.
|
176
|
+
*/
|
177
|
+
if (ring->int_flags & INT_FLAG_REG_RING)
|
178
|
+
io_uring_unregister_ring_fd(ring);
|
179
|
+
__sys_close(ring->ring_fd);
|
180
|
+
}
|
181
|
+
|
182
|
+
struct io_uring_probe *io_uring_get_probe_ring(struct io_uring *ring)
|
183
|
+
{
|
184
|
+
struct io_uring_probe *probe;
|
185
|
+
size_t len;
|
186
|
+
int r;
|
187
|
+
|
188
|
+
len = sizeof(*probe) + 256 * sizeof(struct io_uring_probe_op);
|
189
|
+
probe = uring_malloc(len);
|
190
|
+
if (!probe)
|
191
|
+
return NULL;
|
192
|
+
memset(probe, 0, len);
|
193
|
+
|
194
|
+
r = io_uring_register_probe(ring, probe, 256);
|
195
|
+
if (r >= 0)
|
196
|
+
return probe;
|
197
|
+
|
198
|
+
uring_free(probe);
|
199
|
+
return NULL;
|
200
|
+
}
|
201
|
+
|
202
|
+
struct io_uring_probe *io_uring_get_probe(void)
|
203
|
+
{
|
204
|
+
struct io_uring ring;
|
205
|
+
struct io_uring_probe *probe;
|
206
|
+
int r;
|
207
|
+
|
208
|
+
r = io_uring_queue_init(2, &ring, 0);
|
209
|
+
if (r < 0)
|
210
|
+
return NULL;
|
211
|
+
|
212
|
+
probe = io_uring_get_probe_ring(&ring);
|
213
|
+
io_uring_queue_exit(&ring);
|
214
|
+
return probe;
|
215
|
+
}
|
216
|
+
|
217
|
+
void io_uring_free_probe(struct io_uring_probe *probe)
|
218
|
+
{
|
219
|
+
uring_free(probe);
|
220
|
+
}
|
221
|
+
|
222
|
+
static inline int __fls(int x)
|
223
|
+
{
|
224
|
+
if (!x)
|
225
|
+
return 0;
|
226
|
+
return 8 * sizeof(x) - __builtin_clz(x);
|
227
|
+
}
|
228
|
+
|
229
|
+
static unsigned roundup_pow2(unsigned depth)
|
230
|
+
{
|
231
|
+
return 1UL << __fls(depth - 1);
|
232
|
+
}
|
233
|
+
|
234
|
+
static size_t npages(size_t size, unsigned page_size)
|
235
|
+
{
|
236
|
+
size--;
|
237
|
+
size /= page_size;
|
238
|
+
return __fls(size);
|
239
|
+
}
|
240
|
+
|
241
|
+
#define KRING_SIZE 320
|
242
|
+
|
243
|
+
static size_t rings_size(unsigned entries, unsigned cq_entries, unsigned page_size)
|
244
|
+
{
|
245
|
+
size_t pages, sq_size, cq_size;
|
246
|
+
|
247
|
+
cq_size = KRING_SIZE;
|
248
|
+
cq_size += cq_entries * sizeof(struct io_uring_cqe);
|
249
|
+
cq_size = (cq_size + 63) & ~63UL;
|
250
|
+
pages = (size_t) 1 << npages(cq_size, page_size);
|
251
|
+
|
252
|
+
sq_size = sizeof(struct io_uring_sqe) * entries;
|
253
|
+
pages += (size_t) 1 << npages(sq_size, page_size);
|
254
|
+
return pages * page_size;
|
255
|
+
}
|
256
|
+
|
257
|
+
#define KERN_MAX_ENTRIES 32768
|
258
|
+
#define KERN_MAX_CQ_ENTRIES (2 * KERN_MAX_ENTRIES)
|
259
|
+
|
260
|
+
/*
|
261
|
+
* Return the required ulimit -l memlock memory required for a given ring
|
262
|
+
* setup, in bytes. May return -errno on error. On newer (5.12+) kernels,
|
263
|
+
* io_uring no longer requires any memlock memory, and hence this function
|
264
|
+
* will return 0 for that case. On older (5.11 and prior) kernels, this will
|
265
|
+
* return the required memory so that the caller can ensure that enough space
|
266
|
+
* is available before setting up a ring with the specified parameters.
|
267
|
+
*/
|
268
|
+
ssize_t io_uring_mlock_size_params(unsigned entries, struct io_uring_params *p)
|
269
|
+
{
|
270
|
+
struct io_uring_params lp = { };
|
271
|
+
struct io_uring ring;
|
272
|
+
unsigned cq_entries;
|
273
|
+
long page_size;
|
274
|
+
ssize_t ret;
|
275
|
+
|
276
|
+
/*
|
277
|
+
* We only really use this inited ring to see if the kernel is newer
|
278
|
+
* or not. Newer kernels don't require memlocked memory. If we fail,
|
279
|
+
* it's most likely because it's an older kernel and we have no
|
280
|
+
* available memlock space. Just continue on, lp.features will still
|
281
|
+
* be zeroed at this point and we'll do the right thing.
|
282
|
+
*/
|
283
|
+
ret = io_uring_queue_init_params(entries, &ring, &lp);
|
284
|
+
if (!ret)
|
285
|
+
io_uring_queue_exit(&ring);
|
286
|
+
|
287
|
+
/*
|
288
|
+
* Native workers imply using cgroup memory accounting, and hence no
|
289
|
+
* memlock memory is needed for the ring allocations.
|
290
|
+
*/
|
291
|
+
if (lp.features & IORING_FEAT_NATIVE_WORKERS)
|
292
|
+
return 0;
|
293
|
+
|
294
|
+
if (!entries)
|
295
|
+
return -EINVAL;
|
296
|
+
if (entries > KERN_MAX_ENTRIES) {
|
297
|
+
if (!(p->flags & IORING_SETUP_CLAMP))
|
298
|
+
return -EINVAL;
|
299
|
+
entries = KERN_MAX_ENTRIES;
|
300
|
+
}
|
301
|
+
|
302
|
+
entries = roundup_pow2(entries);
|
303
|
+
if (p->flags & IORING_SETUP_CQSIZE) {
|
304
|
+
if (!p->cq_entries)
|
305
|
+
return -EINVAL;
|
306
|
+
cq_entries = p->cq_entries;
|
307
|
+
if (cq_entries > KERN_MAX_CQ_ENTRIES) {
|
308
|
+
if (!(p->flags & IORING_SETUP_CLAMP))
|
309
|
+
return -EINVAL;
|
310
|
+
cq_entries = KERN_MAX_CQ_ENTRIES;
|
311
|
+
}
|
312
|
+
cq_entries = roundup_pow2(cq_entries);
|
313
|
+
if (cq_entries < entries)
|
314
|
+
return -EINVAL;
|
315
|
+
} else {
|
316
|
+
cq_entries = 2 * entries;
|
317
|
+
}
|
318
|
+
|
319
|
+
page_size = get_page_size();
|
320
|
+
return rings_size(entries, cq_entries, page_size);
|
321
|
+
}
|
322
|
+
|
323
|
+
/*
|
324
|
+
* Return required ulimit -l memory space for a given ring setup. See
|
325
|
+
* @io_uring_mlock_size_params().
|
326
|
+
*/
|
327
|
+
ssize_t io_uring_mlock_size(unsigned entries, unsigned flags)
|
328
|
+
{
|
329
|
+
struct io_uring_params p = { .flags = flags, };
|
330
|
+
|
331
|
+
return io_uring_mlock_size_params(entries, &p);
|
332
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
#define _DEFAULT_SOURCE
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Functions in this file require libc, only build them when we use libc.
|
6
|
+
*
|
7
|
+
* Note:
|
8
|
+
* liburing's tests still need these functions.
|
9
|
+
*/
|
10
|
+
#if defined(CONFIG_NOLIBC) && !defined(LIBURING_BUILD_TEST)
|
11
|
+
# error "This file should only be compiled for libc build, or for liburing tests"
|
12
|
+
#endif
|
13
|
+
|
14
|
+
/*
|
15
|
+
* Will go away once libc support is there
|
16
|
+
*/
|
17
|
+
#include <unistd.h>
|
18
|
+
#include <sys/syscall.h>
|
19
|
+
#include <sys/uio.h>
|
20
|
+
#include "liburing/compat.h"
|
21
|
+
#include "liburing/io_uring.h"
|
22
|
+
#include "syscall.h"
|
23
|
+
|
24
|
+
int __sys_io_uring_register(int fd, unsigned opcode, const void *arg,
|
25
|
+
unsigned nr_args)
|
26
|
+
{
|
27
|
+
return syscall(__NR_io_uring_register, fd, opcode, arg, nr_args);
|
28
|
+
}
|
29
|
+
|
30
|
+
int __sys_io_uring_setup(unsigned entries, struct io_uring_params *p)
|
31
|
+
{
|
32
|
+
return syscall(__NR_io_uring_setup, entries, p);
|
33
|
+
}
|
34
|
+
|
35
|
+
int __sys_io_uring_enter2(int fd, unsigned to_submit, unsigned min_complete,
|
36
|
+
unsigned flags, sigset_t *sig, int sz)
|
37
|
+
{
|
38
|
+
return syscall(__NR_io_uring_enter, fd, to_submit, min_complete, flags,
|
39
|
+
sig, sz);
|
40
|
+
}
|
41
|
+
|
42
|
+
int __sys_io_uring_enter(int fd, unsigned to_submit, unsigned min_complete,
|
43
|
+
unsigned flags, sigset_t *sig)
|
44
|
+
{
|
45
|
+
return __sys_io_uring_enter2(fd, to_submit, min_complete, flags, sig,
|
46
|
+
_NSIG / 8);
|
47
|
+
}
|