All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH liburing] fix accept direct with index allocation
@ 2022-06-30  9:45 Donald Hunter
  0 siblings, 0 replies; only message in thread
From: Donald Hunter @ 2022-06-30  9:45 UTC (permalink / raw)
  To: Jens Axboe, io-uring; +Cc: donald.hunter

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@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-30  9:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30  9:45 [PATCH liburing] fix accept direct with index allocation Donald Hunter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.