From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, io-uring@vger.kernel.org
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org,
Miklos Szeredi <mszeredi@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
ZiyangZhang <ZiyangZhang@linux.alibaba.com>,
Ming Lei <ming.lei@redhat.com>
Subject: [RFC PATCH 2/4] fs/splice: add helper of splice_dismiss_pipe()
Date: Thu, 3 Nov 2022 16:50:02 +0800 [thread overview]
Message-ID: <20221103085004.1029763-3-ming.lei@redhat.com> (raw)
In-Reply-To: <20221103085004.1029763-1-ming.lei@redhat.com>
Add helper of splice_dismiss_pipe(), so cleanup iter_file_splice_write
a bit.
And this helper will be reused in the following patch for supporting
to consume pipe by ->splice_read().
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
fs/splice.c | 47 ++++++++++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 17 deletions(-)
diff --git a/fs/splice.c b/fs/splice.c
index 0878b852b355..f8999ffe6215 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -282,6 +282,34 @@ void splice_shrink_spd(struct splice_pipe_desc *spd)
kfree(spd->partial);
}
+/* return if wakeup is needed */
+static bool splice_dismiss_pipe(struct pipe_inode_info *pipe, ssize_t bytes)
+{
+ unsigned int mask = pipe->ring_size - 1;
+ unsigned int tail = pipe->tail;
+ bool need_wakeup = false;
+
+ while (bytes) {
+ struct pipe_buffer *buf = &pipe->bufs[tail & mask];
+
+ if (bytes >= buf->len) {
+ bytes -= buf->len;
+ buf->len = 0;
+ pipe_buf_release(pipe, buf);
+ tail++;
+ pipe->tail = tail;
+ if (pipe->files)
+ need_wakeup = true;
+ } else {
+ buf->offset += bytes;
+ buf->len -= bytes;
+ bytes = 0;
+ }
+ }
+
+ return need_wakeup;
+}
+
/**
* generic_file_splice_read - splice data from file to a pipe
* @in: file to splice from
@@ -692,23 +720,8 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
*ppos = sd.pos;
/* dismiss the fully eaten buffers, adjust the partial one */
- tail = pipe->tail;
- while (ret) {
- struct pipe_buffer *buf = &pipe->bufs[tail & mask];
- if (ret >= buf->len) {
- ret -= buf->len;
- buf->len = 0;
- pipe_buf_release(pipe, buf);
- tail++;
- pipe->tail = tail;
- if (pipe->files)
- sd.need_wakeup = true;
- } else {
- buf->offset += ret;
- buf->len -= ret;
- ret = 0;
- }
- }
+ if (splice_dismiss_pipe(pipe, ret))
+ sd.need_wakeup = true;
}
done:
kfree(array);
--
2.31.1
next prev parent reply other threads:[~2022-11-03 8:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-03 8:50 [RFC PATCH 0/4] io_uring/splice: extend splice for supporting ublk zero copy Ming Lei
2022-11-03 8:50 ` [RFC PATCH 1/4] io_uring/splice: support do_splice_direct Ming Lei
2022-11-08 7:42 ` Christoph Hellwig
2022-11-03 8:50 ` Ming Lei [this message]
2022-11-03 8:50 ` [RFC PATCH 3/4] io_uring/splice: support splice from ->splice_read to ->splice_read Ming Lei
2022-11-08 7:45 ` Christoph Hellwig
2022-11-08 8:29 ` Ming Lei
2022-11-03 8:50 ` [RFC PATCH 4/4] ublk_drv: support splice based read/write zero copy Ming Lei
2022-11-03 22:28 ` Bernd Schubert
2022-11-04 0:44 ` Ming Lei
2022-11-04 23:37 ` Bernd Schubert
2022-11-07 1:05 ` Ming Lei
2022-11-04 9:15 ` [RFC PATCH 0/4] io_uring/splice: extend splice for supporting ublk " Ziyang Zhang
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=20221103085004.1029763-3-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=ZiyangZhang@linux.alibaba.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mszeredi@redhat.com \
--cc=stefanha@redhat.com \
/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).