From: Christoph Hellwig <hch@infradead.org>
To: Al Viro <viro@zeniv.linux.org.uk>, Jens Axboe <axboe@kernel.dk>,
Mark Fasheh <mfasheh@suse.com>, Joel Becker <jlbec@evilplan.org>
Cc: linux-fsdevel@vger.kernel.org, xfs@oss.sgi.com
Subject: [PATCH 3/5] splice: use splice_from_pipe in generic_file_splice_write
Date: Thu, 12 Dec 2013 10:15:02 -0800 [thread overview]
Message-ID: <20131212181844.848709380@bombadil.infradead.org> (raw)
In-Reply-To: 20131212181459.994196463@bombadil.infradead.org
[-- Attachment #1: 0003-splice-use-splice_from_pipe-in-generic_file_splice_w.patch --]
[-- Type: text/plain, Size: 5600 bytes --]
Reuse generic_write_sync instead of reimplementing it in the splice
write path both in the generic code and ocfs2. Only needs a little
bit of refactoring for the actors to provide the desired functionality.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/ocfs2/file.c | 58 ++++++++++-----------------------------------
fs/splice.c | 61 +++++++++++++++++-------------------------------
include/linux/splice.h | 2 ++
3 files changed, 36 insertions(+), 85 deletions(-)
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index c68e111..5b1b5f9 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -2423,38 +2423,14 @@ out_sems:
return ret;
}
-static int ocfs2_splice_to_file(struct pipe_inode_info *pipe,
- struct file *out,
- struct splice_desc *sd)
-{
- int ret;
-
- ret = ocfs2_prepare_inode_for_write(out, &sd->pos,
- sd->total_len, 0, NULL, NULL);
- if (ret < 0) {
- mlog_errno(ret);
- return ret;
- }
-
- return splice_from_pipe_feed(pipe, sd, pipe_to_file);
-}
-
static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe,
struct file *out,
loff_t *ppos,
size_t len,
unsigned int flags)
{
- int ret;
- struct address_space *mapping = out->f_mapping;
- struct inode *inode = mapping->host;
- struct splice_desc sd = {
- .total_len = len,
- .flags = flags,
- .pos = *ppos,
- .u.file = out,
- };
-
+ struct inode *inode = out->f_mapping->host;
+ ssize_t ret;
trace_ocfs2_file_splice_write(inode, out, out->f_path.dentry,
(unsigned long long)OCFS2_I(inode)->ip_blkno,
@@ -2467,35 +2443,25 @@ static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe,
mlog_errno(ret);
goto out_unlock_inode;
}
- pipe_lock(pipe);
- splice_from_pipe_begin(&sd);
- do {
- ret = splice_from_pipe_next(pipe, &sd);
- if (ret <= 0)
- break;
-
- ret = ocfs2_splice_to_file(pipe, out, &sd);
- } while (ret > 0);
- splice_from_pipe_end(pipe, &sd);
+ ret = ocfs2_prepare_inode_for_write(out, ppos, len, 0, NULL, NULL);
+ if (ret < 0) {
+ mlog_errno(ret);
+ goto out_unlock_rw;
+ }
- pipe_unlock(pipe);
+ ret = splice_from_pipe(pipe, out, ppos, len, flags, __pipe_to_file);
+out_unlock_rw:
ocfs2_rw_unlock(inode, 1);
out_unlock_inode:
mutex_unlock(&inode->i_mutex);
- if (sd.num_spliced)
- ret = sd.num_spliced;
-
if (ret > 0) {
- int err;
-
- err = generic_write_sync(out, *ppos, ret);
+ int err = generic_write_sync(out, *ppos, ret);
if (err)
- ret = err;
- else
- *ppos += ret;
+ return ret;
+ *ppos += ret;
}
return ret;
diff --git a/fs/splice.c b/fs/splice.c
index 4fb6c1f..108e527 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -727,7 +727,7 @@ static int pipe_to_sendpage(struct pipe_inode_info *pipe,
* SPLICE_F_MOVE isn't set, or we cannot move the page, we simply create
* a new page in the output file page cache and fill/dirty that.
*/
-int pipe_to_file(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
+int __pipe_to_file(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
struct splice_desc *sd)
{
struct file *file = sd->u.file;
@@ -766,6 +766,22 @@ int pipe_to_file(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
out:
return ret;
}
+EXPORT_SYMBOL(__pipe_to_file);
+
+int pipe_to_file(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
+ struct splice_desc *sd)
+{
+ struct file *file = sd->u.file;
+ int ret;
+
+ ret = file_remove_suid(file);
+ if (ret)
+ return ret;
+ ret = file_update_time(file);
+ if (ret)
+ return ret;
+ return __pipe_to_file(pipe, buf, sd);
+}
EXPORT_SYMBOL(pipe_to_file);
static void wakeup_pipe_writers(struct pipe_inode_info *pipe)
@@ -995,55 +1011,22 @@ ssize_t
generic_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
loff_t *ppos, size_t len, unsigned int flags)
{
- struct address_space *mapping = out->f_mapping;
- struct inode *inode = mapping->host;
- struct splice_desc sd = {
- .total_len = len,
- .flags = flags,
- .pos = *ppos,
- .u.file = out,
- };
+ struct inode *inode = out->f_mapping->host;
ssize_t ret;
mutex_lock(&inode->i_mutex);
-
- pipe_lock(pipe);
-
- splice_from_pipe_begin(&sd);
- do {
- ret = splice_from_pipe_next(pipe, &sd);
- if (ret <= 0)
- break;
-
- ret = file_remove_suid(out);
- if (!ret) {
- ret = file_update_time(out);
- if (!ret)
- ret = splice_from_pipe_feed(pipe, &sd,
- pipe_to_file);
- }
- } while (ret > 0);
- splice_from_pipe_end(pipe, &sd);
-
- pipe_unlock(pipe);
+ ret = splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_file);
mutex_unlock(&inode->i_mutex);
- if (sd.num_spliced)
- ret = sd.num_spliced;
-
if (ret > 0) {
- int err;
-
- err = generic_write_sync(out, *ppos, ret);
+ int err = generic_write_sync(out, *ppos, ret);
if (err)
- ret = err;
- else
- *ppos += ret;
+ return err;
+ *ppos += ret;
}
return ret;
}
-
EXPORT_SYMBOL(generic_file_splice_write);
static int write_pipe_buf(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
diff --git a/include/linux/splice.h b/include/linux/splice.h
index 74575cb..c5aca88 100644
--- a/include/linux/splice.h
+++ b/include/linux/splice.h
@@ -78,6 +78,8 @@ extern void splice_from_pipe_end(struct pipe_inode_info *,
struct splice_desc *);
extern int pipe_to_file(struct pipe_inode_info *, struct pipe_buffer *,
struct splice_desc *);
+extern int __pipe_to_file(struct pipe_inode_info *, struct pipe_buffer *,
+ struct splice_desc *);
extern ssize_t splice_to_pipe(struct pipe_inode_info *,
struct splice_pipe_desc *);
--
1.7.10.4
next prev parent reply other threads:[~2013-12-12 18:18 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-12 18:14 [PATCH 0/5] splice: locking changes and code refactoring Christoph Hellwig
2013-12-12 18:15 ` [PATCH 1/5] splice: move balance_dirty_pages_ratelimited into pipe_to_file Christoph Hellwig
2013-12-12 18:15 ` [PATCH 2/5] splice: nest i_mutex outside pipe_lock Christoph Hellwig
2013-12-12 18:15 ` Christoph Hellwig [this message]
2013-12-12 18:15 ` [PATCH 4/5] xfs: fix splice_write locking Christoph Hellwig
2013-12-12 18:15 ` [PATCH 5/5] splice: stop exporting splice_from_pipe implementation details Christoph Hellwig
2014-01-13 14:14 ` [PATCH 0/5] splice: locking changes and code refactoring Christoph Hellwig
2014-01-13 23:56 ` Al Viro
2014-01-14 13:22 ` Christoph Hellwig
2014-01-14 17:20 ` Al Viro
2014-01-15 18:10 ` Al Viro
2014-01-18 6:40 ` Al Viro
2014-01-18 7:22 ` Linus Torvalds
2014-01-18 7:46 ` Al Viro
2014-01-18 7:56 ` Al Viro
2014-01-18 8:27 ` Al Viro
2014-01-18 8:44 ` David Miller
2014-02-07 17:10 ` Al Viro
2014-01-18 19:59 ` Linus Torvalds
2014-01-18 20:10 ` Al Viro
2014-01-18 20:27 ` Al Viro
2014-01-18 20:30 ` Al Viro
2014-01-19 5:13 ` [RFC] unifying write variants for filesystems Al Viro
2014-01-20 13:55 ` Christoph Hellwig
2014-01-20 20:32 ` Linus Torvalds
2014-02-01 22:43 ` Al Viro
2014-02-02 0:13 ` Linus Torvalds
2014-02-02 2:02 ` Al Viro
2014-02-02 19:21 ` Al Viro
2014-02-02 19:23 ` Al Viro
2014-02-03 14:41 ` Miklos Szeredi
2014-02-03 15:33 ` Al Viro
2014-02-02 23:16 ` Anton Altaparmakov
2014-02-03 15:12 ` Christoph Hellwig
2014-02-03 16:24 ` Al Viro
2014-02-03 16:50 ` Dave Kleikamp
2014-02-03 16:23 ` Dave Kleikamp
2014-02-04 12:44 ` Al Viro
2014-02-04 12:52 ` Kent Overstreet
2014-02-04 15:17 ` Al Viro
2014-02-04 17:27 ` Zach Brown
2014-02-04 17:35 ` Kent Overstreet
2014-02-04 18:08 ` Al Viro
2014-02-04 18:00 ` Al Viro
2014-02-04 18:33 ` Zach Brown
2014-02-04 18:36 ` Al Viro
2014-02-05 19:58 ` Al Viro
2014-02-05 20:42 ` Zach Brown
2014-02-06 9:08 ` Kent Overstreet
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=20131212181844.848709380@bombadil.infradead.org \
--to=hch@infradead.org \
--cc=axboe@kernel.dk \
--cc=jlbec@evilplan.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=mfasheh@suse.com \
--cc=viro@zeniv.linux.org.uk \
--cc=xfs@oss.sgi.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).