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; 394840e418SJens Axboe __u32 fadvise_advice; 402b188cc1SJens Axboe }; 412b188cc1SJens Axboe __u64 user_data; /* data to be passed back at completion time */ 42edafcceeSJens Axboe union { 43edafcceeSJens Axboe __u16 buf_index; /* index into fixed buffers, if used */ 442b188cc1SJens Axboe __u64 __pad2[3]; 452b188cc1SJens Axboe }; 46edafcceeSJens Axboe }; 472b188cc1SJens Axboe 486b47ee6eSPavel Begunkov enum { 496b47ee6eSPavel Begunkov IOSQE_FIXED_FILE_BIT, 506b47ee6eSPavel Begunkov IOSQE_IO_DRAIN_BIT, 516b47ee6eSPavel Begunkov IOSQE_IO_LINK_BIT, 526b47ee6eSPavel Begunkov IOSQE_IO_HARDLINK_BIT, 536b47ee6eSPavel Begunkov IOSQE_ASYNC_BIT, 546b47ee6eSPavel Begunkov }; 556b47ee6eSPavel Begunkov 56def596e9SJens Axboe /* 576b06314cSJens Axboe * sqe->flags 586b06314cSJens Axboe */ 596b47ee6eSPavel Begunkov /* use fixed fileset */ 606b47ee6eSPavel Begunkov #define IOSQE_FIXED_FILE (1U << IOSQE_FIXED_FILE_BIT) 616b47ee6eSPavel Begunkov /* issue after inflight IO */ 626b47ee6eSPavel Begunkov #define IOSQE_IO_DRAIN (1U << IOSQE_IO_DRAIN_BIT) 636b47ee6eSPavel Begunkov /* links next sqe */ 646b47ee6eSPavel Begunkov #define IOSQE_IO_LINK (1U << IOSQE_IO_LINK_BIT) 656b47ee6eSPavel Begunkov /* like LINK, but stronger */ 666b47ee6eSPavel Begunkov #define IOSQE_IO_HARDLINK (1U << IOSQE_IO_HARDLINK_BIT) 676b47ee6eSPavel Begunkov /* always go async */ 686b47ee6eSPavel Begunkov #define IOSQE_ASYNC (1U << IOSQE_ASYNC_BIT) 696b06314cSJens Axboe 706b06314cSJens Axboe /* 71def596e9SJens Axboe * io_uring_setup() flags 72def596e9SJens Axboe */ 73def596e9SJens Axboe #define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */ 746c271ce2SJens Axboe #define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */ 756c271ce2SJens Axboe #define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */ 7633a107f0SJens Axboe #define IORING_SETUP_CQSIZE (1U << 3) /* app defines CQ size */ 778110c1a6SJens Axboe #define IORING_SETUP_CLAMP (1U << 4) /* clamp SQ/CQ ring sizes */ 78def596e9SJens Axboe 799e3aa61aSJens Axboe enum { 809e3aa61aSJens Axboe IORING_OP_NOP, 819e3aa61aSJens Axboe IORING_OP_READV, 829e3aa61aSJens Axboe IORING_OP_WRITEV, 839e3aa61aSJens Axboe IORING_OP_FSYNC, 849e3aa61aSJens Axboe IORING_OP_READ_FIXED, 859e3aa61aSJens Axboe IORING_OP_WRITE_FIXED, 869e3aa61aSJens Axboe IORING_OP_POLL_ADD, 879e3aa61aSJens Axboe IORING_OP_POLL_REMOVE, 889e3aa61aSJens Axboe IORING_OP_SYNC_FILE_RANGE, 899e3aa61aSJens Axboe IORING_OP_SENDMSG, 909e3aa61aSJens Axboe IORING_OP_RECVMSG, 919e3aa61aSJens Axboe IORING_OP_TIMEOUT, 929e3aa61aSJens Axboe IORING_OP_TIMEOUT_REMOVE, 939e3aa61aSJens Axboe IORING_OP_ACCEPT, 949e3aa61aSJens Axboe IORING_OP_ASYNC_CANCEL, 959e3aa61aSJens Axboe IORING_OP_LINK_TIMEOUT, 969e3aa61aSJens Axboe IORING_OP_CONNECT, 97d63d1b5eSJens Axboe IORING_OP_FALLOCATE, 9815b71abeSJens Axboe IORING_OP_OPENAT, 99b5dba59eSJens Axboe IORING_OP_CLOSE, 10005f3fb3cSJens Axboe IORING_OP_FILES_UPDATE, 101eddc7ef5SJens Axboe IORING_OP_STATX, 1023a6820f2SJens Axboe IORING_OP_READ, 1033a6820f2SJens Axboe IORING_OP_WRITE, 1044840e418SJens Axboe IORING_OP_FADVISE, 105c1ca757bSJens Axboe IORING_OP_MADVISE, 106fddafaceSJens Axboe IORING_OP_SEND, 107fddafaceSJens Axboe IORING_OP_RECV, 108cebdb986SJens Axboe IORING_OP_OPENAT2, 1099e3aa61aSJens Axboe 1109e3aa61aSJens Axboe /* this goes last, obviously */ 1119e3aa61aSJens Axboe IORING_OP_LAST, 1129e3aa61aSJens Axboe }; 113c992fe29SChristoph Hellwig 114c992fe29SChristoph Hellwig /* 115c992fe29SChristoph Hellwig * sqe->fsync_flags 116c992fe29SChristoph Hellwig */ 117c992fe29SChristoph Hellwig #define IORING_FSYNC_DATASYNC (1U << 0) 1182b188cc1SJens Axboe 1192b188cc1SJens Axboe /* 120a41525abSJens Axboe * sqe->timeout_flags 121a41525abSJens Axboe */ 122a41525abSJens Axboe #define IORING_TIMEOUT_ABS (1U << 0) 123a41525abSJens Axboe 124a41525abSJens Axboe /* 1252b188cc1SJens Axboe * IO completion data structure (Completion Queue Entry) 1262b188cc1SJens Axboe */ 1272b188cc1SJens Axboe struct io_uring_cqe { 1282b188cc1SJens Axboe __u64 user_data; /* sqe->data submission passed back */ 1292b188cc1SJens Axboe __s32 res; /* result code for this event */ 1302b188cc1SJens Axboe __u32 flags; 1312b188cc1SJens Axboe }; 1322b188cc1SJens Axboe 1332b188cc1SJens Axboe /* 1342b188cc1SJens Axboe * Magic offsets for the application to mmap the data it needs 1352b188cc1SJens Axboe */ 1362b188cc1SJens Axboe #define IORING_OFF_SQ_RING 0ULL 1372b188cc1SJens Axboe #define IORING_OFF_CQ_RING 0x8000000ULL 1382b188cc1SJens Axboe #define IORING_OFF_SQES 0x10000000ULL 1392b188cc1SJens Axboe 1402b188cc1SJens Axboe /* 1412b188cc1SJens Axboe * Filled with the offset for mmap(2) 1422b188cc1SJens Axboe */ 1432b188cc1SJens Axboe struct io_sqring_offsets { 1442b188cc1SJens Axboe __u32 head; 1452b188cc1SJens Axboe __u32 tail; 1462b188cc1SJens Axboe __u32 ring_mask; 1472b188cc1SJens Axboe __u32 ring_entries; 1482b188cc1SJens Axboe __u32 flags; 1492b188cc1SJens Axboe __u32 dropped; 1502b188cc1SJens Axboe __u32 array; 1512b188cc1SJens Axboe __u32 resv1; 1522b188cc1SJens Axboe __u64 resv2; 1532b188cc1SJens Axboe }; 1542b188cc1SJens Axboe 1556c271ce2SJens Axboe /* 1566c271ce2SJens Axboe * sq_ring->flags 1576c271ce2SJens Axboe */ 1586c271ce2SJens Axboe #define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */ 1596c271ce2SJens Axboe 1602b188cc1SJens Axboe struct io_cqring_offsets { 1612b188cc1SJens Axboe __u32 head; 1622b188cc1SJens Axboe __u32 tail; 1632b188cc1SJens Axboe __u32 ring_mask; 1642b188cc1SJens Axboe __u32 ring_entries; 1652b188cc1SJens Axboe __u32 overflow; 1662b188cc1SJens Axboe __u32 cqes; 1672b188cc1SJens Axboe __u64 resv[2]; 1682b188cc1SJens Axboe }; 1692b188cc1SJens Axboe 1702b188cc1SJens Axboe /* 1712b188cc1SJens Axboe * io_uring_enter(2) flags 1722b188cc1SJens Axboe */ 1732b188cc1SJens Axboe #define IORING_ENTER_GETEVENTS (1U << 0) 1746c271ce2SJens Axboe #define IORING_ENTER_SQ_WAKEUP (1U << 1) 1752b188cc1SJens Axboe 1762b188cc1SJens Axboe /* 1772b188cc1SJens Axboe * Passed in for io_uring_setup(2). Copied back with updated info on success 1782b188cc1SJens Axboe */ 1792b188cc1SJens Axboe struct io_uring_params { 1802b188cc1SJens Axboe __u32 sq_entries; 1812b188cc1SJens Axboe __u32 cq_entries; 1822b188cc1SJens Axboe __u32 flags; 1836c271ce2SJens Axboe __u32 sq_thread_cpu; 1846c271ce2SJens Axboe __u32 sq_thread_idle; 185ac90f249SJens Axboe __u32 features; 186ac90f249SJens Axboe __u32 resv[4]; 1872b188cc1SJens Axboe struct io_sqring_offsets sq_off; 1882b188cc1SJens Axboe struct io_cqring_offsets cq_off; 1892b188cc1SJens Axboe }; 1902b188cc1SJens Axboe 191edafcceeSJens Axboe /* 192ac90f249SJens Axboe * io_uring_params->features flags 193ac90f249SJens Axboe */ 194ac90f249SJens Axboe #define IORING_FEAT_SINGLE_MMAP (1U << 0) 1951d7bb1d5SJens Axboe #define IORING_FEAT_NODROP (1U << 1) 196da8c9690SJens Axboe #define IORING_FEAT_SUBMIT_STABLE (1U << 2) 197ba04291eSJens Axboe #define IORING_FEAT_RW_CUR_POS (1U << 3) 198*cccf0ee8SJens Axboe #define IORING_FEAT_CUR_PERSONALITY (1U << 4) 199ac90f249SJens Axboe 200ac90f249SJens Axboe /* 201edafcceeSJens Axboe * io_uring_register(2) opcodes and arguments 202edafcceeSJens Axboe */ 203edafcceeSJens Axboe #define IORING_REGISTER_BUFFERS 0 204edafcceeSJens Axboe #define IORING_UNREGISTER_BUFFERS 1 2056b06314cSJens Axboe #define IORING_REGISTER_FILES 2 2066b06314cSJens Axboe #define IORING_UNREGISTER_FILES 3 2079b402849SJens Axboe #define IORING_REGISTER_EVENTFD 4 2089b402849SJens Axboe #define IORING_UNREGISTER_EVENTFD 5 209c3a31e60SJens Axboe #define IORING_REGISTER_FILES_UPDATE 6 210f2842ab5SJens Axboe #define IORING_REGISTER_EVENTFD_ASYNC 7 21166f4af93SJens Axboe #define IORING_REGISTER_PROBE 8 212c3a31e60SJens Axboe 213c3a31e60SJens Axboe struct io_uring_files_update { 214c3a31e60SJens Axboe __u32 offset; 2151292e972SEugene Syromiatnikov __u32 resv; 2161292e972SEugene Syromiatnikov __aligned_u64 /* __s32 * */ fds; 217c3a31e60SJens Axboe }; 218edafcceeSJens Axboe 21966f4af93SJens Axboe #define IO_URING_OP_SUPPORTED (1U << 0) 22066f4af93SJens Axboe 22166f4af93SJens Axboe struct io_uring_probe_op { 22266f4af93SJens Axboe __u8 op; 22366f4af93SJens Axboe __u8 resv; 22466f4af93SJens Axboe __u16 flags; /* IO_URING_OP_* flags */ 22566f4af93SJens Axboe __u32 resv2; 22666f4af93SJens Axboe }; 22766f4af93SJens Axboe 22866f4af93SJens Axboe struct io_uring_probe { 22966f4af93SJens Axboe __u8 last_op; /* last opcode supported */ 23066f4af93SJens Axboe __u8 ops_len; /* length of ops[] array below */ 23166f4af93SJens Axboe __u16 resv; 23266f4af93SJens Axboe __u32 resv2[3]; 23366f4af93SJens Axboe struct io_uring_probe_op ops[0]; 23466f4af93SJens Axboe }; 23566f4af93SJens Axboe 2362b188cc1SJens Axboe #endif 237