package: liburing-devel

title: io_uring_enter(2)

text:
# io_uring_enter(2)

## NAME
io_uring_enter - initiate and/or complete asynchronous I/O

## SYNOPSIS

```
#include <linux/io_uring.h>
```

```
int io_uring_enter(unsigned int fd, unsigned int to_submit,
                   unsigned int min_complete, unsigned int flags,
                   sigset_t *sig);
```

## DESCRIPTION
io_uring_enter() is used to initiate and complete I/O using the shared submission and completion queues setup by a call to io_uring_setup(2). A single call can both submit new I/O and wait for completions of I/O initiated by this call or previous calls to io_uring_enter().

fd is the file descriptor returned by io_uring_setup(2). to_submit specifies the number of I/Os to submit from the submission queue. flags is a bitmask of the following values:

IORING_ENTER_GETEVENTS

If this flag is set, then the system call will wait for the specificied number of events in min_complete before returning. This flag can be set along with to_submit to both submit and complete events in a single system call.

IORING_ENTER_SQ_WAKEUP

If the ring has been created with IORING_SETUP_SQPOLL, then this flag asks the kernel to wakeup the SQ kernel thread to submit IO.

IORING_ENTER_SQ_WAIT

If the ring has been created with IORING_SETUP_SQPOLL, then the application has no real insight into when the SQ kernel thread has consumed entries from the SQ ring. This can lead to a situation where the application can no longer get a free SQE entry to submit, without knowing when it one becomes available as the SQ kernel thread consumes them. If the system call is used with this flag set, then it will wait until at least one entry is free in the SQ ring.

IORING_ENTER_EXT_ARG

Since kernel 5.11, the system calls arguments have been modified to look like the following:

```
int io_uring_enter(unsigned int fd, unsigned int to_submit,
                   unsigned int min_complete, unsigned int flags,
                   const void *arg, size_t argsz);
```

which is behaves just like the original definition by default. However, if IORING_ENTER_EXT_ARG is set, then instead of a sigset_t being passed in, a pointer to a struct io_uring_getevents_arg is used instead and argsz must be set to the size of this structure. The definition is as follows:

```
struct io_uring_getevents_args {
        __u64   sigmask;
        __u32   sigmask_sz;
        __u32   pad;
        __u64   ts;
};
```

which allows passing in both a signal mask as well as pointer to a struct __kernel_timespec timeout value. If ts is set to a valid pointer, then this time value indicates the timeout for waiting on events. If an application is waiting on events and wishes to stop waiting after a specified amount of time, then this can be accomplished directly in version 5.11 and newer by using this feature.

IORING_ENTER_REGISTERED_RING

If the ring file descriptor has been registered through use of IORING_REGISTER_RING_FDS, then setting this flag will tell the kernel that the ring_fd passed in is the registered ring offset rather than a normal file descriptor.

If the io_uring instance was configured for polling, by specifying IORING_SETUP_IOPOLL in the call to io_uring_setup(2), then min_complete has a slightly different meaning. Passing a value of 0 instructs the kernel to return any events which are already complete, without blocking. If min_complete is a non-zero value, the kernel will still return immediately if any completion events are available. If no event completions are available, then the call will poll either until one or more completions become available, or until the process has exceeded its scheduler time slice.

Note that, for interrupt driven I/O (where IORING_SETUP_IOPOLL was not specified in the call to io_uring_setup(2)), an application may check the completion queue for event completions without entering the kernel at all.

When the system call returns that a certain amount of SQEs have been consumed and submitted, it's safe to reuse SQE entries in the ring. This is true even if the actual IO submission had to be punted to async context, which means that the SQE may in fact not have been submitted yet. If the kernel requires later use of a particular SQE entry, it will have made a private copy of it.

sig is a pointer to a signal mask (see sigprocmask(2)); if sig is not NULL, io_uring_enter() first replaces the current signal mask by the one pointed to by sig, then waits for events to become available in the completion queue, and then restores the original signal mask. The following io_uring_enter() call:

```
ret = io_uring_enter(fd, 0, 1, IORING_ENTER_GETEVENTS, &sig);
```

is equivalent to atomically executing the following calls:

```
pthread_sigmask(SIG_SETMASK, &sig, &orig);
ret = io_uring_enter(fd, 0, 1, IORING_ENTER_GETEVENTS, NULL);
pthread_sigmask(SIG_SETMASK, &orig, NULL);
```

See the description of pselect(2) for an explanation of why the sig parameter is necessary.

Submission queue entries are represented using the following data structure:

```
/*

 * IO submission data structure (Submission Queue Entry)

 */
struct io_uring_sqe {

    __u8    opcode;         /* type of operation for this sqe */

    __u8    flags;          /* IOSQE_ flags */

    __u16   ioprio;         /* ioprio for the request */

    __s32   fd;             /* file descriptor to do IO on */

    union {

        __u64   off;            /* offset into file */

        __u64   addr2;

    };

    union {

        __u64   addr;       /* pointer to buffer or iovecs */

        __u64   splice_off_in;

    }

    __u32   len;            /* buffer size or number of iovecs */

    union {

        __kernel_rwf_t  rw_flags;

        __u32    fsync_flags;

        __u16    poll_events;   /* compatibility */

        __u32    poll32_events; /* word-reversed for BE */

        __u32    sync_range_flags;

        __u32    msg_flags;

        __u32    timeout_flags;

        __u32    accept_flags;

        __u32    cancel_flags;

        __u32    open_flags;

        __u32    statx_flags;

        __u32    fadvise_advice;

        __u32    splice_flags;

        __u32    rename_flags;

        __u32    unlink_flags;

        __u32    hardlink_flags;

    };

    __u64    user_data;     /* data to be passed back at completion time */

    union {

    struct {

        /* index into fixed buffers, if used */

            union {

                /* index into fixed buffers, if used */

                __u16    buf_index;

                /* for grouped buffer selection */

                __u16    buf_group;

            }

        /* personality to use, if used */

        __u16    personality;

        union {

            __s32    splice_fd_in;

            __u32    file_index;
	};

    };

    __u64    __pad2[3];

    };
};
```

The opcode describes the operation to be performed. It can be one of:

IORING_OP_NOP

Do not perform any I/O. This is useful for testing the performance of the io_uring implementation itself.

IORING_OP_READV

IORING_OP_WRITEV

Vectored read and write operations, similar to preadv2(2) and pwritev2(2). If the file is not seekable, off must be set to zero.

IORING_OP_READ_FIXED

IORING_OP_WRITE_FIXED

Read from or write to pre-mapped buffers. See io_uring_register(2) for details on how to setup a context for fixed reads and writes.

IORING_OP_FSYNC

File sync. See also fsync(2). Note that, while I/O is initiated in the order in which it appears in the submission queue, completions are unordered. For example, an application which places a write I/O followed by an fsync in the submission queue cannot expect the fsync to apply to the write. The two operations execute in parallel, so the fsync may complete before the write is issued to the storage. The same is also true for previously issued writes that have not completed prior to the fsync.

IORING_OP_POLL_ADD

Poll the fd specified in the submission queue entry for the events specified in the poll_events field. Unlike poll or epoll without EPOLLONESHOT, by default this interface always works in one shot mode. That is, once the poll operation is completed, it will have to be resubmitted. If IORING_POLL_ADD_MULTI is set in the SQE len field, then the poll will work in multi shot mode instead. That means it'll repatedly trigger when the requested event becomes true, and hence multiple CQEs can be generated from this single SQE. The CQE flags field will have IORING_CQE_F_MORE set on completion if the application should expect further CQE entries from the original request. If this flag isn't set on completion, then the poll request has been terminated and no further events will be generated. This mode is available since 5.13.

If IORING_POLL_UPDATE_EVENTS is set in the SQE len field, then the request will update an existing poll request with the mask of events passed in with this request. The lookup is based on the user_data field of the original SQE submitted, and this values is passed in the addr field of the SQE. This mode is available since 5.13.

If IORING_POLL_UPDATE_USER_DATA is set in the SQE len field, then the request will update the user_data of an existing poll request based on the value passed in the off field. This mode is available since 5.13.

This command works like an async poll(2) and the completion event result is the returned mask of events. For the variants that update user_data or events , the completion result will be similar to IORING_OP_POLL_REMOVE.

IORING_OP_POLL_REMOVE

Remove an existing poll request. If found, the res field of the struct io_uring_cqe will contain 0. If not found, res will contain -ENOENT, or -EALREADY if the poll request was in the process of completing already.

IORING_OP_EPOLL_CTL

Add, remove or modify entries in the interest list of epoll(7). See epoll_ctl(2) for details of the system call. fd holds the file descriptor that represents the epoll instance, addr holds the file descriptor to add, remove or modify, len holds the operation (EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD) to perform and, off holds a pointer to the epoll_events structure. Available since 5.6.

IORING_OP_SYNC_FILE_RANGE

Issue the equivalent of a sync_file_range (2) on the file descriptor. The fd field is the file descriptor to sync, the off field holds the offset in bytes, the len field holds the length in bytes, and the sync_range_flags field holds the flags for the command. See also sync_file_range(2) for the general description of the related system call. Available since 5.2.

IORING_OP_SENDMSG

Issue the equivalent of a sendmsg(2) system call. fd must be set to the socket file descriptor, addr must contain a pointer to the msghdr structure, and msg_flags holds the flags associated with the system call. See also sendmsg(2) for the general description of the related system call. Available since 5.3.

IORING_OP_RECVMSG

Works just like IORING_OP_SENDMSG, except for recvmsg(2) instead. See the description of IORING_OP_SENDMSG. Available since 5.3.

IORING_OP_SEND

Issue the equivalent of a send(2) system call. fd must be set to the socket file descriptor, addr must contain a pointer to the buffer, len denotes the length of the buffer to send, and msg_flags holds the flags associated with the system call. See also send(2) for the general description of the related system call. Available since 5.6.

IORING_OP_RECV

Works just like IORING_OP_SEND, except for recv(2) instead. See the description of IORING_OP_SEND. Available since 5.6.

IORING_OP_TIMEOUT

This command will register a timeout operation. The addr field must contain a pointer to a struct timespec64 structure, len must contain 1 to signify one timespec64 structure, timeout_flags may contain IORING_TIMEOUT_ABS for an absolute timeout value, or 0 for a relative timeout. off may contain a completion event count. A timeout will trigger a wakeup event on the completion ring for anyone waiting for events. A timeout condition is met when either the specified timeout expires, or the specified number of events have completed. Either condition will trigger the event. If set to 0, completed events are not counted, which effectively acts like a timer. io_uring timeouts use the CLOCK_MONOTONIC clock source. The request will complete with -ETIME if the timeout got completed through expiration of the timer, or 0 if the timeout got completed through requests completing on their own. If the timeout was canceled before it expired, the request will complete with -ECANCELED. Available since 5.4. Since 5.15, this command also supports the following modifiers in timeout_flags:

IORING_TIMEOUT_BOOTTIME If set, then the clocksource used is CLOCK_BOOTTIME instead of CLOCK_MONOTONIC. This clocksource differs in that it includes time elapsed if the system was suspend while having a timeout request in-flight.

IORING_TIMEOUT_REALTIME If set, then the clocksource used is CLOCK_BOOTTIME instead of CLOCK_MONOTONIC.

IORING_OP_TIMEOUT_REMOVE

If timeout_flags are zero, then it attempts to remove an existing timeout operation. addr must contain the user_data field of the previously issued timeout operation. If the specified timeout request is found and canceled successfully, this request will terminate with a result value of 0 If the timeout request was found but expiration was already in progress, this request will terminate with a result value of -EBUSY If the timeout request wasn't found, the request will terminate with a result value of -ENOENT Available since 5.5. If timeout_flags contain IORING_TIMEOUT_UPDATE, instead of removing an existing operation, it updates it. addr and return values are same as before. addr2 field must contain a pointer to a struct timespec64 structure. timeout_flags may also contain IORING_TIMEOUT_ABS, in which case the value given is an absolute one, not a relative one. Available since 5.11.

IORING_OP_ACCEPT

Issue the equivalent of an accept4(2) system call. fd must be set to the socket file descriptor, addr must contain the pointer to the sockaddr structure, and addr2 must contain a pointer to the socklen_t addrlen field. Flags can be passed using the accept_flags field. See also accept4(2) for the general description of the related system call. Available since 5.5. If the file_index field is set to a positive number, the file won't be installed into the normal file table as usual but will be placed into the fixed file table at index file_index - 1. In this case, instead of returning a file descriptor, the result will contain either 0 on success or an error. If the index points to a valid empty slot, the installation is guaranteed to not fail. If there is already a file in the slot, it will be replaced, similar to IORING_OP_FILES_UPDATE. Please note that only io_uring has access to such files and no other syscall can use them. See IOSQE_FIXED_FILE and IORING_REGISTER_FILES.

Available since 5.5.

IORING_OP_ASYNC_CANCEL

Attempt to cancel an already issued request. addr must contain the user_data field of the request that should be canceled. The cancelation request will complete with one of the following results codes. If found, the res field of the cqe will contain 0. If not found, res will contain -ENOENT. If found and attempted canceled, the res field will contain -EALREADY. In this case, the request may or may not terminate. In general, requests that are interruptible (like socket IO) will get canceled, while disk IO requests cannot be canceled if already started. Available since 5.5.

IORING_OP_LINK_TIMEOUT

This request must be linked with another request through IOSQE_IO_LINK which is described below. Unlike IORING_OP_TIMEOUT, IORING_OP_LINK_TIMEOUT acts on the linked request, not the completion queue. The format of the command is otherwise like IORING_OP_TIMEOUT, except there's no completion event count as it's tied to a specific request. If used, the timeout specified in the command will cancel the linked command, unless the linked command completes before the timeout. The timeout will complete with -ETIME if the timer expired and the linked request was attempted canceled, or -ECANCELED if the timer got canceled because of completion of the linked request. Like IORING_OP_TIMEOUT the clock source used is CLOCK_MONOTONIC Available since 5.5.

IORING_OP_CONNECT

Issue the equivalent of a connect(2) system call. fd must be set to the socket file descriptor, addr must contain the const pointer to the sockaddr structure, and off must contain the socklen_t addrlen field. See also connect(2) for the general description of the related system call. Available since 5.5.

IORING_OP_FALLOCATE

Issue the equivalent of a fallocate(2) system call. fd must be set to the file descriptor, len must contain the mode associated with the operation, off must contain the offset on which to operate, and addr must contain the length. See also fallocate(2) for the general description of the related system call. Available since 5.6.

IORING_OP_FADVISE

Issue the equivalent of a posix_fadvise(2) system call. fd must be set to the file descriptor, off must contain the offset on which to operate, len must contain the length, and fadvise_advice must contain the advice associated with the operation. See also posix_fadvise(2) for the general description of the related system call. Available since 5.6.

IORING_OP_MADVISE

Issue the equivalent of a madvise(2) system call. addr must contain the address to operate on, len must contain the length on which to operate, and fadvise_advice must contain the advice associated with the operation. See also madvise(2) for the general description of the related system call. Available since 5.6.

IORING_OP_OPENAT

Issue the equivalent of a openat(2) system call. fd is the dirfd argument, addr must contain a pointer to the *pathname argument, open_flags should contain any flags passed in, and len is access mode of the file. See also openat(2) for the general description of the related system call. Available since 5.6. If the file_index field is set to a positive number, the file won't be installed into the normal file table as usual but will be placed into the fixed file table at index file_index - 1. In this case, instead of returning a file descriptor, the result will contain either 0 on success or an error. If the index points to a valid empty slot, the installation is guaranteed to not fail. If there is already a file in the slot, it will be replaced, similar to IORING_OP_FILES_UPDATE. Please note that only io_uring has access to such files and no other syscall can use them. See IOSQE_FIXED_FILE and IORING_REGISTER_FILES.

Available since 5.15.

IORING_OP_OPENAT2

Issue the equivalent of a openat2(2) system call. fd is the dirfd argument, addr must contain a pointer to the *pathname argument, len should contain the size of the open_how structure, and off should be set to the address of the open_how structure. See also openat2(2) for the general description of the related system call. Available since 5.6. If the file_index field is set to a positive number, the file won't be installed into the normal file table as usual but will be placed into the fixed file table at index file_index - 1. In this case, instead of returning a file descriptor, the result will contain either 0 on success or an error. If the index points to a valid empty slot, the installation is guaranteed to not fail. If there is already a file in the slot, it will be replaced, similar to IORING_OP_FILES_UPDATE. Please note that only io_uring has access to such files and no other syscall can use them. See IOSQE_FIXED_FILE and IORING_REGISTER_FILES.

Available since 5.15.

IORING_OP_CLOSE

Issue the equivalent of a close(2) system call. fd is the file descriptor to be closed. See also close(2) for the general description of the related system call. Available since 5.6. If the file_index field is set to a positive number, this command can be used to close files that were direct opened through IORING_OP_OPENAT , IORING_OP_OPENAT2 , or IORING_OP_ACCEPT using the io_uring specific direct descriptors. Note that only one of the descriptor fields may be set. The direct close feature is available since the 5.15 kernel, where direct descriptors were introduced.

IORING_OP_STATX

Issue the equivalent of a statx(2) system call. fd is the dirfd argument, addr must contain a pointer to the *pathname string, statx_flags is the flags argument, len should be the mask argument, and off must contain a pointer to the statxbuf to be filled in. See also statx(2) for the general description of the related system call. Available since 5.6.

IORING_OP_READ

IORING_OP_WRITE

Issue the equivalent of a pread(2) or pwrite(2) system call. fd is the file descriptor to be operated on, addr contains the buffer in question, len contains the length of the IO operation, and offs contains the read or write offset. If fd does not refer to a seekable file, off must be set to zero. If offs is set to -1 , the offset will use (and advance) the file position, like the read(2) and write(2) system calls. These are non-vectored versions of the IORING_OP_READV and IORING_OP_WRITEV opcodes. See also read(2) and write(2) for the general description of the related system call. Available since 5.6.

IORING_OP_SPLICE

Issue the equivalent of a splice(2) system call. splice_fd_in is the file descriptor to read from, splice_off_in is an offset to read from, fd is the file descriptor to write to, off is an offset from which to start writing to. A sentinel value of -1 is used to pass the equivalent of a NULL for the offsets to splice(2). len contains the number of bytes to copy. splice_flags contains a bit mask for the flag field associated with the system call. Please note that one of the file descriptors must refer to a pipe. See also splice(2) for the general description of the related system call. Available since 5.7.

IORING_OP_TEE

Issue the equivalent of a tee(2) system call. splice_fd_in is the file descriptor to read from, fd is the file descriptor to write to, len contains the number of bytes to copy, and splice_flags contains a bit mask for the flag field associated with the system call. Please note that both of the file descriptors must refer to a pipe. See also tee(2) for the general description of the related system call. Available since 5.8.

IORING_OP_FILES_UPDATE

This command is an alternative to using IORING_REGISTER_FILES_UPDATE which then works in an async fashion, like the rest of the io_uring commands. The arguments passed in are the same. addr must contain a pointer to the array of file descriptors, len must contain the length of the array, and off must contain the offset at which to operate. Note that the array of file descriptors pointed to in addr must remain valid until this operation has completed. Available since 5.6.

IORING_OP_PROVIDE_BUFFERS

This command allows an application to register a group of buffers to be used by commands that read/receive data. Using buffers in this manner can eliminate the need to separate the poll + read, which provides a convenient point in time to allocate a buffer for a given request. It's often infeasible to have as many buffers available as pending reads or receive. With this feature, the application can have its pool of buffers ready in the kernel, and when the file or socket is ready to read/receive data, a buffer can be selected for the operation. fd must contain the number of buffers to provide, addr must contain the starting address to add buffers from, len must contain the length of each buffer to add from the range, buf_group must contain the group ID of this range of buffers, and off must contain the starting buffer ID of this range of buffers. With that set, the kernel adds buffers starting with the memory address in addr, each with a length of len. Hence the application should provide len * fd worth of memory in addr. Buffers are grouped by the group ID, and each buffer within this group will be identical in size according to the above arguments. This allows the application to provide different groups of buffers, and this is often used to have differently sized buffers available depending on what the expectations are of the individual request. When submitting a request that should use a provided buffer, the IOSQE_BUFFER_SELECT flag must be set, and buf_group must be set to the desired buffer group ID where the buffer should be selected from. Available since 5.7.

IORING_OP_REMOVE_BUFFERS

Remove buffers previously registered with IORING_OP_PROVIDE_BUFFERS. fd must contain the number of buffers to remove, and buf_group must contain the buffer group ID from which to remove the buffers. Available since 5.7.

IORING_OP_SHUTDOWN

Issue the equivalent of a shutdown(2) system call. fd is the file descriptor to the socket being shutdown, and len must be set to the how argument. No no other fields should be set. Available since 5.11.

IORING_OP_RENAMEAT

Issue the equivalent of a renameat2(2) system call. fd should be set to the olddirfd, addr should be set to the oldpath, len should be set to the newdirfd, addr should be set to the oldpath, addr2 should be set to the newpath, and finally rename_flags should be set to the flags passed in to renameat2(2). Available since 5.11.

IORING_OP_UNLINKAT

Issue the equivalent of a unlinkat2(2) system call. fd should be set to the dirfd, addr should be set to the pathname, and unlink_flags should be set to the flags being passed in to unlinkat(2). Available since 5.11.

IORING_OP_MKDIRAT

Issue the equivalent of a mkdirat2(2) system call. fd should be set to the dirfd, addr should be set to the pathname, and len should be set to the mode being passed in to mkdirat(2). Available since 5.15.

IORING_OP_SYMLINKAT

Issue the equivalent of a symlinkat2(2) system call. fd should be set to the newdirfd, addr should be set to the target and addr2 should be set to the linkpath being passed in to symlinkat(2). Available since 5.15.

IORING_OP_LINKAT

Issue the equivalent of a linkat2(2) system call. fd should be set to the olddirfd, addr should be set to the oldpath, len should be set to the newdirfd, addr2 should be set to the newpath, and hardlink_flags should be set to the flags being passed in to linkat(2). Available since 5.15.

IORING_OP_MSG_RING

Send a message to an io_uring. fd must be set to a file descriptor of a ring that the application has access to, len can be set to any 32-bit value that the application wishes to pass on, and off should be set any 64-bit value that the application wishes to send. On the target ring, a CQE will be posted with the res field matching the len set, and a user_data field matching the off value being passed in. This request type can be used to either just wake or interrupt anyone waiting for completions on the target ring, ot it can be used to pass messages via the two fields. Available since 5.18.

The flags field is a bit mask. The supported flags are:

IOSQE_FIXED_FILE

When this flag is specified, fd is an index into the files array registered with the io_uring instance (see the IORING_REGISTER_FILES section of the io_uring_register(2) man page). Note that this isn't always available for all commands. If used on a command that doesn't support fixed files, the SQE will error with -EBADF. Available since 5.1.

IOSQE_IO_DRAIN

When this flag is specified, the SQE will not be started before previously submitted SQEs have completed, and new SQEs will not be started before this one completes. Available since 5.2.

IOSQE_IO_LINK

When this flag is specified, the SQE forms a link with the next SQE in the submission ring. That next SQE will not be started before the previous request completes. This, in effect, forms a chain of SQEs, which can be arbitrarily long. The tail of the chain is denoted by the first SQE that does not have this flag set. Chains are not supported across submission boundaries. Even if the last SQE in a submission has this flag set, it will still terminate the current chain. This flag has no effect on previous SQE submissions, nor does it impact SQEs that are outside of the chain tail. This means that multiple chains can be executing in parallel, or chains and individual SQEs. Only members inside the chain are serialized. A chain of SQEs will be broken, if any request in that chain ends in error. io_uring considers any unexpected result an error. This means that, eg, a short read will also terminate the remainder of the chain. If a chain of SQE links is broken, the remaining unstarted part of the chain will be terminated and completed with -ECANCELED as the error code. Available since 5.3.

IOSQE_IO_HARDLINK

Like IOSQE_IO_LINK, but it doesn't sever regardless of the completion result. Note that the link will still sever if we fail submitting the parent request, hard links are only resilient in the presence of completion results for requests that did submit correctly. IOSQE_IO_HARDLINK implies IOSQE_IO_LINK. Available since 5.5.

IOSQE_ASYNC

Normal operation for io_uring is to try and issue an sqe as non-blocking first, and if that fails, execute it in an async manner. To support more efficient overlapped operation of requests that the application knows/assumes will always (or most of the time) block, the application can ask for an sqe to be issued async from the start. Available since 5.6.

IOSQE_BUFFER_SELECT

Used in conjunction with the IORING_OP_PROVIDE_BUFFERS command, which registers a pool of buffers to be used by commands that read or receive data. When buffers are registered for this use case, and this flag is set in the command, io_uring will grab a buffer from this pool when the request is ready to receive or read data. If successful, the resulting CQE will have IORING_CQE_F_BUFFER set in the flags part of the struct, and the upper IORING_CQE_BUFFER_SHIFT bits will contain the ID of the selected buffers. This allows the application to know exactly which buffer was selected for the operation. If no buffers are available and this flag is set, then the request will fail with -ENOBUFS as the error code. Once a buffer has been used, it is no longer available in the kernel pool. The application must re-register the given buffer again when it is ready to recycle it (eg has completed using it). Available since 5.7.

IOSQE_CQE_SKIP_SUCCESS

Don't generate a CQE if the request completes successfully. If the request fails, an appropriate CQE will be posted as usual and if there is no IOSQE_IO_HARDLINK, CQEs for all linked requests will be omitted. The notion of failure/success is opcode specific and is the same as with breaking chains of IOSQE_IO_LINK. One special case is when the request has a linked timeout, then the CQE generation for the linked timeout is decided solely by whether it has IOSQE_CQE_SKIP_SUCCESS set, regardless whether it timed out or was canceled. In other words, if a linked timeout has the flag set, it's guaranteed to not post a CQE. The semantics are chosen to accommodate several use cases. First, when all but the last request of a normal link without linked timeouts are marked with the flag, only one CQE per lin is posted. Additionally, it enables supression of CQEs in cases where the side effects of a successfully executed operation is enough for userspace to know the state of the system. One such example would be writing to a synchronisation file.

This flag is incompatible with IOSQE_IO_DRAIN. Using both of them in a single ring is undefined behavior, even when they are not used together in a single request. Currently, after the first request with IOSQE_CQE_SKIP_SUCCESS, all subsequent requests marked with drain will be failed at submission time. Note that the error reporting is best effort only, and restrictions may change in the future.

Available since 5.17.

ioprio specifies the I/O priority. See ioprio_get(2) for a description of Linux I/O priorities.

fd specifies the file descriptor against which the operation will be performed, with the exception noted above.

If the operation is one of IORING_OP_READ_FIXED or IORING_OP_WRITE_FIXED, addr and len must fall within the buffer located at buf_index in the fixed buffer array. If the operation is either IORING_OP_READV or IORING_OP_WRITEV, then addr points to an iovec array of len entries.

rw_flags, specified for read and write operations, contains a bitwise OR of per-I/O flags, as described in the preadv2(2) man page.

The fsync_flags bit mask may contain either 0, for a normal file integrity sync, or IORING_FSYNC_DATASYNC to provide data sync only semantics. See the descriptions of O_SYNC and O_DSYNC in the open(2) manual page for more information.

The bits that may be set in poll_events are defined in <poll.h>, and documented in poll(2).

user_data is an application-supplied value that will be copied into the completion queue entry (see below). buf_index is an index into an array of fixed buffers, and is only valid if fixed buffers were registered. personality is the credentials id to use for this operation. See io_uring_register(2) for how to register personalities with io_uring. If set to 0, the current personality of the submitting task is used.

Once the submission queue entry is initialized, I/O is submitted by placing the index of the submission queue entry into the tail of the submission queue. After one or more indexes are added to the queue, and the queue tail is advanced, the io_uring_enter(2) system call can be invoked to initiate the I/O.

Completions use the following data structure:

```
/*

 * IO completion data structure (Completion Queue Entry)

 */
struct io_uring_cqe {

    __u64    user_data; /* sqe->data submission passed back */

    __s32    res;       /* result code for this event */

    __u32    flags;
};
```

user_data is copied from the field of the same name in the submission queue entry. The primary use case is to store data that the application will need to access upon completion of this particular I/O. The flags is used for certain commands, like IORING_OP_POLL_ADD or in conjunction with IOSQE_BUFFER_SELECT or IORING_OP_MSG_RING, , see those entries for details. res is the operation-specific result, but io_uring-specific errors (e.g. flags or opcode invalid) are returned through this field. They are described in section CQE ERRORS.

For read and write opcodes, the return values match errno values documented in the preadv2(2) and pwritev2(2) man pages, with res holding the equivalent of -errno for error cases, or the transferred number of bytes in case the operation is successful. Hence both error and success return can be found in that field in the CQE. For other request types, the return values are documented in the matching man page for that type, or in the opcodes section above for io_uring-specific opcodes.

## RETURN VALUE
io_uring_enter() returns the number of I/Os successfully consumed. This can be zero if to_submit was zero or if the submission queue was empty. Note that if the ring was created with IORING_SETUP_SQPOLL specified, then the return value will generally be the same as to_submit as submission happens outside the context of the system call.

The errors related to a submission queue entry will be returned through a completion queue entry (see section CQE ERRORS), rather than through the system call itself.

Errors that occur not on behalf of a submission queue entry are returned via the system call directly. On such an error, -1 is returned and errno is set appropriately.

## ERRORS
These are the errors returned by io_uring_enter() system call.

EAGAIN

The kernel was unable to allocate memory for the request, or otherwise ran out of resources to handle it. The application should wait for some completions and try again.

EBADF

fd is not a valid file descriptor.

EBADFD

fd is a valid file descriptor, but the io_uring ring is not in the right state (enabled). See io_uring_register(2) for details on how to enable the ring.

EBUSY

The application is attempting to overcommit the number of requests it can have pending. The application should wait for some completions and try again. May occur if the application tries to queue more requests than we have room for in the CQ ring, or if the application attempts to wait for more events without having reaped the ones already present in the CQ ring.

EINVAL

Some bits in the flags argument are invalid.

EFAULT

An invalid user space address was specified for the sig argument.

ENXIO

The io_uring instance is in the process of being torn down.

EOPNOTSUPP

fd does not refer to an io_uring instance.

EINTR

The operation was interrupted by a delivery of a signal before it could complete; see signal(7). Can happen while waiting for events with IORING_ENTER_GETEVENTS.

## CQE ERRORS
These io_uring-specific errors are returned as a negative value in the res field of the completion queue entry.

EACCES

The flags field or opcode in a submission queue entry is not allowed due to registered restrictions. See io_uring_register(2) for details on how restrictions work.

EBADF

The fd field in the submission queue entry is invalid, or the IOSQE_FIXED_FILE flag was set in the submission queue entry, but no files were registered with the io_uring instance.

EFAULT

buffer is outside of the process' accessible address space

EFAULT

IORING_OP_READ_FIXED or IORING_OP_WRITE_FIXED was specified in the opcode field of the submission queue entry, but either buffers were not registered for this io_uring instance, or the address range described by addr and len does not fit within the buffer registered at buf_index.

EINVAL

The flags field or opcode in a submission queue entry is invalid.

EINVAL

The buf_index member of the submission queue entry is invalid.

EINVAL

The personality field in a submission queue entry is invalid.

EINVAL

IORING_OP_NOP was specified in the submission queue entry, but the io_uring context was setup for polling (IORING_SETUP_IOPOLL was specified in the call to io_uring_setup).

EINVAL

IORING_OP_READV or IORING_OP_WRITEV was specified in the submission queue entry, but the io_uring instance has fixed buffers registered.

EINVAL

IORING_OP_READ_FIXED or IORING_OP_WRITE_FIXED was specified in the submission queue entry, and the buf_index is invalid.

EINVAL

IORING_OP_READV, IORING_OP_WRITEV, IORING_OP_READ_FIXED, IORING_OP_WRITE_FIXED or IORING_OP_FSYNC was specified in the submission queue entry, but the io_uring instance was configured for IOPOLLing, or any of addr, ioprio, off, len, or buf_index was set in the submission queue entry.

EINVAL

IORING_OP_POLL_ADD or IORING_OP_POLL_REMOVE was specified in the opcode field of the submission queue entry, but the io_uring instance was configured for busy-wait polling (IORING_SETUP_IOPOLL), or any of ioprio, off, len, or buf_index was non-zero in the submission queue entry.

EINVAL

IORING_OP_POLL_ADD was specified in the opcode field of the submission queue entry, and the addr field was non-zero.

EOPNOTSUPP

opcode is valid, but not supported by this kernel.

EOPNOTSUPP

IOSQE_BUFFER_SELECT was set in the flags field of the submission queue entry, but the opcode doesn't support buffer selection.


title: io_uring_register(2)

text:
# io_uring_register(2)

## NAME
io_uring_register - register files or user buffers for asynchronous I/O

## SYNOPSIS

```
#include <linux/io_uring.h>
```

```
int io_uring_register(unsigned int fd, unsigned int opcode,
                      void *arg, unsigned int nr_args);
```

## DESCRIPTION
The io_uring_register() system call registers resources (e.g. user buffers, files, eventfd, personality, restrictions) for use in an io_uring(7) instance referenced by fd. Registering files or user buffers allows the kernel to take long term references to internal data structures or create long term mappings of application memory, greatly reducing per-I/O overhead.

fd is the file descriptor returned by a call to io_uring_setup(2). opcode can be one of:

IORING_REGISTER_BUFFERS

arg points to a struct iovec array of nr_args entries. The buffers associated with the iovecs will be locked in memory and charged against the user's RLIMIT_MEMLOCK resource limit. See getrlimit(2) for more information. Additionally, there is a size limit of 1GiB per buffer. Currently, the buffers must be anonymous, non-file-backed memory, such as that returned by malloc(3) or mmap(2) with the MAP_ANONYMOUS flag set. It is expected that this limitation will be lifted in the future. Huge pages are supported as well. Note that the entire huge page will be pinned in the kernel, even if only a portion of it is used. After a successful call, the supplied buffers are mapped into the kernel and eligible for I/O. To make use of them, the application must specify the IORING_OP_READ_FIXED or IORING_OP_WRITE_FIXED opcodes in the submission queue entry (see the struct io_uring_sqe definition in io_uring_enter(2)), and set the buf_index field to the desired buffer index. The memory range described by the submission queue entry's addr and len fields must fall within the indexed buffer.

It is perfectly valid to setup a large buffer and then only use part of it for an I/O, as long as the range is within the originally mapped region.

An application can increase or decrease the size or number of registered buffers by first unregistering the existing buffers, and then issuing a new call to io_uring_register() with the new buffers.

Note that before 5.13 registering buffers would wait for the ring to idle. If the application currently has requests in-flight, the registration will wait for those to finish before proceeding.

An application need not unregister buffers explicitly before shutting down the io_uring instance. Available since 5.1.

IORING_REGISTER_BUFFERS2

Register buffers for I/O. Similar to IORING_REGISTER_BUFFERS but aims to have a more extensible ABI. arg points to a struct io_uring_rsrc_register, and nr_args should be set to the number of bytes in the structure.

```
struct io_uring_rsrc_register {

    __u32 nr;

    __u32 resv;

    __u64 resv2;

    __aligned_u64 data;

    __aligned_u64 tags;
};
```

The data field contains a pointer to a struct iovec array of nr entries. The tags field should either be 0, then tagging is disabled, or point to an array of nr "tags" (unsigned 64 bit integers). If a tag is zero, then tagging for this particular resource (a buffer in this case) is disabled. Otherwise, after the resource had been unregistered and it's not used anymore, a CQE will be posted with user_data set to the specified tag and all other fields zeroed.

Note that resource updates, e.g. IORING_REGISTER_BUFFERS_UPDATE, don't necessarily deallocate resources by the time it returns, but they might be held alive until all requests using it complete.

Available since 5.13.

IORING_REGISTER_BUFFERS_UPDATE

Updates registered buffers with new ones, either turning a sparse entry into a real one, or replacing an existing entry. arg must contain a pointer to a struct io_uring_rsrc_update2, which contains an offset on which to start the update, and an array of struct iovec. tags points to an array of tags. nr must contain the number of descriptors in the passed in arrays. See IORING_REGISTER_BUFFERS2 for the resource tagging description.

```
struct io_uring_rsrc_update2 {

    __u32 offset;

    __u32 resv;

    __aligned_u64 data;

    __aligned_u64 tags;

    __u32 nr;

    __u32 resv2;
};
```

Available since 5.13.

IORING_UNREGISTER_BUFFERS

This operation takes no argument, and arg must be passed as NULL. All previously registered buffers associated with the io_uring instance will be released. Available since 5.1.

IORING_REGISTER_FILES

Register files for I/O. arg contains a pointer to an array of nr_args file descriptors (signed 32 bit integers). To make use of the registered files, the IOSQE_FIXED_FILE flag must be set in the flags member of the struct io_uring_sqe, and the fd member is set to the index of the file in the file descriptor array.

The file set may be sparse, meaning that the fd field in the array may be set to -1. See IORING_REGISTER_FILES_UPDATE for how to update files in place.

Note that before 5.13 registering files would wait for the ring to idle. If the application currently has requests in-flight, the registration will wait for those to finish before proceeding. See IORING_REGISTER_FILES_UPDATE for how to update an existing set without that limitation.

Files are automatically unregistered when the io_uring instance is torn down. An application needs only unregister if it wishes to register a new set of fds. Available since 5.1.

IORING_REGISTER_FILES2

Register files for I/O. Similar to IORING_REGISTER_FILES. arg points to a struct io_uring_rsrc_register, and nr_args should be set to the number of bytes in the structure.

The data field contains a pointer to an array of nr file descriptors (signed 32 bit integers). tags field should either be 0 or or point to an array of nr "tags" (unsigned 64 bit integers). See IORING_REGISTER_BUFFERS2 for more info on resource tagging.

Note that resource updates, e.g. IORING_REGISTER_FILES_UPDATE, don't necessarily deallocate resources, they might be held until all requests using that resource complete.

Available since 5.13.

IORING_REGISTER_FILES_UPDATE

This operation replaces existing files in the registered file set with new ones, either turning a sparse entry (one where fd is equal to -1 ) into a real one, removing an existing entry (new one is set to -1 ), or replacing an existing entry with a new existing entry. arg must contain a pointer to a struct io_uring_files_update, which contains an offset on which to start the update, and an array of file descriptors to use for the update. nr_args must contain the number of descriptors in the passed in array. Available since 5.5.

File descriptors can be skipped if they are set to IORING_REGISTER_FILES_SKIP. Skipping an fd will not touch the file associated with the previous fd at that index. Available since 5.12.

IORING_REGISTER_FILES_UPDATE2

Similar to IORING_REGISTER_FILES_UPDATE, replaces existing files in the registered file set with new ones, either turning a sparse entry (one where fd is equal to -1 ) into a real one, removing an existing entry (new one is set to -1 ), or replacing an existing entry with a new existing entry. arg must contain a pointer to a struct io_uring_rsrc_update2, which contains an offset on which to start the update, and an array of file descriptors to use for the update stored in data. tags points to an array of tags. nr must contain the number of descriptors in the passed in arrays. See IORING_REGISTER_BUFFERS2 for the resource tagging description.

Available since 5.13.

IORING_UNREGISTER_FILES

This operation requires no argument, and arg must be passed as NULL. All previously registered files associated with the io_uring instance will be unregistered. Available since 5.1.

IORING_REGISTER_EVENTFD

It's possible to use eventfd(2) to get notified of completion events on an io_uring instance. If this is desired, an eventfd file descriptor can be registered through this operation. arg must contain a pointer to the eventfd file descriptor, and nr_args must be 1. Note that while io_uring generally takes care to avoid spurious events, they can occur. Similarly, batched completions of CQEs may only trigger a single eventfd notification even if multiple CQEs are posted. The application should make no assumptions on number of events being available having a direct correlation to eventfd notifications posted. An eventfd notification must thus only be treated as a hint to check the CQ ring for completions. Available since 5.2. An application can temporarily disable notifications, coming through the registered eventfd, by setting the IORING_CQ_EVENTFD_DISABLED bit in the flags field of the CQ ring. Available since 5.8.

IORING_REGISTER_EVENTFD_ASYNC

This works just like IORING_REGISTER_EVENTFD , except notifications are only posted for events that complete in an async manner. This means that events that complete inline while being submitted do not trigger a notification event. The arguments supplied are the same as for IORING_REGISTER_EVENTFD. Available since 5.6.

IORING_UNREGISTER_EVENTFD

Unregister an eventfd file descriptor to stop notifications. Since only one eventfd descriptor is currently supported, this operation takes no argument, and arg must be passed as NULL and nr_args must be zero. Available since 5.2.

IORING_REGISTER_PROBE

This operation returns a structure, io_uring_probe, which contains information about the opcodes supported by io_uring on the running kernel. arg must contain a pointer to a struct io_uring_probe, and nr_args must contain the size of the ops array in that probe struct. The ops array is of the type io_uring_probe_op, which holds the value of the opcode and a flags field. If the flags field has IO_URING_OP_SUPPORTED set, then this opcode is supported on the running kernel. Available since 5.6.

IORING_REGISTER_PERSONALITY

This operation registers credentials of the running application with io_uring, and returns an id associated with these credentials. Applications wishing to share a ring between separate users/processes can pass in this credential id in the sqe personality field. If set, that particular sqe will be issued with these credentials. Must be invoked with arg set to NULL and nr_args set to zero. Available since 5.6.

IORING_UNREGISTER_PERSONALITY

This operation unregisters a previously registered personality with io_uring. nr_args must be set to the id in question, and arg must be set to NULL. Available since 5.6.

IORING_REGISTER_ENABLE_RINGS

This operation enables an io_uring ring started in a disabled state (IORING_SETUP_R_DISABLED was specified in the call to io_uring_setup(2)). While the io_uring ring is disabled, submissions are not allowed and registrations are not restricted. After the execution of this operation, the io_uring ring is enabled: submissions and registration are allowed, but they will be validated following the registered restrictions (if any). This operation takes no argument, must be invoked with arg set to NULL and nr_args set to zero. Available since 5.10.

IORING_REGISTER_RESTRICTIONS

arg points to a struct io_uring_restriction array of nr_args entries. With an entry it is possible to allow an io_uring_register() opcode, or specify which opcode and flags of the submission queue entry are allowed, or require certain flags to be specified (these flags must be set on each submission queue entry).

All the restrictions must be submitted with a single io_uring_register() call and they are handled as an allowlist (opcodes and flags not registered, are not allowed).

Restrictions can be registered only if the io_uring ring started in a disabled state (IORING_SETUP_R_DISABLED must be specified in the call to io_uring_setup(2)).

Available since 5.10.

IORING_REGISTER_IOWQ_AFF

By default, async workers created by io_uring will inherit the CPU mask of its parent. This is usually all the CPUs in the system, unless the parent is being run with a limited set. If this isn't the desired outcome, the application may explicitly tell io_uring what CPUs the async workers may run on. arg must point to a cpu_set_t mask, and nr_args the byte size of that mask. Available since 5.14.

IORING_UNREGISTER_IOWQ_AFF

Undoes a CPU mask previously set with IORING_REGISTER_IOWQ_AFF. Must not have arg or nr_args set. Available since 5.14.

IORING_REGISTER_IOWQ_MAX_WORKERS

By default, io_uring limits the unbounded workers created to the maximum processor count set by RLIMIT_NPROC and the bounded workers is a function of the SQ ring size and the number of CPUs in the system. Sometimes this can be excessive (or too little, for bounded), and this command provides a way to change the count per ring (per NUMA node) instead. arg must be set to an unsigned int pointer to an array of two values, with the values in the array being set to the maximum count of workers per NUMA node. Index 0 holds the bounded worker count, and index 1 holds the unbounded worker count. On successful return, the passed in array will contain the previous maximum valyes for each type. If the count being passed in is 0, then this command returns the current maximum values and doesn't modify the current setting. nr_args must be set to 2, as the command takes two values.

Available since 5.15.

IORING_REGISTER_RING_FDS

Whenever io_uring_enter(2) is called to submit request or wait for completions, the kernel must grab a reference to the file descriptor. If the application using io_uring is threaded, the file table is marked as shared, and the reference grab and put of the file descriptor count is more expensive than it is for a non-threaded application. Similarly to how io_uring allows registration of files, this allow registration of the ring file descriptor itself. This reduces the overhead of the io_uring_enter(2) system call.

arg must be set to an unsigned int pointer to an array of type struct io_uring_rsrc_register of nr_args number of entries. The data field of this struct must point to an io_uring file descriptor, and the offset field can be either -1 or an explicit offset desired for the registered file descriptor value. If -1 is used, then upon successful return of this system call, the field will contain the value of the registered file descriptor to be used for future io_uring_enter(2) system calls.

On successful completion of this request, the returned descriptors may be used instead of the real file descriptor for io_uring_enter(2), provided that IORING_ENTER_REGISTERED_RING is set in the flags for the system call. This flag tells the kernel that a registered descriptor is used rather than a real file descriptor.

Each thread or process using a ring must register the file descriptor directly by issuing this request.o

The maximum number of supported registered ring descriptors is currently limited to 16.

Available since 5.18.

IORING_UNREGISTER_RING_FDS

Unregister descriptors previously registered with IORING_REGISTER_RING_FDS. arg must be set to an unsigned int pointer to an array of type struct io_uring_rsrc_register of nr_args number of entries. Only the offset field should be set in the structure, containing the registered file descriptor offset previously returned from IORING_REGISTER_RING_FDS that the application wishes to unregister.

Note that this isn't done automatically on ring exit, if the thread or task that previously registered a ring file descriptor isn't exiting. It is recommended to manually unregister any previously registered ring descriptors if the ring is closed and the task persists. This will free up a registration slot, making it available for future use.

Available since 5.18.

## RETURN VALUE
On success, io_uring_register() returns 0. On error, -1 is returned, and errno is set accordingly.

## ERRORS
EACCES

The opcode field is not allowed due to registered restrictions.

EBADF

One or more fds in the fd array are invalid.

EBADFD

IORING_REGISTER_ENABLE_RINGS or IORING_REGISTER_RESTRICTIONS was specified, but the io_uring ring is not disabled.

EBUSY

IORING_REGISTER_BUFFERS or IORING_REGISTER_FILES or IORING_REGISTER_RESTRICTIONS was specified, but there were already buffers, files, or restrictions registered.

EFAULT

buffer is outside of the process' accessible address space, or iov_len is greater than 1GiB.

EINVAL

IORING_REGISTER_BUFFERS or IORING_REGISTER_FILES was specified, but nr_args is 0.

EINVAL

IORING_REGISTER_BUFFERS was specified, but nr_args exceeds UIO_MAXIOV

EINVAL

IORING_UNREGISTER_BUFFERS or IORING_UNREGISTER_FILES was specified, and nr_args is non-zero or arg is non-NULL.

EINVAL

IORING_REGISTER_RESTRICTIONS was specified, but nr_args exceeds the maximum allowed number of restrictions or restriction opcode is invalid.

EMFILE

IORING_REGISTER_FILES was specified and nr_args exceeds the maximum allowed number of files in a fixed file set.

EMFILE

IORING_REGISTER_FILES was specified and adding nr_args file references would exceed the maximum allowed number of files the user is allowed to have according to the RLIMIT_NOFILE resource limit and the caller does not have CAP_SYS_RESOURCE capability. Note that this is a per user limit, not per process.

ENOMEM

Insufficient kernel resources are available, or the caller had a non-zero RLIMIT_MEMLOCK soft resource limit, but tried to lock more memory than the limit permitted. This limit is not enforced if the process is privileged (CAP_IPC_LOCK).

ENXIO

IORING_UNREGISTER_BUFFERS or IORING_UNREGISTER_FILES was specified, but there were no buffers or files registered.

ENXIO

Attempt to register files or buffers on an io_uring instance that is already undergoing file or buffer registration, or is being torn down.

EOPNOTSUPP

User buffers point to file-backed memory.


title: io_uring_setup(2)

text:
# io_uring_setup(2)

## NAME
io_uring_setup - setup a context for performing asynchronous I/O

## SYNOPSIS

```
#include <linux/io_uring.h>
```

```
int io_uring_setup(u32 entries, struct io_uring_params *p);
```

## DESCRIPTION
The io_uring_setup() system call sets up a submission queue (SQ) and completion queue (CQ) with at least entries entries, and returns a file descriptor which can be used to perform subsequent operations on the io_uring instance. The submission and completion queues are shared between userspace and the kernel, which eliminates the need to copy data when initiating and completing I/O.

params is used by the application to pass options to the kernel, and by the kernel to convey information about the ring buffers.

```
struct io_uring_params {

    __u32 sq_entries;

    __u32 cq_entries;

    __u32 flags;

    __u32 sq_thread_cpu;

    __u32 sq_thread_idle;

    __u32 features;

    __u32 wq_fd;

    __u32 resv[3];

    struct io_sqring_offsets sq_off;

    struct io_cqring_offsets cq_off;
};
```

The flags, sq_thread_cpu, and sq_thread_idle fields are used to configure the io_uring instance. flags is a bit mask of 0 or more of the following values ORed together:

IORING_SETUP_IOPOLL

Perform busy-waiting for an I/O completion, as opposed to getting notifications via an asynchronous IRQ (Interrupt Request). The file system (if any) and block device must support polling in order for this to work. Busy-waiting provides lower latency, but may consume more CPU resources than interrupt driven I/O. Currently, this feature is usable only on a file descriptor opened using the O_DIRECT flag. When a read or write is submitted to a polled context, the application must poll for completions on the CQ ring by calling io_uring_enter(2). It is illegal to mix and match polled and non-polled I/O on an io_uring instance.

IORING_SETUP_SQPOLL

When this flag is specified, a kernel thread is created to perform submission queue polling. An io_uring instance configured in this way enables an application to issue I/O without ever context switching into the kernel. By using the submission queue to fill in new submission queue entries and watching for completions on the completion queue, the application can submit and reap I/Os without doing a single system call. If the kernel thread is idle for more than sq_thread_idle milliseconds, it will set the IORING_SQ_NEED_WAKEUP bit in the flags field of the struct io_sq_ring. When this happens, the application must call io_uring_enter(2) to wake the kernel thread. If I/O is kept busy, the kernel thread will never sleep. An application making use of this feature will need to guard the io_uring_enter(2) call with the following code sequence:

```
/*

 * Ensure that the wakeup flag is read after the tail pointer

 * has been written. It's important to use memory load acquire

 * semantics for the flags read, as otherwise the application

 * and the kernel might not agree on the consistency of the

 * wakeup flag.

 */
unsigned flags = atomic_load_relaxed(sq_ring->flags);
if (flags & IORING_SQ_NEED_WAKEUP)

    io_uring_enter(fd, 0, 0, IORING_ENTER_SQ_WAKEUP);

```

where sq_ring is a submission queue ring setup using the struct io_sqring_offsets described below.

Before version 5.11 of the Linux kernel, to successfully use this feature, the application must register a set of files to be used for IO through io_uring_register(2) using the IORING_REGISTER_FILES opcode. Failure to do so will result in submitted IO being errored with EBADF. The presence of this feature can be detected by the IORING_FEAT_SQPOLL_NONFIXED feature flag. In version 5.11 and later, it is no longer necessary to register files to use this feature. 5.11 also allows using this as non-root, if the user has the CAP_SYS_NICE capability.

IORING_SETUP_SQ_AFF

If this flag is specified, then the poll thread will be bound to the cpu set in the sq_thread_cpu field of the struct io_uring_params. This flag is only meaningful when IORING_SETUP_SQPOLL is specified. When cgroup setting cpuset.cpus changes (typically in container environment), the bounded cpu set may be changed as well.

IORING_SETUP_CQSIZE

Create the completion queue with struct io_uring_params.cq_entries entries. The value must be greater than entries, and may be rounded up to the next power-of-two.

IORING_SETUP_CLAMP

If this flag is specified, and if entries exceeds IORING_MAX_ENTRIES , then entries will be clamped at IORING_MAX_ENTRIES . If the flag IORING_SETUP_SQPOLL is set, and if the value of struct io_uring_params.cq_entries exceeds IORING_MAX_CQ_ENTRIES , then it will be clamped at IORING_MAX_CQ_ENTRIES .

IORING_SETUP_ATTACH_WQ

This flag should be set in conjunction with struct io_uring_params.wq_fd being set to an existing io_uring ring file descriptor. When set, the io_uring instance being created will share the asynchronous worker thread backend of the specified io_uring ring, rather than create a new separate thread pool.

IORING_SETUP_R_DISABLED

If this flag is specified, the io_uring ring starts in a disabled state. In this state, restrictions can be registered, but submissions are not allowed. See io_uring_register(2) for details on how to enable the ring. Available since 5.10.

IORING_SETUP_SUBMIT_ALL

Normally io_uring stops submitting a batch of request, if one of these requests results in an error. This can cause submission of less than what is expected, if a request ends in error while being submitted. If the ring is created with this flag, io_uring_enter(2) will continue submitting requests even if it encounters an error submitting a request. CQEs are still posted for errored request regardless of whether or not this flag is set at ring creation time, the only difference is if the submit sequence is halted or continued when an error is observed. Available since 5.18.

IORING_SETUP_COOP_TASKRUN

By default, io_uring will interrupt a task running in userspace when a completion event comes in. This is to ensure that completions run in a timely manner. For a lot of use cases, this is overkill and can cause reduced performance from both the inter-processor interrupt used to do this, the kernel/user transition, the needless interruption of the tasks userspace activities, and reduced batching if completions come in at a rapid rate. Most applications don't need the forceful interruption, as the events are processed at any kernel/user transition. The exception are setups where the application uses multiple threads operating on the same ring, where the application waiting on completions isn't the one that submitted them. For most other use cases, setting this flag will improve performance. Available since 5.19.

IORING_SETUP_TASKRUN_FLAG

Used in conjunction with IORING_SETUP_COOP_TASKRUN, this provides a flag, IORING_SQ_TASKRUN, which is set in the SQ ring flags whenever completions are pending that should be processed. liburing will check for this flag even when doing io_uring_peek_cqe(3) and enter the kernel to process them, and applications can do the same. This makes IORING_SETUP_TASKRUN_FLAG safe to use even when applications rely on a peek style operation on the CQ ring to see if anything might be pending to reap. Available since 5.19.

IORING_SETUP_SQE128

If set, io_uring will use 128-byte SQEs rather than the normal 64-byte sized variant. This is a requirement for using certain request types, as of 5.19 only the IORING_OP_URING_CMD passthrough command for NVMe passthrough needs this. Available since 5.19.

IORING_SETUP_CQE32

If set, io_uring will use 32-byte CQEs rather than the normal 32-byte sized variant. This is a requirement for using certain request types, as of 5.19 only the IORING_OP_URING_CMD passthrough command for NVMe passthrough needs this. Available since 5.19.

If no flags are specified, the io_uring instance is setup for interrupt driven I/O. I/O may be submitted using io_uring_enter(2) and can be reaped by polling the completion queue.

The resv array must be initialized to zero.

features is filled in by the kernel, which specifies various features supported by current kernel version.

IORING_FEAT_SINGLE_MMAP

If this flag is set, the two SQ and CQ rings can be mapped with a single mmap(2) call. The SQEs must still be allocated separately. This brings the necessary mmap(2) calls down from three to two. Available since kernel 5.4.

IORING_FEAT_NODROP

If this flag is set, io_uring supports never dropping completion events. If a completion event occurs and the CQ ring is full, the kernel stores the event internally until such a time that the CQ ring has room for more entries. If this overflow condition is entered, attempting to submit more IO will fail with the -EBUSY error value, if it can't flush the overflown events to the CQ ring. If this happens, the application must reap events from the CQ ring and attempt the submit again. Available since kernel 5.5.

IORING_FEAT_SUBMIT_STABLE

If this flag is set, applications can be certain that any data for async offload has been consumed when the kernel has consumed the SQE. Available since kernel 5.5.

IORING_FEAT_RW_CUR_POS

If this flag is set, applications can specify offset == -1 with IORING_OP_{READV,WRITEV} , IORING_OP_{READ,WRITE}_FIXED , and IORING_OP_{READ,WRITE} to mean current file position, which behaves like preadv2(2) and pwritev2(2) with offset == -1. It'll use (and update) the current file position. This obviously comes with the caveat that if the application has multiple reads or writes in flight, then the end result will not be as expected. This is similar to threads sharing a file descriptor and doing IO using the current file position. Available since kernel 5.6.

IORING_FEAT_CUR_PERSONALITY

If this flag is set, then io_uring guarantees that both sync and async execution of a request assumes the credentials of the task that called io_uring_enter(2) to queue the requests. If this flag isn't set, then requests are issued with the credentials of the task that originally registered the io_uring. If only one task is using a ring, then this flag doesn't matter as the credentials will always be the same. Note that this is the default behavior, tasks can still register different personalities through io_uring_register(2) with IORING_REGISTER_PERSONALITY and specify the personality to use in the sqe. Available since kernel 5.6.

IORING_FEAT_FAST_POLL

If this flag is set, then io_uring supports using an internal poll mechanism to drive data/space readiness. This means that requests that cannot read or write data to a file no longer need to be punted to an async thread for handling, instead they will begin operation when the file is ready. This is similar to doing poll + read/write in userspace, but eliminates the need to do so. If this flag is set, requests waiting on space/data consume a lot less resources doing so as they are not blocking a thread. Available since kernel 5.7.

IORING_FEAT_POLL_32BITS

If this flag is set, the IORING_OP_POLL_ADD command accepts the full 32-bit range of epoll based flags. Most notably EPOLLEXCLUSIVE which allows exclusive (waking single waiters) behavior. Available since kernel 5.9.

IORING_FEAT_SQPOLL_NONFIXED

If this flag is set, the IORING_SETUP_SQPOLL feature no longer requires the use of fixed files. Any normal file descriptor can be used for IO commands without needing registration. Available since kernel 5.11.

IORING_FEAT_ENTER_EXT_ARG

If this flag is set, then the io_uring_enter(2) system call supports passing in an extended argument instead of just the sigset_t of earlier kernels. This. extended argument is of type struct io_uring_getevents_arg and allows the caller to pass in both a sigset_t and a timeout argument for waiting on events. The struct layout is as follows:

```
struct io_uring_getevents_arg {

    __u64 sigmask;

    __u32 sigmask_sz;

    __u32 pad;

    __u64 ts;
};
```

and a pointer to this struct must be passed in if IORING_ENTER_EXT_ARG is set in the flags for the enter system call. Available since kernel 5.11.

IORING_FEAT_NATIVE_WORKERS

If this flag is set, io_uring is using native workers for its async helpers. Previous kernels used kernel threads that assumed the identity of the original io_uring owning task, but later kernels will actively create what looks more like regular process threads instead. Available since kernel 5.12.

IORING_FEAT_RSRC_TAGS

If this flag is set, then io_uring supports a variety of features related to fixed files and buffers. In particular, it indicates that registered buffers can be updated in-place, whereas before the full set would have to be unregistered first. Available since kernel 5.13.

IORING_FEAT_CQE_SKIP

If this flag is set, then io_uring supports setting IOSQE_CQE_SKIP_SUCCESS in the submitted SQE, indicating that no CQE should be generated for this SQE if it executes normally. If an error happens processing the SQE, a CQE with the appropriate error value will still be generated. Available since kernel 5.17.

IORING_FEAT_LINKED_FILE

If this flag is set, then io_uring supports sane assignment of files for SQEs that have dependencies. For example, if a chain of SQEs are submitted with IOSQE_IO_LINK, then kernels without this flag will prepare the file for each link upfront. If a previous link opens a file with a known index, eg if direct descriptors are used with open or accept, then file assignment needs to happen post execution of that SQE. If this flag is set, then the kernel will defer file assignment until execution of a given request is started. Available since kernel 5.17.

The rest of the fields in the struct io_uring_params are filled in by the kernel, and provide the information necessary to memory map the submission queue, completion queue, and the array of submission queue entries. sq_entries specifies the number of submission queue entries allocated. sq_off describes the offsets of various ring buffer fields:

```
struct io_sqring_offsets {

    __u32 head;

    __u32 tail;

    __u32 ring_mask;

    __u32 ring_entries;

    __u32 flags;

    __u32 dropped;

    __u32 array;

    __u32 resv[3];
};
```

Taken together, sq_entries and sq_off provide all of the information necessary for accessing the submission queue ring buffer and the submission queue entry array. The submission queue can be mapped with a call like:

```
ptr = mmap(0, sq_off.array + sq_entries * sizeof(__u32),

           PROT_READ|PROT_WRITE, MAP_SHARED|MAP_POPULATE,

           ring_fd, IORING_OFF_SQ_RING);
```

where sq_off is the io_sqring_offsets structure, and ring_fd is the file descriptor returned from io_uring_setup(2). The addition of sq_off.array to the length of the region accounts for the fact that the ring located at the end of the data structure. As an example, the ring buffer head pointer can be accessed by adding sq_off.head to the address returned from mmap(2):

```
head = ptr + sq_off.head;
```

The flags field is used by the kernel to communicate state information to the application. Currently, it is used to inform the application when a call to io_uring_enter(2) is necessary. See the documentation for the IORING_SETUP_SQPOLL flag above. The dropped member is incremented for each invalid submission queue entry encountered in the ring buffer.

The head and tail track the ring buffer state. The tail is incremented by the application when submitting new I/O, and the head is incremented by the kernel when the I/O has been successfully submitted. Determining the index of the head or tail into the ring is accomplished by applying a mask:

```
index = tail & ring_mask;
```

The array of submission queue entries is mapped with:

```
sqentries = mmap(0, sq_entries * sizeof(struct io_uring_sqe),

                 PROT_READ|PROT_WRITE, MAP_SHARED|MAP_POPULATE,

                 ring_fd, IORING_OFF_SQES);
```

The completion queue is described by cq_entries and cq_off shown here:

```
struct io_cqring_offsets {

    __u32 head;

    __u32 tail;

    __u32 ring_mask;

    __u32 ring_entries;

    __u32 overflow;

    __u32 cqes;

    __u32 flags;

    __u32 resv[3];
};
```

The completion queue is simpler, since the entries are not separated from the queue itself, and can be mapped with:

```
ptr = mmap(0, cq_off.cqes + cq_entries * sizeof(struct io_uring_cqe),

           PROT_READ|PROT_WRITE, MAP_SHARED|MAP_POPULATE, ring_fd,

           IORING_OFF_CQ_RING);
```

Closing the file descriptor returned by io_uring_setup(2) will free all resources associated with the io_uring context.

## RETURN VALUE
io_uring_setup(2) returns a new file descriptor on success. The application may then provide the file descriptor in a subsequent mmap(2) call to map the submission and completion queues, or to the io_uring_register(2) or io_uring_enter(2) system calls.

On error, -1 is returned and errno is set appropriately.

## ERRORS
EFAULT

params is outside your accessible address space.

EINVAL

The resv array contains non-zero data, p.flags contains an unsupported flag, entries is out of bounds, IORING_SETUP_SQ_AFF was specified, but IORING_SETUP_SQPOLL was not, or IORING_SETUP_CQSIZE was specified, but io_uring_params.cq_entries was invalid.

EMFILE

The per-process limit on the number of open file descriptors has been reached (see the description of RLIMIT_NOFILE in getrlimit(2)).

ENFILE

The system-wide limit on the total number of open files has been reached.

ENOMEM

Insufficient kernel resources are available.

EPERM

IORING_SETUP_SQPOLL was specified, but the effective user ID of the caller did not have sufficient privileges.

## SEE ALSO
io_uring_register(2), io_uring_enter(2)


package: libxfs-devel

title: ioctl_xfs_ag_geometry(2)

text:
# ioctl_xfs_ag_geometry(2)

## NAME
ioctl_xfs_ag_geometry - query XFS allocation group geometry information

## SYNOPSIS
\#include <xfs/xfs_fs.h>

int ioctl(int fd, XFS_IOC_AG_GEOMETRY, struct xfs_ag_geometry *arg);

## DESCRIPTION
This XFS ioctl retrieves the geometry information for a given allocation group. The geometry information is conveyed in a structure of the following form:

```
struct xfs_ag_geometry {
	uint32_t  ag_number;
	uint32_t  ag_length;
	uint32_t  ag_freeblks;
	uint32_t  ag_icount;
	uint32_t  ag_ifree;
	uint32_t  ag_sick;
	uint32_t  ag_checked;
	uint32_t  ag_flags;
	uint64_t  ag_reserved[12];
};
```

ag_number

The caller must set this field to the index of the allocation group that the caller wishes to learn about.

ag_length

The length of the allocation group is returned in this field, in units of filesystem blocks.

ag_freeblks

The number of free blocks in the allocation group is returned in this field, in units of filesystem blocks.

ag_icount

The number of inode records allocated in this allocation group is returned in this field.

ag_ifree

The number of unused inode records (of the space allocated) in this allocation group is returned in this field.

ag_flags

The caller can set this field to change the operational behavior of the ioctl. Currently no flags are defined, so this field must be zero.

ag_reserved

All reserved fields will be set to zero on return.

The fields ag_sick and ag_checked indicate the relative health of various allocation group metadata:

•

If a given sick flag is set in ag_sick, then that piece of metadata has been observed to be damaged. The same bit will be set in ag_checked.

•

If a given sick flag is set in ag_checked and is not set in ag_sick, then that piece of metadata has been checked and is not faulty.

•

If a given sick flag is not set in ag_checked, then no conclusion can be made.

The following flags apply to these fields:

XFS_AG_GEOM_SICK_SB

Allocation group superblock.

XFS_AG_GEOM_SICK_AGF

Free space header.

XFS_AG_GEOM_SICK_AGFL

Free space reserve list.

XFS_AG_GEOM_SICK_AGI

Inode header.

XFS_AG_GEOM_SICK_BNOBT or XFS_AG_GEOM_SICK_CNTBT

Free space btrees.

XFS_AG_GEOM_SICK_INOBT or XFS_AG_GEOM_SICK_FINOBT

Inode btrees.

XFS_AG_GEOM_SICK_RMAPBT

Reverse mapping btree.

XFS_AG_GEOM_SICK_REFCNTBT

Reference count btree.

## RETURN VALUE
On error, -1 is returned, and errno is set to indicate the error.

## ERRORS
Error codes can be one of, but are not limited to, the following:

EFSBADCRC

Metadata checksum validation failed while performing the query.

EFSCORRUPTED

Metadata corruption was encountered while performing the query.

EINVAL

The specified allocation group number is not valid for this filesystem.

EIO

An I/O error was encountered while performing the query.

## CONFORMING TO
This API is specific to XFS filesystem on the Linux kernel.

## SEE ALSO
ioctl(2)


title: ioctl_xfs_bulkstat(2)

text:
# ioctl_xfs_bulkstat(2)

## NAME
ioctl_xfs_bulkstat - query information for a batch of XFS inodes

## SYNOPSIS
\#include <xfs/xfs_fs.h>

int ioctl(int fd, XFS_IOC_BULKSTAT, struct xfs_bulkstat_req *arg);

## DESCRIPTION
Query stat information for a group of XFS inodes. This ioctl uses struct xfs_bulkstat_req to set up a bulk transfer from the kernel:

```
struct xfs_bulkstat_req {
	struct xfs_bulk_ireq    hdr;
	struct xfs_bulkstat     bulkstat[];
};
```

See below for the xfs_bulkstat structure definition.

```
struct xfs_bulk_ireq {
	uint64_t                ino;
	uint32_t                flags;
	uint32_t                icount;
	uint32_t                ocount;
	uint32_t                agno;
	uint64_t                reserved[5];
};
```

hdr.ino should be set to the number of the first inode for which the caller wants information; or zero to start with the first inode in the filesystem; or a special value if XFS_BULK_IREQ_SPECIAL is set in the flags field. Note that this is a different semantic than the lastip in the old FSBULKSTAT ioctl. After the call, this value will be set to the number of the next inode for which information could supplied. This sets up the next call for an iteration loop.

If the XFS_BULK_IREQ_SPECIAL flag is set in the flags field, the ino field is interpreted according to the following special values:

XFS_BULK_IREQ_SPECIAL_ROOT

Return stat information for the root directory inode.

hdr.flags is a bit set of operational flags:

XFS_BULK_IREQ_AGNO

If this is set, the call will only return results for the allocation group (AG) set in hdr.agno. If hdr.ino is set to zero, results will be returned starting with the first inode in the AG. This flag may not be set at the same time as the XFS_BULK_IREQ_SPECIAL flag.

XFS_BULK_IREQ_SPECIAL

If this is set, results will be returned for only the special inode specified in the hdr.ino field. This flag may not be set at the same time as the XFS_BULK_IREQ_AGNO flag.

hdr.icount is the maximum number of records to return. This should be the size of the array that comes after the header.

hdr.ocount will be set to the number of records actually returned.

hdr.agno is the number of the allocation group (AG) for which we want results. If the XFS_BULK_IREQ_AGNO flag is not set, this field is ignored.

hdr.reserved must be set to zero.

bulkstat is an array of struct xfs_bulkstat which is described below. The array must have at least icount elements.

```
struct xfs_bulkstat {
	uint64_t                bs_ino;
	uint64_t                bs_size;
	uint64_t                bs_blocks;
	uint64_t                bs_xflags;
	uint64_t                bs_atime;
	uint64_t                bs_mtime;
	uint64_t                bs_ctime;
	uint64_t                bs_btime;
	uint32_t                bs_gen;
	uint32_t                bs_uid;
	uint32_t                bs_gid;
	uint32_t                bs_projectid;
	uint32_t                bs_atime_nsec;
	uint32_t                bs_mtime_nsec;
	uint32_t                bs_ctime_nsec;
	uint32_t                bs_btime_nsec;
	uint32_t                bs_blksize;
	uint32_t                bs_rdev;
	uint32_t                bs_cowextsize_blks;
	uint32_t                bs_extsize_blks;
	uint32_t                bs_nlink;
	uint32_t                bs_extents;
	uint32_t                bs_aextents;
	uint16_t                bs_version;
	uint16_t                bs_forkoff;
	uint16_t                bs_sick;
	uint16_t                bs_checked;
	uint16_t                bs_mode;
	uint16_t                bs_pad2;
	uint64_t                bs_pad[7];
};
```

bs_ino is the inode number of this record.

bs_size is the size of the file, in bytes.

bs_blocks is the number of filesystem blocks allocated to this file, including metadata.

bs_xflags tell us what extended flags are set this inode. These flags are the same values as those defined in the XFS INODE FLAGS section of the ioctl_xfs_fsgetxattr(2) manpage.

bs_atime is the last time this file was accessed, in seconds.

bs_mtime is the last time the contents of this file were modified, in seconds.

bs_ctime is the last time this inode record was modified, in seconds.

bs_btime is the time this inode record was created, in seconds.

bs_gen is the generation number of the inode record.

bs_uid is the user id.

bs_gid is the group id.

bs_projectid is the the project id.

bs_atime_nsec is the nanoseconds component of the last time this file was accessed.

bs_mtime_nsec is the nanoseconds component of the last time the contents of this file were modified.

bs_ctime_nsec is the nanoseconds component of the last time this inode record was modified.

bs_btime_nsec is the nanoseconds component of the time this inode record was created.

bs_blksize is the size of a data block for this file, in units of bytes.

bs_rdev is the encoded device id if this is a special file.

bs_cowextsize_blks is the Copy on Write extent size hint for this file, in units of data blocks.

bs_extsize_blks is the extent size hint for this file, in units of data blocks.

bs_nlink is the number of hard links to this inode.

bs_extents is the number of storage mappings associated with this file's data.

bs_aextents is the number of storage mappings associated with this file's extended attributes.

bs_version is the version of this data structure. This will be set to XFS_BULKSTAT_VERSION_V5 by the kernel.

bs_forkoff is the offset of the attribute fork in the inode record, in bytes.

The fields bs_sick and bs_checked indicate the relative health of various allocation group metadata. Please see the section XFS INODE METADATA HEALTH REPORTING for more information.

bs_mode is the file type and mode.

bs_pad[7] is zeroed.

## RETURN VALUE
On error, -1 is returned, and errno is set to indicate the error.

## XFS INODE METADATA HEALTH REPORTING
The online filesystem checking utility scans inode metadata and records what it finds in the kernel incore state. The following scheme is used for userspace to read the incore health status of an inode:

•

If a given sick flag is set in bs_sick, then that piece of metadata has been observed to be damaged. The same bit should be set in bs_checked.

•

If a given sick flag is set in bs_checked but is not set in bs_sick, then that piece of metadata has been checked and is not faulty.

•

If a given sick flag is not set in bs_checked, then no conclusion can be made.

The following flags apply to these fields:

XFS_BS_SICK_INODE

The inode's record itself.

XFS_BS_SICK_BMBTD

File data extent mappings.

XFS_BS_SICK_BMBTA

Extended attribute extent mappings.

XFS_BS_SICK_BMBTC

Copy on Write staging extent mappings.

XFS_BS_SICK_DIR

Directory information.

XFS_BS_SICK_XATTR

Extended attribute data.

XFS_BS_SICK_SYMLINK

Symbolic link target.

XFS_BS_SICK_PARENT

Parent pointers.

## ERRORS
Error codes can be one of, but are not limited to, the following:

EFAULT

The kernel was not able to copy into the userspace buffer.

EFSBADCRC

Metadata checksum validation failed while performing the query.

EFSCORRUPTED

Metadata corruption was encountered while performing the query.

EINVAL

One of the arguments was not valid.

EIO

An I/O error was encountered while performing the query.

ENOMEM

There was insufficient memory to perform the query.

## CONFORMING TO
This API is specific to XFS filesystem on the Linux kernel.

## SEE ALSO
ioctl(2), ioctl_xfs_fsgetxattr(2)


title: ioctl_xfs_fsbulkstat(2)

text:
# ioctl_xfs_fsbulkstat(2)

## NAME
ioctl_xfs_fsbulkstat - query information for a batch of XFS inodes

## SYNOPSIS
\#include <xfs/xfs_fs.h>

int ioctl(int fd, XFS_IOC_FSBULKSTAT, struct xfs_fsop_bulkreq *arg);

int ioctl(int fd, XFS_IOC_FSBULKSTAT_SINGLE, struct xfs_fsop_bulkreq *arg);

## DESCRIPTION
Query stat information for a group of XFS inodes.

NOTE: This ioctl has been superseded. Please see the ioctl_xfs_bulkstat(2) manpage for information about its replacement.

These ioctls use struct xfs_fsop_bulkreq to set up a bulk transfer with the kernel:

```
struct xfs_fsop_bulkreq {
	__u64             *lastip;
	__s32             count;
	void              *ubuffer;
	__s32             *ocount;
};
```

lastip points to a value that will receive the number of the "last inode." This cannot be NULL. For FSBULKSTAT, this should be set to one less than the number of the first inode for which the caller wants information, or zero to start with the first inode in the filesystem. For FSBULKSTAT_SINGLE, this should be set to the number of the inode for which the caller wants information. After the call, this value will be set to the number of the last inode for which information was supplied. This field will not be updated if ocount is NULL.

count is the number of elements in the ubuffer array and therefore the number of inodes for which to return stat information. This value must be set to 1 for FSBULKSTAT_SINGLE.

ocount points to a value that will receive the number of records returned. If this value is NULL, then neither ocount nor lastip will be updated.

ubuffer points to a memory buffer into which inode stat information will be copied. This buffer must be an array of struct xfs_bstat which is described below. The array must have at least count elements.

```
struct xfs_bstat {
	__u64             bs_ino;
	__u16             bs_mode;
	__u16             bs_nlink;
	__u32             bs_uid;
	__u32             bs_gid;
	__u32             bs_rdev;
	__s32             bs_blksize;
	__s64             bs_size;
	struct xfs_bstime bs_atime;
	struct xfs_bstime bs_mtime;
	struct xfs_bstime bs_ctime;
	int64_t           bs_blocks;
	__u32             bs_xflags;
	__s32             bs_extsize;
	__s32             bs_extents;
	__u32             bs_gen;
	__u16             bs_projid_lo;
	__u16             bs_forkoff;
	__u16             bs_projid_hi;
	uint16_t          bs_sick;
	uint16_t          bs_checked;
	unsigned char     bs_pad[2];
	__u32             bs_cowextsize;
	__u32             bs_dmevmask;
	__u16             bs_dmstate;
	__u16             bs_aextents;
};
```

The structure members are as follows:

bs_ino is the inode number for this record.

bs_mode is the file type and mode.

bs_nlink is the number of hard links to this inode.

bs_uid is the user id.

bs_gid is the group id.

bs_rdev is the encoded device id if this is a special file.

bs_blksize is the size of a data block for this file, in units of bytes.

bs_size is the size of the file, in bytes.

bs_atime is the last time this file was accessed.

bs_mtime is the last time the contents of this file were modified.

bs_ctime is the last time this inode record was modified.

bs_blocks is the number of filesystem blocks allocated to this file, including metadata.

bs_xflags contains the extended flags that are set on this inode. These flags are the same values as those defined in the XFS INODE FLAGS section of the ioctl_xfs_fsgetxattr(2) manpage.

bs_extsize is the extent size hint for this file, in bytes.

bs_extents is the number of storage mappings associated with this file's data.

bs_gen is the generation number of the inode record.

bs_projid_lo is the lower 16-bits of the project id.

bs_forkoff is the offset of the attribute fork in the inode record, in bytes.

bs_projid_hi is the upper 16-bits of the project id.

bs_pad[6] is zeroed.

bs_cowextsize is the Copy on Write extent size hint for this file, in bytes.

bs_dmevmask is unused on Linux.

bs_dmstate is unused on Linux.

bs_aextents is the number of storage mappings associated with this file's extended attributes.

The fields bs_sick and bs_checked indicate the relative health of various inode metadata:

•

If a given sick flag is set in bs_sick, then that piece of metadata has been observed to be damaged. The same bit should be set in bs_checked.

•

If a given sick flag is set in bs_checked but is not set in bs_sick, then that piece of metadata has been checked and is not faulty.

•

If a given sick flag is not set in bs_checked, then no conclusion can be made.

The following flags apply to these fields:

XFS_BS_SICK_INODE

The inode's record itself.

XFS_BS_SICK_BMBTD

File data extent mappings.

XFS_BS_SICK_BMBTA

Extended attribute extent mappings.

XFS_BS_SICK_BMBTC

Copy on Write staging extent mappings.

XFS_BS_SICK_DIR

Directory information.

XFS_BS_SICK_XATTR

Extended attribute data.

XFS_BS_SICK_SYMLINK

Symbolic link target.

XFS_BS_SICK_PARENT

Parent pointers.

## RETURN VALUE
On error, -1 is returned, and errno is set to indicate the error.

## ERRORS
Error codes can be one of, but are not limited to, the following:

EFAULT

The kernel was not able to copy into the userspace buffer.

EFSBADCRC

Metadata checksum validation failed while performing the query.

EFSCORRUPTED

Metadata corruption was encountered while performing the query.

EINVAL

One of the arguments was not valid.

EIO

An I/O error was encountered while performing the query.

ENOMEM

There was insufficient memory to perform the query.

## CONFORMING TO
This API is specific to XFS filesystem on the Linux kernel.

## SEE ALSO
ioctl(2), ioctl_xfs_fsgetxattr(2)


title: ioctl_xfs_fscounts(2)

summary: query XFS summary counter information

text:
# ioctl_xfs_fscounts(2)

## NAME
ioctl_xfs_fscounts - query XFS summary counter information

## SYNOPSIS
\#include <xfs/xfs_fs.h>

int ioctl(int fd, XFS_IOC_FSCOUNTS, struct xfs_fsop_counts *arg);

## DESCRIPTION
Query the raw filesystem summary counters. Unlike statvfs(3), the values returned here are the raw values, which do not reflect any alterations or limits set by project quotas. The counter information is conveyed in a structure of the following form:

```
struct xfs_fsop_counts {
	__u64   freedata;
	__u64   freertx;
	__u64   freeino;
	__u64   allocino;
};
```

The fields of this structure are as follows:

freedata is the number of free filesystem blocks on the data device.

freertx is the number of free extents on the realtime device.

freeino is the number of inode records that are not in use within the space that has been allocated for them.

allocino is the number of inode records for which space has been allocated.

## RETURN VALUE
On error, -1 is returned, and errno is set to indicate the error.

## ERRORS
Error codes can be one of, but are not limited to, the following:

EFSBADCRC

Metadata checksum validation failed while performing the query.

EFSCORRUPTED

Metadata corruption was encountered while performing the query.

EINVAL

The specified allocation group number is not valid for this filesystem.

EIO

An I/O error was encountered while performing the query.

## CONFORMING TO
This API is specific to XFS filesystem on the Linux kernel.

## SEE ALSO
ioctl(2)


title: ioctl_xfs_fsgeometry(2)

text:
# ioctl_xfs_fsgeometry(2)

## NAME
ioctl_xfs_fsgeometry - report XFS filesystem layout and features

## SYNOPSIS
\#include <xfs/xfs_fs.h>

int ioctl(int fd, XFS_IOC_FSGEOMETRY, struct xfs_fsop_geom *arg);

int ioctl(int fd, XFS_IOC_FSGEOMETRY_V4, struct xfs_fsop_geom_v4 *arg);

int ioctl(int fd, XFS_IOC_FSGEOMETRY_V1, struct xfs_fsop_geom_v1 *arg);

## DESCRIPTION
Report the details of an XFS filesystem layout, features, and other descriptive items. This information is conveyed in a structure of the following form:

```
struct xfs_fsop_geom {
	__u32         blocksize;
	__u32         rtextsize;
	__u32         agblocks;
	__u32         agcount;
	__u32         logblocks;
	__u32         sectsize;
	__u32         inodesize;
	__u32         imaxpct;
	__u64         datablocks;
	__u64         rtblocks;
	__u64         rtextents;
	__u64         logstart;
	unsigned char uuid[16];
	__u32         sunit;
	__u32         swidth;
	__s32         version;
	__u32         flags;
	__u32         logsectsize;
	__u32         rtsectsize;
	__u32         dirblocksize;
	/* struct xfs_fsop_geom_v1 stops here. */
	__u32         logsunit;
	/* struct xfs_fsop_geom_v4 stops here. */
	__u32         sick;
	__u32         checked;
	__u64         reserved[17];
};
```

blocksize is the size of a fundamental filesystem block, in bytes.

rtextsize is the size of an extent on the realtime volume, in bytes.

agblocks is the size of an allocation group, in units of filesystem blocks.

agcount is the number of allocation groups in the filesystem.

logblocks is the size of the log, in units of filesystem blocks.

sectsize is the smallest amount of data that can be written to the data device atomically, in bytes.

inodesize is the size of an inode record, in bytes.

imaxpct is the maximum percentage of the filesystem that can be allocated to inode record blocks.

datablocks is the size of the data device, in units of filesystem blocks.

rtblocks is the size of the realtime device, in units of filesystem blocks.

rtextents is the number of extents that can be allocated on the realtime device.

logstart is the start of the log, in units of filesystem blocks. If the filesystem has an external log, this will be zero.

uuid is the universal unique identifier of the filesystem.

sunit is what the filesystem has been told is the size of a RAID stripe unit on the underlying data device, in filesystem blocks.

swidth is what the filesystem has been told is the width of a RAID stripe on the underlying data device, in units of RAID stripe units.

version is the version of this structure. This value will be XFS_FSOP_GEOM_VERSION.

flags tell us what features are enabled on the filesystem. Refer to the section FILESYSTEM FEATURE FLAGS below for more information about each feature.

logsectsize is the smallest amount of data that can be written to the log device atomically, in bytes.

rtsectsize is the smallest amount of data that can be written to the realtime device atomically, in bytes.

dirblocksize is the size of directory blocks, in bytes.

logsunit is what the filesystem has been told is the size of a RAID stripe unit on the underlying log device, in filesystem blocks. This field is meaningful only if the flag XFS_FSOP_GEOM_FLAGS_LOGV2 is set.

The fields sick and checked indicate the relative health of various whole-filesystem metadata. Please see the section XFS METADATA HEALTH REPORTING for more details.

reserved is set to zero.

## FILESYSTEM FEATURE FLAGS
Filesystem features are reported to userspace as a combination the following flags:

XFS_FSOP_GEOM_FLAGS_ATTR

Extended attributes are present.

XFS_FSOP_GEOM_FLAGS_NLINK

Files on this filesystem support up to 2^32 hard links. If this flag is not set, files on this filesystem support only up to 2^16 hard links.

XFS_FSOP_GEOM_FLAGS_QUOTA

Quotas are enabled.

XFS_FSOP_GEOM_FLAGS_IALIGN

Inodes are aligned for better performance.

XFS_FSOP_GEOM_FLAGS_DALIGN

Filesystem tries to align data block allocations to RAID stripe units for better performance.

XFS_FSOP_GEOM_FLAGS_SHARED

Unused.

XFS_FSOP_GEOM_FLAGS_EXTFLG

Filesystem supports unwritten extents.

XFS_FSOP_GEOM_FLAGS_DIRV2

Directories are in version 2 format and maintain free space data for better performance. Version 1 format directories are no longer supported.

XFS_FSOP_GEOM_FLAGS_LOGV2

Log uses the V2 format.

XFS_FSOP_GEOM_FLAGS_SECTOR

The log device has a sector size larger than 512 bytes.

XFS_FSOP_GEOM_FLAGS_ATTR2

Filesystem contains V2 extended attributes.

XFS_FSOP_GEOM_FLAGS_PROJID32

Project IDs can be as large as 2^32. If this flag is not set, the filesystem supports only 2^16 project IDs.

XFS_FSOP_GEOM_FLAGS_DIRV2CI

Case-insensitive lookups are supported on directories.

XFS_FSOP_GEOM_FLAGS_LAZYSB

On-disk superblock counters are updated only at unmount time.

XFS_FSOP_GEOM_FLAGS_V5SB

Metadata blocks are self describing and contain checksums.

XFS_FSOP_GEOM_FLAGS_FTYPE

Directories contain inode types in directory entries.

XFS_FSOP_GEOM_FLAGS_FINOBT

Filesystem maintains an index of free inodes.

XFS_FSOP_GEOM_FLAGS_SPINODES

Filesystem may allocate discontiguous inode chunks when free space is fragmented.

XFS_FSOP_GEOM_FLAGS_RMAPBT

Filesystem stores reverse mappings of blocks to owners.

XFS_FSOP_GEOM_FLAGS_REFLINK

Filesystem supports sharing blocks between files.

## XFS METADATA HEALTH REPORTING
The online filesystem checking utility scans metadata and records what it finds in the kernel incore state. The following scheme is used for userspace to read the incore health status of the filesystem:

•

If a given sick flag is set in sick, then that piece of metadata has been observed to be damaged. The same bit should be set in checked.

•

If a given sick flag is set in checked but is not set in sick, then that piece of metadata has been checked and is not faulty.

•

If a given sick flag is not set in checked, then no conclusion can be made.

The following flags apply to these fields:

XFS_FSOP_GEOM_SICK_COUNTERS

Inode and space summary counters.

XFS_FSOP_GEOM_SICK_UQUOTA

User quota information.

XFS_FSOP_GEOM_SICK_GQUOTA

Group quota information.

XFS_FSOP_GEOM_SICK_PQUOTA

Project quota information.

XFS_FSOP_GEOM_SICK_RT_BITMAP

Free space bitmap for the realtime device.

XFS_FSOP_GEOM_SICK_RT_SUMMARY

Free space summary for the realtime device.

## RETURN VALUE
On error, -1 is returned, and errno is set to indicate the error.

## ERRORS
Error codes can be one of, but are not limited to, the following:

EFAULT

The kernel was not able to copy into the userspace buffer.

EFSBADCRC

Metadata checksum validation failed while performing the query.

EFSCORRUPTED

Metadata corruption was encountered while performing the query.

EIO

An I/O error was encountered while performing the query.

## CONFORMING TO
This API is specific to XFS filesystem on the Linux kernel.

## SEE ALSO
ioctl(2)