1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2020 ARM. All rights reserved.
4*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2020 Petr Vorel <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker *
6*49cdfc7eSAndroid Build Coastguard Worker * Mostly copied/adapted from <linux/io_uring.h>
7*49cdfc7eSAndroid Build Coastguard Worker */
8*49cdfc7eSAndroid Build Coastguard Worker
9*49cdfc7eSAndroid Build Coastguard Worker #ifndef LAPI_IO_URING_H__
10*49cdfc7eSAndroid Build Coastguard Worker #define LAPI_IO_URING_H__
11*49cdfc7eSAndroid Build Coastguard Worker
12*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
13*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
14*49cdfc7eSAndroid Build Coastguard Worker #include <sys/uio.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include <linux/types.h>
17*49cdfc7eSAndroid Build Coastguard Worker
18*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker #ifdef HAVE_LINUX_IO_URING_H
21*49cdfc7eSAndroid Build Coastguard Worker #include <linux/io_uring.h>
22*49cdfc7eSAndroid Build Coastguard Worker #endif
23*49cdfc7eSAndroid Build Coastguard Worker
24*49cdfc7eSAndroid Build Coastguard Worker #ifndef IOSQE_FIXED_FILE
25*49cdfc7eSAndroid Build Coastguard Worker
26*49cdfc7eSAndroid Build Coastguard Worker #ifndef __kernel_rwf_t
27*49cdfc7eSAndroid Build Coastguard Worker typedef int __kernel_rwf_t;
28*49cdfc7eSAndroid Build Coastguard Worker #endif
29*49cdfc7eSAndroid Build Coastguard Worker
30*49cdfc7eSAndroid Build Coastguard Worker /*
31*49cdfc7eSAndroid Build Coastguard Worker * IO submission data structure (Submission Queue Entry)
32*49cdfc7eSAndroid Build Coastguard Worker */
33*49cdfc7eSAndroid Build Coastguard Worker struct io_uring_sqe {
34*49cdfc7eSAndroid Build Coastguard Worker uint8_t opcode; /* type of operation for this sqe */
35*49cdfc7eSAndroid Build Coastguard Worker uint8_t flags; /* IOSQE_ flags */
36*49cdfc7eSAndroid Build Coastguard Worker uint16_t ioprio; /* ioprio for the request */
37*49cdfc7eSAndroid Build Coastguard Worker int32_t fd; /* file descriptor to do IO on */
38*49cdfc7eSAndroid Build Coastguard Worker union {
39*49cdfc7eSAndroid Build Coastguard Worker uint64_t off; /* offset into file */
40*49cdfc7eSAndroid Build Coastguard Worker uint64_t addr2;
41*49cdfc7eSAndroid Build Coastguard Worker };
42*49cdfc7eSAndroid Build Coastguard Worker uint64_t addr; /* pointer to buffer or iovecs */
43*49cdfc7eSAndroid Build Coastguard Worker uint32_t len; /* buffer size or number of iovecs */
44*49cdfc7eSAndroid Build Coastguard Worker union {
45*49cdfc7eSAndroid Build Coastguard Worker __kernel_rwf_t rw_flags;
46*49cdfc7eSAndroid Build Coastguard Worker uint32_t fsync_flags;
47*49cdfc7eSAndroid Build Coastguard Worker uint16_t poll_events;
48*49cdfc7eSAndroid Build Coastguard Worker uint32_t sync_range_flags;
49*49cdfc7eSAndroid Build Coastguard Worker uint32_t msg_flags;
50*49cdfc7eSAndroid Build Coastguard Worker uint32_t timeout_flags;
51*49cdfc7eSAndroid Build Coastguard Worker uint32_t accept_flags;
52*49cdfc7eSAndroid Build Coastguard Worker uint32_t cancel_flags;
53*49cdfc7eSAndroid Build Coastguard Worker uint32_t open_flags;
54*49cdfc7eSAndroid Build Coastguard Worker uint32_t statx_flags;
55*49cdfc7eSAndroid Build Coastguard Worker uint32_t fadvise_advice;
56*49cdfc7eSAndroid Build Coastguard Worker };
57*49cdfc7eSAndroid Build Coastguard Worker uint64_t user_data; /* data to be passed back at completion time */
58*49cdfc7eSAndroid Build Coastguard Worker union {
59*49cdfc7eSAndroid Build Coastguard Worker struct {
60*49cdfc7eSAndroid Build Coastguard Worker /* index into fixed buffers, if used */
61*49cdfc7eSAndroid Build Coastguard Worker uint16_t buf_index;
62*49cdfc7eSAndroid Build Coastguard Worker /* personality to use, if used */
63*49cdfc7eSAndroid Build Coastguard Worker uint16_t personality;
64*49cdfc7eSAndroid Build Coastguard Worker };
65*49cdfc7eSAndroid Build Coastguard Worker uint64_t __pad2[3];
66*49cdfc7eSAndroid Build Coastguard Worker };
67*49cdfc7eSAndroid Build Coastguard Worker };
68*49cdfc7eSAndroid Build Coastguard Worker
69*49cdfc7eSAndroid Build Coastguard Worker enum {
70*49cdfc7eSAndroid Build Coastguard Worker IOSQE_FIXED_FILE_BIT,
71*49cdfc7eSAndroid Build Coastguard Worker IOSQE_IO_DRAIN_BIT,
72*49cdfc7eSAndroid Build Coastguard Worker IOSQE_IO_LINK_BIT,
73*49cdfc7eSAndroid Build Coastguard Worker };
74*49cdfc7eSAndroid Build Coastguard Worker
75*49cdfc7eSAndroid Build Coastguard Worker /*
76*49cdfc7eSAndroid Build Coastguard Worker * sqe->flags
77*49cdfc7eSAndroid Build Coastguard Worker */
78*49cdfc7eSAndroid Build Coastguard Worker /* use fixed fileset */
79*49cdfc7eSAndroid Build Coastguard Worker #define IOSQE_FIXED_FILE (1U << IOSQE_FIXED_FILE_BIT)
80*49cdfc7eSAndroid Build Coastguard Worker /* issue after inflight IO */
81*49cdfc7eSAndroid Build Coastguard Worker #define IOSQE_IO_DRAIN (1U << IOSQE_IO_DRAIN_BIT)
82*49cdfc7eSAndroid Build Coastguard Worker /* links next sqe */
83*49cdfc7eSAndroid Build Coastguard Worker #define IOSQE_IO_LINK (1U << IOSQE_IO_LINK_BIT)
84*49cdfc7eSAndroid Build Coastguard Worker
85*49cdfc7eSAndroid Build Coastguard Worker /*
86*49cdfc7eSAndroid Build Coastguard Worker * io_uring_setup() flags
87*49cdfc7eSAndroid Build Coastguard Worker */
88*49cdfc7eSAndroid Build Coastguard Worker #define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */
89*49cdfc7eSAndroid Build Coastguard Worker #define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */
90*49cdfc7eSAndroid Build Coastguard Worker #define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */
91*49cdfc7eSAndroid Build Coastguard Worker #define IORING_SETUP_CQSIZE (1U << 3) /* app defines CQ size */
92*49cdfc7eSAndroid Build Coastguard Worker #define IORING_SETUP_CLAMP (1U << 4) /* clamp SQ/CQ ring sizes */
93*49cdfc7eSAndroid Build Coastguard Worker #define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */
94*49cdfc7eSAndroid Build Coastguard Worker
95*49cdfc7eSAndroid Build Coastguard Worker enum {
96*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_NOP,
97*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_READV,
98*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_WRITEV,
99*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_FSYNC,
100*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_READ_FIXED,
101*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_WRITE_FIXED,
102*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_POLL_ADD,
103*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_POLL_REMOVE,
104*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_SYNC_FILE_RANGE,
105*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_SENDMSG,
106*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_RECVMSG,
107*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_TIMEOUT,
108*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_TIMEOUT_REMOVE,
109*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_ACCEPT,
110*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_ASYNC_CANCEL,
111*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_LINK_TIMEOUT,
112*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_CONNECT,
113*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_FALLOCATE,
114*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_OPENAT,
115*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_CLOSE,
116*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_FILES_UPDATE,
117*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_STATX,
118*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_READ,
119*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_WRITE,
120*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_FADVISE,
121*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_MADVISE,
122*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_SEND,
123*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_RECV,
124*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_OPENAT2,
125*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_EPOLL_CTL,
126*49cdfc7eSAndroid Build Coastguard Worker
127*49cdfc7eSAndroid Build Coastguard Worker /* this goes last, obviously */
128*49cdfc7eSAndroid Build Coastguard Worker IORING_OP_LAST,
129*49cdfc7eSAndroid Build Coastguard Worker };
130*49cdfc7eSAndroid Build Coastguard Worker
131*49cdfc7eSAndroid Build Coastguard Worker /*
132*49cdfc7eSAndroid Build Coastguard Worker * sqe->fsync_flags
133*49cdfc7eSAndroid Build Coastguard Worker */
134*49cdfc7eSAndroid Build Coastguard Worker #define IORING_FSYNC_DATASYNC (1U << 0)
135*49cdfc7eSAndroid Build Coastguard Worker
136*49cdfc7eSAndroid Build Coastguard Worker /*
137*49cdfc7eSAndroid Build Coastguard Worker * sqe->timeout_flags
138*49cdfc7eSAndroid Build Coastguard Worker */
139*49cdfc7eSAndroid Build Coastguard Worker #define IORING_TIMEOUT_ABS (1U << 0)
140*49cdfc7eSAndroid Build Coastguard Worker
141*49cdfc7eSAndroid Build Coastguard Worker /*
142*49cdfc7eSAndroid Build Coastguard Worker * IO completion data structure (Completion Queue Entry)
143*49cdfc7eSAndroid Build Coastguard Worker */
144*49cdfc7eSAndroid Build Coastguard Worker struct io_uring_cqe {
145*49cdfc7eSAndroid Build Coastguard Worker uint64_t user_data; /* sqe->data submission passed back */
146*49cdfc7eSAndroid Build Coastguard Worker int32_t res; /* result code for this event */
147*49cdfc7eSAndroid Build Coastguard Worker uint32_t flags;
148*49cdfc7eSAndroid Build Coastguard Worker };
149*49cdfc7eSAndroid Build Coastguard Worker
150*49cdfc7eSAndroid Build Coastguard Worker /*
151*49cdfc7eSAndroid Build Coastguard Worker * Magic offsets for the application to mmap the data it needs
152*49cdfc7eSAndroid Build Coastguard Worker */
153*49cdfc7eSAndroid Build Coastguard Worker #define IORING_OFF_SQ_RING 0ULL
154*49cdfc7eSAndroid Build Coastguard Worker #define IORING_OFF_CQ_RING 0x8000000ULL
155*49cdfc7eSAndroid Build Coastguard Worker #define IORING_OFF_SQES 0x10000000ULL
156*49cdfc7eSAndroid Build Coastguard Worker
157*49cdfc7eSAndroid Build Coastguard Worker /*
158*49cdfc7eSAndroid Build Coastguard Worker * Filled with the offset for mmap(2)
159*49cdfc7eSAndroid Build Coastguard Worker */
160*49cdfc7eSAndroid Build Coastguard Worker struct io_sqring_offsets {
161*49cdfc7eSAndroid Build Coastguard Worker uint32_t head;
162*49cdfc7eSAndroid Build Coastguard Worker uint32_t tail;
163*49cdfc7eSAndroid Build Coastguard Worker uint32_t ring_mask;
164*49cdfc7eSAndroid Build Coastguard Worker uint32_t ring_entries;
165*49cdfc7eSAndroid Build Coastguard Worker uint32_t flags;
166*49cdfc7eSAndroid Build Coastguard Worker uint32_t dropped;
167*49cdfc7eSAndroid Build Coastguard Worker uint32_t array;
168*49cdfc7eSAndroid Build Coastguard Worker uint32_t resv1;
169*49cdfc7eSAndroid Build Coastguard Worker uint64_t resv2;
170*49cdfc7eSAndroid Build Coastguard Worker };
171*49cdfc7eSAndroid Build Coastguard Worker
172*49cdfc7eSAndroid Build Coastguard Worker /*
173*49cdfc7eSAndroid Build Coastguard Worker * sq_ring->flags
174*49cdfc7eSAndroid Build Coastguard Worker */
175*49cdfc7eSAndroid Build Coastguard Worker #define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */
176*49cdfc7eSAndroid Build Coastguard Worker
177*49cdfc7eSAndroid Build Coastguard Worker struct io_cqring_offsets {
178*49cdfc7eSAndroid Build Coastguard Worker uint32_t head;
179*49cdfc7eSAndroid Build Coastguard Worker uint32_t tail;
180*49cdfc7eSAndroid Build Coastguard Worker uint32_t ring_mask;
181*49cdfc7eSAndroid Build Coastguard Worker uint32_t ring_entries;
182*49cdfc7eSAndroid Build Coastguard Worker uint32_t overflow;
183*49cdfc7eSAndroid Build Coastguard Worker uint32_t cqes;
184*49cdfc7eSAndroid Build Coastguard Worker uint64_t resv[2];
185*49cdfc7eSAndroid Build Coastguard Worker };
186*49cdfc7eSAndroid Build Coastguard Worker
187*49cdfc7eSAndroid Build Coastguard Worker /*
188*49cdfc7eSAndroid Build Coastguard Worker * io_uring_enter(2) flags
189*49cdfc7eSAndroid Build Coastguard Worker */
190*49cdfc7eSAndroid Build Coastguard Worker #define IORING_ENTER_GETEVENTS (1U << 0)
191*49cdfc7eSAndroid Build Coastguard Worker #define IORING_ENTER_SQ_WAKEUP (1U << 1)
192*49cdfc7eSAndroid Build Coastguard Worker
193*49cdfc7eSAndroid Build Coastguard Worker /*
194*49cdfc7eSAndroid Build Coastguard Worker * Passed in for io_uring_setup(2). Copied back with updated info on success
195*49cdfc7eSAndroid Build Coastguard Worker */
196*49cdfc7eSAndroid Build Coastguard Worker struct io_uring_params {
197*49cdfc7eSAndroid Build Coastguard Worker uint32_t sq_entries;
198*49cdfc7eSAndroid Build Coastguard Worker uint32_t cq_entries;
199*49cdfc7eSAndroid Build Coastguard Worker uint32_t flags;
200*49cdfc7eSAndroid Build Coastguard Worker uint32_t sq_thread_cpu;
201*49cdfc7eSAndroid Build Coastguard Worker uint32_t sq_thread_idle;
202*49cdfc7eSAndroid Build Coastguard Worker uint32_t features;
203*49cdfc7eSAndroid Build Coastguard Worker uint32_t wq_fd;
204*49cdfc7eSAndroid Build Coastguard Worker uint32_t resv[3];
205*49cdfc7eSAndroid Build Coastguard Worker struct io_sqring_offsets sq_off;
206*49cdfc7eSAndroid Build Coastguard Worker struct io_cqring_offsets cq_off;
207*49cdfc7eSAndroid Build Coastguard Worker };
208*49cdfc7eSAndroid Build Coastguard Worker
209*49cdfc7eSAndroid Build Coastguard Worker /*
210*49cdfc7eSAndroid Build Coastguard Worker * io_uring_params->features flags
211*49cdfc7eSAndroid Build Coastguard Worker */
212*49cdfc7eSAndroid Build Coastguard Worker #define IORING_FEAT_SINGLE_MMAP (1U << 0)
213*49cdfc7eSAndroid Build Coastguard Worker #define IORING_FEAT_NODROP (1U << 1)
214*49cdfc7eSAndroid Build Coastguard Worker #define IORING_FEAT_SUBMIT_STABLE (1U << 2)
215*49cdfc7eSAndroid Build Coastguard Worker #define IORING_FEAT_RW_CUR_POS (1U << 3)
216*49cdfc7eSAndroid Build Coastguard Worker #define IORING_FEAT_CUR_PERSONALITY (1U << 4)
217*49cdfc7eSAndroid Build Coastguard Worker
218*49cdfc7eSAndroid Build Coastguard Worker /*
219*49cdfc7eSAndroid Build Coastguard Worker * io_uring_register(2) opcodes and arguments
220*49cdfc7eSAndroid Build Coastguard Worker */
221*49cdfc7eSAndroid Build Coastguard Worker #define IORING_REGISTER_BUFFERS 0
222*49cdfc7eSAndroid Build Coastguard Worker #define IORING_UNREGISTER_BUFFERS 1
223*49cdfc7eSAndroid Build Coastguard Worker #define IORING_REGISTER_FILES 2
224*49cdfc7eSAndroid Build Coastguard Worker #define IORING_UNREGISTER_FILES 3
225*49cdfc7eSAndroid Build Coastguard Worker #define IORING_REGISTER_EVENTFD 4
226*49cdfc7eSAndroid Build Coastguard Worker #define IORING_UNREGISTER_EVENTFD 5
227*49cdfc7eSAndroid Build Coastguard Worker #define IORING_REGISTER_FILES_UPDATE 6
228*49cdfc7eSAndroid Build Coastguard Worker #define IORING_REGISTER_EVENTFD_ASYNC 7
229*49cdfc7eSAndroid Build Coastguard Worker #define IORING_REGISTER_PROBE 8
230*49cdfc7eSAndroid Build Coastguard Worker #define IORING_REGISTER_PERSONALITY 9
231*49cdfc7eSAndroid Build Coastguard Worker #define IORING_UNREGISTER_PERSONALITY 10
232*49cdfc7eSAndroid Build Coastguard Worker
233*49cdfc7eSAndroid Build Coastguard Worker struct io_uring_files_update {
234*49cdfc7eSAndroid Build Coastguard Worker uint32_t offset;
235*49cdfc7eSAndroid Build Coastguard Worker uint32_t resv;
236*49cdfc7eSAndroid Build Coastguard Worker uint64_t __attribute__((aligned(8))) fds;
237*49cdfc7eSAndroid Build Coastguard Worker };
238*49cdfc7eSAndroid Build Coastguard Worker
239*49cdfc7eSAndroid Build Coastguard Worker #define IO_URING_OP_SUPPORTED (1U << 0)
240*49cdfc7eSAndroid Build Coastguard Worker
241*49cdfc7eSAndroid Build Coastguard Worker struct io_uring_probe_op {
242*49cdfc7eSAndroid Build Coastguard Worker uint8_t op;
243*49cdfc7eSAndroid Build Coastguard Worker uint8_t resv;
244*49cdfc7eSAndroid Build Coastguard Worker uint16_t flags; /* IO_URING_OP_* flags */
245*49cdfc7eSAndroid Build Coastguard Worker uint32_t resv2;
246*49cdfc7eSAndroid Build Coastguard Worker };
247*49cdfc7eSAndroid Build Coastguard Worker
248*49cdfc7eSAndroid Build Coastguard Worker struct io_uring_probe {
249*49cdfc7eSAndroid Build Coastguard Worker uint8_t last_op; /* last opcode supported */
250*49cdfc7eSAndroid Build Coastguard Worker uint8_t ops_len; /* length of ops[] array below */
251*49cdfc7eSAndroid Build Coastguard Worker uint16_t resv;
252*49cdfc7eSAndroid Build Coastguard Worker uint32_t resv2[3];
253*49cdfc7eSAndroid Build Coastguard Worker struct io_uring_probe_op ops[0];
254*49cdfc7eSAndroid Build Coastguard Worker };
255*49cdfc7eSAndroid Build Coastguard Worker
256*49cdfc7eSAndroid Build Coastguard Worker #endif /* IOSQE_FIXED_FILE */
257*49cdfc7eSAndroid Build Coastguard Worker
258*49cdfc7eSAndroid Build Coastguard Worker #ifndef IOSQE_IO_HADRLINK
259*49cdfc7eSAndroid Build Coastguard Worker /* like LINK, but stronger */
260*49cdfc7eSAndroid Build Coastguard Worker #define IOSQE_IO_HARDLINK_BIT 3
261*49cdfc7eSAndroid Build Coastguard Worker #define IOSQE_IO_HARDLINK (1U << IOSQE_IO_HARDLINK_BIT)
262*49cdfc7eSAndroid Build Coastguard Worker #endif /* IOSQE_IO_HADRLINK */
263*49cdfc7eSAndroid Build Coastguard Worker
264*49cdfc7eSAndroid Build Coastguard Worker #ifndef IOSQE_ASYNC
265*49cdfc7eSAndroid Build Coastguard Worker /* always go async */
266*49cdfc7eSAndroid Build Coastguard Worker #define IOSQE_ASYNC_BIT 4
267*49cdfc7eSAndroid Build Coastguard Worker #define IOSQE_ASYNC (1U << IOSQE_ASYNC_BIT)
268*49cdfc7eSAndroid Build Coastguard Worker #endif /* IOSQE_ASYNC */
269*49cdfc7eSAndroid Build Coastguard Worker
270*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_IO_URING_REGISTER
io_uring_register(int fd,unsigned int opcode,void * arg,unsigned int nr_args)271*49cdfc7eSAndroid Build Coastguard Worker static inline int io_uring_register(int fd, unsigned int opcode, void *arg,
272*49cdfc7eSAndroid Build Coastguard Worker unsigned int nr_args)
273*49cdfc7eSAndroid Build Coastguard Worker {
274*49cdfc7eSAndroid Build Coastguard Worker return tst_syscall(__NR_io_uring_register, fd, opcode, arg, nr_args);
275*49cdfc7eSAndroid Build Coastguard Worker }
276*49cdfc7eSAndroid Build Coastguard Worker #endif /* HAVE_IO_URING_REGISTER */
277*49cdfc7eSAndroid Build Coastguard Worker
278*49cdfc7eSAndroid Build Coastguard Worker
279*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_IO_URING_SETUP
io_uring_setup(unsigned int entries,struct io_uring_params * p)280*49cdfc7eSAndroid Build Coastguard Worker static inline int io_uring_setup(unsigned int entries,
281*49cdfc7eSAndroid Build Coastguard Worker struct io_uring_params *p)
282*49cdfc7eSAndroid Build Coastguard Worker {
283*49cdfc7eSAndroid Build Coastguard Worker return tst_syscall(__NR_io_uring_setup, entries, p);
284*49cdfc7eSAndroid Build Coastguard Worker }
285*49cdfc7eSAndroid Build Coastguard Worker #endif /* HAVE_IO_URING_SETUP */
286*49cdfc7eSAndroid Build Coastguard Worker
287*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_IO_URING_ENTER
io_uring_enter(int fd,unsigned int to_submit,unsigned int min_complete,unsigned int flags,sigset_t * sig)288*49cdfc7eSAndroid Build Coastguard Worker static inline int io_uring_enter(int fd, unsigned int to_submit,
289*49cdfc7eSAndroid Build Coastguard Worker unsigned int min_complete, unsigned int flags, sigset_t *sig)
290*49cdfc7eSAndroid Build Coastguard Worker {
291*49cdfc7eSAndroid Build Coastguard Worker return tst_syscall(__NR_io_uring_enter, fd, to_submit, min_complete,
292*49cdfc7eSAndroid Build Coastguard Worker flags, sig, _NSIG / 8);
293*49cdfc7eSAndroid Build Coastguard Worker }
294*49cdfc7eSAndroid Build Coastguard Worker #endif /* HAVE_IO_URING_ENTER */
295*49cdfc7eSAndroid Build Coastguard Worker
io_uring_setup_supported_by_kernel(void)296*49cdfc7eSAndroid Build Coastguard Worker static inline void io_uring_setup_supported_by_kernel(void)
297*49cdfc7eSAndroid Build Coastguard Worker {
298*49cdfc7eSAndroid Build Coastguard Worker long ret;
299*49cdfc7eSAndroid Build Coastguard Worker ret = syscall(__NR_io_uring_setup, NULL, 0);
300*49cdfc7eSAndroid Build Coastguard Worker if (ret != -1) {
301*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(ret);
302*49cdfc7eSAndroid Build Coastguard Worker return;
303*49cdfc7eSAndroid Build Coastguard Worker }
304*49cdfc7eSAndroid Build Coastguard Worker
305*49cdfc7eSAndroid Build Coastguard Worker if (errno == ENOSYS) {
306*49cdfc7eSAndroid Build Coastguard Worker if ((tst_kvercmp(5, 1, 0)) < 0) {
307*49cdfc7eSAndroid Build Coastguard Worker tst_brk(TCONF,
308*49cdfc7eSAndroid Build Coastguard Worker "Test not supported on kernel version < v5.1");
309*49cdfc7eSAndroid Build Coastguard Worker }
310*49cdfc7eSAndroid Build Coastguard Worker tst_brk(TCONF, "CONFIG_IO_URING not set?");
311*49cdfc7eSAndroid Build Coastguard Worker }
312*49cdfc7eSAndroid Build Coastguard Worker }
313*49cdfc7eSAndroid Build Coastguard Worker
314*49cdfc7eSAndroid Build Coastguard Worker #endif /* LAPI_IO_URING_H__ */
315