From: Mike Rapoport <rppt@linux.vnet.ibm.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
criu@openvz.org, gdb@sourceware.org, devel@lists.open-mpi.org,
rr-dev@mozilla.org, Arnd Bergmann <arnd@arndb.de>,
Pavel Emelyanov <xemul@virtuozzo.com>,
Michael Kerrisk <mtk.manpages@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Josh Triplett <josh@joshtriplett.org>,
Jann Horn <jannh@google.com>,
Greg KH <gregkh@linuxfoundation.org>,
Andrei Vagin <avagin@openvz.org>,
Mike Rapoport <rppt@linux.vnet.ibm.com>
Subject: [PATCH v5 1/4] fs/splice: introduce pages_to_pipe helper
Date: Tue, 9 Jan 2018 08:30:50 +0200 [thread overview]
Message-ID: <1515479453-14672-2-git-send-email-rppt@linux.vnet.ibm.com> (raw)
In-Reply-To: <1515479453-14672-1-git-send-email-rppt@linux.vnet.ibm.com>
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
fs/splice.c | 57 ++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 36 insertions(+), 21 deletions(-)
diff --git a/fs/splice.c b/fs/splice.c
index 39e2dc01ac12..7f1ffc50ff1d 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1185,6 +1185,36 @@ static long do_splice(struct file *in, loff_t __user *off_in,
return -EINVAL;
}
+static int pages_to_pipe(struct page **pages, struct pipe_inode_info *pipe,
+ struct pipe_buffer *buf, size_t *total,
+ ssize_t copied, size_t start)
+{
+ bool failed = false;
+ size_t len = 0;
+ int ret = 0;
+ int n;
+
+ for (n = 0; copied; n++, start = 0) {
+ int size = min_t(int, copied, PAGE_SIZE - start);
+ if (!failed) {
+ buf->page = pages[n];
+ buf->offset = start;
+ buf->len = size;
+ ret = add_to_pipe(pipe, buf);
+ if (unlikely(ret < 0))
+ failed = true;
+ else
+ len += ret;
+ } else {
+ put_page(pages[n]);
+ }
+ copied -= size;
+ }
+
+ *total += len;
+ return failed ? ret : len;
+}
+
static int iter_to_pipe(struct iov_iter *from,
struct pipe_inode_info *pipe,
unsigned flags)
@@ -1195,13 +1225,11 @@ static int iter_to_pipe(struct iov_iter *from,
};
size_t total = 0;
int ret = 0;
- bool failed = false;
- while (iov_iter_count(from) && !failed) {
+ while (iov_iter_count(from)) {
struct page *pages[16];
ssize_t copied;
size_t start;
- int n;
copied = iov_iter_get_pages(from, pages, ~0UL, 16, &start);
if (copied <= 0) {
@@ -1209,24 +1237,11 @@ static int iter_to_pipe(struct iov_iter *from,
break;
}
- for (n = 0; copied; n++, start = 0) {
- int size = min_t(int, copied, PAGE_SIZE - start);
- if (!failed) {
- buf.page = pages[n];
- buf.offset = start;
- buf.len = size;
- ret = add_to_pipe(pipe, &buf);
- if (unlikely(ret < 0)) {
- failed = true;
- } else {
- iov_iter_advance(from, ret);
- total += ret;
- }
- } else {
- put_page(pages[n]);
- }
- copied -= size;
- }
+ ret = pages_to_pipe(pages, pipe, &buf, &total, copied, start);
+ if (unlikely(ret < 0))
+ break;
+
+ iov_iter_advance(from, ret);
}
return total ? total : ret;
}
--
2.7.4
next prev parent reply other threads:[~2018-01-09 6:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-09 6:30 [PATCH v5 0/4] vm: add a syscall to map a process memory into a pipe Mike Rapoport
2018-01-09 6:30 ` Mike Rapoport [this message]
2018-01-09 6:30 ` [PATCH v5 2/4] " Mike Rapoport
2018-01-09 6:30 ` [PATCH v5 3/4] x86: wire up the process_vmsplice syscall Mike Rapoport
2018-01-11 17:10 ` kbuild test robot
2018-01-09 6:30 ` [PATCH v5 4/4] test: add a test for " Mike Rapoport
2018-02-21 0:44 ` [PATCH v5 0/4] vm: add a syscall to map a process memory into a pipe Andrew Morton
2018-02-26 9:02 ` Pavel Emelyanov
2018-02-26 16:38 ` [OMPI devel] " Nathan Hjelm
2018-02-27 7:10 ` Mike Rapoport
2018-02-27 2:18 ` Dmitry V. Levin
2018-02-28 6:11 ` Andrei Vagin
2018-02-28 7:12 ` Pavel Emelyanov
2018-02-28 17:50 ` Andrei Vagin
2018-02-28 23:12 ` [OMPI devel] " Atchley, Scott
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=1515479453-14672-2-git-send-email-rppt@linux.vnet.ibm.com \
--to=rppt@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=avagin@openvz.org \
--cc=criu@openvz.org \
--cc=devel@lists.open-mpi.org \
--cc=gdb@sourceware.org \
--cc=gregkh@linuxfoundation.org \
--cc=jannh@google.com \
--cc=josh@joshtriplett.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mtk.manpages@gmail.com \
--cc=rr-dev@mozilla.org \
--cc=tglx@linutronix.de \
--cc=viro@zeniv.linux.org.uk \
--cc=xemul@virtuozzo.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).