public inbox for [email protected]
 help / color / mirror / Atom feed
From: Hao Xu <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>,
	Pavel Begunkov <[email protected]>,
	[email protected],
	Alexander Viro <[email protected]>,
	Andrew Morton <[email protected]>,
	Luis Chamberlain <[email protected]>,
	Kuniyuki Iwashima <[email protected]>
Subject: [PATCH 5/5] io_uring: add file_in in io_splice{} to avoid duplicate calculation
Date: Tue,  7 Jun 2022 16:06:19 +0800	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

From: Hao Xu <[email protected]>

Add a member file_in in io_splice{} to avoid duplicate calculation of
input file for splice. This is for the case where we do splice from
pipe to pipe and get -EAGAIN for the inline submission.

Signed-off-by: Hao Xu <[email protected]>
---
 io_uring/splice.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/io_uring/splice.c b/io_uring/splice.c
index 650c70e3dde1..c97f2971fe7e 100644
--- a/io_uring/splice.c
+++ b/io_uring/splice.c
@@ -21,6 +21,7 @@ struct io_splice {
 	loff_t				off_in;
 	u64				len;
 	int				splice_fd_in;
+	struct file			*file_in;
 	unsigned int			flags;
 };
 
@@ -35,6 +36,7 @@ static int __io_splice_prep(struct io_kiocb *req,
 	if (unlikely(sp->flags & ~valid_flags))
 		return -EINVAL;
 	sp->splice_fd_in = READ_ONCE(sqe->splice_fd_in);
+	sp->file_in = NULL;
 	return 0;
 }
 
@@ -108,34 +110,37 @@ int io_splice(struct io_kiocb *req, unsigned int issue_flags)
 	if (unlikely(!sp->len))
 		goto done;
 
-	if (sp->flags & SPLICE_F_FD_IN_FIXED)
-		in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags);
-	else
-		in = io_file_get_normal(req, sp->splice_fd_in);
-	if (!in) {
-		ret = -EBADF;
-		goto done;
+	if (!sp->file_in) {
+		if (sp->flags & SPLICE_F_FD_IN_FIXED)
+			in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags);
+		else
+			in = io_file_get_normal(req, sp->splice_fd_in);
+
+		if (!in) {
+			ret = -EBADF;
+			goto done;
+		}
+		sp->file_in = in;
+	} else {
+		in = sp->file_in;
 	}
 
 	if (issue_flags & IO_URING_F_NONBLOCK) {
-		if (io_splice_support_nowait(in, out)) {
+		if (io_splice_support_nowait(in, out))
 			flags |= SPLICE_F_NONBLOCK;
-		} else {
-			if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
-				io_put_file(in);
+		else
 			return -EAGAIN;
-		}
 	}
 
 	poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
 	poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
 
 	ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
+	if (ret == -EAGAIN)
+		return ret;
 
 	if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
 		io_put_file(in);
-	if (ret == -EAGAIN)
-		return ret;
 
 done:
 	if (ret != sp->len)
-- 
2.25.1


  parent reply	other threads:[~2022-06-07  8:07 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07  8:06 [RFC 0/5] support nonblock submission for splice pipe to pipe Hao Xu
2022-06-07  8:06 ` [PATCH 1/5] io_uring: move sp->len check up for splice and tee Hao Xu
2022-06-07  8:06 ` [PATCH 2/5] pipe: add trylock helpers for pipe lock Hao Xu
2022-06-07  8:06 ` [PATCH 3/5] splice: support nonblock for splice from pipe to pipe Hao Xu
2022-06-07  8:06 ` [PATCH 4/5] io_uring: support nonblock try for splicing " Hao Xu
2022-06-07 21:38   ` kernel test robot
2022-06-08 14:18   ` kernel test robot
2022-06-09  2:24   ` kernel test robot
2022-06-07  8:06 ` Hao Xu [this message]
2022-06-07  8:13 ` [RFC 0/5] support nonblock submission for splice " Hao Xu
2022-06-07  9:27 ` Pavel Begunkov
2022-06-08  4:19   ` Hao Xu
2022-06-08  4:31     ` Jens Axboe
2022-06-08 11:33     ` Pavel Begunkov
2022-06-14 13:23 ` Hao Xu

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