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 3/5] splice: support nonblock for splice from pipe to pipe
Date: Tue, 7 Jun 2022 16:06:17 +0800 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
From: Hao Xu <[email protected]>
When SPLICE_F_NONBLOCK is set, splice() still may be blocked by pipe
lock in pipe to pipe scenario. Add trylock logic to make it more
nonblock
Signed-off-by: Hao Xu <[email protected]>
---
fs/splice.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/fs/splice.c b/fs/splice.c
index 047b79db8eb5..b087e00ed079 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1372,7 +1372,12 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
return 0;
ret = 0;
- pipe_lock(pipe);
+ if (flags & SPLICE_F_NONBLOCK) {
+ if (!pipe_trylock(pipe))
+ return -EAGAIN;
+ } else {
+ pipe_lock(pipe);
+ }
while (pipe_empty(pipe->head, pipe->tail)) {
if (signal_pending(current)) {
@@ -1408,7 +1413,12 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
return 0;
ret = 0;
- pipe_lock(pipe);
+ if (flags & SPLICE_F_NONBLOCK) {
+ if (!pipe_trylock(pipe))
+ return -EAGAIN;
+ } else {
+ pipe_lock(pipe);
+ }
while (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) {
if (!pipe->readers) {
@@ -1460,7 +1470,12 @@ static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe,
* grabbing by pipe info address. Otherwise two different processes
* could deadlock (one doing tee from A -> B, the other from B -> A).
*/
- pipe_double_lock(ipipe, opipe);
+ if (flags & SPLICE_F_NONBLOCK) {
+ if (!pipe_double_trylock(ipipe, opipe))
+ return -EAGAIN;
+ } else {
+ pipe_double_lock(ipipe, opipe);
+ }
i_tail = ipipe->tail;
i_mask = ipipe->ring_size - 1;
--
2.25.1
next prev parent reply other threads:[~2022-06-07 8:06 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 ` Hao Xu [this message]
2022-06-07 8:06 ` [PATCH 4/5] io_uring: support nonblock try for splicing from pipe to pipe 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 ` [PATCH 5/5] io_uring: add file_in in io_splice{} to avoid duplicate calculation Hao Xu
2022-06-07 8:13 ` [RFC 0/5] support nonblock submission for splice pipe to pipe 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