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