@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 @@
|
|
|
1
|
+
extend-diff-ignore = "(^|/)(config\.log|config-host\.h|config-host\.mak|liburing\.pc)$"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
CPPFLAGS ?=
|
|
2
|
+
override CPPFLAGS += -D_GNU_SOURCE -I../src/include/
|
|
3
|
+
CFLAGS ?= -g -O2
|
|
4
|
+
XCFLAGS =
|
|
5
|
+
override CFLAGS += -D_GNU_SOURCE -Wall -L../src/
|
|
6
|
+
|
|
7
|
+
include ../Makefile.quiet
|
|
8
|
+
|
|
9
|
+
ifneq ($(MAKECMDGOALS),clean)
|
|
10
|
+
include ../config-host.mak
|
|
11
|
+
endif
|
|
12
|
+
|
|
13
|
+
all_targets += io_uring-test io_uring-cp link-cp
|
|
14
|
+
|
|
15
|
+
ifdef CONFIG_HAVE_UCONTEXT
|
|
16
|
+
all_targets += ucontext-cp
|
|
17
|
+
endif
|
|
18
|
+
|
|
19
|
+
all: $(all_targets)
|
|
20
|
+
|
|
21
|
+
test_srcs := io_uring-test.c io_uring-cp.c link-cp.c
|
|
22
|
+
|
|
23
|
+
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
|
|
24
|
+
|
|
25
|
+
%: %.c
|
|
26
|
+
$(QUIET_CC)$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< -luring $(XCFLAGS)
|
|
27
|
+
|
|
28
|
+
clean:
|
|
29
|
+
@rm -f $(all_targets) $(test_objs)
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/*
|
|
3
|
+
* gcc -Wall -O2 -D_GNU_SOURCE -o io_uring-cp io_uring-cp.c -luring
|
|
4
|
+
*/
|
|
5
|
+
#include <stdio.h>
|
|
6
|
+
#include <fcntl.h>
|
|
7
|
+
#include <string.h>
|
|
8
|
+
#include <stdlib.h>
|
|
9
|
+
#include <unistd.h>
|
|
10
|
+
#include <assert.h>
|
|
11
|
+
#include <errno.h>
|
|
12
|
+
#include <inttypes.h>
|
|
13
|
+
#include <sys/types.h>
|
|
14
|
+
#include <sys/stat.h>
|
|
15
|
+
#include <sys/ioctl.h>
|
|
16
|
+
#include "liburing.h"
|
|
17
|
+
|
|
18
|
+
#define QD 64
|
|
19
|
+
#define BS (32*1024)
|
|
20
|
+
|
|
21
|
+
static int infd, outfd;
|
|
22
|
+
|
|
23
|
+
struct io_data {
|
|
24
|
+
int read;
|
|
25
|
+
off_t first_offset, offset;
|
|
26
|
+
size_t first_len;
|
|
27
|
+
struct iovec iov;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
static int setup_context(unsigned entries, struct io_uring *ring)
|
|
31
|
+
{
|
|
32
|
+
int ret;
|
|
33
|
+
|
|
34
|
+
ret = io_uring_queue_init(entries, ring, 0);
|
|
35
|
+
if (ret < 0) {
|
|
36
|
+
fprintf(stderr, "queue_init: %s\n", strerror(-ret));
|
|
37
|
+
return -1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static int get_file_size(int fd, off_t *size)
|
|
44
|
+
{
|
|
45
|
+
struct stat st;
|
|
46
|
+
|
|
47
|
+
if (fstat(fd, &st) < 0)
|
|
48
|
+
return -1;
|
|
49
|
+
if (S_ISREG(st.st_mode)) {
|
|
50
|
+
*size = st.st_size;
|
|
51
|
+
return 0;
|
|
52
|
+
} else if (S_ISBLK(st.st_mode)) {
|
|
53
|
+
unsigned long long bytes;
|
|
54
|
+
|
|
55
|
+
if (ioctl(fd, BLKGETSIZE64, &bytes) != 0)
|
|
56
|
+
return -1;
|
|
57
|
+
|
|
58
|
+
*size = bytes;
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return -1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static void queue_prepped(struct io_uring *ring, struct io_data *data)
|
|
66
|
+
{
|
|
67
|
+
struct io_uring_sqe *sqe;
|
|
68
|
+
|
|
69
|
+
sqe = io_uring_get_sqe(ring);
|
|
70
|
+
assert(sqe);
|
|
71
|
+
|
|
72
|
+
if (data->read)
|
|
73
|
+
io_uring_prep_readv(sqe, infd, &data->iov, 1, data->offset);
|
|
74
|
+
else
|
|
75
|
+
io_uring_prep_writev(sqe, outfd, &data->iov, 1, data->offset);
|
|
76
|
+
|
|
77
|
+
io_uring_sqe_set_data(sqe, data);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static int queue_read(struct io_uring *ring, off_t size, off_t offset)
|
|
81
|
+
{
|
|
82
|
+
struct io_uring_sqe *sqe;
|
|
83
|
+
struct io_data *data;
|
|
84
|
+
|
|
85
|
+
data = malloc(size + sizeof(*data));
|
|
86
|
+
if (!data)
|
|
87
|
+
return 1;
|
|
88
|
+
|
|
89
|
+
sqe = io_uring_get_sqe(ring);
|
|
90
|
+
if (!sqe) {
|
|
91
|
+
free(data);
|
|
92
|
+
return 1;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
data->read = 1;
|
|
96
|
+
data->offset = data->first_offset = offset;
|
|
97
|
+
|
|
98
|
+
data->iov.iov_base = data + 1;
|
|
99
|
+
data->iov.iov_len = size;
|
|
100
|
+
data->first_len = size;
|
|
101
|
+
|
|
102
|
+
io_uring_prep_readv(sqe, infd, &data->iov, 1, offset);
|
|
103
|
+
io_uring_sqe_set_data(sqe, data);
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static void queue_write(struct io_uring *ring, struct io_data *data)
|
|
108
|
+
{
|
|
109
|
+
data->read = 0;
|
|
110
|
+
data->offset = data->first_offset;
|
|
111
|
+
|
|
112
|
+
data->iov.iov_base = data + 1;
|
|
113
|
+
data->iov.iov_len = data->first_len;
|
|
114
|
+
|
|
115
|
+
queue_prepped(ring, data);
|
|
116
|
+
io_uring_submit(ring);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static int copy_file(struct io_uring *ring, off_t insize)
|
|
120
|
+
{
|
|
121
|
+
unsigned long reads, writes;
|
|
122
|
+
struct io_uring_cqe *cqe;
|
|
123
|
+
off_t write_left, offset;
|
|
124
|
+
int ret;
|
|
125
|
+
|
|
126
|
+
write_left = insize;
|
|
127
|
+
writes = reads = offset = 0;
|
|
128
|
+
|
|
129
|
+
while (insize || write_left) {
|
|
130
|
+
int had_reads, got_comp;
|
|
131
|
+
|
|
132
|
+
/*
|
|
133
|
+
* Queue up as many reads as we can
|
|
134
|
+
*/
|
|
135
|
+
had_reads = reads;
|
|
136
|
+
while (insize) {
|
|
137
|
+
off_t this_size = insize;
|
|
138
|
+
|
|
139
|
+
if (reads + writes >= QD)
|
|
140
|
+
break;
|
|
141
|
+
if (this_size > BS)
|
|
142
|
+
this_size = BS;
|
|
143
|
+
else if (!this_size)
|
|
144
|
+
break;
|
|
145
|
+
|
|
146
|
+
if (queue_read(ring, this_size, offset))
|
|
147
|
+
break;
|
|
148
|
+
|
|
149
|
+
insize -= this_size;
|
|
150
|
+
offset += this_size;
|
|
151
|
+
reads++;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (had_reads != reads) {
|
|
155
|
+
ret = io_uring_submit(ring);
|
|
156
|
+
if (ret < 0) {
|
|
157
|
+
fprintf(stderr, "io_uring_submit: %s\n", strerror(-ret));
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/*
|
|
163
|
+
* Queue is full at this point. Find at least one completion.
|
|
164
|
+
*/
|
|
165
|
+
got_comp = 0;
|
|
166
|
+
while (write_left) {
|
|
167
|
+
struct io_data *data;
|
|
168
|
+
|
|
169
|
+
if (!got_comp) {
|
|
170
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
|
171
|
+
got_comp = 1;
|
|
172
|
+
} else {
|
|
173
|
+
ret = io_uring_peek_cqe(ring, &cqe);
|
|
174
|
+
if (ret == -EAGAIN) {
|
|
175
|
+
cqe = NULL;
|
|
176
|
+
ret = 0;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (ret < 0) {
|
|
180
|
+
fprintf(stderr, "io_uring_peek_cqe: %s\n",
|
|
181
|
+
strerror(-ret));
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
184
|
+
if (!cqe)
|
|
185
|
+
break;
|
|
186
|
+
|
|
187
|
+
data = io_uring_cqe_get_data(cqe);
|
|
188
|
+
if (cqe->res < 0) {
|
|
189
|
+
if (cqe->res == -EAGAIN) {
|
|
190
|
+
queue_prepped(ring, data);
|
|
191
|
+
io_uring_cqe_seen(ring, cqe);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
fprintf(stderr, "cqe failed: %s\n",
|
|
195
|
+
strerror(-cqe->res));
|
|
196
|
+
return 1;
|
|
197
|
+
} else if (cqe->res != data->iov.iov_len) {
|
|
198
|
+
/* Short read/write, adjust and requeue */
|
|
199
|
+
data->iov.iov_base += cqe->res;
|
|
200
|
+
data->iov.iov_len -= cqe->res;
|
|
201
|
+
data->offset += cqe->res;
|
|
202
|
+
queue_prepped(ring, data);
|
|
203
|
+
io_uring_cqe_seen(ring, cqe);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/*
|
|
208
|
+
* All done. if write, nothing else to do. if read,
|
|
209
|
+
* queue up corresponding write.
|
|
210
|
+
*/
|
|
211
|
+
if (data->read) {
|
|
212
|
+
queue_write(ring, data);
|
|
213
|
+
write_left -= data->first_len;
|
|
214
|
+
reads--;
|
|
215
|
+
writes++;
|
|
216
|
+
} else {
|
|
217
|
+
free(data);
|
|
218
|
+
writes--;
|
|
219
|
+
}
|
|
220
|
+
io_uring_cqe_seen(ring, cqe);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* wait out pending writes */
|
|
225
|
+
while (writes) {
|
|
226
|
+
struct io_data *data;
|
|
227
|
+
|
|
228
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
|
229
|
+
if (ret) {
|
|
230
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
|
231
|
+
return 1;
|
|
232
|
+
}
|
|
233
|
+
if (cqe->res < 0) {
|
|
234
|
+
fprintf(stderr, "write res=%d\n", cqe->res);
|
|
235
|
+
return 1;
|
|
236
|
+
}
|
|
237
|
+
data = io_uring_cqe_get_data(cqe);
|
|
238
|
+
free(data);
|
|
239
|
+
writes--;
|
|
240
|
+
io_uring_cqe_seen(ring, cqe);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return 0;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
int main(int argc, char *argv[])
|
|
247
|
+
{
|
|
248
|
+
struct io_uring ring;
|
|
249
|
+
off_t insize;
|
|
250
|
+
int ret;
|
|
251
|
+
|
|
252
|
+
if (argc < 3) {
|
|
253
|
+
printf("%s: infile outfile\n", argv[0]);
|
|
254
|
+
return 1;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
infd = open(argv[1], O_RDONLY);
|
|
258
|
+
if (infd < 0) {
|
|
259
|
+
perror("open infile");
|
|
260
|
+
return 1;
|
|
261
|
+
}
|
|
262
|
+
outfd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
|
263
|
+
if (outfd < 0) {
|
|
264
|
+
perror("open outfile");
|
|
265
|
+
return 1;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (setup_context(QD, &ring))
|
|
269
|
+
return 1;
|
|
270
|
+
if (get_file_size(infd, &insize))
|
|
271
|
+
return 1;
|
|
272
|
+
|
|
273
|
+
ret = copy_file(&ring, insize);
|
|
274
|
+
|
|
275
|
+
close(infd);
|
|
276
|
+
close(outfd);
|
|
277
|
+
io_uring_queue_exit(&ring);
|
|
278
|
+
return ret;
|
|
279
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/*
|
|
3
|
+
* Simple app that demonstrates how to setup an io_uring interface,
|
|
4
|
+
* submit and complete IO against it, and then tear it down.
|
|
5
|
+
*
|
|
6
|
+
* gcc -Wall -O2 -D_GNU_SOURCE -o io_uring-test io_uring-test.c -luring
|
|
7
|
+
*/
|
|
8
|
+
#include <stdio.h>
|
|
9
|
+
#include <fcntl.h>
|
|
10
|
+
#include <string.h>
|
|
11
|
+
#include <stdlib.h>
|
|
12
|
+
#include <sys/types.h>
|
|
13
|
+
#include <sys/stat.h>
|
|
14
|
+
#include <unistd.h>
|
|
15
|
+
#include "liburing.h"
|
|
16
|
+
|
|
17
|
+
#define QD 4
|
|
18
|
+
|
|
19
|
+
int main(int argc, char *argv[])
|
|
20
|
+
{
|
|
21
|
+
struct io_uring ring;
|
|
22
|
+
int i, fd, ret, pending, done;
|
|
23
|
+
struct io_uring_sqe *sqe;
|
|
24
|
+
struct io_uring_cqe *cqe;
|
|
25
|
+
struct iovec *iovecs;
|
|
26
|
+
struct stat sb;
|
|
27
|
+
ssize_t fsize;
|
|
28
|
+
off_t offset;
|
|
29
|
+
void *buf;
|
|
30
|
+
|
|
31
|
+
if (argc < 2) {
|
|
32
|
+
printf("%s: file\n", argv[0]);
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
ret = io_uring_queue_init(QD, &ring, 0);
|
|
37
|
+
if (ret < 0) {
|
|
38
|
+
fprintf(stderr, "queue_init: %s\n", strerror(-ret));
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fd = open(argv[1], O_RDONLY | O_DIRECT);
|
|
43
|
+
if (fd < 0) {
|
|
44
|
+
perror("open");
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (fstat(fd, &sb) < 0) {
|
|
49
|
+
perror("fstat");
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
fsize = 0;
|
|
54
|
+
iovecs = calloc(QD, sizeof(struct iovec));
|
|
55
|
+
for (i = 0; i < QD; i++) {
|
|
56
|
+
if (posix_memalign(&buf, 4096, 4096))
|
|
57
|
+
return 1;
|
|
58
|
+
iovecs[i].iov_base = buf;
|
|
59
|
+
iovecs[i].iov_len = 4096;
|
|
60
|
+
fsize += 4096;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
offset = 0;
|
|
64
|
+
i = 0;
|
|
65
|
+
do {
|
|
66
|
+
sqe = io_uring_get_sqe(&ring);
|
|
67
|
+
if (!sqe)
|
|
68
|
+
break;
|
|
69
|
+
io_uring_prep_readv(sqe, fd, &iovecs[i], 1, offset);
|
|
70
|
+
offset += iovecs[i].iov_len;
|
|
71
|
+
i++;
|
|
72
|
+
if (offset > sb.st_size)
|
|
73
|
+
break;
|
|
74
|
+
} while (1);
|
|
75
|
+
|
|
76
|
+
ret = io_uring_submit(&ring);
|
|
77
|
+
if (ret < 0) {
|
|
78
|
+
fprintf(stderr, "io_uring_submit: %s\n", strerror(-ret));
|
|
79
|
+
return 1;
|
|
80
|
+
} else if (ret != i) {
|
|
81
|
+
fprintf(stderr, "io_uring_submit submitted less %d\n", ret);
|
|
82
|
+
return 1;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
done = 0;
|
|
86
|
+
pending = ret;
|
|
87
|
+
fsize = 0;
|
|
88
|
+
for (i = 0; i < pending; i++) {
|
|
89
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
|
90
|
+
if (ret < 0) {
|
|
91
|
+
fprintf(stderr, "io_uring_wait_cqe: %s\n", strerror(-ret));
|
|
92
|
+
return 1;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
done++;
|
|
96
|
+
ret = 0;
|
|
97
|
+
if (cqe->res != 4096 && cqe->res + fsize != sb.st_size) {
|
|
98
|
+
fprintf(stderr, "ret=%d, wanted 4096\n", cqe->res);
|
|
99
|
+
ret = 1;
|
|
100
|
+
}
|
|
101
|
+
fsize += cqe->res;
|
|
102
|
+
io_uring_cqe_seen(&ring, cqe);
|
|
103
|
+
if (ret)
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
printf("Submitted=%d, completed=%d, bytes=%lu\n", pending, done,
|
|
108
|
+
(unsigned long) fsize);
|
|
109
|
+
close(fd);
|
|
110
|
+
io_uring_queue_exit(&ring);
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/*
|
|
3
|
+
* Very basic proof-of-concept for doing a copy with linked SQEs. Needs a
|
|
4
|
+
* bit of error handling and short read love.
|
|
5
|
+
*/
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
#include <fcntl.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
#include <stdlib.h>
|
|
10
|
+
#include <unistd.h>
|
|
11
|
+
#include <assert.h>
|
|
12
|
+
#include <errno.h>
|
|
13
|
+
#include <inttypes.h>
|
|
14
|
+
#include <sys/types.h>
|
|
15
|
+
#include <sys/stat.h>
|
|
16
|
+
#include <sys/ioctl.h>
|
|
17
|
+
#include "liburing.h"
|
|
18
|
+
|
|
19
|
+
#define QD 64
|
|
20
|
+
#define BS (32*1024)
|
|
21
|
+
|
|
22
|
+
struct io_data {
|
|
23
|
+
size_t offset;
|
|
24
|
+
int index;
|
|
25
|
+
struct iovec iov;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
static int infd, outfd;
|
|
29
|
+
static unsigned inflight;
|
|
30
|
+
|
|
31
|
+
static int setup_context(unsigned entries, struct io_uring *ring)
|
|
32
|
+
{
|
|
33
|
+
int ret;
|
|
34
|
+
|
|
35
|
+
ret = io_uring_queue_init(entries, ring, 0);
|
|
36
|
+
if (ret < 0) {
|
|
37
|
+
fprintf(stderr, "queue_init: %s\n", strerror(-ret));
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static int get_file_size(int fd, off_t *size)
|
|
45
|
+
{
|
|
46
|
+
struct stat st;
|
|
47
|
+
|
|
48
|
+
if (fstat(fd, &st) < 0)
|
|
49
|
+
return -1;
|
|
50
|
+
if (S_ISREG(st.st_mode)) {
|
|
51
|
+
*size = st.st_size;
|
|
52
|
+
return 0;
|
|
53
|
+
} else if (S_ISBLK(st.st_mode)) {
|
|
54
|
+
unsigned long long bytes;
|
|
55
|
+
|
|
56
|
+
if (ioctl(fd, BLKGETSIZE64, &bytes) != 0)
|
|
57
|
+
return -1;
|
|
58
|
+
|
|
59
|
+
*size = bytes;
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return -1;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static void queue_rw_pair(struct io_uring *ring, off_t size, off_t offset)
|
|
67
|
+
{
|
|
68
|
+
struct io_uring_sqe *sqe;
|
|
69
|
+
struct io_data *data;
|
|
70
|
+
void *ptr;
|
|
71
|
+
|
|
72
|
+
ptr = malloc(size + sizeof(*data));
|
|
73
|
+
data = ptr + size;
|
|
74
|
+
data->index = 0;
|
|
75
|
+
data->offset = offset;
|
|
76
|
+
data->iov.iov_base = ptr;
|
|
77
|
+
data->iov.iov_len = size;
|
|
78
|
+
|
|
79
|
+
sqe = io_uring_get_sqe(ring);
|
|
80
|
+
io_uring_prep_readv(sqe, infd, &data->iov, 1, offset);
|
|
81
|
+
sqe->flags |= IOSQE_IO_LINK;
|
|
82
|
+
io_uring_sqe_set_data(sqe, data);
|
|
83
|
+
|
|
84
|
+
sqe = io_uring_get_sqe(ring);
|
|
85
|
+
io_uring_prep_writev(sqe, outfd, &data->iov, 1, offset);
|
|
86
|
+
io_uring_sqe_set_data(sqe, data);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static int handle_cqe(struct io_uring *ring, struct io_uring_cqe *cqe)
|
|
90
|
+
{
|
|
91
|
+
struct io_data *data = io_uring_cqe_get_data(cqe);
|
|
92
|
+
int ret = 0;
|
|
93
|
+
|
|
94
|
+
data->index++;
|
|
95
|
+
|
|
96
|
+
if (cqe->res < 0) {
|
|
97
|
+
if (cqe->res == -ECANCELED) {
|
|
98
|
+
queue_rw_pair(ring, BS, data->offset);
|
|
99
|
+
inflight += 2;
|
|
100
|
+
} else {
|
|
101
|
+
printf("cqe error: %s\n", strerror(-cqe->res));
|
|
102
|
+
ret = 1;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (data->index == 2) {
|
|
107
|
+
void *ptr = (void *) data - data->iov.iov_len;
|
|
108
|
+
|
|
109
|
+
free(ptr);
|
|
110
|
+
}
|
|
111
|
+
io_uring_cqe_seen(ring, cqe);
|
|
112
|
+
return ret;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static int copy_file(struct io_uring *ring, off_t insize)
|
|
116
|
+
{
|
|
117
|
+
struct io_uring_cqe *cqe;
|
|
118
|
+
size_t this_size;
|
|
119
|
+
off_t offset;
|
|
120
|
+
|
|
121
|
+
offset = 0;
|
|
122
|
+
while (insize) {
|
|
123
|
+
int has_inflight = inflight;
|
|
124
|
+
int depth;
|
|
125
|
+
|
|
126
|
+
while (insize && inflight < QD) {
|
|
127
|
+
this_size = BS;
|
|
128
|
+
if (this_size > insize)
|
|
129
|
+
this_size = insize;
|
|
130
|
+
queue_rw_pair(ring, this_size, offset);
|
|
131
|
+
offset += this_size;
|
|
132
|
+
insize -= this_size;
|
|
133
|
+
inflight += 2;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (has_inflight != inflight)
|
|
137
|
+
io_uring_submit(ring);
|
|
138
|
+
|
|
139
|
+
if (insize)
|
|
140
|
+
depth = QD;
|
|
141
|
+
else
|
|
142
|
+
depth = 1;
|
|
143
|
+
while (inflight >= depth) {
|
|
144
|
+
int ret;
|
|
145
|
+
|
|
146
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
|
147
|
+
if (ret < 0) {
|
|
148
|
+
printf("wait cqe: %s\n", strerror(-ret));
|
|
149
|
+
return 1;
|
|
150
|
+
}
|
|
151
|
+
if (handle_cqe(ring, cqe))
|
|
152
|
+
return 1;
|
|
153
|
+
inflight--;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
int main(int argc, char *argv[])
|
|
161
|
+
{
|
|
162
|
+
struct io_uring ring;
|
|
163
|
+
off_t insize;
|
|
164
|
+
int ret;
|
|
165
|
+
|
|
166
|
+
if (argc < 3) {
|
|
167
|
+
printf("%s: infile outfile\n", argv[0]);
|
|
168
|
+
return 1;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
infd = open(argv[1], O_RDONLY);
|
|
172
|
+
if (infd < 0) {
|
|
173
|
+
perror("open infile");
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
176
|
+
outfd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
|
177
|
+
if (outfd < 0) {
|
|
178
|
+
perror("open outfile");
|
|
179
|
+
return 1;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (setup_context(QD, &ring))
|
|
183
|
+
return 1;
|
|
184
|
+
if (get_file_size(infd, &insize))
|
|
185
|
+
return 1;
|
|
186
|
+
|
|
187
|
+
ret = copy_file(&ring, insize);
|
|
188
|
+
|
|
189
|
+
close(infd);
|
|
190
|
+
close(outfd);
|
|
191
|
+
io_uring_queue_exit(&ring);
|
|
192
|
+
return ret;
|
|
193
|
+
}
|