xref: /linux/include/uapi/linux/io_uring.h (revision 3a6820f2bb8a079975109c25a5d1f29f46bce5d2)
12b188cc1SJens Axboe /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
22b188cc1SJens Axboe /*
32b188cc1SJens Axboe  * Header file for the io_uring interface.
42b188cc1SJens Axboe  *
52b188cc1SJens Axboe  * Copyright (C) 2019 Jens Axboe
62b188cc1SJens Axboe  * Copyright (C) 2019 Christoph Hellwig
72b188cc1SJens Axboe  */
82b188cc1SJens Axboe #ifndef LINUX_IO_URING_H
92b188cc1SJens Axboe #define LINUX_IO_URING_H
102b188cc1SJens Axboe 
112b188cc1SJens Axboe #include <linux/fs.h>
122b188cc1SJens Axboe #include <linux/types.h>
132b188cc1SJens Axboe 
142b188cc1SJens Axboe /*
152b188cc1SJens Axboe  * IO submission data structure (Submission Queue Entry)
162b188cc1SJens Axboe  */
172b188cc1SJens Axboe struct io_uring_sqe {
182b188cc1SJens Axboe 	__u8	opcode;		/* type of operation for this sqe */
196b06314cSJens Axboe 	__u8	flags;		/* IOSQE_ flags */
202b188cc1SJens Axboe 	__u16	ioprio;		/* ioprio for the request */
212b188cc1SJens Axboe 	__s32	fd;		/* file descriptor to do IO on */
2217f2fe35SJens Axboe 	union {
232b188cc1SJens Axboe 		__u64	off;	/* offset into file */
2417f2fe35SJens Axboe 		__u64	addr2;
2517f2fe35SJens Axboe 	};
262b188cc1SJens Axboe 	__u64	addr;		/* pointer to buffer or iovecs */
272b188cc1SJens Axboe 	__u32	len;		/* buffer size or number of iovecs */
282b188cc1SJens Axboe 	union {
292b188cc1SJens Axboe 		__kernel_rwf_t	rw_flags;
30c992fe29SChristoph Hellwig 		__u32		fsync_flags;
31221c5eb2SJens Axboe 		__u16		poll_events;
325d17b4a4SJens Axboe 		__u32		sync_range_flags;
330fa03c62SJens Axboe 		__u32		msg_flags;
345262f567SJens Axboe 		__u32		timeout_flags;
3517f2fe35SJens Axboe 		__u32		accept_flags;
3662755e35SJens Axboe 		__u32		cancel_flags;
3715b71abeSJens Axboe 		__u32		open_flags;
38eddc7ef5SJens Axboe 		__u32		statx_flags;
392b188cc1SJens Axboe 	};
402b188cc1SJens Axboe 	__u64	user_data;	/* data to be passed back at completion time */
41edafcceeSJens Axboe 	union {
42edafcceeSJens Axboe 		__u16	buf_index;	/* index into fixed buffers, if used */
432b188cc1SJens Axboe 		__u64	__pad2[3];
442b188cc1SJens Axboe 	};
45edafcceeSJens Axboe };
462b188cc1SJens Axboe 
47def596e9SJens Axboe /*
486b06314cSJens Axboe  * sqe->flags
496b06314cSJens Axboe  */
506b06314cSJens Axboe #define IOSQE_FIXED_FILE	(1U << 0)	/* use fixed fileset */
51de0617e4SJens Axboe #define IOSQE_IO_DRAIN		(1U << 1)	/* issue after inflight IO */
529e645e11SJens Axboe #define IOSQE_IO_LINK		(1U << 2)	/* links next sqe */
534e88d6e7SJens Axboe #define IOSQE_IO_HARDLINK	(1U << 3)	/* like LINK, but stronger */
54ce35a47aSJens Axboe #define IOSQE_ASYNC		(1U << 4)	/* always go async */
556b06314cSJens Axboe 
566b06314cSJens Axboe /*
57def596e9SJens Axboe  * io_uring_setup() flags
58def596e9SJens Axboe  */
59def596e9SJens Axboe #define IORING_SETUP_IOPOLL	(1U << 0)	/* io_context is polled */
606c271ce2SJens Axboe #define IORING_SETUP_SQPOLL	(1U << 1)	/* SQ poll thread */
616c271ce2SJens Axboe #define IORING_SETUP_SQ_AFF	(1U << 2)	/* sq_thread_cpu is valid */
6233a107f0SJens Axboe #define IORING_SETUP_CQSIZE	(1U << 3)	/* app defines CQ size */
63def596e9SJens Axboe 
649e3aa61aSJens Axboe enum {
659e3aa61aSJens Axboe 	IORING_OP_NOP,
669e3aa61aSJens Axboe 	IORING_OP_READV,
679e3aa61aSJens Axboe 	IORING_OP_WRITEV,
689e3aa61aSJens Axboe 	IORING_OP_FSYNC,
699e3aa61aSJens Axboe 	IORING_OP_READ_FIXED,
709e3aa61aSJens Axboe 	IORING_OP_WRITE_FIXED,
719e3aa61aSJens Axboe 	IORING_OP_POLL_ADD,
729e3aa61aSJens Axboe 	IORING_OP_POLL_REMOVE,
739e3aa61aSJens Axboe 	IORING_OP_SYNC_FILE_RANGE,
749e3aa61aSJens Axboe 	IORING_OP_SENDMSG,
759e3aa61aSJens Axboe 	IORING_OP_RECVMSG,
769e3aa61aSJens Axboe 	IORING_OP_TIMEOUT,
779e3aa61aSJens Axboe 	IORING_OP_TIMEOUT_REMOVE,
789e3aa61aSJens Axboe 	IORING_OP_ACCEPT,
799e3aa61aSJens Axboe 	IORING_OP_ASYNC_CANCEL,
809e3aa61aSJens Axboe 	IORING_OP_LINK_TIMEOUT,
819e3aa61aSJens Axboe 	IORING_OP_CONNECT,
82d63d1b5eSJens Axboe 	IORING_OP_FALLOCATE,
8315b71abeSJens Axboe 	IORING_OP_OPENAT,
84b5dba59eSJens Axboe 	IORING_OP_CLOSE,
8505f3fb3cSJens Axboe 	IORING_OP_FILES_UPDATE,
86eddc7ef5SJens Axboe 	IORING_OP_STATX,
87*3a6820f2SJens Axboe 	IORING_OP_READ,
88*3a6820f2SJens Axboe 	IORING_OP_WRITE,
899e3aa61aSJens Axboe 
909e3aa61aSJens Axboe 	/* this goes last, obviously */
919e3aa61aSJens Axboe 	IORING_OP_LAST,
929e3aa61aSJens Axboe };
93c992fe29SChristoph Hellwig 
94c992fe29SChristoph Hellwig /*
95c992fe29SChristoph Hellwig  * sqe->fsync_flags
96c992fe29SChristoph Hellwig  */
97c992fe29SChristoph Hellwig #define IORING_FSYNC_DATASYNC	(1U << 0)
982b188cc1SJens Axboe 
992b188cc1SJens Axboe /*
100a41525abSJens Axboe  * sqe->timeout_flags
101a41525abSJens Axboe  */
102a41525abSJens Axboe #define IORING_TIMEOUT_ABS	(1U << 0)
103a41525abSJens Axboe 
104a41525abSJens Axboe /*
1052b188cc1SJens Axboe  * IO completion data structure (Completion Queue Entry)
1062b188cc1SJens Axboe  */
1072b188cc1SJens Axboe struct io_uring_cqe {
1082b188cc1SJens Axboe 	__u64	user_data;	/* sqe->data submission passed back */
1092b188cc1SJens Axboe 	__s32	res;		/* result code for this event */
1102b188cc1SJens Axboe 	__u32	flags;
1112b188cc1SJens Axboe };
1122b188cc1SJens Axboe 
1132b188cc1SJens Axboe /*
1142b188cc1SJens Axboe  * Magic offsets for the application to mmap the data it needs
1152b188cc1SJens Axboe  */
1162b188cc1SJens Axboe #define IORING_OFF_SQ_RING		0ULL
1172b188cc1SJens Axboe #define IORING_OFF_CQ_RING		0x8000000ULL
1182b188cc1SJens Axboe #define IORING_OFF_SQES			0x10000000ULL
1192b188cc1SJens Axboe 
1202b188cc1SJens Axboe /*
1212b188cc1SJens Axboe  * Filled with the offset for mmap(2)
1222b188cc1SJens Axboe  */
1232b188cc1SJens Axboe struct io_sqring_offsets {
1242b188cc1SJens Axboe 	__u32 head;
1252b188cc1SJens Axboe 	__u32 tail;
1262b188cc1SJens Axboe 	__u32 ring_mask;
1272b188cc1SJens Axboe 	__u32 ring_entries;
1282b188cc1SJens Axboe 	__u32 flags;
1292b188cc1SJens Axboe 	__u32 dropped;
1302b188cc1SJens Axboe 	__u32 array;
1312b188cc1SJens Axboe 	__u32 resv1;
1322b188cc1SJens Axboe 	__u64 resv2;
1332b188cc1SJens Axboe };
1342b188cc1SJens Axboe 
1356c271ce2SJens Axboe /*
1366c271ce2SJens Axboe  * sq_ring->flags
1376c271ce2SJens Axboe  */
1386c271ce2SJens Axboe #define IORING_SQ_NEED_WAKEUP	(1U << 0) /* needs io_uring_enter wakeup */
1396c271ce2SJens Axboe 
1402b188cc1SJens Axboe struct io_cqring_offsets {
1412b188cc1SJens Axboe 	__u32 head;
1422b188cc1SJens Axboe 	__u32 tail;
1432b188cc1SJens Axboe 	__u32 ring_mask;
1442b188cc1SJens Axboe 	__u32 ring_entries;
1452b188cc1SJens Axboe 	__u32 overflow;
1462b188cc1SJens Axboe 	__u32 cqes;
1472b188cc1SJens Axboe 	__u64 resv[2];
1482b188cc1SJens Axboe };
1492b188cc1SJens Axboe 
1502b188cc1SJens Axboe /*
1512b188cc1SJens Axboe  * io_uring_enter(2) flags
1522b188cc1SJens Axboe  */
1532b188cc1SJens Axboe #define IORING_ENTER_GETEVENTS	(1U << 0)
1546c271ce2SJens Axboe #define IORING_ENTER_SQ_WAKEUP	(1U << 1)
1552b188cc1SJens Axboe 
1562b188cc1SJens Axboe /*
1572b188cc1SJens Axboe  * Passed in for io_uring_setup(2). Copied back with updated info on success
1582b188cc1SJens Axboe  */
1592b188cc1SJens Axboe struct io_uring_params {
1602b188cc1SJens Axboe 	__u32 sq_entries;
1612b188cc1SJens Axboe 	__u32 cq_entries;
1622b188cc1SJens Axboe 	__u32 flags;
1636c271ce2SJens Axboe 	__u32 sq_thread_cpu;
1646c271ce2SJens Axboe 	__u32 sq_thread_idle;
165ac90f249SJens Axboe 	__u32 features;
166ac90f249SJens Axboe 	__u32 resv[4];
1672b188cc1SJens Axboe 	struct io_sqring_offsets sq_off;
1682b188cc1SJens Axboe 	struct io_cqring_offsets cq_off;
1692b188cc1SJens Axboe };
1702b188cc1SJens Axboe 
171edafcceeSJens Axboe /*
172ac90f249SJens Axboe  * io_uring_params->features flags
173ac90f249SJens Axboe  */
174ac90f249SJens Axboe #define IORING_FEAT_SINGLE_MMAP		(1U << 0)
1751d7bb1d5SJens Axboe #define IORING_FEAT_NODROP		(1U << 1)
176da8c9690SJens Axboe #define IORING_FEAT_SUBMIT_STABLE	(1U << 2)
177ac90f249SJens Axboe 
178ac90f249SJens Axboe /*
179edafcceeSJens Axboe  * io_uring_register(2) opcodes and arguments
180edafcceeSJens Axboe  */
181edafcceeSJens Axboe #define IORING_REGISTER_BUFFERS		0
182edafcceeSJens Axboe #define IORING_UNREGISTER_BUFFERS	1
1836b06314cSJens Axboe #define IORING_REGISTER_FILES		2
1846b06314cSJens Axboe #define IORING_UNREGISTER_FILES		3
1859b402849SJens Axboe #define IORING_REGISTER_EVENTFD		4
1869b402849SJens Axboe #define IORING_UNREGISTER_EVENTFD	5
187c3a31e60SJens Axboe #define IORING_REGISTER_FILES_UPDATE	6
188c3a31e60SJens Axboe 
189c3a31e60SJens Axboe struct io_uring_files_update {
190c3a31e60SJens Axboe 	__u32 offset;
1911292e972SEugene Syromiatnikov 	__u32 resv;
1921292e972SEugene Syromiatnikov 	__aligned_u64 /* __s32 * */ fds;
193c3a31e60SJens Axboe };
194edafcceeSJens Axboe 
1952b188cc1SJens Axboe #endif
196