Skip to content

Commit 147b31c

Browse files
Eric Van HensbergenLinus Torvalds
authored andcommitted
[PATCH] v9fs: add readpage support
v9fs mmap support was originally removed from v9fs at Al Viro's request, but recently there have been requests from folks who want readpage functionality (primarily to enable execution of files mounted via 9P). This patch adds readpage support (but not writepage which contained most of the objectionable code). It passes fsx-linux (and other regressions) so it should be relatively safe. Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent a374a48 commit 147b31c

5 files changed

Lines changed: 116 additions & 0 deletions

File tree

‎fs/9p/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ obj-$(CONFIG_9P_FS) := 9p2000.o
88
conv.o \
99
vfs_super.o \
1010
vfs_inode.o \
11+
vfs_addr.o \
1112
vfs_file.o \
1213
vfs_dir.o \
1314
vfs_dentry.o \

‎fs/9p/v9fs_vfs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*/
4040

4141
extern struct file_system_type v9fs_fs_type;
42+
extern struct address_space_operations v9fs_addr_operations;
4243
extern struct file_operations v9fs_file_operations;
4344
extern struct file_operations v9fs_dir_operations;
4445
extern struct dentry_operations v9fs_dentry_operations;

‎fs/9p/vfs_addr.c‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* linux/fs/9p/vfs_addr.c
3+
*
4+
* This file contians vfs address (mmap) ops for 9P2000.
5+
*
6+
* Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com>
7+
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8+
*
9+
* This program is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation; either version 2 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program; if not, write to:
21+
* Free Software Foundation
22+
* 51 Franklin Street, Fifth Floor
23+
* Boston, MA 02111-1301 USA
24+
*
25+
*/
26+
27+
#include <linux/module.h>
28+
#include <linux/errno.h>
29+
#include <linux/fs.h>
30+
#include <linux/file.h>
31+
#include <linux/stat.h>
32+
#include <linux/string.h>
33+
#include <linux/smp_lock.h>
34+
#include <linux/inet.h>
35+
#include <linux/version.h>
36+
#include <linux/pagemap.h>
37+
#include <linux/idr.h>
38+
39+
#include "debug.h"
40+
#include "v9fs.h"
41+
#include "9p.h"
42+
#include "v9fs_vfs.h"
43+
#include "fid.h"
44+
45+
/**
46+
* v9fs_vfs_readpage - read an entire page in from 9P
47+
*
48+
* @file: file being read
49+
* @page: structure to page
50+
*
51+
*/
52+
53+
static int v9fs_vfs_readpage(struct file *filp, struct page *page)
54+
{
55+
char *buffer = NULL;
56+
int retval = -EIO;
57+
loff_t offset = page_offset(page);
58+
int count = PAGE_CACHE_SIZE;
59+
struct inode *inode = filp->f_dentry->d_inode;
60+
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
61+
int rsize = v9ses->maxdata - V9FS_IOHDRSZ;
62+
struct v9fs_fid *v9f = filp->private_data;
63+
struct v9fs_fcall *fcall = NULL;
64+
int fid = v9f->fid;
65+
int total = 0;
66+
int result = 0;
67+
68+
buffer = kmap(page);
69+
do {
70+
if (count < rsize)
71+
rsize = count;
72+
73+
result = v9fs_t_read(v9ses, fid, offset, rsize, &fcall);
74+
75+
if (result < 0) {
76+
printk(KERN_ERR "v9fs_t_read returned %d\n",
77+
result);
78+
79+
kfree(fcall);
80+
goto UnmapAndUnlock;
81+
} else
82+
offset += result;
83+
84+
memcpy(buffer, fcall->params.rread.data, result);
85+
86+
count -= result;
87+
buffer += result;
88+
total += result;
89+
90+
kfree(fcall);
91+
92+
if (result < rsize)
93+
break;
94+
} while (count);
95+
96+
memset(buffer, 0, count);
97+
flush_dcache_page(page);
98+
SetPageUptodate(page);
99+
retval = 0;
100+
101+
UnmapAndUnlock:
102+
kunmap(page);
103+
unlock_page(page);
104+
return retval;
105+
}
106+
107+
struct address_space_operations v9fs_addr_operations = {
108+
.readpage = v9fs_vfs_readpage,
109+
};

‎fs/9p/vfs_file.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ v9fs_file_write(struct file *filp, const char __user * data,
289289
total += result;
290290
} while (count);
291291

292+
if(inode->i_mapping->nrpages)
293+
invalidate_inode_pages2(inode->i_mapping);
294+
292295
return total;
293296
}
294297

@@ -299,4 +302,5 @@ struct file_operations v9fs_file_operations = {
299302
.open = v9fs_file_open,
300303
.release = v9fs_dir_release,
301304
.lock = v9fs_file_lock,
305+
.mmap = generic_file_mmap,
302306
};

‎fs/9p/vfs_inode.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
177177
inode->i_blocks = 0;
178178
inode->i_rdev = 0;
179179
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
180+
inode->i_mapping->a_ops = &v9fs_addr_operations;
180181

181182
switch (mode & S_IFMT) {
182183
case S_IFIFO:

0 commit comments

Comments
 (0)