polyphony 0.94 → 0.95
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -2
- data/.gitignore +3 -3
- data/CHANGELOG.md +14 -0
- data/docs/api-reference/fiber.md +2 -2
- data/docs/api-reference/object.md +3 -3
- data/docs/main-concepts/exception-handling.md +2 -2
- data/ext/polyphony/backend_common.c +3 -3
- data/ext/polyphony/backend_io_uring.c +18 -16
- data/ext/polyphony/event.c +1 -1
- data/ext/polyphony/extconf.rb +5 -3
- data/ext/polyphony/fiber.c +5 -13
- data/ext/polyphony/io_extensions.c +1 -1
- data/ext/polyphony/pipe.c +1 -1
- data/ext/polyphony/polyphony.c +1 -1
- data/ext/polyphony/polyphony_ext.c +1 -1
- data/ext/polyphony/queue.c +1 -1
- data/ext/polyphony/ring_buffer.c +1 -0
- data/ext/polyphony/socket_extensions.c +1 -1
- data/ext/polyphony/thread.c +1 -1
- data/lib/polyphony/extensions/enumerator.rb +16 -0
- data/lib/polyphony/extensions/socket.rb +2 -0
- data/lib/polyphony/extensions.rb +1 -0
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +2 -2
- data/test/test_backend.rb +5 -1
- data/test/test_enumerator.rb +46 -0
- data/test/test_io.rb +241 -216
- data/test/test_socket.rb +1 -1
- data/test/test_thread_pool.rb +3 -3
- data/vendor/liburing/.github/workflows/build.yml +51 -5
- data/vendor/liburing/.github/workflows/shellcheck.yml +1 -1
- data/vendor/liburing/.gitignore +6 -123
- data/vendor/liburing/CHANGELOG +35 -0
- data/vendor/liburing/CITATION.cff +11 -0
- data/vendor/liburing/LICENSE +16 -3
- data/vendor/liburing/Makefile +3 -1
- data/vendor/liburing/Makefile.common +1 -0
- data/vendor/liburing/README +14 -2
- data/vendor/liburing/SECURITY.md +6 -0
- data/vendor/liburing/configure +16 -15
- data/vendor/liburing/examples/Makefile +4 -1
- data/vendor/liburing/examples/io_uring-udp.c +395 -0
- data/vendor/liburing/examples/poll-bench.c +101 -0
- data/vendor/liburing/examples/send-zerocopy.c +339 -0
- data/vendor/liburing/liburing.spec +1 -1
- data/vendor/liburing/man/io_uring.7 +38 -11
- data/vendor/liburing/man/io_uring_buf_ring_add.3 +53 -0
- data/vendor/liburing/man/io_uring_buf_ring_advance.3 +31 -0
- data/vendor/liburing/man/io_uring_buf_ring_cq_advance.3 +41 -0
- data/vendor/liburing/man/io_uring_buf_ring_init.3 +30 -0
- data/vendor/liburing/man/io_uring_buf_ring_mask.3 +27 -0
- data/vendor/liburing/man/io_uring_cq_advance.3 +29 -15
- data/vendor/liburing/man/io_uring_cq_has_overflow.3 +25 -0
- data/vendor/liburing/man/io_uring_cq_ready.3 +9 -8
- data/vendor/liburing/man/io_uring_cqe_get_data.3 +32 -13
- data/vendor/liburing/man/io_uring_cqe_get_data64.3 +1 -0
- data/vendor/liburing/man/io_uring_cqe_seen.3 +22 -12
- data/vendor/liburing/man/io_uring_enter.2 +249 -32
- data/vendor/liburing/man/io_uring_enter2.2 +1 -0
- data/vendor/liburing/man/io_uring_free_probe.3 +11 -8
- data/vendor/liburing/man/io_uring_get_events.3 +33 -0
- data/vendor/liburing/man/io_uring_get_probe.3 +9 -8
- data/vendor/liburing/man/io_uring_get_sqe.3 +29 -10
- data/vendor/liburing/man/io_uring_opcode_supported.3 +11 -10
- data/vendor/liburing/man/io_uring_peek_cqe.3 +38 -0
- data/vendor/liburing/man/io_uring_prep_accept.3 +197 -0
- data/vendor/liburing/man/io_uring_prep_accept_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_cancel.3 +118 -0
- data/vendor/liburing/man/io_uring_prep_cancel64.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_close.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_close_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_connect.3 +66 -0
- data/vendor/liburing/man/io_uring_prep_fadvise.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_fallocate.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_files_update.3 +92 -0
- data/vendor/liburing/man/io_uring_prep_fsync.3 +70 -0
- data/vendor/liburing/man/io_uring_prep_link.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_linkat.3 +91 -0
- data/vendor/liburing/man/io_uring_prep_madvise.3 +56 -0
- data/vendor/liburing/man/io_uring_prep_mkdir.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_mkdirat.3 +83 -0
- data/vendor/liburing/man/io_uring_prep_msg_ring.3 +39 -25
- data/vendor/liburing/man/io_uring_prep_multishot_accept.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_multishot_accept_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_nop.3 +28 -0
- data/vendor/liburing/man/io_uring_prep_openat.3 +117 -0
- data/vendor/liburing/man/io_uring_prep_openat2.3 +117 -0
- data/vendor/liburing/man/io_uring_prep_openat2_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_openat_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_poll_add.3 +72 -0
- data/vendor/liburing/man/io_uring_prep_poll_multishot.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_poll_remove.3 +55 -0
- data/vendor/liburing/man/io_uring_prep_poll_update.3 +89 -0
- data/vendor/liburing/man/io_uring_prep_provide_buffers.3 +131 -0
- data/vendor/liburing/man/io_uring_prep_read.3 +33 -14
- data/vendor/liburing/man/io_uring_prep_read_fixed.3 +39 -21
- data/vendor/liburing/man/io_uring_prep_readv.3 +49 -15
- data/vendor/liburing/man/io_uring_prep_readv2.3 +49 -17
- data/vendor/liburing/man/io_uring_prep_recv.3 +105 -0
- data/vendor/liburing/man/io_uring_prep_recv_multishot.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_recvmsg.3 +124 -0
- data/vendor/liburing/man/io_uring_prep_recvmsg_multishot.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_remove_buffers.3 +52 -0
- data/vendor/liburing/man/io_uring_prep_rename.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_renameat.3 +96 -0
- data/vendor/liburing/man/io_uring_prep_send.3 +57 -0
- data/vendor/liburing/man/io_uring_prep_send_zc.3 +64 -0
- data/vendor/liburing/man/io_uring_prep_sendmsg.3 +69 -0
- data/vendor/liburing/man/io_uring_prep_shutdown.3 +53 -0
- data/vendor/liburing/man/io_uring_prep_socket.3 +118 -0
- data/vendor/liburing/man/io_uring_prep_socket_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_socket_direct_alloc.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_splice.3 +80 -0
- data/vendor/liburing/man/io_uring_prep_statx.3 +74 -0
- data/vendor/liburing/man/io_uring_prep_symlink.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_symlinkat.3 +85 -0
- data/vendor/liburing/man/io_uring_prep_sync_file_range.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_tee.3 +74 -0
- data/vendor/liburing/man/io_uring_prep_timeout.3 +95 -0
- data/vendor/liburing/man/io_uring_prep_timeout_remove.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_timeout_update.3 +98 -0
- data/vendor/liburing/man/io_uring_prep_unlink.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_unlinkat.3 +82 -0
- data/vendor/liburing/man/io_uring_prep_write.3 +32 -15
- data/vendor/liburing/man/io_uring_prep_write_fixed.3 +39 -21
- data/vendor/liburing/man/io_uring_prep_writev.3 +50 -16
- data/vendor/liburing/man/io_uring_prep_writev2.3 +50 -17
- data/vendor/liburing/man/io_uring_queue_exit.3 +3 -4
- data/vendor/liburing/man/io_uring_queue_init.3 +58 -13
- data/vendor/liburing/man/io_uring_queue_init_params.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_cmsg_firsthdr.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_cmsg_nexthdr.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_name.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_out.3 +78 -0
- data/vendor/liburing/man/io_uring_recvmsg_payload.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_payload_length.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_validate.3 +1 -0
- data/vendor/liburing/man/io_uring_register.2 +153 -13
- data/vendor/liburing/man/io_uring_register_buf_ring.3 +140 -0
- data/vendor/liburing/man/io_uring_register_buffers.3 +32 -12
- data/vendor/liburing/man/io_uring_register_eventfd.3 +51 -0
- data/vendor/liburing/man/io_uring_register_eventfd_async.3 +1 -0
- data/vendor/liburing/man/io_uring_register_file_alloc_range.3 +52 -0
- data/vendor/liburing/man/io_uring_register_files.3 +33 -11
- data/vendor/liburing/man/io_uring_register_files_sparse.3 +1 -0
- data/vendor/liburing/man/io_uring_register_iowq_aff.3 +61 -0
- data/vendor/liburing/man/io_uring_register_iowq_max_workers.3 +71 -0
- data/vendor/liburing/man/io_uring_register_ring_fd.3 +49 -0
- data/vendor/liburing/man/io_uring_register_sync_cancel.3 +71 -0
- data/vendor/liburing/man/io_uring_setup.2 +119 -13
- data/vendor/liburing/man/io_uring_sq_ready.3 +14 -8
- data/vendor/liburing/man/io_uring_sq_space_left.3 +9 -9
- data/vendor/liburing/man/io_uring_sqe_set_data.3 +29 -11
- data/vendor/liburing/man/io_uring_sqe_set_data64.3 +1 -0
- data/vendor/liburing/man/io_uring_sqe_set_flags.3 +38 -11
- data/vendor/liburing/man/io_uring_sqring_wait.3 +13 -9
- data/vendor/liburing/man/io_uring_submit.3 +29 -12
- data/vendor/liburing/man/io_uring_submit_and_get_events.3 +31 -0
- data/vendor/liburing/man/io_uring_submit_and_wait.3 +16 -12
- data/vendor/liburing/man/io_uring_submit_and_wait_timeout.3 +30 -23
- data/vendor/liburing/man/io_uring_unregister_buf_ring.3 +30 -0
- data/vendor/liburing/man/io_uring_unregister_buffers.3 +11 -10
- data/vendor/liburing/man/io_uring_unregister_eventfd.3 +1 -0
- data/vendor/liburing/man/io_uring_unregister_files.3 +11 -10
- data/vendor/liburing/man/io_uring_unregister_iowq_aff.3 +1 -0
- data/vendor/liburing/man/io_uring_unregister_ring_fd.3 +32 -0
- data/vendor/liburing/man/io_uring_wait_cqe.3 +19 -12
- data/vendor/liburing/man/io_uring_wait_cqe_nr.3 +21 -14
- data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +27 -13
- data/vendor/liburing/man/io_uring_wait_cqes.3 +24 -14
- data/vendor/liburing/src/Makefile +8 -7
- data/vendor/liburing/src/arch/aarch64/lib.h +48 -0
- data/vendor/liburing/src/arch/aarch64/syscall.h +0 -4
- data/vendor/liburing/src/arch/generic/lib.h +0 -4
- data/vendor/liburing/src/arch/generic/syscall.h +29 -16
- data/vendor/liburing/src/arch/syscall-defs.h +41 -14
- data/vendor/liburing/src/arch/x86/lib.h +0 -21
- data/vendor/liburing/src/arch/x86/syscall.h +146 -10
- data/vendor/liburing/src/include/liburing/io_uring.h +245 -5
- data/vendor/liburing/src/include/liburing.h +468 -35
- data/vendor/liburing/src/int_flags.h +1 -0
- data/vendor/liburing/src/lib.h +20 -16
- data/vendor/liburing/src/liburing.map +16 -0
- data/vendor/liburing/src/nolibc.c +1 -1
- data/vendor/liburing/src/queue.c +87 -55
- data/vendor/liburing/src/register.c +129 -53
- data/vendor/liburing/src/setup.c +65 -28
- data/vendor/liburing/src/syscall.c +14 -32
- data/vendor/liburing/src/syscall.h +12 -64
- data/vendor/liburing/test/{232c93d07b74-test.c → 232c93d07b74.c} +8 -9
- data/vendor/liburing/test/{35fa71a030ca-test.c → 35fa71a030ca.c} +4 -4
- data/vendor/liburing/test/{500f9fbadef8-test.c → 500f9fbadef8.c} +7 -7
- data/vendor/liburing/test/{7ad0e4b2f83c-test.c → 7ad0e4b2f83c.c} +8 -7
- data/vendor/liburing/test/{8a9973408177-test.c → 8a9973408177.c} +4 -3
- data/vendor/liburing/test/{917257daa0fe-test.c → 917257daa0fe.c} +3 -2
- data/vendor/liburing/test/Makefile +60 -62
- data/vendor/liburing/test/{a0908ae19763-test.c → a0908ae19763.c} +3 -2
- data/vendor/liburing/test/{a4c0b3decb33-test.c → a4c0b3decb33.c} +3 -2
- data/vendor/liburing/test/accept-link.c +5 -4
- data/vendor/liburing/test/accept-reuse.c +17 -16
- data/vendor/liburing/test/accept-test.c +14 -10
- data/vendor/liburing/test/accept.c +529 -107
- data/vendor/liburing/test/across-fork.c +7 -6
- data/vendor/liburing/test/{b19062a56726-test.c → b19062a56726.c} +3 -2
- data/vendor/liburing/test/{b5837bd5311d-test.c → b5837bd5311d.c} +10 -9
- data/vendor/liburing/test/buf-ring.c +420 -0
- data/vendor/liburing/test/{ce593a6c480a-test.c → ce593a6c480a.c} +15 -12
- data/vendor/liburing/test/connect.c +8 -7
- data/vendor/liburing/test/cq-full.c +5 -4
- data/vendor/liburing/test/cq-overflow.c +242 -12
- data/vendor/liburing/test/cq-peek-batch.c +5 -4
- data/vendor/liburing/test/cq-ready.c +5 -4
- data/vendor/liburing/test/cq-size.c +5 -4
- data/vendor/liburing/test/{d4ae271dfaae-test.c → d4ae271dfaae.c} +2 -2
- data/vendor/liburing/test/{d77a67ed5f27-test.c → d77a67ed5f27.c} +6 -6
- data/vendor/liburing/test/defer-taskrun.c +336 -0
- data/vendor/liburing/test/defer.c +26 -14
- data/vendor/liburing/test/double-poll-crash.c +15 -5
- data/vendor/liburing/test/drop-submit.c +5 -3
- data/vendor/liburing/test/{eeed8b54e0df-test.c → eeed8b54e0df.c} +7 -6
- data/vendor/liburing/test/empty-eownerdead.c +4 -4
- data/vendor/liburing/test/eventfd-disable.c +48 -20
- data/vendor/liburing/test/eventfd-reg.c +10 -9
- data/vendor/liburing/test/eventfd-ring.c +13 -12
- data/vendor/liburing/test/eventfd.c +13 -12
- data/vendor/liburing/test/exit-no-cleanup.c +1 -1
- data/vendor/liburing/test/fadvise.c +3 -3
- data/vendor/liburing/test/fallocate.c +16 -9
- data/vendor/liburing/test/{fc2a85cb02ef-test.c → fc2a85cb02ef.c} +4 -3
- data/vendor/liburing/test/fd-pass.c +187 -0
- data/vendor/liburing/test/file-register.c +302 -36
- data/vendor/liburing/test/file-update.c +62 -4
- data/vendor/liburing/test/file-verify.c +6 -2
- data/vendor/liburing/test/files-exit-hang-poll.c +11 -25
- data/vendor/liburing/test/files-exit-hang-timeout.c +13 -10
- data/vendor/liburing/test/fixed-buf-iter.c +115 -0
- data/vendor/liburing/test/fixed-link.c +10 -10
- data/vendor/liburing/test/fixed-reuse.c +160 -0
- data/vendor/liburing/test/fpos.c +6 -3
- data/vendor/liburing/test/fsync.c +3 -3
- data/vendor/liburing/test/hardlink.c +10 -6
- data/vendor/liburing/test/helpers.c +137 -4
- data/vendor/liburing/test/helpers.h +27 -0
- data/vendor/liburing/test/io-cancel.c +16 -11
- data/vendor/liburing/test/io_uring_enter.c +46 -81
- data/vendor/liburing/test/io_uring_passthrough.c +451 -0
- data/vendor/liburing/test/io_uring_register.c +59 -229
- data/vendor/liburing/test/io_uring_setup.c +24 -29
- data/vendor/liburing/test/iopoll-leak.c +85 -0
- data/vendor/liburing/test/iopoll.c +16 -9
- data/vendor/liburing/test/lfs-openat-write.c +3 -1
- data/vendor/liburing/test/link-timeout.c +4 -3
- data/vendor/liburing/test/link.c +8 -7
- data/vendor/liburing/test/madvise.c +2 -2
- data/vendor/liburing/test/mkdir.c +9 -5
- data/vendor/liburing/test/msg-ring.c +46 -20
- data/vendor/liburing/test/multicqes_drain.c +51 -12
- data/vendor/liburing/test/nolibc.c +60 -0
- data/vendor/liburing/test/nop.c +78 -16
- data/vendor/liburing/test/nvme.h +168 -0
- data/vendor/liburing/test/open-direct-link.c +188 -0
- data/vendor/liburing/test/open-direct-pick.c +180 -0
- data/vendor/liburing/test/openat2.c +3 -3
- data/vendor/liburing/test/poll-cancel-all.c +472 -0
- data/vendor/liburing/test/poll-link.c +9 -18
- data/vendor/liburing/test/poll-mshot-overflow.c +162 -0
- data/vendor/liburing/test/poll-mshot-update.c +83 -33
- data/vendor/liburing/test/pollfree.c +2 -2
- data/vendor/liburing/test/read-before-exit.c +112 -0
- data/vendor/liburing/test/read-write.c +83 -1
- data/vendor/liburing/test/recv-msgall-stream.c +398 -0
- data/vendor/liburing/test/recv-msgall.c +265 -0
- data/vendor/liburing/test/recv-multishot.c +505 -0
- data/vendor/liburing/test/rename.c +2 -5
- data/vendor/liburing/test/ring-leak.c +97 -0
- data/vendor/liburing/test/ringbuf-read.c +200 -0
- data/vendor/liburing/test/rsrc_tags.c +25 -13
- data/vendor/liburing/test/runtests-quiet.sh +11 -0
- data/vendor/liburing/test/runtests.sh +18 -20
- data/vendor/liburing/test/rw_merge_test.c +3 -2
- data/vendor/liburing/test/send-zerocopy.c +684 -0
- data/vendor/liburing/test/send_recv.c +49 -2
- data/vendor/liburing/test/send_recvmsg.c +165 -55
- data/vendor/liburing/test/shutdown.c +3 -4
- data/vendor/liburing/test/sigfd-deadlock.c +22 -8
- data/vendor/liburing/test/single-issuer.c +171 -0
- data/vendor/liburing/test/socket-rw-eagain.c +2 -12
- data/vendor/liburing/test/socket-rw-offset.c +2 -11
- data/vendor/liburing/test/socket-rw.c +2 -11
- data/vendor/liburing/test/socket.c +409 -0
- data/vendor/liburing/test/sq-poll-dup.c +1 -1
- data/vendor/liburing/test/sq-poll-share.c +1 -1
- data/vendor/liburing/test/statx.c +2 -2
- data/vendor/liburing/test/submit-and-wait.c +108 -0
- data/vendor/liburing/test/submit-link-fail.c +5 -3
- data/vendor/liburing/test/submit-reuse.c +0 -2
- data/vendor/liburing/test/sync-cancel.c +235 -0
- data/vendor/liburing/test/test.h +35 -0
- data/vendor/liburing/test/timeout-overflow.c +11 -11
- data/vendor/liburing/test/timeout.c +7 -7
- data/vendor/liburing/test/tty-write-dpoll.c +60 -0
- data/vendor/liburing/test/unlink.c +1 -1
- data/vendor/liburing/test/xattr.c +425 -0
- metadata +143 -22
- data/Gemfile.lock +0 -78
@@ -0,0 +1,451 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: basic read/write tests for io_uring passthrough commands
|
4
|
+
*/
|
5
|
+
#include <errno.h>
|
6
|
+
#include <stdio.h>
|
7
|
+
#include <unistd.h>
|
8
|
+
#include <stdlib.h>
|
9
|
+
#include <string.h>
|
10
|
+
|
11
|
+
#include "helpers.h"
|
12
|
+
#include "liburing.h"
|
13
|
+
#include "../src/syscall.h"
|
14
|
+
#include "nvme.h"
|
15
|
+
|
16
|
+
#define FILE_SIZE (256 * 1024)
|
17
|
+
#define BS 8192
|
18
|
+
#define BUFFERS (FILE_SIZE / BS)
|
19
|
+
|
20
|
+
static struct iovec *vecs;
|
21
|
+
|
22
|
+
/*
|
23
|
+
* Each offset in the file has the ((test_case / 2) * FILE_SIZE)
|
24
|
+
* + (offset / sizeof(int)) stored for every
|
25
|
+
* sizeof(int) address.
|
26
|
+
*/
|
27
|
+
static int verify_buf(int tc, void *buf, off_t off)
|
28
|
+
{
|
29
|
+
int i, u_in_buf = BS / sizeof(unsigned int);
|
30
|
+
unsigned int *ptr;
|
31
|
+
|
32
|
+
off /= sizeof(unsigned int);
|
33
|
+
off += (tc / 2) * FILE_SIZE;
|
34
|
+
ptr = buf;
|
35
|
+
for (i = 0; i < u_in_buf; i++) {
|
36
|
+
if (off != *ptr) {
|
37
|
+
fprintf(stderr, "Found %u, wanted %lu\n", *ptr, off);
|
38
|
+
return 1;
|
39
|
+
}
|
40
|
+
ptr++;
|
41
|
+
off++;
|
42
|
+
}
|
43
|
+
|
44
|
+
return 0;
|
45
|
+
}
|
46
|
+
|
47
|
+
static int fill_pattern(int tc)
|
48
|
+
{
|
49
|
+
unsigned int val, *ptr;
|
50
|
+
int i, j;
|
51
|
+
int u_in_buf = BS / sizeof(val);
|
52
|
+
|
53
|
+
val = (tc / 2) * FILE_SIZE;
|
54
|
+
for (i = 0; i < BUFFERS; i++) {
|
55
|
+
ptr = vecs[i].iov_base;
|
56
|
+
for (j = 0; j < u_in_buf; j++) {
|
57
|
+
*ptr = val;
|
58
|
+
val++;
|
59
|
+
ptr++;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
return 0;
|
64
|
+
}
|
65
|
+
|
66
|
+
static int __test_io(const char *file, struct io_uring *ring, int tc, int read,
|
67
|
+
int sqthread, int fixed, int nonvec)
|
68
|
+
{
|
69
|
+
struct io_uring_sqe *sqe;
|
70
|
+
struct io_uring_cqe *cqe;
|
71
|
+
struct nvme_uring_cmd *cmd;
|
72
|
+
int open_flags;
|
73
|
+
int do_fixed;
|
74
|
+
int i, ret, fd = -1;
|
75
|
+
off_t offset;
|
76
|
+
__u64 slba;
|
77
|
+
__u32 nlb;
|
78
|
+
|
79
|
+
if (read)
|
80
|
+
open_flags = O_RDONLY;
|
81
|
+
else
|
82
|
+
open_flags = O_WRONLY;
|
83
|
+
|
84
|
+
if (fixed) {
|
85
|
+
ret = t_register_buffers(ring, vecs, BUFFERS);
|
86
|
+
if (ret == T_SETUP_SKIP)
|
87
|
+
return 0;
|
88
|
+
if (ret != T_SETUP_OK) {
|
89
|
+
fprintf(stderr, "buffer reg failed: %d\n", ret);
|
90
|
+
goto err;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
fd = open(file, open_flags);
|
95
|
+
if (fd < 0) {
|
96
|
+
perror("file open");
|
97
|
+
goto err;
|
98
|
+
}
|
99
|
+
|
100
|
+
if (sqthread) {
|
101
|
+
ret = io_uring_register_files(ring, &fd, 1);
|
102
|
+
if (ret) {
|
103
|
+
fprintf(stderr, "file reg failed: %d\n", ret);
|
104
|
+
goto err;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
if (!read)
|
109
|
+
fill_pattern(tc);
|
110
|
+
|
111
|
+
offset = 0;
|
112
|
+
for (i = 0; i < BUFFERS; i++) {
|
113
|
+
sqe = io_uring_get_sqe(ring);
|
114
|
+
if (!sqe) {
|
115
|
+
fprintf(stderr, "sqe get failed\n");
|
116
|
+
goto err;
|
117
|
+
}
|
118
|
+
if (read) {
|
119
|
+
int use_fd = fd;
|
120
|
+
|
121
|
+
do_fixed = fixed;
|
122
|
+
|
123
|
+
if (sqthread)
|
124
|
+
use_fd = 0;
|
125
|
+
if (fixed && (i & 1))
|
126
|
+
do_fixed = 0;
|
127
|
+
if (do_fixed) {
|
128
|
+
io_uring_prep_read_fixed(sqe, use_fd, vecs[i].iov_base,
|
129
|
+
vecs[i].iov_len,
|
130
|
+
offset, i);
|
131
|
+
sqe->cmd_op = NVME_URING_CMD_IO;
|
132
|
+
} else if (nonvec) {
|
133
|
+
io_uring_prep_read(sqe, use_fd, vecs[i].iov_base,
|
134
|
+
vecs[i].iov_len, offset);
|
135
|
+
sqe->cmd_op = NVME_URING_CMD_IO;
|
136
|
+
} else {
|
137
|
+
io_uring_prep_readv(sqe, use_fd, &vecs[i], 1,
|
138
|
+
offset);
|
139
|
+
sqe->cmd_op = NVME_URING_CMD_IO_VEC;
|
140
|
+
}
|
141
|
+
} else {
|
142
|
+
int use_fd = fd;
|
143
|
+
|
144
|
+
do_fixed = fixed;
|
145
|
+
|
146
|
+
if (sqthread)
|
147
|
+
use_fd = 0;
|
148
|
+
if (fixed && (i & 1))
|
149
|
+
do_fixed = 0;
|
150
|
+
if (do_fixed) {
|
151
|
+
io_uring_prep_write_fixed(sqe, use_fd, vecs[i].iov_base,
|
152
|
+
vecs[i].iov_len,
|
153
|
+
offset, i);
|
154
|
+
sqe->cmd_op = NVME_URING_CMD_IO;
|
155
|
+
} else if (nonvec) {
|
156
|
+
io_uring_prep_write(sqe, use_fd, vecs[i].iov_base,
|
157
|
+
vecs[i].iov_len, offset);
|
158
|
+
sqe->cmd_op = NVME_URING_CMD_IO;
|
159
|
+
} else {
|
160
|
+
io_uring_prep_writev(sqe, use_fd, &vecs[i], 1,
|
161
|
+
offset);
|
162
|
+
sqe->cmd_op = NVME_URING_CMD_IO_VEC;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
sqe->opcode = IORING_OP_URING_CMD;
|
166
|
+
sqe->user_data = ((uint64_t)offset << 32) | i;
|
167
|
+
if (sqthread)
|
168
|
+
sqe->flags |= IOSQE_FIXED_FILE;
|
169
|
+
|
170
|
+
cmd = (struct nvme_uring_cmd *)sqe->cmd;
|
171
|
+
memset(cmd, 0, sizeof(struct nvme_uring_cmd));
|
172
|
+
|
173
|
+
cmd->opcode = read ? nvme_cmd_read : nvme_cmd_write;
|
174
|
+
|
175
|
+
slba = offset >> lba_shift;
|
176
|
+
nlb = (BS >> lba_shift) - 1;
|
177
|
+
|
178
|
+
/* cdw10 and cdw11 represent starting lba */
|
179
|
+
cmd->cdw10 = slba & 0xffffffff;
|
180
|
+
cmd->cdw11 = slba >> 32;
|
181
|
+
/* cdw12 represent number of lba's for read/write */
|
182
|
+
cmd->cdw12 = nlb;
|
183
|
+
if (do_fixed || nonvec) {
|
184
|
+
cmd->addr = (__u64)(uintptr_t)vecs[i].iov_base;
|
185
|
+
cmd->data_len = vecs[i].iov_len;
|
186
|
+
} else {
|
187
|
+
cmd->addr = (__u64)(uintptr_t)&vecs[i];
|
188
|
+
cmd->data_len = 1;
|
189
|
+
}
|
190
|
+
cmd->nsid = nsid;
|
191
|
+
|
192
|
+
offset += BS;
|
193
|
+
}
|
194
|
+
|
195
|
+
ret = io_uring_submit(ring);
|
196
|
+
if (ret != BUFFERS) {
|
197
|
+
fprintf(stderr, "submit got %d, wanted %d\n", ret, BUFFERS);
|
198
|
+
goto err;
|
199
|
+
}
|
200
|
+
|
201
|
+
for (i = 0; i < BUFFERS; i++) {
|
202
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
203
|
+
if (ret) {
|
204
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
205
|
+
goto err;
|
206
|
+
}
|
207
|
+
if (cqe->res != 0) {
|
208
|
+
fprintf(stderr, "cqe res %d, wanted 0\n", cqe->res);
|
209
|
+
goto err;
|
210
|
+
}
|
211
|
+
io_uring_cqe_seen(ring, cqe);
|
212
|
+
if (read) {
|
213
|
+
int index = cqe->user_data & 0xffffffff;
|
214
|
+
void *buf = vecs[index].iov_base;
|
215
|
+
off_t voff = cqe->user_data >> 32;
|
216
|
+
|
217
|
+
if (verify_buf(tc, buf, voff))
|
218
|
+
goto err;
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
if (fixed) {
|
223
|
+
ret = io_uring_unregister_buffers(ring);
|
224
|
+
if (ret) {
|
225
|
+
fprintf(stderr, "buffer unreg failed: %d\n", ret);
|
226
|
+
goto err;
|
227
|
+
}
|
228
|
+
}
|
229
|
+
if (sqthread) {
|
230
|
+
ret = io_uring_unregister_files(ring);
|
231
|
+
if (ret) {
|
232
|
+
fprintf(stderr, "file unreg failed: %d\n", ret);
|
233
|
+
goto err;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
close(fd);
|
238
|
+
return 0;
|
239
|
+
err:
|
240
|
+
if (fd != -1)
|
241
|
+
close(fd);
|
242
|
+
return 1;
|
243
|
+
}
|
244
|
+
|
245
|
+
static int test_io(const char *file, int tc, int read, int sqthread,
|
246
|
+
int fixed, int nonvec)
|
247
|
+
{
|
248
|
+
struct io_uring ring;
|
249
|
+
int ret, ring_flags = 0;
|
250
|
+
|
251
|
+
ring_flags |= IORING_SETUP_SQE128;
|
252
|
+
ring_flags |= IORING_SETUP_CQE32;
|
253
|
+
|
254
|
+
if (sqthread)
|
255
|
+
ring_flags |= IORING_SETUP_SQPOLL;
|
256
|
+
|
257
|
+
ret = t_create_ring(64, &ring, ring_flags);
|
258
|
+
if (ret == T_SETUP_SKIP)
|
259
|
+
return 0;
|
260
|
+
if (ret != T_SETUP_OK) {
|
261
|
+
fprintf(stderr, "ring create failed: %d\n", ret);
|
262
|
+
return 1;
|
263
|
+
}
|
264
|
+
|
265
|
+
ret = __test_io(file, &ring, tc, read, sqthread, fixed, nonvec);
|
266
|
+
io_uring_queue_exit(&ring);
|
267
|
+
|
268
|
+
return ret;
|
269
|
+
}
|
270
|
+
|
271
|
+
extern unsigned __io_uring_flush_sq(struct io_uring *ring);
|
272
|
+
|
273
|
+
/*
|
274
|
+
* Send a passthrough command that nvme will fail during submission.
|
275
|
+
* This comes handy for testing error handling.
|
276
|
+
*/
|
277
|
+
static int test_invalid_passthru_submit(const char *file)
|
278
|
+
{
|
279
|
+
struct io_uring ring;
|
280
|
+
int fd, ret, ring_flags, open_flags;
|
281
|
+
struct io_uring_cqe *cqe;
|
282
|
+
struct io_uring_sqe *sqe;
|
283
|
+
struct nvme_uring_cmd *cmd;
|
284
|
+
|
285
|
+
ring_flags = IORING_SETUP_IOPOLL | IORING_SETUP_SQE128;
|
286
|
+
ring_flags |= IORING_SETUP_CQE32;
|
287
|
+
|
288
|
+
ret = t_create_ring(1, &ring, ring_flags);
|
289
|
+
if (ret != T_SETUP_OK) {
|
290
|
+
fprintf(stderr, "ring create failed: %d\n", ret);
|
291
|
+
return 1;
|
292
|
+
}
|
293
|
+
|
294
|
+
open_flags = O_RDONLY;
|
295
|
+
fd = open(file, open_flags);
|
296
|
+
if (fd < 0) {
|
297
|
+
perror("file open");
|
298
|
+
goto err;
|
299
|
+
}
|
300
|
+
|
301
|
+
sqe = io_uring_get_sqe(&ring);
|
302
|
+
io_uring_prep_read(sqe, fd, vecs[0].iov_base, vecs[0].iov_len, 0);
|
303
|
+
sqe->cmd_op = NVME_URING_CMD_IO;
|
304
|
+
sqe->opcode = IORING_OP_URING_CMD;
|
305
|
+
sqe->user_data = 1;
|
306
|
+
cmd = (struct nvme_uring_cmd *)sqe->cmd;
|
307
|
+
memset(cmd, 0, sizeof(struct nvme_uring_cmd));
|
308
|
+
cmd->opcode = nvme_cmd_read;
|
309
|
+
cmd->addr = (__u64)(uintptr_t)&vecs[0].iov_base;
|
310
|
+
cmd->data_len = vecs[0].iov_len;
|
311
|
+
/* populate wrong nsid to force failure */
|
312
|
+
cmd->nsid = nsid + 1;
|
313
|
+
|
314
|
+
ret = io_uring_submit(&ring);
|
315
|
+
if (ret != 1) {
|
316
|
+
fprintf(stderr, "submit got %d, wanted %d\n", ret, 1);
|
317
|
+
goto err;
|
318
|
+
}
|
319
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
320
|
+
if (ret) {
|
321
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
322
|
+
goto err;
|
323
|
+
}
|
324
|
+
if (cqe->res == 0) {
|
325
|
+
fprintf(stderr, "cqe res %d, wanted failure\n", cqe->res);
|
326
|
+
goto err;
|
327
|
+
}
|
328
|
+
io_uring_cqe_seen(&ring, cqe);
|
329
|
+
close(fd);
|
330
|
+
io_uring_queue_exit(&ring);
|
331
|
+
return 0;
|
332
|
+
err:
|
333
|
+
if (fd != -1)
|
334
|
+
close(fd);
|
335
|
+
io_uring_queue_exit(&ring);
|
336
|
+
return 1;
|
337
|
+
}
|
338
|
+
|
339
|
+
/*
|
340
|
+
* if we are polling io_uring_submit needs to always enter the
|
341
|
+
* kernel to fetch events
|
342
|
+
*/
|
343
|
+
static int test_io_uring_submit_enters(const char *file)
|
344
|
+
{
|
345
|
+
struct io_uring ring;
|
346
|
+
int fd, i, ret, ring_flags, open_flags;
|
347
|
+
unsigned head;
|
348
|
+
struct io_uring_cqe *cqe;
|
349
|
+
|
350
|
+
ring_flags = IORING_SETUP_IOPOLL;
|
351
|
+
ring_flags |= IORING_SETUP_SQE128;
|
352
|
+
ring_flags |= IORING_SETUP_CQE32;
|
353
|
+
|
354
|
+
ret = io_uring_queue_init(64, &ring, ring_flags);
|
355
|
+
if (ret) {
|
356
|
+
fprintf(stderr, "ring create failed: %d\n", ret);
|
357
|
+
return 1;
|
358
|
+
}
|
359
|
+
|
360
|
+
open_flags = O_WRONLY;
|
361
|
+
fd = open(file, open_flags);
|
362
|
+
if (fd < 0) {
|
363
|
+
perror("file open");
|
364
|
+
goto err;
|
365
|
+
}
|
366
|
+
|
367
|
+
for (i = 0; i < BUFFERS; i++) {
|
368
|
+
struct io_uring_sqe *sqe;
|
369
|
+
off_t offset = BS * (rand() % BUFFERS);
|
370
|
+
|
371
|
+
sqe = io_uring_get_sqe(&ring);
|
372
|
+
io_uring_prep_writev(sqe, fd, &vecs[i], 1, offset);
|
373
|
+
sqe->user_data = 1;
|
374
|
+
}
|
375
|
+
|
376
|
+
/* submit manually to avoid adding IORING_ENTER_GETEVENTS */
|
377
|
+
ret = __sys_io_uring_enter(ring.ring_fd, __io_uring_flush_sq(&ring), 0,
|
378
|
+
0, NULL);
|
379
|
+
if (ret < 0)
|
380
|
+
goto err;
|
381
|
+
|
382
|
+
for (i = 0; i < 500; i++) {
|
383
|
+
ret = io_uring_submit(&ring);
|
384
|
+
if (ret != 0) {
|
385
|
+
fprintf(stderr, "still had %d sqes to submit\n", ret);
|
386
|
+
goto err;
|
387
|
+
}
|
388
|
+
|
389
|
+
io_uring_for_each_cqe(&ring, head, cqe) {
|
390
|
+
if (cqe->res == -EOPNOTSUPP)
|
391
|
+
fprintf(stdout, "Device doesn't support polled IO\n");
|
392
|
+
goto ok;
|
393
|
+
}
|
394
|
+
usleep(10000);
|
395
|
+
}
|
396
|
+
err:
|
397
|
+
ret = 1;
|
398
|
+
if (fd != -1)
|
399
|
+
close(fd);
|
400
|
+
|
401
|
+
ok:
|
402
|
+
io_uring_queue_exit(&ring);
|
403
|
+
return ret;
|
404
|
+
}
|
405
|
+
|
406
|
+
int main(int argc, char *argv[])
|
407
|
+
{
|
408
|
+
int i, ret;
|
409
|
+
char *fname;
|
410
|
+
|
411
|
+
if (argc < 2)
|
412
|
+
return T_EXIT_SKIP;
|
413
|
+
|
414
|
+
fname = argv[1];
|
415
|
+
ret = nvme_get_info(fname);
|
416
|
+
|
417
|
+
if (ret)
|
418
|
+
return T_EXIT_SKIP;
|
419
|
+
|
420
|
+
vecs = t_create_buffers(BUFFERS, BS);
|
421
|
+
|
422
|
+
for (i = 0; i < 16; i++) {
|
423
|
+
int read = (i & 1) != 0;
|
424
|
+
int sqthread = (i & 2) != 0;
|
425
|
+
int fixed = (i & 4) != 0;
|
426
|
+
int nonvec = (i & 8) != 0;
|
427
|
+
|
428
|
+
ret = test_io(fname, i, read, sqthread, fixed, nonvec);
|
429
|
+
if (ret) {
|
430
|
+
fprintf(stderr, "test_io failed %d/%d/%d/%d\n",
|
431
|
+
read, sqthread, fixed, nonvec);
|
432
|
+
goto err;
|
433
|
+
}
|
434
|
+
}
|
435
|
+
|
436
|
+
ret = test_io_uring_submit_enters(fname);
|
437
|
+
if (ret) {
|
438
|
+
fprintf(stderr, "test_io_uring_submit_enters failed\n");
|
439
|
+
goto err;
|
440
|
+
}
|
441
|
+
|
442
|
+
ret = test_invalid_passthru_submit(fname);
|
443
|
+
if (ret) {
|
444
|
+
fprintf(stderr, "test_invalid_passthru_submit failed\n");
|
445
|
+
goto err;
|
446
|
+
}
|
447
|
+
|
448
|
+
return T_EXIT_PASS;
|
449
|
+
err:
|
450
|
+
return T_EXIT_FAIL;
|
451
|
+
}
|