1io_uring_prep_openat2(3) liburing Manual io_uring_prep_openat2(3)
2
3
4
6 io_uring_prep_openat2 - prepare an openat2 request
7
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <fcntl.h>
12 #include <linux/openat2.h>
13 #include <liburing.h>
14
15 void io_uring_prep_openat2(struct io_uring_sqe *sqe,
16 int dfd,
17 const char *path,
18 int flags,
19 struct open_how *how);
20
21 void io_uring_prep_openat2_direct(struct io_uring_sqe *sqe,
22 int dfd,
23 const char *path,
24 int flags,
25 struct open_how *how,
26 unsigned file_index);
27
29 The io_uring_prep_openat2(3) function prepares an openat2 request. The
30 submission queue entry sqe is setup to use the directory file descrip‐
31 tor dfd to start opening a file described by path and using the open
32 flags in flags and using the instructions on how to open the file given
33 in how.
34
35 For a direct descriptor open request, the offset is specified by the
36 file_index argument. Direct descriptors are io_uring private file de‐
37 scriptors. They avoid some of the overhead associated with thread
38 shared file tables, and can be used in any io_uring request that takes
39 a file descriptor. To do so, IOSQE_FIXED_FILE must be set in the SQE
40 flags member, and the SQE fd field should use the direct descriptor
41 value rather than the regular file descriptor. Direct descriptors are
42 managed like registered files.
43
44 If the direct variant is used, the application must first have regis‐
45 tered a file table using io_uring_register_files(3) of the appropriate
46 size. Once registered, a direct accept request may use any entry in
47 that table, as long as it is within the size of the registered table.
48 If a specified entry already contains a file, the file will first be
49 removed from the table and closed. It's consistent with the behavior of
50 updating an existing file with io_uring_register_files_update(3). Note
51 that old kernels don't check the SQE file_index field, which is not a
52 problem for liburing helpers, but users of the raw io_uring interface
53 need to zero SQEs to avoid unexpected behavior. If IORING_FILE_IN‐
54 DEX_ALLOC is used as the file_index for a direct open, then io_uring
55 will allocate a free direct descriptor in the existing table. The allo‐
56 cated descriptor is returned in the CQE res field just like it would be
57 for a non-direct open request. If no more entries are available in the
58 direct descriptor table, -ENFILE is returned instead.
59
60 These functions prepare an async openat2(2) request. See that man page
61 for details.
62
63
65 None
66
68 The CQE res field will contain the result of the operation. See the re‐
69 lated man page for details on possible values. Note that where synchro‐
70 nous system calls will return -1 on failure and set errno to the actual
71 error value, io_uring never uses errno. Instead it returns the negated
72 errno directly in the CQE res field.
73
75 As with any request that passes in data in a struct, that data must re‐
76 main valid until the request has been successfully submitted. It need
77 not remain valid until completion. Once a request has been submitted,
78 the in-kernel state is stable. Very early kernels (5.4 and earlier) re‐
79 quired state to be stable until the completion occurred. Applications
80 can test for this behavior by inspecting the IORING_FEAT_SUBMIT_STABLE
81 flag passed back from io_uring_queue_init_params(3).
82
84 io_uring_get_sqe(3), io_uring_submit(3), io_uring_register(2), ope‐
85 nat2(2)
86
87
88
89liburing-2.2 March 13, 2022 io_uring_prep_openat2(3)