public inbox for [email protected]
 help / color / mirror / Atom feed
From: Donald Hunter <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Cc: [email protected]
Subject: [PATCH liburing] fix accept direct with index allocation
Date: Thu, 30 Jun 2022 10:45:38 +0100	[thread overview]
Message-ID: <[email protected]> (raw)

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 <[email protected]>
---
 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



                 reply	other threads:[~2022-06-30  9:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox