From 7581fee4f0679d4f079b61912a24d086e97e78f0 Mon Sep 17 00:00:00 2001 From: YoSTEALTH Date: Thu, 7 Mar 2024 07:59:48 -0600 Subject: [PATCH] file: Argument position changed! Effects `io_uring_prep_openat_direct` & `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. --- src/liburing/file.pxd | 4 ++-- src/liburing/file.pyx | 16 ++++++++++++---- test/file/open_close_test.py | 6 +++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/liburing/file.pxd b/src/liburing/file.pxd index 10941df..cf41ea8 100644 --- a/src/liburing/file.pxd +++ b/src/liburing/file.pxd @@ -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, diff --git a/src/liburing/file.pyx b/src/liburing/file.pyx index a78b1b8..f836092 100644 --- a/src/liburing/file.pyx +++ b/src/liburing/file.pyx @@ -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 @@ -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, diff --git a/test/file/open_close_test.py b/test/file/open_close_test.py index 2788b00..b6e945b 100644 --- a/test/file/open_close_test.py +++ b/test/file/open_close_test.py @@ -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) @@ -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) @@ -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