From: Neil Brown <neilb@suse.de>
To: Jens Axboe <jens.axboe@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>,
linux-kernel@vger.kernel.org, cotte@de.ibm.com, hugh@veritas.com,
zanussi@us.ibm.com, Linus Torvalds <torvalds@osdl.org>
Subject: Re: [PATCH] sendfile removal (nfsd update)
Date: Fri, 1 Jun 2007 12:44:30 +1000 [thread overview]
Message-ID: <18015.34830.401191.916084@notabene.brown> (raw)
In-Reply-To: message from Jens Axboe on Thursday May 31
Ok, here is a patch that makes nfsd use splice instead of sendfile.
It appears to both compile and work.
Some observations:
- __splice_from_pipe wants a "struct file*" and I wanted to pass a
"struct svcrqst *". Maybe it should take a void * ?
- It also wants a *ppos which I had no use for.. It that really
need? Cannot &file->f_pos be used?
- I copied do_splice_to from splice.c as it wasn't exported, and
then found I couldn't compile because rw_verify_area wasn't
exported. As nfsd doesn't need that (we never export
mandatory-locking files) I just remove it and some other cruft
that I didn't need.... Not sure if that was the best approach.
- I needed to export alloc_pipe_info. Maybe there should be a
get_current_pipe instead which does the alloc if needed.
- I would much rather have something like free_pipe_info exported
than open code it in do_splice_read (which is based heavily on
do_splice_direct).
NeilBrown
-------------------------------
Replace ->sendfile with ->splice_read
Apparently ->sendfile is going away, so change nfsd to use ->splice_read
to get pages for a file.
Signed-off-by: Neil Brown <neilb@suse.de>
### Diffstat output
./fs/nfsd/vfs.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++--------
./fs/pipe.c | 1
2 files changed, 109 insertions(+), 17 deletions(-)
diff .prev/fs/nfsd/vfs.c ./fs/nfsd/vfs.c
--- .prev/fs/nfsd/vfs.c 2007-06-01 10:41:27.000000000 +1000
+++ ./fs/nfsd/vfs.c 2007-06-01 12:32:51.000000000 +1000
@@ -23,7 +23,7 @@
#include <linux/file.h>
#include <linux/mount.h>
#include <linux/major.h>
-#include <linux/ext2_fs.h>
+#include <linux/pipe_fs_i.h>
#include <linux/proc_fs.h>
#include <linux/stat.h>
#include <linux/fcntl.h>
@@ -801,26 +801,32 @@ found:
}
/*
- * Grab and keep cached pages assosiated with a file in the svc_rqst
- * so that they can be passed to the netowork sendmsg/sendpage routines
- * directrly. They will be released after the sending has completed.
+ * Grab and keep cached pages associated with a file in the svc_rqst
+ * so that they can be passed to the network sendmsg/sendpage routines
+ * directly. They will be released after the sending has completed.
*/
static int
-nfsd_read_actor(read_descriptor_t *desc, struct page *page, unsigned long offset , unsigned long size)
+nfsd_splice_actor(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
+ struct splice_desc *sd)
{
- unsigned long count = desc->count;
- struct svc_rqst *rqstp = desc->arg.data;
+ struct svc_rqst *rqstp = (struct svc_rqst *)sd->file;
struct page **pp = rqstp->rq_respages + rqstp->rq_resused;
+ struct page *page = buf->page;
+ size_t size;
+ int ret;
+
+ ret = buf->ops->pin(pipe, buf);
+ if (unlikely(ret))
+ return ret;
- if (size > count)
- size = count;
+ size = sd->len;
if (rqstp->rq_res.page_len == 0) {
get_page(page);
put_page(*pp);
*pp = page;
rqstp->rq_resused++;
- rqstp->rq_res.page_base = offset;
+ rqstp->rq_res.page_base = buf->offset;
rqstp->rq_res.page_len = size;
} else if (page != pp[-1]) {
get_page(page);
@@ -832,11 +838,98 @@ nfsd_read_actor(read_descriptor_t *desc,
} else
rqstp->rq_res.page_len += size;
- desc->count = count - size;
- desc->written += size;
return size;
}
+static long do_splice_to(struct file *in, loff_t *ppos,
+ struct pipe_inode_info *pipe, size_t len,
+ unsigned int flags)
+{
+ loff_t isize, left;
+
+ isize = i_size_read(in->f_mapping->host);
+ if (unlikely(*ppos >= isize))
+ return 0;
+
+ left = isize - *ppos;
+ if (unlikely(left < len))
+ len = left;
+
+ return in->f_op->splice_read(in, ppos, pipe, len, flags);
+}
+
+static int do_splice_read(struct file *in, loff_t *ppos, size_t count,
+ struct svc_rqst *rqstp)
+{
+ struct pipe_inode_info *pipe;
+ long ret, bytes;
+ int i;
+
+ rqstp->rq_resused = 1;
+
+ pipe = current->splice_pipe;
+ if (unlikely(!pipe)) {
+ pipe = alloc_pipe_info(NULL);
+ if (!pipe)
+ return -ENOMEM;
+
+ pipe->readers = 1;
+ current->splice_pipe = pipe;
+ }
+
+ ret = 0;
+ bytes = 0;
+
+ while (count) {
+ loff_t unused = 0;
+ size_t read_len, max_read_len;
+
+ max_read_len = min(count, (size_t)(PIPE_BUFFERS*PAGE_SIZE));
+
+ ret = do_splice_to(in, ppos, pipe, max_read_len, 0);
+ if (unlikely(ret < 0))
+ goto out_release;
+
+ read_len = ret;
+
+ ret = __splice_from_pipe(pipe, (struct file *)rqstp,
+ &unused, read_len, 0,
+ nfsd_splice_actor);
+ if (unlikely(ret < 0))
+ goto out_release;
+
+ bytes += ret;
+ count -= ret;
+ }
+
+ pipe->nrbufs = pipe->curbuf = 0;
+
+ return bytes;
+
+ out_release:
+ /*
+ * If we did an incomplete transfer we must release
+ * the pipe buffers in question:
+ */
+ for (i = 0; i < PIPE_BUFFERS; i++) {
+ struct pipe_buffer *buf = pipe->bufs + i;
+
+ if (buf->ops) {
+ buf->ops->release(pipe, buf);
+ buf->ops = NULL;
+ }
+ }
+ pipe->nrbufs = pipe->curbuf = 0;
+
+ /*
+ * If we transferred some data, return the number of bytes:
+ */
+ if (bytes > 0)
+ return bytes;
+
+ return ret;
+}
+
static __be32
nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
loff_t offset, struct kvec *vec, int vlen, unsigned long *count)
@@ -861,11 +954,9 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
if (ra && ra->p_set)
file->f_ra = ra->p_ra;
- if (file->f_op->sendfile && rqstp->rq_sendfile_ok) {
- rqstp->rq_resused = 1;
- host_err = file->f_op->sendfile(file, &offset, *count,
- nfsd_read_actor, rqstp);
- } else {
+ if (file->f_op->splice_read && rqstp->rq_sendfile_ok)
+ host_err = do_splice_read(file, &offset, *count, rqstp);
+ else {
oldfs = get_fs();
set_fs(KERNEL_DS);
host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
diff .prev/fs/pipe.c ./fs/pipe.c
--- .prev/fs/pipe.c 2007-06-01 12:30:43.000000000 +1000
+++ ./fs/pipe.c 2007-06-01 12:31:58.000000000 +1000
@@ -865,6 +865,7 @@ struct pipe_inode_info * alloc_pipe_info
return pipe;
}
+EXPORT_SYMBOL(alloc_pipe_info);
void __free_pipe_info(struct pipe_inode_info *pipe)
{
next prev parent reply other threads:[~2007-06-01 2:45 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-31 10:33 [PATCH] sendfile removal Jens Axboe
2007-05-31 10:47 ` Jens Axboe
2007-05-31 10:47 ` Eric Dumazet
2007-05-31 10:53 ` Jens Axboe
2007-06-01 4:09 ` H. Peter Anvin
2007-06-01 5:41 ` Jens Axboe
2007-06-01 5:50 ` H. Peter Anvin
2007-06-01 7:22 ` Eric Dumazet
2007-06-01 15:52 ` H. Peter Anvin
2007-06-01 16:18 ` Linus Torvalds
2007-06-01 16:47 ` Eric Dumazet
2007-06-01 16:53 ` H. Peter Anvin
2007-06-02 15:02 ` Jens Axboe
2007-06-02 15:01 ` Jens Axboe
2007-06-02 15:40 ` Linus Torvalds
2007-06-02 16:35 ` Jens Axboe
[not found] ` <20070603130507.GA11170@mail.ustc.edu.cn>
2007-06-03 13:05 ` Fengguang Wu
[not found] ` <20070603142931.GA5916@mail.ustc.edu.cn>
2007-06-03 14:29 ` Fengguang Wu
[not found] ` <20070604004647.GA8076@mail.ustc.edu.cn>
2007-06-04 0:46 ` Fengguang Wu
2007-06-04 8:05 ` Jens Axboe
[not found] ` <20070604112214.GA7457@mail.ustc.edu.cn>
2007-06-04 11:22 ` Fengguang Wu
2007-06-01 16:22 ` Pádraig Brady
2007-05-31 10:55 ` Christoph Hellwig
2007-05-31 11:05 ` Jens Axboe
2007-05-31 12:26 ` Neil Brown
2007-05-31 12:27 ` Jens Axboe
2007-06-01 2:44 ` Neil Brown [this message]
2007-06-01 5:44 ` [PATCH] sendfile removal (nfsd update) Jens Axboe
2007-06-01 8:01 ` Jens Axboe
2007-06-01 8:15 ` [PATCH] sendfile removal Jens Axboe
2007-05-31 11:04 ` Carsten Otte
2007-05-31 11:06 ` Jens Axboe
2007-05-31 15:33 ` Tom Zanussi
2007-05-31 19:01 ` Jens Axboe
2007-05-31 17:06 ` Hugh Dickins
2007-05-31 17:31 ` Christoph Hellwig
2007-05-31 19:03 ` Jens Axboe
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=18015.34830.401191.916084@notabene.brown \
--to=neilb@suse.de \
--cc=cotte@de.ibm.com \
--cc=hch@infradead.org \
--cc=hugh@veritas.com \
--cc=jens.axboe@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
--cc=zanussi@us.ibm.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