From 3f70085369e26560737a804c8dcb880d51c8af5e Mon Sep 17 00:00:00 2001 From: Erez Zadok Date: Sun, 25 Nov 2007 18:32:12 -0500 Subject: [PATCH] Unionfs: support splice(2) Also remove redundant variable from unionfs_readpage (saves a bit on stack space). Signed-off-by: Erez Zadok --- fs/unionfs/mmap.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/unionfs/mmap.c b/fs/unionfs/mmap.c index ba05bf0dc09..bfd2cadfdd0 100644 --- a/fs/unionfs/mmap.c +++ b/fs/unionfs/mmap.c @@ -179,7 +179,7 @@ static int unionfs_readpage(struct file *file, struct page *page) struct inode *inode; mm_segment_t old_fs; char *page_data = NULL; - loff_t offset; + mode_t orig_mode; unionfs_read_lock(file->f_path.dentry->d_sb); err = unionfs_file_revalidate(file, false); @@ -207,11 +207,17 @@ static int unionfs_readpage(struct file *file, struct page *page) * the necessary magic for us. */ lower_file->f_pos = page_offset(page); - offset = page_offset(page); old_fs = get_fs(); set_fs(KERNEL_DS); + /* + * generic_file_splice_write may call us on a file not opened for + * reading, so temporarily allow reading. + */ + orig_mode = lower_file->f_mode; + lower_file->f_mode |= FMODE_READ; err = vfs_read(lower_file, page_data, PAGE_CACHE_SIZE, &lower_file->f_pos); + lower_file->f_mode = orig_mode; set_fs(old_fs); if (err >= 0 && err < PAGE_CACHE_SIZE) memset(page_data + err, 0, PAGE_CACHE_SIZE - err); -- 2.43.0