linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: noah <goldstein.w.n@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: goldstein.w.n@gmail.com, noah <goldstein.n@wustl.edu>,
	Jens Axboe <axboe@kernel.dk>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update
Date: Sun, 20 Dec 2020 01:50:25 -0500	[thread overview]
Message-ID: <20201220065025.116516-1-goldstein.w.n@gmail.com> (raw)

From: noah <goldstein.n@wustl.edu>

This patch makes it so that specify a file descriptor value of -2 will
skip updating the corresponding fixed file index.

This will allow for users to reduce the number of syscalls necessary
to update a sparse file range when using the fixed file option.

Signed-off-by: noah <goldstein.w.n@gmail.com>
---
 fs/io_uring.c | 72 ++++++++++++++++++++++++++-------------------------
 1 file changed, 37 insertions(+), 35 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 6f9392c35eef..43ab2b7a87d4 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7876,42 +7876,44 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
 			err = -EFAULT;
 			break;
 		}
-		i = array_index_nospec(up->offset, ctx->nr_user_files);
-		table = &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT];
-		index = i & IORING_FILE_TABLE_MASK;
-		if (table->files[index]) {
-			file = table->files[index];
-			err = io_queue_file_removal(data, file);
-			if (err)
-				break;
-			table->files[index] = NULL;
-			needs_switch = true;
-		}
-		if (fd != -1) {
-			file = fget(fd);
-			if (!file) {
-				err = -EBADF;
-				break;
-			}
-			/*
-			 * Don't allow io_uring instances to be registered. If
-			 * UNIX isn't enabled, then this causes a reference
-			 * cycle and this instance can never get freed. If UNIX
-			 * is enabled we'll handle it just fine, but there's
-			 * still no point in allowing a ring fd as it doesn't
-			 * support regular read/write anyway.
-			 */
-			if (file->f_op == &io_uring_fops) {
-				fput(file);
-				err = -EBADF;
-				break;
-			}
-			table->files[index] = file;
-			err = io_sqe_file_register(ctx, file, i);
-			if (err) {
+		if (fd != -2) {
+			i = array_index_nospec(up->offset, ctx->nr_user_files);
+			table = &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT];
+			index = i & IORING_FILE_TABLE_MASK;
+			if (table->files[index]) {
+				file = table->files[index];
+				err = io_queue_file_removal(data, file);
+				if (err)
+					break;
 				table->files[index] = NULL;
-				fput(file);
-				break;
+				needs_switch = true;
+			}
+			if (fd != -1) {
+				file = fget(fd);
+				if (!file) {
+					err = -EBADF;
+					break;
+				}
+				/*
+				 * Don't allow io_uring instances to be registered. If
+				 * UNIX isn't enabled, then this causes a reference
+				 * cycle and this instance can never get freed. If UNIX
+				 * is enabled we'll handle it just fine, but there's
+				 * still no point in allowing a ring fd as it doesn't
+				 * support regular read/write anyway.
+				 */
+				if (file->f_op == &io_uring_fops) {
+					fput(file);
+					err = -EBADF;
+					break;
+				}
+				table->files[index] = file;
+				err = io_sqe_file_register(ctx, file, i);
+				if (err) {
+					table->files[index] = NULL;
+					fput(file);
+					break;
+				}
 			}
 		}
 		nr_args--;
-- 
2.29.2


             reply	other threads:[~2020-12-20  6:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-20  6:50 noah [this message]
2020-12-20 15:18 ` [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update Pavel Begunkov
2020-12-22  2:10   ` Noah Goldstein
2021-01-26 12:26     ` Pavel Begunkov
2021-01-26 17:14       ` Noah Goldstein
2021-01-26 17:20         ` Pavel Begunkov
2021-01-26 18:43           ` Noah Goldstein
2021-01-26 19:39             ` Pavel Begunkov

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 \
    --in-reply-to=20201220065025.116516-1-goldstein.w.n@gmail.com \
    --to=goldstein.w.n@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=goldstein.n@wustl.edu \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).