xref: /aosp_15_r20/external/ltp/include/tst_safe_io_uring.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
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) Linux Test Project, 2021
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker #ifndef TST_IO_URING_H__
7*49cdfc7eSAndroid Build Coastguard Worker #define TST_IO_URING_H__
8*49cdfc7eSAndroid Build Coastguard Worker 
9*49cdfc7eSAndroid Build Coastguard Worker #include "config.h"
10*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/io_uring.h"
11*49cdfc7eSAndroid Build Coastguard Worker 
12*49cdfc7eSAndroid Build Coastguard Worker struct tst_io_uring {
13*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
14*49cdfc7eSAndroid Build Coastguard Worker 	void *sqr_base, *cqr_base;
15*49cdfc7eSAndroid Build Coastguard Worker 	/* buffer sizes in bytes for unmapping */
16*49cdfc7eSAndroid Build Coastguard Worker 	size_t sqr_mapsize, cqr_mapsize;
17*49cdfc7eSAndroid Build Coastguard Worker 
18*49cdfc7eSAndroid Build Coastguard Worker 	/* Number of entries in the ring buffers */
19*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t sqr_size, cqr_size;
20*49cdfc7eSAndroid Build Coastguard Worker 
21*49cdfc7eSAndroid Build Coastguard Worker 	/* Submission queue pointers */
22*49cdfc7eSAndroid Build Coastguard Worker 	struct io_uring_sqe *sqr_entries;
23*49cdfc7eSAndroid Build Coastguard Worker 	const uint32_t *sqr_head, *sqr_mask, *sqr_flags, *sqr_dropped;
24*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t *sqr_tail, *sqr_array;
25*49cdfc7eSAndroid Build Coastguard Worker 
26*49cdfc7eSAndroid Build Coastguard Worker 	/* Completion queue pointers */
27*49cdfc7eSAndroid Build Coastguard Worker 	const struct io_uring_cqe *cqr_entries;
28*49cdfc7eSAndroid Build Coastguard Worker 	const uint32_t *cqr_tail, *cqr_mask, *cqr_overflow;
29*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t *cqr_head;
30*49cdfc7eSAndroid Build Coastguard Worker };
31*49cdfc7eSAndroid Build Coastguard Worker 
32*49cdfc7eSAndroid Build Coastguard Worker /*
33*49cdfc7eSAndroid Build Coastguard Worker  * Call io_uring_setup() with given arguments and prepare memory mappings
34*49cdfc7eSAndroid Build Coastguard Worker  * into the tst_io_uring structure passed in the third argument.
35*49cdfc7eSAndroid Build Coastguard Worker  */
36*49cdfc7eSAndroid Build Coastguard Worker #define SAFE_IO_URING_INIT(entries, params, uring) \
37*49cdfc7eSAndroid Build Coastguard Worker 	safe_io_uring_init(__FILE__, __LINE__, (entries), (params), (uring))
38*49cdfc7eSAndroid Build Coastguard Worker int safe_io_uring_init(const char *file, const int lineno,
39*49cdfc7eSAndroid Build Coastguard Worker 	unsigned int entries, struct io_uring_params *params,
40*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_io_uring *uring);
41*49cdfc7eSAndroid Build Coastguard Worker 
42*49cdfc7eSAndroid Build Coastguard Worker /*
43*49cdfc7eSAndroid Build Coastguard Worker  * Release io_uring mappings and close the file descriptor. uring->fd will
44*49cdfc7eSAndroid Build Coastguard Worker  * be set to -1 after close.
45*49cdfc7eSAndroid Build Coastguard Worker  */
46*49cdfc7eSAndroid Build Coastguard Worker #define SAFE_IO_URING_CLOSE(uring) \
47*49cdfc7eSAndroid Build Coastguard Worker 	safe_io_uring_close(__FILE__, __LINE__, (uring))
48*49cdfc7eSAndroid Build Coastguard Worker int safe_io_uring_close(const char *file, const int lineno,
49*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_io_uring *uring);
50*49cdfc7eSAndroid Build Coastguard Worker 
51*49cdfc7eSAndroid Build Coastguard Worker /*
52*49cdfc7eSAndroid Build Coastguard Worker  * Call io_uring_enter() and check for errors. The "strict" argument controls
53*49cdfc7eSAndroid Build Coastguard Worker  * pedantic check whether return value is equal to "to_submit" argument.
54*49cdfc7eSAndroid Build Coastguard Worker  */
55*49cdfc7eSAndroid Build Coastguard Worker #define SAFE_IO_URING_ENTER(strict, fd, to_submit, min_complete, flags, sig) \
56*49cdfc7eSAndroid Build Coastguard Worker 	safe_io_uring_enter(__FILE__, __LINE__, (strict), (fd), (to_submit), \
57*49cdfc7eSAndroid Build Coastguard Worker 		(min_complete), (flags), (sig))
58*49cdfc7eSAndroid Build Coastguard Worker int safe_io_uring_enter(const char *file, const int lineno, int strict,
59*49cdfc7eSAndroid Build Coastguard Worker 	int fd, unsigned int to_submit, unsigned int min_complete,
60*49cdfc7eSAndroid Build Coastguard Worker 	unsigned int flags, sigset_t *sig);
61*49cdfc7eSAndroid Build Coastguard Worker 
62*49cdfc7eSAndroid Build Coastguard Worker #endif /* TST_IO_URING_H__ */
63