[PATCH liburing] fix accept direct with index allocation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When io_uring_prep_accept_direct is called with IORING_FILE_INDEX_ALLOC,
sqe->file_index ends up being set to 0 which disables fixed files.

This patch changes __io_uring_set_target_fixed_file to do the right thing,
in preference to a check in io_uring_prep_accept_direct. I thought this was
the better approach, to clean up the other special cases.

Signed-off-by: Donald Hunter <donald.hunter@xxxxxxxxx>
---
 src/include/liburing.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/include/liburing.h b/src/include/liburing.h
index bb2fb87..da9dd41 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -292,8 +292,13 @@ static inline void io_uring_sqe_set_flags(struct io_uring_sqe *sqe,
 static inline void __io_uring_set_target_fixed_file(struct io_uring_sqe *sqe,
 						    unsigned int file_index)
 {
-	/* 0 means no fixed files, indexes should be encoded as "index + 1" */
-	sqe->file_index = file_index + 1;
+	/*
+	 * 0 means no fixed files, indexes should be encoded as "index + 1"
+	 * but we must leave IORING_FILE_INDEX_ALLOC unchanged
+	 */
+	sqe->file_index = (file_index == IORING_FILE_INDEX_ALLOC
+			   ? IORING_FILE_INDEX_ALLOC
+			   : file_index + 1);
 }
 
 static inline void io_uring_prep_rw(int op, struct io_uring_sqe *sqe, int fd,
@@ -537,7 +542,7 @@ static inline void io_uring_prep_multishot_accept_direct(struct io_uring_sqe *sq
 							 int flags)
 {
 	io_uring_prep_multishot_accept(sqe, fd, addr, addrlen, flags);
-	__io_uring_set_target_fixed_file(sqe, IORING_FILE_INDEX_ALLOC - 1);
+	__io_uring_set_target_fixed_file(sqe, IORING_FILE_INDEX_ALLOC);
 }
 
 static inline void io_uring_prep_cancel64(struct io_uring_sqe *sqe,
@@ -881,7 +886,7 @@ static inline void io_uring_prep_socket_direct_alloc(struct io_uring_sqe *sqe,
 {
 	io_uring_prep_rw(IORING_OP_SOCKET, sqe, domain, NULL, protocol, type);
 	sqe->rw_flags = flags;
-	__io_uring_set_target_fixed_file(sqe, IORING_FILE_INDEX_ALLOC - 1);
+	__io_uring_set_target_fixed_file(sqe, IORING_FILE_INDEX_ALLOC);
 }
 
 /*
-- 
2.36.1




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux