Skip to content

Commit

Permalink
file: Argument position changed! Effects io_uring_prep_openat_direct &
Browse files Browse the repository at this point in the history
`io_uring_prep_openat2_direct`.

- Changed `flags` default value from `0` to `O_RDONLY`.
- `file_index` now has default value of `IORING_FILE_INDEX_ALLOC`, this
will auto assign free direct descriptor(if available)
- Updated effect test.
  • Loading branch information
YoSTEALTH committed Mar 7, 2024
1 parent c27bb82 commit 7581fee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/liburing/file.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ cpdef void io_uring_prep_openat2(io_uring_sqe sqe,
int dfd=?) noexcept nogil
cpdef void io_uring_prep_openat_direct(io_uring_sqe sqe,
const char *path,
unsigned int file_index,
int flags=?,
unsigned int file_index=?,
mode_t mode=?,
int dfd=?) noexcept nogil
cpdef void io_uring_prep_openat2_direct(io_uring_sqe sqe,
const char *path,
unsigned int file_index,
open_how how,
unsigned int file_index=?,
int dfd=?) noexcept nogil
cpdef void io_uring_prep_read(io_uring_sqe sqe,
int fd,
Expand Down
16 changes: 12 additions & 4 deletions src/liburing/file.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ cpdef inline void io_uring_prep_sync_file_range(io_uring_sqe sqe,

cpdef inline void io_uring_prep_openat(io_uring_sqe sqe,
const char *path,
int flags=0,
int flags=__O_RDONLY,
mode_t mode=0o777,
int dfd=__AT_FDCWD) noexcept nogil:
''' Open File
Expand All @@ -200,17 +200,25 @@ cpdef inline void io_uring_prep_openat2(io_uring_sqe sqe,

cpdef inline void io_uring_prep_openat_direct(io_uring_sqe sqe,
const char *path,
unsigned int file_index, # unsigned int file_index,
int flags=0,
int flags=__O_RDONLY,
unsigned int file_index=__IORING_FILE_INDEX_ALLOC,
mode_t mode=0o777,
int dfd=__AT_FDCWD) noexcept nogil:
''' Note
- If `file_index=IORING_FILE_INDEX_ALLOC` free direct descriptor will be auto assigned.
Allocated descriptor is returned in the `cqe.res`.
'''
__io_uring_prep_openat_direct(sqe.ptr, dfd, path, flags, mode, file_index)

cpdef inline void io_uring_prep_openat2_direct(io_uring_sqe sqe,
const char *path,
unsigned int file_index,
open_how how,
unsigned int file_index=__IORING_FILE_INDEX_ALLOC,
int dfd=__AT_FDCWD) noexcept nogil:
''' Note
- If `file_index=IORING_FILE_INDEX_ALLOC` free direct descriptor will be auto assigned.
Allocated descriptor is returned in the `cqe.res`.
'''
__io_uring_prep_openat2_direct(sqe.ptr, dfd, path, how.ptr, file_index)

cpdef inline void io_uring_prep_read(io_uring_sqe sqe,
Expand Down
6 changes: 3 additions & 3 deletions test/file/open_close_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_openat_close_direct(ring, cqe):
liburing.io_uring_register_files(ring, [index, 1, 2, 3])
# open
sqe = liburing.io_uring_get_sqe(ring)
liburing.io_uring_prep_openat_direct(sqe, b'.', index, flags)
liburing.io_uring_prep_openat_direct(sqe, b'.', flags, index)
sqe.user_data = 123
# submit
liburing.io_uring_submit(ring)
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_openat2_close_direct(ring, cqe):
liburing.io_uring_register_files(ring, [0, 1, 2, index])
# open
sqe = liburing.io_uring_get_sqe(ring)
liburing.io_uring_prep_openat2_direct(sqe, b'.', index, how)
liburing.io_uring_prep_openat2_direct(sqe, b'.', how, index)
sqe.user_data = 123
# submit
liburing.io_uring_submit(ring)
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_openat2_close_direct_auto_file_index_alloc(ring, cqe):
liburing.io_uring_register_files(ring, [0, 1, 2, -1])
# open
sqe = liburing.io_uring_get_sqe(ring)
liburing.io_uring_prep_openat2_direct(sqe, b'.', liburing.IORING_FILE_INDEX_ALLOC, how)
liburing.io_uring_prep_openat2_direct(sqe, b'.', how) # `file_index=IORING_FILE_INDEX_ALLOC`
sqe.user_data = 123
# submit
assert liburing.io_uring_submit(ring) == 1
Expand Down

0 comments on commit 7581fee

Please sign in to comment.