@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,537 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/*
|
|
3
|
+
* Description: Basic IO cancel test
|
|
4
|
+
*/
|
|
5
|
+
#include <errno.h>
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
#include <unistd.h>
|
|
8
|
+
#include <stdlib.h>
|
|
9
|
+
#include <string.h>
|
|
10
|
+
#include <fcntl.h>
|
|
11
|
+
#include <sys/types.h>
|
|
12
|
+
#include <sys/time.h>
|
|
13
|
+
#include <sys/wait.h>
|
|
14
|
+
#include <sys/poll.h>
|
|
15
|
+
|
|
16
|
+
#include "helpers.h"
|
|
17
|
+
#include "liburing.h"
|
|
18
|
+
|
|
19
|
+
#define FILE_SIZE (128 * 1024)
|
|
20
|
+
#define BS 4096
|
|
21
|
+
#define BUFFERS (FILE_SIZE / BS)
|
|
22
|
+
|
|
23
|
+
static struct iovec *vecs;
|
|
24
|
+
|
|
25
|
+
static unsigned long long utime_since(const struct timeval *s,
|
|
26
|
+
const struct timeval *e)
|
|
27
|
+
{
|
|
28
|
+
long long sec, usec;
|
|
29
|
+
|
|
30
|
+
sec = e->tv_sec - s->tv_sec;
|
|
31
|
+
usec = (e->tv_usec - s->tv_usec);
|
|
32
|
+
if (sec > 0 && usec < 0) {
|
|
33
|
+
sec--;
|
|
34
|
+
usec += 1000000;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
sec *= 1000000;
|
|
38
|
+
return sec + usec;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static unsigned long long utime_since_now(struct timeval *tv)
|
|
42
|
+
{
|
|
43
|
+
struct timeval end;
|
|
44
|
+
|
|
45
|
+
gettimeofday(&end, NULL);
|
|
46
|
+
return utime_since(tv, &end);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static int start_io(struct io_uring *ring, int fd, int do_write)
|
|
50
|
+
{
|
|
51
|
+
struct io_uring_sqe *sqe;
|
|
52
|
+
int i, ret;
|
|
53
|
+
|
|
54
|
+
for (i = 0; i < BUFFERS; i++) {
|
|
55
|
+
off_t offset;
|
|
56
|
+
|
|
57
|
+
sqe = io_uring_get_sqe(ring);
|
|
58
|
+
if (!sqe) {
|
|
59
|
+
fprintf(stderr, "sqe get failed\n");
|
|
60
|
+
goto err;
|
|
61
|
+
}
|
|
62
|
+
offset = BS * (rand() % BUFFERS);
|
|
63
|
+
if (do_write) {
|
|
64
|
+
io_uring_prep_writev(sqe, fd, &vecs[i], 1, offset);
|
|
65
|
+
} else {
|
|
66
|
+
io_uring_prep_readv(sqe, fd, &vecs[i], 1, offset);
|
|
67
|
+
}
|
|
68
|
+
sqe->user_data = i + 1;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
ret = io_uring_submit(ring);
|
|
72
|
+
if (ret != BUFFERS) {
|
|
73
|
+
fprintf(stderr, "submit got %d, wanted %d\n", ret, BUFFERS);
|
|
74
|
+
goto err;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return 0;
|
|
78
|
+
err:
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static int wait_io(struct io_uring *ring, unsigned nr_io, int do_partial)
|
|
83
|
+
{
|
|
84
|
+
struct io_uring_cqe *cqe;
|
|
85
|
+
int i, ret;
|
|
86
|
+
|
|
87
|
+
for (i = 0; i < nr_io; i++) {
|
|
88
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
|
89
|
+
if (ret) {
|
|
90
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
|
91
|
+
goto err;
|
|
92
|
+
}
|
|
93
|
+
if (do_partial && cqe->user_data) {
|
|
94
|
+
if (!(cqe->user_data & 1)) {
|
|
95
|
+
if (cqe->res != BS) {
|
|
96
|
+
fprintf(stderr, "IO %d wasn't cancelled but got error %d\n", (unsigned) cqe->user_data, cqe->res);
|
|
97
|
+
goto err;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
io_uring_cqe_seen(ring, cqe);
|
|
102
|
+
}
|
|
103
|
+
return 0;
|
|
104
|
+
err:
|
|
105
|
+
return 1;
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static int do_io(struct io_uring *ring, int fd, int do_write)
|
|
110
|
+
{
|
|
111
|
+
if (start_io(ring, fd, do_write))
|
|
112
|
+
return 1;
|
|
113
|
+
if (wait_io(ring, BUFFERS, 0))
|
|
114
|
+
return 1;
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static int start_cancel(struct io_uring *ring, int do_partial, int async_cancel)
|
|
119
|
+
{
|
|
120
|
+
struct io_uring_sqe *sqe;
|
|
121
|
+
int i, ret, submitted = 0;
|
|
122
|
+
|
|
123
|
+
for (i = 0; i < BUFFERS; i++) {
|
|
124
|
+
if (do_partial && (i & 1))
|
|
125
|
+
continue;
|
|
126
|
+
sqe = io_uring_get_sqe(ring);
|
|
127
|
+
if (!sqe) {
|
|
128
|
+
fprintf(stderr, "sqe get failed\n");
|
|
129
|
+
goto err;
|
|
130
|
+
}
|
|
131
|
+
io_uring_prep_cancel(sqe, (void *) (unsigned long) i + 1, 0);
|
|
132
|
+
if (async_cancel)
|
|
133
|
+
sqe->flags |= IOSQE_ASYNC;
|
|
134
|
+
sqe->user_data = 0;
|
|
135
|
+
submitted++;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
ret = io_uring_submit(ring);
|
|
139
|
+
if (ret != submitted) {
|
|
140
|
+
fprintf(stderr, "submit got %d, wanted %d\n", ret, submitted);
|
|
141
|
+
goto err;
|
|
142
|
+
}
|
|
143
|
+
return 0;
|
|
144
|
+
err:
|
|
145
|
+
return 1;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/*
|
|
149
|
+
* Test cancels. If 'do_partial' is set, then we only attempt to cancel half of
|
|
150
|
+
* the submitted IO. This is done to verify that cancelling one piece of IO doesn't
|
|
151
|
+
* impact others.
|
|
152
|
+
*/
|
|
153
|
+
static int test_io_cancel(const char *file, int do_write, int do_partial,
|
|
154
|
+
int async_cancel)
|
|
155
|
+
{
|
|
156
|
+
struct io_uring ring;
|
|
157
|
+
struct timeval start_tv;
|
|
158
|
+
unsigned long usecs;
|
|
159
|
+
unsigned to_wait;
|
|
160
|
+
int fd, ret;
|
|
161
|
+
|
|
162
|
+
fd = open(file, O_RDWR | O_DIRECT);
|
|
163
|
+
if (fd < 0) {
|
|
164
|
+
perror("file open");
|
|
165
|
+
goto err;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
ret = io_uring_queue_init(4 * BUFFERS, &ring, 0);
|
|
169
|
+
if (ret) {
|
|
170
|
+
fprintf(stderr, "ring create failed: %d\n", ret);
|
|
171
|
+
goto err;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (do_io(&ring, fd, do_write))
|
|
175
|
+
goto err;
|
|
176
|
+
gettimeofday(&start_tv, NULL);
|
|
177
|
+
if (do_io(&ring, fd, do_write))
|
|
178
|
+
goto err;
|
|
179
|
+
usecs = utime_since_now(&start_tv);
|
|
180
|
+
|
|
181
|
+
if (start_io(&ring, fd, do_write))
|
|
182
|
+
goto err;
|
|
183
|
+
/* sleep for 1/3 of the total time, to allow some to start/complete */
|
|
184
|
+
usleep(usecs / 3);
|
|
185
|
+
if (start_cancel(&ring, do_partial, async_cancel))
|
|
186
|
+
goto err;
|
|
187
|
+
to_wait = BUFFERS;
|
|
188
|
+
if (do_partial)
|
|
189
|
+
to_wait += BUFFERS / 2;
|
|
190
|
+
else
|
|
191
|
+
to_wait += BUFFERS;
|
|
192
|
+
if (wait_io(&ring, to_wait, do_partial))
|
|
193
|
+
goto err;
|
|
194
|
+
|
|
195
|
+
io_uring_queue_exit(&ring);
|
|
196
|
+
close(fd);
|
|
197
|
+
return 0;
|
|
198
|
+
err:
|
|
199
|
+
if (fd != -1)
|
|
200
|
+
close(fd);
|
|
201
|
+
return 1;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
static int test_dont_cancel_another_ring(void)
|
|
205
|
+
{
|
|
206
|
+
struct io_uring ring1, ring2;
|
|
207
|
+
struct io_uring_cqe *cqe;
|
|
208
|
+
struct io_uring_sqe *sqe;
|
|
209
|
+
char buffer[128];
|
|
210
|
+
int ret, fds[2];
|
|
211
|
+
struct __kernel_timespec ts = { .tv_sec = 0, .tv_nsec = 100000000, };
|
|
212
|
+
|
|
213
|
+
ret = io_uring_queue_init(8, &ring1, 0);
|
|
214
|
+
if (ret) {
|
|
215
|
+
fprintf(stderr, "ring create failed: %d\n", ret);
|
|
216
|
+
return 1;
|
|
217
|
+
}
|
|
218
|
+
ret = io_uring_queue_init(8, &ring2, 0);
|
|
219
|
+
if (ret) {
|
|
220
|
+
fprintf(stderr, "ring create failed: %d\n", ret);
|
|
221
|
+
return 1;
|
|
222
|
+
}
|
|
223
|
+
if (pipe(fds)) {
|
|
224
|
+
perror("pipe");
|
|
225
|
+
return 1;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
sqe = io_uring_get_sqe(&ring1);
|
|
229
|
+
if (!sqe) {
|
|
230
|
+
fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__);
|
|
231
|
+
return 1;
|
|
232
|
+
}
|
|
233
|
+
io_uring_prep_read(sqe, fds[0], buffer, 10, 0);
|
|
234
|
+
sqe->flags |= IOSQE_ASYNC;
|
|
235
|
+
sqe->user_data = 1;
|
|
236
|
+
|
|
237
|
+
ret = io_uring_submit(&ring1);
|
|
238
|
+
if (ret != 1) {
|
|
239
|
+
fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret);
|
|
240
|
+
return 1;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* make sure it doesn't cancel requests of the other ctx */
|
|
244
|
+
sqe = io_uring_get_sqe(&ring2);
|
|
245
|
+
if (!sqe) {
|
|
246
|
+
fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__);
|
|
247
|
+
return 1;
|
|
248
|
+
}
|
|
249
|
+
io_uring_prep_cancel(sqe, (void *) (unsigned long)1, 0);
|
|
250
|
+
sqe->user_data = 2;
|
|
251
|
+
|
|
252
|
+
ret = io_uring_submit(&ring2);
|
|
253
|
+
if (ret != 1) {
|
|
254
|
+
fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret);
|
|
255
|
+
return 1;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
ret = io_uring_wait_cqe(&ring2, &cqe);
|
|
259
|
+
if (ret) {
|
|
260
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
|
261
|
+
return 1;
|
|
262
|
+
}
|
|
263
|
+
if (cqe->user_data != 2 || cqe->res != -ENOENT) {
|
|
264
|
+
fprintf(stderr, "error: cqe %i: res=%i, but expected -ENOENT\n",
|
|
265
|
+
(int)cqe->user_data, (int)cqe->res);
|
|
266
|
+
return 1;
|
|
267
|
+
}
|
|
268
|
+
io_uring_cqe_seen(&ring2, cqe);
|
|
269
|
+
|
|
270
|
+
ret = io_uring_wait_cqe_timeout(&ring1, &cqe, &ts);
|
|
271
|
+
if (ret != -ETIME) {
|
|
272
|
+
fprintf(stderr, "read got cancelled or wait failed\n");
|
|
273
|
+
return 1;
|
|
274
|
+
}
|
|
275
|
+
io_uring_cqe_seen(&ring1, cqe);
|
|
276
|
+
|
|
277
|
+
close(fds[0]);
|
|
278
|
+
close(fds[1]);
|
|
279
|
+
io_uring_queue_exit(&ring1);
|
|
280
|
+
io_uring_queue_exit(&ring2);
|
|
281
|
+
return 0;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
static int test_cancel_req_across_fork(void)
|
|
285
|
+
{
|
|
286
|
+
struct io_uring ring;
|
|
287
|
+
struct io_uring_cqe *cqe;
|
|
288
|
+
struct io_uring_sqe *sqe;
|
|
289
|
+
char buffer[128];
|
|
290
|
+
int ret, i, fds[2];
|
|
291
|
+
pid_t p;
|
|
292
|
+
|
|
293
|
+
ret = io_uring_queue_init(8, &ring, 0);
|
|
294
|
+
if (ret) {
|
|
295
|
+
fprintf(stderr, "ring create failed: %d\n", ret);
|
|
296
|
+
return 1;
|
|
297
|
+
}
|
|
298
|
+
if (pipe(fds)) {
|
|
299
|
+
perror("pipe");
|
|
300
|
+
return 1;
|
|
301
|
+
}
|
|
302
|
+
sqe = io_uring_get_sqe(&ring);
|
|
303
|
+
if (!sqe) {
|
|
304
|
+
fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__);
|
|
305
|
+
return 1;
|
|
306
|
+
}
|
|
307
|
+
io_uring_prep_read(sqe, fds[0], buffer, 10, 0);
|
|
308
|
+
sqe->flags |= IOSQE_ASYNC;
|
|
309
|
+
sqe->user_data = 1;
|
|
310
|
+
|
|
311
|
+
ret = io_uring_submit(&ring);
|
|
312
|
+
if (ret != 1) {
|
|
313
|
+
fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret);
|
|
314
|
+
return 1;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
p = fork();
|
|
318
|
+
if (p == -1) {
|
|
319
|
+
fprintf(stderr, "fork() failed\n");
|
|
320
|
+
return 1;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (p == 0) {
|
|
324
|
+
sqe = io_uring_get_sqe(&ring);
|
|
325
|
+
if (!sqe) {
|
|
326
|
+
fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__);
|
|
327
|
+
return 1;
|
|
328
|
+
}
|
|
329
|
+
io_uring_prep_cancel(sqe, (void *) (unsigned long)1, 0);
|
|
330
|
+
sqe->user_data = 2;
|
|
331
|
+
|
|
332
|
+
ret = io_uring_submit(&ring);
|
|
333
|
+
if (ret != 1) {
|
|
334
|
+
fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret);
|
|
335
|
+
return 1;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
for (i = 0; i < 2; ++i) {
|
|
339
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
|
340
|
+
if (ret) {
|
|
341
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
|
342
|
+
return 1;
|
|
343
|
+
}
|
|
344
|
+
if ((cqe->user_data == 1 && cqe->res != -EINTR) ||
|
|
345
|
+
(cqe->user_data == 2 && cqe->res != -EALREADY && cqe->res)) {
|
|
346
|
+
fprintf(stderr, "%i %i\n", (int)cqe->user_data, cqe->res);
|
|
347
|
+
exit(1);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
io_uring_cqe_seen(&ring, cqe);
|
|
351
|
+
}
|
|
352
|
+
exit(0);
|
|
353
|
+
} else {
|
|
354
|
+
int wstatus;
|
|
355
|
+
|
|
356
|
+
if (waitpid(p, &wstatus, 0) == (pid_t)-1) {
|
|
357
|
+
perror("waitpid()");
|
|
358
|
+
return 1;
|
|
359
|
+
}
|
|
360
|
+
if (!WIFEXITED(wstatus) || WEXITSTATUS(wstatus)) {
|
|
361
|
+
fprintf(stderr, "child failed %i\n", WEXITSTATUS(wstatus));
|
|
362
|
+
return 1;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
close(fds[0]);
|
|
367
|
+
close(fds[1]);
|
|
368
|
+
io_uring_queue_exit(&ring);
|
|
369
|
+
return 0;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
static int test_cancel_inflight_exit(void)
|
|
373
|
+
{
|
|
374
|
+
struct __kernel_timespec ts = { .tv_sec = 1, .tv_nsec = 0, };
|
|
375
|
+
struct io_uring ring;
|
|
376
|
+
struct io_uring_cqe *cqe;
|
|
377
|
+
struct io_uring_sqe *sqe;
|
|
378
|
+
int ret, i;
|
|
379
|
+
pid_t p;
|
|
380
|
+
|
|
381
|
+
ret = io_uring_queue_init(8, &ring, 0);
|
|
382
|
+
if (ret) {
|
|
383
|
+
fprintf(stderr, "ring create failed: %d\n", ret);
|
|
384
|
+
return 1;
|
|
385
|
+
}
|
|
386
|
+
p = fork();
|
|
387
|
+
if (p == -1) {
|
|
388
|
+
fprintf(stderr, "fork() failed\n");
|
|
389
|
+
return 1;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (p == 0) {
|
|
393
|
+
sqe = io_uring_get_sqe(&ring);
|
|
394
|
+
io_uring_prep_poll_add(sqe, ring.ring_fd, POLLIN);
|
|
395
|
+
sqe->user_data = 1;
|
|
396
|
+
sqe->flags |= IOSQE_IO_LINK;
|
|
397
|
+
|
|
398
|
+
sqe = io_uring_get_sqe(&ring);
|
|
399
|
+
io_uring_prep_timeout(sqe, &ts, 0, 0);
|
|
400
|
+
sqe->user_data = 2;
|
|
401
|
+
|
|
402
|
+
sqe = io_uring_get_sqe(&ring);
|
|
403
|
+
io_uring_prep_timeout(sqe, &ts, 0, 0);
|
|
404
|
+
sqe->user_data = 3;
|
|
405
|
+
|
|
406
|
+
ret = io_uring_submit(&ring);
|
|
407
|
+
if (ret != 3) {
|
|
408
|
+
fprintf(stderr, "io_uring_submit() failed %s, ret %i\n", __FUNCTION__, ret);
|
|
409
|
+
exit(1);
|
|
410
|
+
}
|
|
411
|
+
exit(0);
|
|
412
|
+
} else {
|
|
413
|
+
int wstatus;
|
|
414
|
+
|
|
415
|
+
if (waitpid(p, &wstatus, 0) == (pid_t)-1) {
|
|
416
|
+
perror("waitpid()");
|
|
417
|
+
return 1;
|
|
418
|
+
}
|
|
419
|
+
if (!WIFEXITED(wstatus) || WEXITSTATUS(wstatus)) {
|
|
420
|
+
fprintf(stderr, "child failed %i\n", WEXITSTATUS(wstatus));
|
|
421
|
+
return 1;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
for (i = 0; i < 3; ++i) {
|
|
426
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
|
427
|
+
if (ret) {
|
|
428
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
|
429
|
+
return 1;
|
|
430
|
+
}
|
|
431
|
+
if ((cqe->user_data == 1 && cqe->res != -ECANCELED) ||
|
|
432
|
+
(cqe->user_data == 2 && cqe->res != -ECANCELED) ||
|
|
433
|
+
(cqe->user_data == 3 && cqe->res != -ETIME)) {
|
|
434
|
+
fprintf(stderr, "%i %i\n", (int)cqe->user_data, cqe->res);
|
|
435
|
+
return 1;
|
|
436
|
+
}
|
|
437
|
+
io_uring_cqe_seen(&ring, cqe);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
io_uring_queue_exit(&ring);
|
|
441
|
+
return 0;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
static int test_sqpoll_cancel_iowq_requests(void)
|
|
445
|
+
{
|
|
446
|
+
struct io_uring ring;
|
|
447
|
+
struct io_uring_sqe *sqe;
|
|
448
|
+
int ret, fds[2];
|
|
449
|
+
char buffer[16];
|
|
450
|
+
|
|
451
|
+
ret = io_uring_queue_init(8, &ring, IORING_SETUP_SQPOLL);
|
|
452
|
+
if (ret) {
|
|
453
|
+
fprintf(stderr, "ring create failed: %d\n", ret);
|
|
454
|
+
return 1;
|
|
455
|
+
}
|
|
456
|
+
if (pipe(fds)) {
|
|
457
|
+
perror("pipe");
|
|
458
|
+
return 1;
|
|
459
|
+
}
|
|
460
|
+
/* pin both pipe ends via io-wq */
|
|
461
|
+
sqe = io_uring_get_sqe(&ring);
|
|
462
|
+
io_uring_prep_read(sqe, fds[0], buffer, 10, 0);
|
|
463
|
+
sqe->flags |= IOSQE_ASYNC | IOSQE_IO_LINK;
|
|
464
|
+
sqe->user_data = 1;
|
|
465
|
+
|
|
466
|
+
sqe = io_uring_get_sqe(&ring);
|
|
467
|
+
io_uring_prep_write(sqe, fds[1], buffer, 10, 0);
|
|
468
|
+
sqe->flags |= IOSQE_ASYNC;
|
|
469
|
+
sqe->user_data = 2;
|
|
470
|
+
ret = io_uring_submit(&ring);
|
|
471
|
+
if (ret != 2) {
|
|
472
|
+
fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret);
|
|
473
|
+
return 1;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/* wait for sqpoll to kick in and submit before exit */
|
|
477
|
+
sleep(1);
|
|
478
|
+
io_uring_queue_exit(&ring);
|
|
479
|
+
|
|
480
|
+
/* close the write end, so if ring is cancelled properly read() fails*/
|
|
481
|
+
close(fds[1]);
|
|
482
|
+
ret = read(fds[0], buffer, 10);
|
|
483
|
+
close(fds[0]);
|
|
484
|
+
return 0;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
int main(int argc, char *argv[])
|
|
488
|
+
{
|
|
489
|
+
const char *fname = ".io-cancel-test";
|
|
490
|
+
int i, ret;
|
|
491
|
+
|
|
492
|
+
if (argc > 1)
|
|
493
|
+
return 0;
|
|
494
|
+
|
|
495
|
+
if (test_dont_cancel_another_ring()) {
|
|
496
|
+
fprintf(stderr, "test_dont_cancel_another_ring() failed\n");
|
|
497
|
+
return 1;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (test_cancel_req_across_fork()) {
|
|
501
|
+
fprintf(stderr, "test_cancel_req_across_fork() failed\n");
|
|
502
|
+
return 1;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
if (test_cancel_inflight_exit()) {
|
|
506
|
+
fprintf(stderr, "test_cancel_inflight_exit() failed\n");
|
|
507
|
+
return 1;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (test_sqpoll_cancel_iowq_requests()) {
|
|
511
|
+
fprintf(stderr, "test_sqpoll_cancel_iowq_requests() failed\n");
|
|
512
|
+
return 1;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
t_create_file(fname, FILE_SIZE);
|
|
516
|
+
|
|
517
|
+
vecs = t_create_buffers(BUFFERS, BS);
|
|
518
|
+
|
|
519
|
+
for (i = 0; i < 8; i++) {
|
|
520
|
+
int write = (i & 1) != 0;
|
|
521
|
+
int partial = (i & 2) != 0;
|
|
522
|
+
int async = (i & 4) != 0;
|
|
523
|
+
|
|
524
|
+
ret = test_io_cancel(fname, write, partial, async);
|
|
525
|
+
if (ret) {
|
|
526
|
+
fprintf(stderr, "test_io_cancel %d %d %d failed\n",
|
|
527
|
+
write, partial, async);
|
|
528
|
+
goto err;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
unlink(fname);
|
|
533
|
+
return 0;
|
|
534
|
+
err:
|
|
535
|
+
unlink(fname);
|
|
536
|
+
return 1;
|
|
537
|
+
}
|