diff mbox series

[1/5] io_uring: move sp->len check up for splice and tee

Message ID 20220607080619.513187-2-hao.xu@linux.dev (mailing list archive)
State New
Headers show
Series support nonblock submission for splice pipe to pipe | expand

Commit Message

Hao Xu June 7, 2022, 8:06 a.m. UTC
From: Hao Xu <howeyxu@tencent.com>

The traditional sync splice code return 0 if len is 0 at the beginning
of syscall, similar thing for tee. So move up sp->len zero check so that
it reaches quick ending when len is 0.

Signed-off-by: Hao Xu <howeyxu@tencent.com>
---
 io_uring/splice.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/io_uring/splice.c b/io_uring/splice.c
index 0e19d6330345..b2cd1044c3ee 100644
--- a/io_uring/splice.c
+++ b/io_uring/splice.c
@@ -53,6 +53,9 @@  int io_tee(struct io_kiocb *req, unsigned int issue_flags)
 	struct file *in;
 	long ret = 0;
 
+	if (unlikely(!sp->len))
+		goto done;
+
 	if (issue_flags & IO_URING_F_NONBLOCK)
 		return -EAGAIN;
 
@@ -65,8 +68,7 @@  int io_tee(struct io_kiocb *req, unsigned int issue_flags)
 		goto done;
 	}
 
-	if (sp->len)
-		ret = do_tee(in, out, sp->len, flags);
+	ret = do_tee(in, out, sp->len, flags);
 
 	if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
 		io_put_file(in);
@@ -95,6 +97,9 @@  int io_splice(struct io_kiocb *req, unsigned int issue_flags)
 	struct file *in;
 	long ret = 0;
 
+	if (unlikely(!sp->len))
+		goto done;
+
 	if (issue_flags & IO_URING_F_NONBLOCK)
 		return -EAGAIN;
 
@@ -110,8 +115,7 @@  int io_splice(struct io_kiocb *req, unsigned int issue_flags)
 	poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
 	poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
 
-	if (sp->len)
-		ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
+	ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
 
 	if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
 		io_put_file(in);