@nxtedition/rocksdb 5.2.36 → 5.2.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.cc +66 -91
- package/deps/liburing/liburing/COPYING +502 -0
- package/deps/liburing/liburing/COPYING.GPL +339 -0
- package/deps/liburing/liburing/LICENSE +7 -0
- package/deps/liburing/liburing/Makefile +84 -0
- package/deps/liburing/liburing/Makefile.quiet +11 -0
- package/deps/liburing/liburing/README +46 -0
- package/deps/liburing/liburing/configure +420 -0
- package/deps/liburing/liburing/debian/README.Debian +7 -0
- package/deps/liburing/liburing/debian/changelog +27 -0
- package/deps/liburing/liburing/debian/compat +1 -0
- package/deps/liburing/liburing/debian/control +48 -0
- package/deps/liburing/liburing/debian/copyright +49 -0
- package/deps/liburing/liburing/debian/liburing-dev.install +4 -0
- package/deps/liburing/liburing/debian/liburing-dev.manpages +6 -0
- package/deps/liburing/liburing/debian/liburing1-udeb.install +1 -0
- package/deps/liburing/liburing/debian/liburing1.install +1 -0
- package/deps/liburing/liburing/debian/liburing1.symbols +32 -0
- package/deps/liburing/liburing/debian/patches/series +1 -0
- package/deps/liburing/liburing/debian/rules +81 -0
- package/deps/liburing/liburing/debian/source/format +1 -0
- package/deps/liburing/liburing/debian/source/local-options +2 -0
- package/deps/liburing/liburing/debian/source/options +1 -0
- package/deps/liburing/liburing/debian/watch +3 -0
- package/deps/liburing/liburing/examples/Makefile +29 -0
- package/deps/liburing/liburing/examples/io_uring-cp.c +279 -0
- package/deps/liburing/liburing/examples/io_uring-test.c +112 -0
- package/deps/liburing/liburing/examples/link-cp.c +193 -0
- package/deps/liburing/liburing/examples/ucontext-cp.c +273 -0
- package/deps/liburing/liburing/liburing.pc.in +12 -0
- package/deps/liburing/liburing/liburing.spec +66 -0
- package/deps/liburing/liburing/make-debs.sh +53 -0
- package/deps/liburing/liburing/man/io_uring.7 +736 -0
- package/deps/liburing/liburing/man/io_uring_enter.2 +1403 -0
- package/deps/liburing/liburing/man/io_uring_get_sqe.3 +37 -0
- package/deps/liburing/liburing/man/io_uring_queue_exit.3 +27 -0
- package/deps/liburing/liburing/man/io_uring_queue_init.3 +44 -0
- package/deps/liburing/liburing/man/io_uring_register.2 +605 -0
- package/deps/liburing/liburing/man/io_uring_setup.2 +515 -0
- package/deps/liburing/liburing/src/Makefile +76 -0
- package/deps/liburing/liburing/src/include/liburing/barrier.h +73 -0
- package/deps/liburing/liburing/src/include/liburing/io_uring.h +422 -0
- package/deps/liburing/liburing/src/include/liburing.h +775 -0
- package/deps/liburing/liburing/src/liburing.map +46 -0
- package/deps/liburing/liburing/src/queue.c +403 -0
- package/deps/liburing/liburing/src/register.c +299 -0
- package/deps/liburing/liburing/src/setup.c +356 -0
- package/deps/liburing/liburing/src/syscall.c +73 -0
- package/deps/liburing/liburing/src/syscall.h +20 -0
- package/deps/liburing/liburing/test/232c93d07b74-test.c +305 -0
- package/deps/liburing/liburing/test/35fa71a030ca-test.c +329 -0
- package/deps/liburing/liburing/test/500f9fbadef8-test.c +89 -0
- package/deps/liburing/liburing/test/7ad0e4b2f83c-test.c +93 -0
- package/deps/liburing/liburing/test/8a9973408177-test.c +106 -0
- package/deps/liburing/liburing/test/917257daa0fe-test.c +53 -0
- package/deps/liburing/liburing/test/Makefile +312 -0
- package/deps/liburing/liburing/test/a0908ae19763-test.c +58 -0
- package/deps/liburing/liburing/test/a4c0b3decb33-test.c +180 -0
- package/deps/liburing/liburing/test/accept-link.c +251 -0
- package/deps/liburing/liburing/test/accept-reuse.c +164 -0
- package/deps/liburing/liburing/test/accept-test.c +79 -0
- package/deps/liburing/liburing/test/accept.c +476 -0
- package/deps/liburing/liburing/test/across-fork.c +283 -0
- package/deps/liburing/liburing/test/b19062a56726-test.c +53 -0
- package/deps/liburing/liburing/test/b5837bd5311d-test.c +77 -0
- package/deps/liburing/liburing/test/ce593a6c480a-test.c +135 -0
- package/deps/liburing/liburing/test/close-opath.c +122 -0
- package/deps/liburing/liburing/test/config +10 -0
- package/deps/liburing/liburing/test/connect.c +398 -0
- package/deps/liburing/liburing/test/cq-full.c +96 -0
- package/deps/liburing/liburing/test/cq-overflow.c +294 -0
- package/deps/liburing/liburing/test/cq-peek-batch.c +102 -0
- package/deps/liburing/liburing/test/cq-ready.c +94 -0
- package/deps/liburing/liburing/test/cq-size.c +58 -0
- package/deps/liburing/liburing/test/d4ae271dfaae-test.c +96 -0
- package/deps/liburing/liburing/test/d77a67ed5f27-test.c +65 -0
- package/deps/liburing/liburing/test/defer.c +307 -0
- package/deps/liburing/liburing/test/double-poll-crash.c +186 -0
- package/deps/liburing/liburing/test/eeed8b54e0df-test.c +114 -0
- package/deps/liburing/liburing/test/empty-eownerdead.c +42 -0
- package/deps/liburing/liburing/test/eventfd-disable.c +151 -0
- package/deps/liburing/liburing/test/eventfd-ring.c +97 -0
- package/deps/liburing/liburing/test/eventfd.c +112 -0
- package/deps/liburing/liburing/test/fadvise.c +202 -0
- package/deps/liburing/liburing/test/fallocate.c +249 -0
- package/deps/liburing/liburing/test/fc2a85cb02ef-test.c +138 -0
- package/deps/liburing/liburing/test/file-register.c +843 -0
- package/deps/liburing/liburing/test/file-update.c +173 -0
- package/deps/liburing/liburing/test/files-exit-hang-poll.c +128 -0
- package/deps/liburing/liburing/test/files-exit-hang-timeout.c +134 -0
- package/deps/liburing/liburing/test/fixed-link.c +90 -0
- package/deps/liburing/liburing/test/fsync.c +224 -0
- package/deps/liburing/liburing/test/hardlink.c +136 -0
- package/deps/liburing/liburing/test/helpers.c +135 -0
- package/deps/liburing/liburing/test/helpers.h +67 -0
- package/deps/liburing/liburing/test/io-cancel.c +537 -0
- package/deps/liburing/liburing/test/io_uring_enter.c +296 -0
- package/deps/liburing/liburing/test/io_uring_register.c +664 -0
- package/deps/liburing/liburing/test/io_uring_setup.c +192 -0
- package/deps/liburing/liburing/test/iopoll.c +366 -0
- package/deps/liburing/liburing/test/lfs-openat-write.c +117 -0
- package/deps/liburing/liburing/test/lfs-openat.c +273 -0
- package/deps/liburing/liburing/test/link-timeout.c +1107 -0
- package/deps/liburing/liburing/test/link.c +496 -0
- package/deps/liburing/liburing/test/link_drain.c +229 -0
- package/deps/liburing/liburing/test/madvise.c +195 -0
- package/deps/liburing/liburing/test/mkdir.c +108 -0
- package/deps/liburing/liburing/test/multicqes_drain.c +383 -0
- package/deps/liburing/liburing/test/nop-all-sizes.c +107 -0
- package/deps/liburing/liburing/test/nop.c +115 -0
- package/deps/liburing/liburing/test/open-close.c +146 -0
- package/deps/liburing/liburing/test/openat2.c +240 -0
- package/deps/liburing/liburing/test/personality.c +204 -0
- package/deps/liburing/liburing/test/pipe-eof.c +81 -0
- package/deps/liburing/liburing/test/pipe-reuse.c +105 -0
- package/deps/liburing/liburing/test/poll-cancel-ton.c +139 -0
- package/deps/liburing/liburing/test/poll-cancel.c +135 -0
- package/deps/liburing/liburing/test/poll-link.c +227 -0
- package/deps/liburing/liburing/test/poll-many.c +208 -0
- package/deps/liburing/liburing/test/poll-mshot-update.c +273 -0
- package/deps/liburing/liburing/test/poll-ring.c +48 -0
- package/deps/liburing/liburing/test/poll-v-poll.c +353 -0
- package/deps/liburing/liburing/test/poll.c +109 -0
- package/deps/liburing/liburing/test/probe.c +137 -0
- package/deps/liburing/liburing/test/read-write.c +876 -0
- package/deps/liburing/liburing/test/register-restrictions.c +633 -0
- package/deps/liburing/liburing/test/rename.c +134 -0
- package/deps/liburing/liburing/test/ring-leak.c +173 -0
- package/deps/liburing/liburing/test/ring-leak2.c +249 -0
- package/deps/liburing/liburing/test/rsrc_tags.c +449 -0
- package/deps/liburing/liburing/test/runtests-loop.sh +16 -0
- package/deps/liburing/liburing/test/runtests.sh +170 -0
- package/deps/liburing/liburing/test/rw_merge_test.c +97 -0
- package/deps/liburing/liburing/test/self.c +91 -0
- package/deps/liburing/liburing/test/send_recv.c +291 -0
- package/deps/liburing/liburing/test/send_recvmsg.c +345 -0
- package/deps/liburing/liburing/test/sendmsg_fs_cve.c +198 -0
- package/deps/liburing/liburing/test/shared-wq.c +84 -0
- package/deps/liburing/liburing/test/short-read.c +75 -0
- package/deps/liburing/liburing/test/shutdown.c +163 -0
- package/deps/liburing/liburing/test/sigfd-deadlock.c +74 -0
- package/deps/liburing/liburing/test/socket-rw-eagain.c +156 -0
- package/deps/liburing/liburing/test/socket-rw.c +147 -0
- package/deps/liburing/liburing/test/splice.c +511 -0
- package/deps/liburing/liburing/test/sq-full-cpp.cc +45 -0
- package/deps/liburing/liburing/test/sq-full.c +45 -0
- package/deps/liburing/liburing/test/sq-poll-dup.c +200 -0
- package/deps/liburing/liburing/test/sq-poll-kthread.c +168 -0
- package/deps/liburing/liburing/test/sq-poll-share.c +137 -0
- package/deps/liburing/liburing/test/sq-space_left.c +159 -0
- package/deps/liburing/liburing/test/sqpoll-cancel-hang.c +159 -0
- package/deps/liburing/liburing/test/sqpoll-disable-exit.c +195 -0
- package/deps/liburing/liburing/test/sqpoll-exit-hang.c +77 -0
- package/deps/liburing/liburing/test/sqpoll-sleep.c +68 -0
- package/deps/liburing/liburing/test/statx.c +172 -0
- package/deps/liburing/liburing/test/stdout.c +232 -0
- package/deps/liburing/liburing/test/submit-link-fail.c +154 -0
- package/deps/liburing/liburing/test/submit-reuse.c +239 -0
- package/deps/liburing/liburing/test/symlink.c +116 -0
- package/deps/liburing/liburing/test/teardowns.c +58 -0
- package/deps/liburing/liburing/test/thread-exit.c +131 -0
- package/deps/liburing/liburing/test/timeout-new.c +246 -0
- package/deps/liburing/liburing/test/timeout-overflow.c +204 -0
- package/deps/liburing/liburing/test/timeout.c +1354 -0
- package/deps/liburing/liburing/test/unlink.c +111 -0
- package/deps/liburing/liburing/test/wakeup-hang.c +162 -0
- package/deps/liburing/liburing.gyp +20 -0
- package/deps/rocksdb/rocksdb/db/corruption_test.cc +62 -0
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +7 -62
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +25 -11
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +74 -155
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +1 -2
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.h +2 -2
- package/deps/rocksdb/rocksdb/env/fs_posix.cc +13 -0
- package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +4 -2
- package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +22 -4
- package/deps/rocksdb/rocksdb/file/prefetch_test.cc +5 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +15 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +5 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/version.h +1 -1
- package/deps/rocksdb/rocksdb/monitoring/statistics.cc +3 -0
- package/deps/rocksdb/rocksdb/monitoring/stats_history_test.cc +3 -7
- package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +2 -1
- package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +44 -29
- package/deps/rocksdb/rocksdb.gyp +4 -3
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
- package/prebuilds/darwin-x64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
- package/prebuilds/prebuilds/linux-x64/node.napi.node +0 -0
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/*
|
|
3
|
+
* io_uring_register.c
|
|
4
|
+
*
|
|
5
|
+
* Description: Unit tests for the io_uring_register system call.
|
|
6
|
+
*
|
|
7
|
+
* Copyright 2019, Red Hat, Inc.
|
|
8
|
+
* Author: Jeff Moyer <jmoyer@redhat.com>
|
|
9
|
+
*/
|
|
10
|
+
#include <stdio.h>
|
|
11
|
+
#include <fcntl.h>
|
|
12
|
+
#include <string.h>
|
|
13
|
+
#include <stdlib.h>
|
|
14
|
+
#include <unistd.h>
|
|
15
|
+
#include <errno.h>
|
|
16
|
+
#include <sys/sysinfo.h>
|
|
17
|
+
#include <poll.h>
|
|
18
|
+
#include <assert.h>
|
|
19
|
+
#include <sys/uio.h>
|
|
20
|
+
#include <sys/mman.h>
|
|
21
|
+
#include <linux/mman.h>
|
|
22
|
+
#include <sys/time.h>
|
|
23
|
+
#include <sys/resource.h>
|
|
24
|
+
#include <limits.h>
|
|
25
|
+
|
|
26
|
+
#include "helpers.h"
|
|
27
|
+
#include "liburing.h"
|
|
28
|
+
#include "../src/syscall.h"
|
|
29
|
+
|
|
30
|
+
static int pagesize;
|
|
31
|
+
static rlim_t mlock_limit;
|
|
32
|
+
static int devnull;
|
|
33
|
+
|
|
34
|
+
int
|
|
35
|
+
expect_fail(int fd, unsigned int opcode, void *arg,
|
|
36
|
+
unsigned int nr_args, int error)
|
|
37
|
+
{
|
|
38
|
+
int ret;
|
|
39
|
+
|
|
40
|
+
printf("io_uring_register(%d, %u, %p, %u)\n",
|
|
41
|
+
fd, opcode, arg, nr_args);
|
|
42
|
+
ret = __sys_io_uring_register(fd, opcode, arg, nr_args);
|
|
43
|
+
if (ret != -1) {
|
|
44
|
+
int ret2 = 0;
|
|
45
|
+
|
|
46
|
+
printf("expected %s, but call succeeded\n", strerror(error));
|
|
47
|
+
if (opcode == IORING_REGISTER_BUFFERS) {
|
|
48
|
+
ret2 = __sys_io_uring_register(fd,
|
|
49
|
+
IORING_UNREGISTER_BUFFERS, 0, 0);
|
|
50
|
+
} else if (opcode == IORING_REGISTER_FILES) {
|
|
51
|
+
ret2 = __sys_io_uring_register(fd,
|
|
52
|
+
IORING_UNREGISTER_FILES, 0, 0);
|
|
53
|
+
}
|
|
54
|
+
if (ret2) {
|
|
55
|
+
printf("internal error: failed to unregister\n");
|
|
56
|
+
exit(1);
|
|
57
|
+
}
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (errno != error) {
|
|
62
|
+
printf("expected %d, got %d\n", error, errno);
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
int
|
|
69
|
+
new_io_uring(int entries, struct io_uring_params *p)
|
|
70
|
+
{
|
|
71
|
+
int fd;
|
|
72
|
+
|
|
73
|
+
fd = __sys_io_uring_setup(entries, p);
|
|
74
|
+
if (fd < 0) {
|
|
75
|
+
perror("io_uring_setup");
|
|
76
|
+
exit(1);
|
|
77
|
+
}
|
|
78
|
+
return fd;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#define MAXFDS (UINT_MAX * sizeof(int))
|
|
82
|
+
|
|
83
|
+
void *
|
|
84
|
+
map_filebacked(size_t size)
|
|
85
|
+
{
|
|
86
|
+
int fd, ret;
|
|
87
|
+
void *addr;
|
|
88
|
+
char template[32] = "io_uring_register-test-XXXXXXXX";
|
|
89
|
+
|
|
90
|
+
fd = mkstemp(template);
|
|
91
|
+
if (fd < 0) {
|
|
92
|
+
perror("mkstemp");
|
|
93
|
+
return NULL;
|
|
94
|
+
}
|
|
95
|
+
unlink(template);
|
|
96
|
+
|
|
97
|
+
ret = ftruncate(fd, size);
|
|
98
|
+
if (ret < 0) {
|
|
99
|
+
perror("ftruncate");
|
|
100
|
+
close(fd);
|
|
101
|
+
return NULL;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
addr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
|
105
|
+
if (addr == MAP_FAILED) {
|
|
106
|
+
perror("mmap");
|
|
107
|
+
close(fd);
|
|
108
|
+
return NULL;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
close(fd);
|
|
112
|
+
return addr;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/*
|
|
116
|
+
* NOTE: this is now limited by SCM_MAX_FD (253). Keep the code for now,
|
|
117
|
+
* but probably should augment it to test 253 and 254, specifically.
|
|
118
|
+
*/
|
|
119
|
+
int
|
|
120
|
+
test_max_fds(int uring_fd)
|
|
121
|
+
{
|
|
122
|
+
int status = 1;
|
|
123
|
+
int ret;
|
|
124
|
+
void *fd_as; /* file descriptor address space */
|
|
125
|
+
int fdtable_fd; /* fd for the file that will be mapped over and over */
|
|
126
|
+
int io_fd; /* the valid fd for I/O -- /dev/null */
|
|
127
|
+
int *fds; /* used to map the file into the address space */
|
|
128
|
+
char template[32] = "io_uring_register-test-XXXXXXXX";
|
|
129
|
+
unsigned long long i, nr_maps, nr_fds;
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
* First, mmap anonymous the full size. That will guarantee the
|
|
133
|
+
* mapping will fit in the memory area selected by mmap. Then,
|
|
134
|
+
* over-write that mapping using a file-backed mapping, 128MiB at
|
|
135
|
+
* a time using MAP_FIXED.
|
|
136
|
+
*/
|
|
137
|
+
fd_as = mmap(NULL, UINT_MAX * sizeof(int), PROT_READ|PROT_WRITE,
|
|
138
|
+
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
|
139
|
+
if (fd_as == MAP_FAILED) {
|
|
140
|
+
if (errno == ENOMEM) {
|
|
141
|
+
printf("Not enough memory for this test, skipping\n");
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
perror("mmap fd_as");
|
|
145
|
+
exit(1);
|
|
146
|
+
}
|
|
147
|
+
printf("allocated %zu bytes of address space\n", UINT_MAX * sizeof(int));
|
|
148
|
+
|
|
149
|
+
fdtable_fd = mkstemp(template);
|
|
150
|
+
if (fdtable_fd < 0) {
|
|
151
|
+
perror("mkstemp");
|
|
152
|
+
exit(1);
|
|
153
|
+
}
|
|
154
|
+
unlink(template);
|
|
155
|
+
ret = ftruncate(fdtable_fd, 128*1024*1024);
|
|
156
|
+
if (ret < 0) {
|
|
157
|
+
perror("ftruncate");
|
|
158
|
+
exit(1);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
io_fd = open("/dev/null", O_RDWR);
|
|
162
|
+
if (io_fd < 0) {
|
|
163
|
+
perror("open /dev/null");
|
|
164
|
+
exit(1);
|
|
165
|
+
}
|
|
166
|
+
fds = mmap(fd_as, 128*1024*1024, PROT_READ|PROT_WRITE,
|
|
167
|
+
MAP_SHARED|MAP_FIXED, fdtable_fd, 0);
|
|
168
|
+
if (fds == MAP_FAILED) {
|
|
169
|
+
perror("mmap fdtable");
|
|
170
|
+
exit(1);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* fill the fd table */
|
|
174
|
+
nr_fds = 128*1024*1024 / sizeof(int);
|
|
175
|
+
for (i = 0; i < nr_fds; i++)
|
|
176
|
+
fds[i] = io_fd;
|
|
177
|
+
|
|
178
|
+
/* map the file through the rest of the address space */
|
|
179
|
+
nr_maps = (UINT_MAX * sizeof(int)) / (128*1024*1024);
|
|
180
|
+
for (i = 0; i < nr_maps; i++) {
|
|
181
|
+
fds = &fds[nr_fds]; /* advance fds by 128MiB */
|
|
182
|
+
fds = mmap(fds, 128*1024*1024, PROT_READ|PROT_WRITE,
|
|
183
|
+
MAP_SHARED|MAP_FIXED, fdtable_fd, 0);
|
|
184
|
+
if (fds == MAP_FAILED) {
|
|
185
|
+
printf("mmap failed at offset %lu\n",
|
|
186
|
+
(unsigned long)((char *)fd_as - (char *)fds));
|
|
187
|
+
exit(1);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/* Now fd_as points to the file descriptor array. */
|
|
192
|
+
/*
|
|
193
|
+
* We may not be able to map all of these files. Let's back off
|
|
194
|
+
* until success.
|
|
195
|
+
*/
|
|
196
|
+
nr_fds = UINT_MAX;
|
|
197
|
+
while (nr_fds) {
|
|
198
|
+
ret = __sys_io_uring_register(uring_fd, IORING_REGISTER_FILES,
|
|
199
|
+
fd_as, nr_fds);
|
|
200
|
+
if (ret != 0) {
|
|
201
|
+
nr_fds /= 2;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
printf("io_uring_register(%d, IORING_REGISTER_FILES, %p, %llu)"
|
|
205
|
+
"...succeeded\n", uring_fd, fd_as, nr_fds);
|
|
206
|
+
status = 0;
|
|
207
|
+
printf("io_uring_register(%d, IORING_UNREGISTER_FILES, 0, 0)...",
|
|
208
|
+
uring_fd);
|
|
209
|
+
ret = __sys_io_uring_register(uring_fd, IORING_UNREGISTER_FILES,
|
|
210
|
+
0, 0);
|
|
211
|
+
if (ret < 0) {
|
|
212
|
+
ret = errno;
|
|
213
|
+
printf("failed\n");
|
|
214
|
+
errno = ret;
|
|
215
|
+
perror("io_uring_register UNREGISTER_FILES");
|
|
216
|
+
exit(1);
|
|
217
|
+
}
|
|
218
|
+
printf("succeeded\n");
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
close(io_fd);
|
|
223
|
+
close(fdtable_fd);
|
|
224
|
+
ret = munmap(fd_as, UINT_MAX * sizeof(int));
|
|
225
|
+
if (ret != 0) {
|
|
226
|
+
printf("munmap(%zu) failed\n", UINT_MAX * sizeof(int));
|
|
227
|
+
exit(1);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return status;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
int
|
|
234
|
+
test_memlock_exceeded(int fd)
|
|
235
|
+
{
|
|
236
|
+
int ret;
|
|
237
|
+
void *buf;
|
|
238
|
+
struct iovec iov;
|
|
239
|
+
|
|
240
|
+
/* if limit is larger than 2gb, just skip this test */
|
|
241
|
+
if (mlock_limit >= 2 * 1024 * 1024 * 1024ULL)
|
|
242
|
+
return 0;
|
|
243
|
+
|
|
244
|
+
iov.iov_len = mlock_limit * 2;
|
|
245
|
+
buf = t_malloc(iov.iov_len);
|
|
246
|
+
iov.iov_base = buf;
|
|
247
|
+
|
|
248
|
+
while (iov.iov_len) {
|
|
249
|
+
ret = __sys_io_uring_register(fd, IORING_REGISTER_BUFFERS, &iov, 1);
|
|
250
|
+
if (ret < 0) {
|
|
251
|
+
if (errno == ENOMEM) {
|
|
252
|
+
printf("io_uring_register of %zu bytes failed "
|
|
253
|
+
"with ENOMEM (expected).\n", iov.iov_len);
|
|
254
|
+
iov.iov_len /= 2;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (errno == EFAULT) {
|
|
258
|
+
free(buf);
|
|
259
|
+
return 0;
|
|
260
|
+
}
|
|
261
|
+
printf("expected success or EFAULT, got %d\n", errno);
|
|
262
|
+
free(buf);
|
|
263
|
+
return 1;
|
|
264
|
+
}
|
|
265
|
+
printf("successfully registered %zu bytes (%d).\n",
|
|
266
|
+
iov.iov_len, ret);
|
|
267
|
+
ret = __sys_io_uring_register(fd, IORING_UNREGISTER_BUFFERS,
|
|
268
|
+
NULL, 0);
|
|
269
|
+
if (ret != 0) {
|
|
270
|
+
printf("error: unregister failed with %d\n", errno);
|
|
271
|
+
free(buf);
|
|
272
|
+
return 1;
|
|
273
|
+
}
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
if (!iov.iov_len)
|
|
277
|
+
printf("Unable to register buffers. Check memlock rlimit.\n");
|
|
278
|
+
|
|
279
|
+
free(buf);
|
|
280
|
+
return 0;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
int
|
|
284
|
+
test_iovec_nr(int fd)
|
|
285
|
+
{
|
|
286
|
+
int i, ret, status = 0;
|
|
287
|
+
unsigned int nr = 1000000;
|
|
288
|
+
struct iovec *iovs;
|
|
289
|
+
void *buf;
|
|
290
|
+
|
|
291
|
+
iovs = malloc(nr * sizeof(struct iovec));
|
|
292
|
+
if (!iovs) {
|
|
293
|
+
fprintf(stdout, "can't allocate iovecs, skip\n");
|
|
294
|
+
return 0;
|
|
295
|
+
}
|
|
296
|
+
buf = t_malloc(pagesize);
|
|
297
|
+
|
|
298
|
+
for (i = 0; i < nr; i++) {
|
|
299
|
+
iovs[i].iov_base = buf;
|
|
300
|
+
iovs[i].iov_len = pagesize;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
status |= expect_fail(fd, IORING_REGISTER_BUFFERS, iovs, nr, EINVAL);
|
|
304
|
+
|
|
305
|
+
/* reduce to UIO_MAXIOV */
|
|
306
|
+
nr = UIO_MAXIOV;
|
|
307
|
+
printf("io_uring_register(%d, %u, %p, %u)\n",
|
|
308
|
+
fd, IORING_REGISTER_BUFFERS, iovs, nr);
|
|
309
|
+
ret = __sys_io_uring_register(fd, IORING_REGISTER_BUFFERS, iovs, nr);
|
|
310
|
+
if (ret && (errno == ENOMEM || errno == EPERM) && geteuid()) {
|
|
311
|
+
printf("can't register large iovec for regular users, skip\n");
|
|
312
|
+
} else if (ret != 0) {
|
|
313
|
+
printf("expected success, got %d\n", errno);
|
|
314
|
+
status = 1;
|
|
315
|
+
} else {
|
|
316
|
+
__sys_io_uring_register(fd, IORING_UNREGISTER_BUFFERS, 0, 0);
|
|
317
|
+
}
|
|
318
|
+
free(buf);
|
|
319
|
+
free(iovs);
|
|
320
|
+
return status;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/*
|
|
324
|
+
* io_uring limit is 1G. iov_len limit is ~OUL, I think
|
|
325
|
+
*/
|
|
326
|
+
int
|
|
327
|
+
test_iovec_size(int fd)
|
|
328
|
+
{
|
|
329
|
+
unsigned int status = 0;
|
|
330
|
+
int ret;
|
|
331
|
+
struct iovec iov;
|
|
332
|
+
void *buf;
|
|
333
|
+
|
|
334
|
+
/* NULL pointer for base */
|
|
335
|
+
iov.iov_base = 0;
|
|
336
|
+
iov.iov_len = 4096;
|
|
337
|
+
status |= expect_fail(fd, IORING_REGISTER_BUFFERS, &iov, 1, EFAULT);
|
|
338
|
+
|
|
339
|
+
/* valid base, 0 length */
|
|
340
|
+
iov.iov_base = &buf;
|
|
341
|
+
iov.iov_len = 0;
|
|
342
|
+
status |= expect_fail(fd, IORING_REGISTER_BUFFERS, &iov, 1, EFAULT);
|
|
343
|
+
|
|
344
|
+
/* valid base, length exceeds size */
|
|
345
|
+
/* this requires an unampped page directly after buf */
|
|
346
|
+
buf = mmap(NULL, 2 * pagesize, PROT_READ|PROT_WRITE,
|
|
347
|
+
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
|
348
|
+
assert(buf != MAP_FAILED);
|
|
349
|
+
ret = munmap(buf + pagesize, pagesize);
|
|
350
|
+
assert(ret == 0);
|
|
351
|
+
iov.iov_base = buf;
|
|
352
|
+
iov.iov_len = 2 * pagesize;
|
|
353
|
+
status |= expect_fail(fd, IORING_REGISTER_BUFFERS, &iov, 1, EFAULT);
|
|
354
|
+
munmap(buf, pagesize);
|
|
355
|
+
|
|
356
|
+
/* huge page */
|
|
357
|
+
buf = mmap(NULL, 2*1024*1024, PROT_READ|PROT_WRITE,
|
|
358
|
+
MAP_PRIVATE | MAP_HUGETLB | MAP_HUGE_2MB | MAP_ANONYMOUS,
|
|
359
|
+
-1, 0);
|
|
360
|
+
if (buf == MAP_FAILED) {
|
|
361
|
+
printf("Unable to map a huge page. Try increasing "
|
|
362
|
+
"/proc/sys/vm/nr_hugepages by at least 1.\n");
|
|
363
|
+
printf("Skipping the hugepage test\n");
|
|
364
|
+
} else {
|
|
365
|
+
/*
|
|
366
|
+
* This should succeed, so long as RLIMIT_MEMLOCK is
|
|
367
|
+
* not exceeded
|
|
368
|
+
*/
|
|
369
|
+
iov.iov_base = buf;
|
|
370
|
+
iov.iov_len = 2*1024*1024;
|
|
371
|
+
ret = __sys_io_uring_register(fd, IORING_REGISTER_BUFFERS, &iov, 1);
|
|
372
|
+
if (ret < 0) {
|
|
373
|
+
if (errno == ENOMEM)
|
|
374
|
+
printf("Unable to test registering of a huge "
|
|
375
|
+
"page. Try increasing the "
|
|
376
|
+
"RLIMIT_MEMLOCK resource limit by at "
|
|
377
|
+
"least 2MB.");
|
|
378
|
+
else {
|
|
379
|
+
printf("expected success, got %d\n", errno);
|
|
380
|
+
status = 1;
|
|
381
|
+
}
|
|
382
|
+
} else {
|
|
383
|
+
printf("Success!\n");
|
|
384
|
+
ret = __sys_io_uring_register(fd,
|
|
385
|
+
IORING_UNREGISTER_BUFFERS, 0, 0);
|
|
386
|
+
if (ret < 0) {
|
|
387
|
+
perror("io_uring_unregister");
|
|
388
|
+
status = 1;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
ret = munmap(iov.iov_base, iov.iov_len);
|
|
393
|
+
assert(ret == 0);
|
|
394
|
+
|
|
395
|
+
/* file-backed buffers -- not supported */
|
|
396
|
+
buf = map_filebacked(2*1024*1024);
|
|
397
|
+
if (!buf)
|
|
398
|
+
status = 1;
|
|
399
|
+
iov.iov_base = buf;
|
|
400
|
+
iov.iov_len = 2*1024*1024;
|
|
401
|
+
printf("reserve file-backed buffers\n");
|
|
402
|
+
status |= expect_fail(fd, IORING_REGISTER_BUFFERS, &iov, 1, EOPNOTSUPP);
|
|
403
|
+
munmap(buf, 2*1024*1024);
|
|
404
|
+
|
|
405
|
+
/* bump up against the soft limit and make sure we get EFAULT
|
|
406
|
+
* or whatever we're supposed to get. NOTE: this requires
|
|
407
|
+
* running the test as non-root. */
|
|
408
|
+
if (getuid() != 0)
|
|
409
|
+
status |= test_memlock_exceeded(fd);
|
|
410
|
+
|
|
411
|
+
return status;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
void
|
|
415
|
+
dump_sqe(struct io_uring_sqe *sqe)
|
|
416
|
+
{
|
|
417
|
+
printf("\topcode: %d\n", sqe->opcode);
|
|
418
|
+
printf("\tflags: 0x%.8x\n", sqe->flags);
|
|
419
|
+
printf("\tfd: %d\n", sqe->fd);
|
|
420
|
+
if (sqe->opcode == IORING_OP_POLL_ADD)
|
|
421
|
+
printf("\tpoll_events: 0x%.8x\n", sqe->poll_events);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
int
|
|
425
|
+
ioring_poll(struct io_uring *ring, int fd, int fixed)
|
|
426
|
+
{
|
|
427
|
+
int ret;
|
|
428
|
+
struct io_uring_sqe *sqe;
|
|
429
|
+
struct io_uring_cqe *cqe;
|
|
430
|
+
|
|
431
|
+
sqe = io_uring_get_sqe(ring);
|
|
432
|
+
memset(sqe, 0, sizeof(*sqe));
|
|
433
|
+
sqe->opcode = IORING_OP_POLL_ADD;
|
|
434
|
+
if (fixed)
|
|
435
|
+
sqe->flags = IOSQE_FIXED_FILE;
|
|
436
|
+
sqe->fd = fd;
|
|
437
|
+
sqe->poll_events = POLLIN|POLLOUT;
|
|
438
|
+
|
|
439
|
+
printf("io_uring_submit:\n");
|
|
440
|
+
dump_sqe(sqe);
|
|
441
|
+
ret = io_uring_submit(ring);
|
|
442
|
+
if (ret != 1) {
|
|
443
|
+
printf("failed to submit poll sqe: %d.\n", errno);
|
|
444
|
+
return 1;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
|
448
|
+
if (ret < 0) {
|
|
449
|
+
printf("io_uring_wait_cqe failed with %d\n", ret);
|
|
450
|
+
return 1;
|
|
451
|
+
}
|
|
452
|
+
ret = 0;
|
|
453
|
+
if (cqe->res != POLLOUT) {
|
|
454
|
+
printf("io_uring_wait_cqe: expected 0x%.8x, got 0x%.8x\n",
|
|
455
|
+
POLLOUT, cqe->res);
|
|
456
|
+
ret = 1;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
io_uring_cqe_seen(ring, cqe);
|
|
460
|
+
return ret;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
int
|
|
464
|
+
test_poll_ringfd(void)
|
|
465
|
+
{
|
|
466
|
+
int status = 0;
|
|
467
|
+
int ret;
|
|
468
|
+
int fd;
|
|
469
|
+
struct io_uring ring;
|
|
470
|
+
|
|
471
|
+
ret = io_uring_queue_init(1, &ring, 0);
|
|
472
|
+
if (ret) {
|
|
473
|
+
perror("io_uring_queue_init");
|
|
474
|
+
return 1;
|
|
475
|
+
}
|
|
476
|
+
fd = ring.ring_fd;
|
|
477
|
+
|
|
478
|
+
/* try polling the ring fd */
|
|
479
|
+
status = ioring_poll(&ring, fd, 0);
|
|
480
|
+
|
|
481
|
+
/*
|
|
482
|
+
* now register the ring fd, and try the poll again. This should
|
|
483
|
+
* fail, because the kernel does not allow registering of the
|
|
484
|
+
* ring_fd.
|
|
485
|
+
*/
|
|
486
|
+
status |= expect_fail(fd, IORING_REGISTER_FILES, &fd, 1, EBADF);
|
|
487
|
+
|
|
488
|
+
/* tear down queue */
|
|
489
|
+
io_uring_queue_exit(&ring);
|
|
490
|
+
|
|
491
|
+
return status;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
static int test_shmem(void)
|
|
495
|
+
{
|
|
496
|
+
const char pattern = 0xEA;
|
|
497
|
+
const int len = 4096;
|
|
498
|
+
struct io_uring_sqe *sqe;
|
|
499
|
+
struct io_uring_cqe *cqe;
|
|
500
|
+
struct io_uring ring;
|
|
501
|
+
struct iovec iov;
|
|
502
|
+
int memfd, ret, i;
|
|
503
|
+
char *mem;
|
|
504
|
+
int pipefd[2] = {-1, -1};
|
|
505
|
+
|
|
506
|
+
ret = io_uring_queue_init(8, &ring, 0);
|
|
507
|
+
if (ret)
|
|
508
|
+
return 1;
|
|
509
|
+
|
|
510
|
+
if (pipe(pipefd)) {
|
|
511
|
+
perror("pipe");
|
|
512
|
+
return 1;
|
|
513
|
+
}
|
|
514
|
+
memfd = memfd_create("uring-shmem-test", 0);
|
|
515
|
+
if (memfd < 0) {
|
|
516
|
+
fprintf(stderr, "memfd_create() failed %i\n", -errno);
|
|
517
|
+
return 1;
|
|
518
|
+
}
|
|
519
|
+
if (ftruncate(memfd, len)) {
|
|
520
|
+
fprintf(stderr, "can't truncate memfd\n");
|
|
521
|
+
return 1;
|
|
522
|
+
}
|
|
523
|
+
mem = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, 0);
|
|
524
|
+
if (!mem) {
|
|
525
|
+
fprintf(stderr, "mmap failed\n");
|
|
526
|
+
return 1;
|
|
527
|
+
}
|
|
528
|
+
for (i = 0; i < len; i++)
|
|
529
|
+
mem[i] = pattern;
|
|
530
|
+
|
|
531
|
+
iov.iov_base = mem;
|
|
532
|
+
iov.iov_len = len;
|
|
533
|
+
ret = io_uring_register_buffers(&ring, &iov, 1);
|
|
534
|
+
if (ret) {
|
|
535
|
+
if (ret == -EOPNOTSUPP) {
|
|
536
|
+
fprintf(stdout, "memfd registration isn't supported, "
|
|
537
|
+
"skip\n");
|
|
538
|
+
goto out;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
fprintf(stderr, "buffer reg failed: %d\n", ret);
|
|
542
|
+
return 1;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/* check that we can read and write from/to shmem reg buffer */
|
|
546
|
+
sqe = io_uring_get_sqe(&ring);
|
|
547
|
+
io_uring_prep_write_fixed(sqe, pipefd[1], mem, 512, 0, 0);
|
|
548
|
+
sqe->user_data = 1;
|
|
549
|
+
|
|
550
|
+
ret = io_uring_submit(&ring);
|
|
551
|
+
if (ret != 1) {
|
|
552
|
+
fprintf(stderr, "submit write failed\n");
|
|
553
|
+
return 1;
|
|
554
|
+
}
|
|
555
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
|
556
|
+
if (ret < 0 || cqe->user_data != 1 || cqe->res != 512) {
|
|
557
|
+
fprintf(stderr, "reading from shmem failed\n");
|
|
558
|
+
return 1;
|
|
559
|
+
}
|
|
560
|
+
io_uring_cqe_seen(&ring, cqe);
|
|
561
|
+
|
|
562
|
+
/* clean it, should be populated with the pattern back from the pipe */
|
|
563
|
+
memset(mem, 0, 512);
|
|
564
|
+
sqe = io_uring_get_sqe(&ring);
|
|
565
|
+
io_uring_prep_read_fixed(sqe, pipefd[0], mem, 512, 0, 0);
|
|
566
|
+
sqe->user_data = 2;
|
|
567
|
+
|
|
568
|
+
ret = io_uring_submit(&ring);
|
|
569
|
+
if (ret != 1) {
|
|
570
|
+
fprintf(stderr, "submit write failed\n");
|
|
571
|
+
return 1;
|
|
572
|
+
}
|
|
573
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
|
574
|
+
if (ret < 0 || cqe->user_data != 2 || cqe->res != 512) {
|
|
575
|
+
fprintf(stderr, "reading from shmem failed\n");
|
|
576
|
+
return 1;
|
|
577
|
+
}
|
|
578
|
+
io_uring_cqe_seen(&ring, cqe);
|
|
579
|
+
|
|
580
|
+
for (i = 0; i < 512; i++) {
|
|
581
|
+
if (mem[i] != pattern) {
|
|
582
|
+
fprintf(stderr, "data integrity fail\n");
|
|
583
|
+
return 1;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
ret = io_uring_unregister_buffers(&ring);
|
|
588
|
+
if (ret) {
|
|
589
|
+
fprintf(stderr, "buffer unreg failed: %d\n", ret);
|
|
590
|
+
return 1;
|
|
591
|
+
}
|
|
592
|
+
out:
|
|
593
|
+
io_uring_queue_exit(&ring);
|
|
594
|
+
close(pipefd[0]);
|
|
595
|
+
close(pipefd[1]);
|
|
596
|
+
munmap(mem, len);
|
|
597
|
+
close(memfd);
|
|
598
|
+
return 0;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
int
|
|
602
|
+
main(int argc, char **argv)
|
|
603
|
+
{
|
|
604
|
+
int fd, ret;
|
|
605
|
+
unsigned int status = 0;
|
|
606
|
+
struct io_uring_params p;
|
|
607
|
+
struct rlimit rlim;
|
|
608
|
+
|
|
609
|
+
if (argc > 1)
|
|
610
|
+
return 0;
|
|
611
|
+
|
|
612
|
+
/* setup globals */
|
|
613
|
+
pagesize = getpagesize();
|
|
614
|
+
ret = getrlimit(RLIMIT_MEMLOCK, &rlim);
|
|
615
|
+
if (ret < 0) {
|
|
616
|
+
perror("getrlimit");
|
|
617
|
+
return 1;
|
|
618
|
+
}
|
|
619
|
+
mlock_limit = rlim.rlim_cur;
|
|
620
|
+
printf("RELIMIT_MEMLOCK: %lu (%lu)\n", rlim.rlim_cur, rlim.rlim_max);
|
|
621
|
+
devnull = open("/dev/null", O_RDWR);
|
|
622
|
+
if (devnull < 0) {
|
|
623
|
+
perror("open /dev/null");
|
|
624
|
+
exit(1);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/* invalid fd */
|
|
628
|
+
status |= expect_fail(-1, 0, NULL, 0, EBADF);
|
|
629
|
+
/* valid fd that is not an io_uring fd */
|
|
630
|
+
status |= expect_fail(devnull, 0, NULL, 0, EOPNOTSUPP);
|
|
631
|
+
|
|
632
|
+
/* invalid opcode */
|
|
633
|
+
memset(&p, 0, sizeof(p));
|
|
634
|
+
fd = new_io_uring(1, &p);
|
|
635
|
+
ret = expect_fail(fd, ~0U, NULL, 0, EINVAL);
|
|
636
|
+
if (ret) {
|
|
637
|
+
/* if this succeeds, tear down the io_uring instance
|
|
638
|
+
* and start clean for the next test. */
|
|
639
|
+
close(fd);
|
|
640
|
+
fd = new_io_uring(1, &p);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/* IORING_REGISTER_BUFFERS */
|
|
644
|
+
status |= test_iovec_size(fd);
|
|
645
|
+
status |= test_iovec_nr(fd);
|
|
646
|
+
/* IORING_REGISTER_FILES */
|
|
647
|
+
status |= test_max_fds(fd);
|
|
648
|
+
close(fd);
|
|
649
|
+
/* uring poll on the uring fd */
|
|
650
|
+
status |= test_poll_ringfd();
|
|
651
|
+
|
|
652
|
+
if (!status)
|
|
653
|
+
printf("PASS\n");
|
|
654
|
+
else
|
|
655
|
+
printf("FAIL\n");
|
|
656
|
+
|
|
657
|
+
ret = test_shmem();
|
|
658
|
+
if (ret) {
|
|
659
|
+
fprintf(stderr, "test_shmem() failed\n");
|
|
660
|
+
status |= 1;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
return status;
|
|
664
|
+
}
|