Commit ae976416 authored by Hugh Dickins's avatar Hugh Dickins Committed by Jens Axboe

shmem: convert to using splice instead of sendfile()

Remove shmem_file_sendfile and resurrect shmem_readpage, as used by tmpfs
to support loop and sendfile in 2.4 and 2.5.  Now tmpfs can support splice,
loop and sendfile in the simplest way, using generic_file_splice_read and
generic_file_splice_write (with the aid of shmem_prepare_write).

We could make some efficiency tweaks later, if there's a real need;
but this is stable and works well as is.
Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 1db60cf2
...@@ -1100,9 +1100,9 @@ static int shmem_getpage(struct inode *inode, unsigned long idx, ...@@ -1100,9 +1100,9 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
* Normally, filepage is NULL on entry, and either found * Normally, filepage is NULL on entry, and either found
* uptodate immediately, or allocated and zeroed, or read * uptodate immediately, or allocated and zeroed, or read
* in under swappage, which is then assigned to filepage. * in under swappage, which is then assigned to filepage.
* But shmem_prepare_write passes in a locked filepage, * But shmem_readpage and shmem_prepare_write pass in a locked
* which may be found not uptodate by other callers too, * filepage, which may be found not uptodate by other callers
* and may need to be copied from the swappage read in. * too, and may need to be copied from the swappage read in.
*/ */
repeat: repeat:
if (!filepage) if (!filepage)
...@@ -1485,9 +1485,18 @@ static const struct inode_operations shmem_symlink_inode_operations; ...@@ -1485,9 +1485,18 @@ static const struct inode_operations shmem_symlink_inode_operations;
static const struct inode_operations shmem_symlink_inline_operations; static const struct inode_operations shmem_symlink_inline_operations;
/* /*
* Normally tmpfs makes no use of shmem_prepare_write, but it * Normally tmpfs avoids the use of shmem_readpage and shmem_prepare_write;
* lets a tmpfs file be used read-write below the loop driver. * but providing them allows a tmpfs file to be used for splice, sendfile, and
* below the loop driver, in the generic fashion that many filesystems support.
*/ */
static int shmem_readpage(struct file *file, struct page *page)
{
struct inode *inode = page->mapping->host;
int error = shmem_getpage(inode, page->index, &page, SGP_CACHE, NULL);
unlock_page(page);
return error;
}
static int static int
shmem_prepare_write(struct file *file, struct page *page, unsigned offset, unsigned to) shmem_prepare_write(struct file *file, struct page *page, unsigned offset, unsigned to)
{ {
...@@ -1711,25 +1720,6 @@ static ssize_t shmem_file_read(struct file *filp, char __user *buf, size_t count ...@@ -1711,25 +1720,6 @@ static ssize_t shmem_file_read(struct file *filp, char __user *buf, size_t count
return desc.error; return desc.error;
} }
static ssize_t shmem_file_sendfile(struct file *in_file, loff_t *ppos,
size_t count, read_actor_t actor, void *target)
{
read_descriptor_t desc;
if (!count)
return 0;
desc.written = 0;
desc.count = count;
desc.arg.data = target;
desc.error = 0;
do_shmem_file_read(in_file, ppos, &desc, actor);
if (desc.written)
return desc.written;
return desc.error;
}
static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf) static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf)
{ {
struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb); struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
...@@ -2386,6 +2376,7 @@ static const struct address_space_operations shmem_aops = { ...@@ -2386,6 +2376,7 @@ static const struct address_space_operations shmem_aops = {
.writepage = shmem_writepage, .writepage = shmem_writepage,
.set_page_dirty = __set_page_dirty_no_writeback, .set_page_dirty = __set_page_dirty_no_writeback,
#ifdef CONFIG_TMPFS #ifdef CONFIG_TMPFS
.readpage = shmem_readpage,
.prepare_write = shmem_prepare_write, .prepare_write = shmem_prepare_write,
.commit_write = simple_commit_write, .commit_write = simple_commit_write,
#endif #endif
...@@ -2399,7 +2390,8 @@ static const struct file_operations shmem_file_operations = { ...@@ -2399,7 +2390,8 @@ static const struct file_operations shmem_file_operations = {
.read = shmem_file_read, .read = shmem_file_read,
.write = shmem_file_write, .write = shmem_file_write,
.fsync = simple_sync_file, .fsync = simple_sync_file,
.sendfile = shmem_file_sendfile, .splice_read = generic_file_splice_read,
.splice_write = generic_file_splice_write,
#endif #endif
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment