[PATCH 5/5] io_uring: add file_in in io_splice{} to avoid duplicate calculation

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

 



From: Hao Xu <howeyxu@xxxxxxxxxxx>

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 <howeyxu@xxxxxxxxxxx>
---
 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




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux