aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-17 18:05:58 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-17 18:05:58 -0400
commit9d8190f87b5458160ba75d05e8ad6abefbe48a26 (patch)
tree7abeb91aa2a40b91004f53520b7bf1f2c80aab7e /fs
parentc2f73fd07d2ce4605b404f34395eb734a7ba9967 (diff)
parent982c37cfb6e61c0e64634abc2e305d757c1405b2 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs: 9p: remove sysctl 9p: fix bad kconfig cross-dependency 9p: soften invalidation in loose_mode 9p: attach-per-user 9p: rename uid and gid parameters 9p: define session flags 9p: Make transports dynamic
Diffstat (limited to 'fs')
-rw-r--r--fs/9p/fid.c157
-rw-r--r--fs/9p/v9fs.c189
-rw-r--r--fs/9p/v9fs.h38
-rw-r--r--fs/9p/vfs_file.c6
-rw-r--r--fs/9p/vfs_inode.c50
-rw-r--r--fs/9p/vfs_super.c19
6 files changed, 266 insertions, 193 deletions
diff --git a/fs/9p/fid.c b/fs/9p/fid.c
index 15e05a15b575..b364da70ff28 100644
--- a/fs/9p/fid.c
+++ b/fs/9p/fid.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * V9FS FID Management 2 * V9FS FID Management
3 * 3 *
4 * Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
4 * Copyright (C) 2005, 2006 by Eric Van Hensbergen <ericvh@gmail.com> 5 * Copyright (C) 2005, 2006 by Eric Van Hensbergen <ericvh@gmail.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -34,9 +35,9 @@
34#include "fid.h" 35#include "fid.h"
35 36
36/** 37/**
37 * v9fs_fid_insert - add a fid to a dentry 38 * v9fs_fid_add - add a fid to a dentry
39 * @dentry: dentry that the fid is being added to
38 * @fid: fid to add 40 * @fid: fid to add
39 * @dentry: dentry that it is being added to
40 * 41 *
41 */ 42 */
42 43
@@ -66,52 +67,144 @@ int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid)
66} 67}
67 68
68/** 69/**
69 * v9fs_fid_lookup - return a locked fid from a dentry 70 * v9fs_fid_find - retrieve a fid that belongs to the specified uid
70 * @dentry: dentry to look for fid in 71 * @dentry: dentry to look for fid in
71 * 72 * @uid: return fid that belongs to the specified user
72 * find a fid in the dentry, obtain its semaphore and return a reference to it. 73 * @any: if non-zero, return any fid associated with the dentry
73 * code calling lookup is responsible for releasing lock
74 *
75 * TODO: only match fids that have the same uid as current user
76 * 74 *
77 */ 75 */
78 76
79struct p9_fid *v9fs_fid_lookup(struct dentry *dentry) 77static struct p9_fid *v9fs_fid_find(struct dentry *dentry, u32 uid, int any)
80{ 78{
81 struct v9fs_dentry *dent; 79 struct v9fs_dentry *dent;
82 struct p9_fid *fid; 80 struct p9_fid *fid, *ret;
83 81
84 P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry); 82 P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p) uid %d any %d\n",
85 dent = dentry->d_fsdata; 83 dentry->d_iname, dentry, uid, any);
86 if (dent) 84 dent = (struct v9fs_dentry *) dentry->d_fsdata;
87 fid = list_entry(dent->fidlist.next, struct p9_fid, dlist); 85 ret = NULL;
88 else 86 if (dent) {
89 fid = ERR_PTR(-EBADF); 87 spin_lock(&dent->lock);
88 list_for_each_entry(fid, &dent->fidlist, dlist) {
89 if (any || fid->uid == uid) {
90 ret = fid;
91 break;
92 }
93 }
94 spin_unlock(&dent->lock);
95 }
90 96
91 P9_DPRINTK(P9_DEBUG_VFS, " fid: %p\n", fid); 97 return ret;
92 return fid;
93} 98}
94 99
95/** 100/**
96 * v9fs_fid_clone - lookup the fid for a dentry, clone a private copy and 101 * v9fs_fid_lookup - lookup for a fid, try to walk if not found
97 * release it
98 * @dentry: dentry to look for fid in 102 * @dentry: dentry to look for fid in
99 * 103 *
100 * find a fid in the dentry and then clone to a new private fid 104 * Look for a fid in the specified dentry for the current user.
101 * 105 * If no fid is found, try to create one walking from a fid from the parent
102 * TODO: only match fids that have the same uid as current user 106 * dentry (if it has one), or the root dentry. If the user haven't accessed
103 * 107 * the fs yet, attach now and walk from the root.
104 */ 108 */
105 109
106struct p9_fid *v9fs_fid_clone(struct dentry *dentry) 110struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
107{ 111{
108 struct p9_fid *ofid, *fid; 112 int i, n, l, clone, any, access;
113 u32 uid;
114 struct p9_fid *fid;
115 struct dentry *d, *ds;
116 struct v9fs_session_info *v9ses;
117 char **wnames, *uname;
118
119 v9ses = v9fs_inode2v9ses(dentry->d_inode);
120 access = v9ses->flags & V9FS_ACCESS_MASK;
121 switch (access) {
122 case V9FS_ACCESS_SINGLE:
123 case V9FS_ACCESS_USER:
124 uid = current->fsuid;
125 any = 0;
126 break;
127
128 case V9FS_ACCESS_ANY:
129 uid = v9ses->uid;
130 any = 1;
131 break;
132
133 default:
134 uid = ~0;
135 any = 0;
136 break;
137 }
109 138
110 P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry); 139 fid = v9fs_fid_find(dentry, uid, any);
111 ofid = v9fs_fid_lookup(dentry); 140 if (fid)
112 if (IS_ERR(ofid)) 141 return fid;
113 return ofid; 142
143 ds = dentry->d_parent;
144 fid = v9fs_fid_find(ds, uid, any);
145 if (!fid) { /* walk from the root */
146 n = 0;
147 for (ds = dentry; !IS_ROOT(ds); ds = ds->d_parent)
148 n++;
149
150 fid = v9fs_fid_find(ds, uid, any);
151 if (!fid) { /* the user is not attached to the fs yet */
152 if (access == V9FS_ACCESS_SINGLE)
153 return ERR_PTR(-EPERM);
154
155 if (v9fs_extended(v9ses))
156 uname = NULL;
157 else
158 uname = v9ses->uname;
159
160 fid = p9_client_attach(v9ses->clnt, NULL, uname, uid,
161 v9ses->aname);
162
163 if (IS_ERR(fid))
164 return fid;
165
166 v9fs_fid_add(ds, fid);
167 }
168 } else /* walk from the parent */
169 n = 1;
170
171 if (ds == dentry)
172 return fid;
173
174 wnames = kmalloc(sizeof(char *) * n, GFP_KERNEL);
175 if (!wnames)
176 return ERR_PTR(-ENOMEM);
177
178 for (d = dentry, i = n; i >= 0; i--, d = d->d_parent)
179 wnames[i] = (char *) d->d_name.name;
180
181 clone = 1;
182 i = 0;
183 while (i < n) {
184 l = min(n - i, P9_MAXWELEM);
185 fid = p9_client_walk(fid, l, &wnames[i], clone);
186 if (!fid) {
187 kfree(wnames);
188 return fid;
189 }
190
191 i += l;
192 clone = 0;
193 }
114 194
115 fid = p9_client_walk(ofid, 0, NULL, 1); 195 kfree(wnames);
196 v9fs_fid_add(dentry, fid);
116 return fid; 197 return fid;
117} 198}
199
200struct p9_fid *v9fs_fid_clone(struct dentry *dentry)
201{
202 struct p9_fid *fid, *ret;
203
204 fid = v9fs_fid_lookup(dentry);
205 if (IS_ERR(fid))
206 return fid;
207
208 ret = p9_client_walk(fid, 0, NULL, 1);
209 return ret;
210}
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index 0a7068e30ecb..873802de21cd 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -38,56 +38,41 @@
38 38
39/* 39/*
40 * Option Parsing (code inspired by NFS code) 40 * Option Parsing (code inspired by NFS code)
41 * 41 * NOTE: each transport will parse its own options
42 */ 42 */
43 43
44enum { 44enum {
45 /* Options that take integer arguments */ 45 /* Options that take integer arguments */
46 Opt_debug, Opt_port, Opt_msize, Opt_uid, Opt_gid, Opt_afid, 46 Opt_debug, Opt_msize, Opt_dfltuid, Opt_dfltgid, Opt_afid,
47 Opt_rfdno, Opt_wfdno,
48 /* String options */ 47 /* String options */
49 Opt_uname, Opt_remotename, 48 Opt_uname, Opt_remotename, Opt_trans,
50 /* Options that take no arguments */ 49 /* Options that take no arguments */
51 Opt_legacy, Opt_nodevmap, Opt_unix, Opt_tcp, Opt_fd, Opt_pci, 50 Opt_legacy, Opt_nodevmap,
52 /* Cache options */ 51 /* Cache options */
53 Opt_cache_loose, 52 Opt_cache_loose,
53 /* Access options */
54 Opt_access,
54 /* Error token */ 55 /* Error token */
55 Opt_err 56 Opt_err
56}; 57};
57 58
58static match_table_t tokens = { 59static match_table_t tokens = {
59 {Opt_debug, "debug=%x"}, 60 {Opt_debug, "debug=%x"},
60 {Opt_port, "port=%u"},
61 {Opt_msize, "msize=%u"}, 61 {Opt_msize, "msize=%u"},
62 {Opt_uid, "uid=%u"}, 62 {Opt_dfltuid, "dfltuid=%u"},
63 {Opt_gid, "gid=%u"}, 63 {Opt_dfltgid, "dfltgid=%u"},
64 {Opt_afid, "afid=%u"}, 64 {Opt_afid, "afid=%u"},
65 {Opt_rfdno, "rfdno=%u"},
66 {Opt_wfdno, "wfdno=%u"},
67 {Opt_uname, "uname=%s"}, 65 {Opt_uname, "uname=%s"},
68 {Opt_remotename, "aname=%s"}, 66 {Opt_remotename, "aname=%s"},
69 {Opt_unix, "proto=unix"}, 67 {Opt_trans, "trans=%s"},
70 {Opt_tcp, "proto=tcp"},
71 {Opt_fd, "proto=fd"},
72#ifdef CONFIG_PCI_9P
73 {Opt_pci, "proto=pci"},
74#endif
75 {Opt_tcp, "tcp"},
76 {Opt_unix, "unix"},
77 {Opt_fd, "fd"},
78 {Opt_legacy, "noextend"}, 68 {Opt_legacy, "noextend"},
79 {Opt_nodevmap, "nodevmap"}, 69 {Opt_nodevmap, "nodevmap"},
80 {Opt_cache_loose, "cache=loose"}, 70 {Opt_cache_loose, "cache=loose"},
81 {Opt_cache_loose, "loose"}, 71 {Opt_cache_loose, "loose"},
72 {Opt_access, "access=%s"},
82 {Opt_err, NULL} 73 {Opt_err, NULL}
83}; 74};
84 75
85extern struct p9_transport *p9pci_trans_create(void);
86
87/*
88 * Parse option string.
89 */
90
91/** 76/**
92 * v9fs_parse_options - parse mount options into session structure 77 * v9fs_parse_options - parse mount options into session structure
93 * @options: options string passed from mount 78 * @options: options string passed from mount
@@ -95,23 +80,21 @@ extern struct p9_transport *p9pci_trans_create(void);
95 * 80 *
96 */ 81 */
97 82
98static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses) 83static void v9fs_parse_options(struct v9fs_session_info *v9ses)
99{ 84{
100 char *p; 85 char *options = v9ses->options;
101 substring_t args[MAX_OPT_ARGS]; 86 substring_t args[MAX_OPT_ARGS];
87 char *p;
102 int option; 88 int option;
103 int ret; 89 int ret;
90 char *s, *e;
104 91
105 /* setup defaults */ 92 /* setup defaults */
106 v9ses->port = V9FS_PORT; 93 v9ses->maxdata = 8192;
107 v9ses->maxdata = 9000;
108 v9ses->proto = PROTO_TCP;
109 v9ses->extended = 1;
110 v9ses->afid = ~0; 94 v9ses->afid = ~0;
111 v9ses->debug = 0; 95 v9ses->debug = 0;
112 v9ses->rfdno = ~0;
113 v9ses->wfdno = ~0;
114 v9ses->cache = 0; 96 v9ses->cache = 0;
97 v9ses->trans = v9fs_default_trans();
115 98
116 if (!options) 99 if (!options)
117 return; 100 return;
@@ -135,47 +118,29 @@ static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses)
135 p9_debug_level = option; 118 p9_debug_level = option;
136#endif 119#endif
137 break; 120 break;
138 case Opt_port:
139 v9ses->port = option;
140 break;
141 case Opt_msize: 121 case Opt_msize:
142 v9ses->maxdata = option; 122 v9ses->maxdata = option;
143 break; 123 break;
144 case Opt_uid: 124 case Opt_dfltuid:
145 v9ses->uid = option; 125 v9ses->dfltuid = option;
146 break; 126 break;
147 case Opt_gid: 127 case Opt_dfltgid:
148 v9ses->gid = option; 128 v9ses->dfltgid = option;
149 break; 129 break;
150 case Opt_afid: 130 case Opt_afid:
151 v9ses->afid = option; 131 v9ses->afid = option;
152 break; 132 break;
153 case Opt_rfdno: 133 case Opt_trans:
154 v9ses->rfdno = option; 134 v9ses->trans = v9fs_match_trans(&args[0]);
155 break;
156 case Opt_wfdno:
157 v9ses->wfdno = option;
158 break;
159 case Opt_tcp:
160 v9ses->proto = PROTO_TCP;
161 break;
162 case Opt_unix:
163 v9ses->proto = PROTO_UNIX;
164 break;
165 case Opt_pci:
166 v9ses->proto = PROTO_PCI;
167 break;
168 case Opt_fd:
169 v9ses->proto = PROTO_FD;
170 break; 135 break;
171 case Opt_uname: 136 case Opt_uname:
172 match_strcpy(v9ses->name, &args[0]); 137 match_strcpy(v9ses->uname, &args[0]);
173 break; 138 break;
174 case Opt_remotename: 139 case Opt_remotename:
175 match_strcpy(v9ses->remotename, &args[0]); 140 match_strcpy(v9ses->aname, &args[0]);
176 break; 141 break;
177 case Opt_legacy: 142 case Opt_legacy:
178 v9ses->extended = 0; 143 v9ses->flags &= ~V9FS_EXTENDED;
179 break; 144 break;
180 case Opt_nodevmap: 145 case Opt_nodevmap:
181 v9ses->nodev = 1; 146 v9ses->nodev = 1;
@@ -183,6 +148,22 @@ static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses)
183 case Opt_cache_loose: 148 case Opt_cache_loose:
184 v9ses->cache = CACHE_LOOSE; 149 v9ses->cache = CACHE_LOOSE;
185 break; 150 break;
151
152 case Opt_access:
153 s = match_strdup(&args[0]);
154 v9ses->flags &= ~V9FS_ACCESS_MASK;
155 if (strcmp(s, "user") == 0)
156 v9ses->flags |= V9FS_ACCESS_USER;
157 else if (strcmp(s, "any") == 0)
158 v9ses->flags |= V9FS_ACCESS_ANY;
159 else {
160 v9ses->flags |= V9FS_ACCESS_SINGLE;
161 v9ses->uid = simple_strtol(s, &e, 10);
162 if (*e != '\0')
163 v9ses->uid = ~0;
164 }
165 break;
166
186 default: 167 default:
187 continue; 168 continue;
188 } 169 }
@@ -201,56 +182,46 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
201 const char *dev_name, char *data) 182 const char *dev_name, char *data)
202{ 183{
203 int retval = -EINVAL; 184 int retval = -EINVAL;
204 struct p9_transport *trans; 185 struct p9_trans *trans = NULL;
205 struct p9_fid *fid; 186 struct p9_fid *fid;
206 187
207 v9ses->name = __getname(); 188 v9ses->uname = __getname();
208 if (!v9ses->name) 189 if (!v9ses->uname)
209 return ERR_PTR(-ENOMEM); 190 return ERR_PTR(-ENOMEM);
210 191
211 v9ses->remotename = __getname(); 192 v9ses->aname = __getname();
212 if (!v9ses->remotename) { 193 if (!v9ses->aname) {
213 __putname(v9ses->name); 194 __putname(v9ses->uname);
214 return ERR_PTR(-ENOMEM); 195 return ERR_PTR(-ENOMEM);
215 } 196 }
216 197
217 strcpy(v9ses->name, V9FS_DEFUSER); 198 v9ses->flags = V9FS_EXTENDED | V9FS_ACCESS_USER;
218 strcpy(v9ses->remotename, V9FS_DEFANAME); 199 strcpy(v9ses->uname, V9FS_DEFUSER);
219 200 strcpy(v9ses->aname, V9FS_DEFANAME);
220 v9fs_parse_options(data, v9ses); 201 v9ses->uid = ~0;
221 202 v9ses->dfltuid = V9FS_DEFUID;
222 switch (v9ses->proto) { 203 v9ses->dfltgid = V9FS_DEFGID;
223 case PROTO_TCP: 204 v9ses->options = kstrdup(data, GFP_KERNEL);
224 trans = p9_trans_create_tcp(dev_name, v9ses->port); 205 v9fs_parse_options(v9ses);
225 break; 206
226 case PROTO_UNIX: 207 if (v9ses->trans == NULL) {
227 trans = p9_trans_create_unix(dev_name); 208 retval = -EPROTONOSUPPORT;
228 *v9ses->remotename = 0; 209 P9_DPRINTK(P9_DEBUG_ERROR,
229 break; 210 "No transport defined or default transport\n");
230 case PROTO_FD:
231 trans = p9_trans_create_fd(v9ses->rfdno, v9ses->wfdno);
232 *v9ses->remotename = 0;
233 break;
234#ifdef CONFIG_PCI_9P
235 case PROTO_PCI:
236 trans = p9pci_trans_create();
237 *v9ses->remotename = 0;
238 break;
239#endif
240 default:
241 printk(KERN_ERR "v9fs: Bad mount protocol %d\n", v9ses->proto);
242 retval = -ENOPROTOOPT;
243 goto error; 211 goto error;
244 }; 212 }
245 213
214 trans = v9ses->trans->create(dev_name, v9ses->options);
246 if (IS_ERR(trans)) { 215 if (IS_ERR(trans)) {
247 retval = PTR_ERR(trans); 216 retval = PTR_ERR(trans);
248 trans = NULL; 217 trans = NULL;
249 goto error; 218 goto error;
250 } 219 }
220 if ((v9ses->maxdata+P9_IOHDRSZ) > v9ses->trans->maxsize)
221 v9ses->maxdata = v9ses->trans->maxsize-P9_IOHDRSZ;
251 222
252 v9ses->clnt = p9_client_create(trans, v9ses->maxdata + P9_IOHDRSZ, 223 v9ses->clnt = p9_client_create(trans, v9ses->maxdata+P9_IOHDRSZ,
253 v9ses->extended); 224 v9fs_extended(v9ses));
254 225
255 if (IS_ERR(v9ses->clnt)) { 226 if (IS_ERR(v9ses->clnt)) {
256 retval = PTR_ERR(v9ses->clnt); 227 retval = PTR_ERR(v9ses->clnt);
@@ -259,8 +230,20 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
259 goto error; 230 goto error;
260 } 231 }
261 232
262 fid = p9_client_attach(v9ses->clnt, NULL, v9ses->name, 233 if (!v9ses->clnt->dotu)
263 v9ses->remotename); 234 v9ses->flags &= ~V9FS_EXTENDED;
235
236 /* for legacy mode, fall back to V9FS_ACCESS_ANY */
237 if (!v9fs_extended(v9ses) &&
238 ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) {
239
240 v9ses->flags &= ~V9FS_ACCESS_MASK;
241 v9ses->flags |= V9FS_ACCESS_ANY;
242 v9ses->uid = ~0;
243 }
244
245 fid = p9_client_attach(v9ses->clnt, NULL, v9ses->uname, ~0,
246 v9ses->aname);
264 if (IS_ERR(fid)) { 247 if (IS_ERR(fid)) {
265 retval = PTR_ERR(fid); 248 retval = PTR_ERR(fid);
266 fid = NULL; 249 fid = NULL;
@@ -268,6 +251,11 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
268 goto error; 251 goto error;
269 } 252 }
270 253
254 if ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_SINGLE)
255 fid->uid = v9ses->uid;
256 else
257 fid->uid = ~0;
258
271 return fid; 259 return fid;
272 260
273error: 261error:
@@ -288,8 +276,9 @@ void v9fs_session_close(struct v9fs_session_info *v9ses)
288 v9ses->clnt = NULL; 276 v9ses->clnt = NULL;
289 } 277 }
290 278
291 __putname(v9ses->name); 279 __putname(v9ses->uname);
292 __putname(v9ses->remotename); 280 __putname(v9ses->aname);
281 kfree(v9ses->options);
293} 282}
294 283
295/** 284/**
@@ -311,7 +300,7 @@ extern int v9fs_error_init(void);
311static int __init init_v9fs(void) 300static int __init init_v9fs(void)
312{ 301{
313 printk(KERN_INFO "Installing v9fs 9p2000 file system support\n"); 302 printk(KERN_INFO "Installing v9fs 9p2000 file system support\n");
314 303 /* TODO: Setup list of registered trasnport modules */
315 return register_filesystem(&v9fs_fs_type); 304 return register_filesystem(&v9fs_fs_type);
316} 305}
317 306
diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h
index abc4b1668ace..db4b4193f2e2 100644
--- a/fs/9p/v9fs.h
+++ b/fs/9p/v9fs.h
@@ -29,31 +29,30 @@
29struct v9fs_session_info { 29struct v9fs_session_info {
30 /* options */ 30 /* options */
31 unsigned int maxdata; 31 unsigned int maxdata;
32 unsigned char extended; /* set to 1 if we are using UNIX extensions */ 32 unsigned char flags; /* session flags */
33 unsigned char nodev; /* set to 1 if no disable device mapping */ 33 unsigned char nodev; /* set to 1 if no disable device mapping */
34 unsigned short port; /* port to connect to */
35 unsigned short debug; /* debug level */ 34 unsigned short debug; /* debug level */
36 unsigned short proto; /* protocol to use */
37 unsigned int afid; /* authentication fid */ 35 unsigned int afid; /* authentication fid */
38 unsigned int rfdno; /* read file descriptor number */
39 unsigned int wfdno; /* write file descriptor number */
40 unsigned int cache; /* cache mode */ 36 unsigned int cache; /* cache mode */
41 37
42 char *name; /* user name to mount as */ 38 char *options; /* copy of mount options */
43 char *remotename; /* name of remote hierarchy being mounted */ 39 char *uname; /* user name to mount as */
44 unsigned int uid; /* default uid/muid for legacy support */ 40 char *aname; /* name of remote hierarchy being mounted */
45 unsigned int gid; /* default gid for legacy support */ 41 unsigned int dfltuid; /* default uid/muid for legacy support */
46 42 unsigned int dfltgid; /* default gid for legacy support */
43 u32 uid; /* if ACCESS_SINGLE, the uid that has access */
44 struct p9_trans_module *trans; /* 9p transport */
47 struct p9_client *clnt; /* 9p client */ 45 struct p9_client *clnt; /* 9p client */
48 struct dentry *debugfs_dir; 46 struct dentry *debugfs_dir;
49}; 47};
50 48
51/* possible values of ->proto */ 49/* session flags */
52enum { 50enum {
53 PROTO_TCP, 51 V9FS_EXTENDED = 0x01, /* 9P2000.u */
54 PROTO_UNIX, 52 V9FS_ACCESS_MASK = 0x06, /* access mask */
55 PROTO_FD, 53 V9FS_ACCESS_SINGLE = 0x02, /* only one user can access the files */
56 PROTO_PCI, 54 V9FS_ACCESS_USER = 0x04, /* attache per user */
55 V9FS_ACCESS_ANY = 0x06, /* use the same attach for all users */
57}; 56};
58 57
59/* possible values of ->cache */ 58/* possible values of ->cache */
@@ -73,11 +72,18 @@ void v9fs_session_cancel(struct v9fs_session_info *v9ses);
73#define V9FS_MAGIC 0x01021997 72#define V9FS_MAGIC 0x01021997
74 73
75/* other default globals */ 74/* other default globals */
76#define V9FS_PORT 564 75#define V9FS_PORT 564
77#define V9FS_DEFUSER "nobody" 76#define V9FS_DEFUSER "nobody"
78#define V9FS_DEFANAME "" 77#define V9FS_DEFANAME ""
78#define V9FS_DEFUID (-2)
79#define V9FS_DEFGID (-2)
79 80
80static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode) 81static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)
81{ 82{
82 return (inode->i_sb->s_fs_info); 83 return (inode->i_sb->s_fs_info);
83} 84}
85
86static inline int v9fs_extended(struct v9fs_session_info *v9ses)
87{
88 return v9ses->flags & V9FS_EXTENDED;
89}
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index 716691689fd5..ba4b1caa9c43 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -162,15 +162,17 @@ v9fs_file_write(struct file *filp, const char __user * data,
162 162
163 fid = filp->private_data; 163 fid = filp->private_data;
164 ret = p9_client_uwrite(fid, data, *offset, count); 164 ret = p9_client_uwrite(fid, data, *offset, count);
165 if (ret > 0) 165 if (ret > 0) {
166 invalidate_inode_pages2_range(inode->i_mapping, *offset,
167 *offset+ret);
166 *offset += ret; 168 *offset += ret;
169 }
167 170
168 if (*offset > inode->i_size) { 171 if (*offset > inode->i_size) {
169 inode->i_size = *offset; 172 inode->i_size = *offset;
170 inode->i_blocks = (inode->i_size + 512 - 1) >> 9; 173 inode->i_blocks = (inode->i_size + 512 - 1) >> 9;
171 } 174 }
172 175
173 invalidate_inode_pages2(inode->i_mapping);
174 return ret; 176 return ret;
175} 177}
176 178
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index e5c45eed58a9..175b4d9bf3f8 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -59,7 +59,7 @@ static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
59 res = mode & 0777; 59 res = mode & 0777;
60 if (S_ISDIR(mode)) 60 if (S_ISDIR(mode))
61 res |= P9_DMDIR; 61 res |= P9_DMDIR;
62 if (v9ses->extended) { 62 if (v9fs_extended(v9ses)) {
63 if (S_ISLNK(mode)) 63 if (S_ISLNK(mode))
64 res |= P9_DMSYMLINK; 64 res |= P9_DMSYMLINK;
65 if (v9ses->nodev == 0) { 65 if (v9ses->nodev == 0) {
@@ -99,21 +99,21 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
99 99
100 if ((mode & P9_DMDIR) == P9_DMDIR) 100 if ((mode & P9_DMDIR) == P9_DMDIR)
101 res |= S_IFDIR; 101 res |= S_IFDIR;
102 else if ((mode & P9_DMSYMLINK) && (v9ses->extended)) 102 else if ((mode & P9_DMSYMLINK) && (v9fs_extended(v9ses)))
103 res |= S_IFLNK; 103 res |= S_IFLNK;
104 else if ((mode & P9_DMSOCKET) && (v9ses->extended) 104 else if ((mode & P9_DMSOCKET) && (v9fs_extended(v9ses))
105 && (v9ses->nodev == 0)) 105 && (v9ses->nodev == 0))
106 res |= S_IFSOCK; 106 res |= S_IFSOCK;
107 else if ((mode & P9_DMNAMEDPIPE) && (v9ses->extended) 107 else if ((mode & P9_DMNAMEDPIPE) && (v9fs_extended(v9ses))
108 && (v9ses->nodev == 0)) 108 && (v9ses->nodev == 0))
109 res |= S_IFIFO; 109 res |= S_IFIFO;
110 else if ((mode & P9_DMDEVICE) && (v9ses->extended) 110 else if ((mode & P9_DMDEVICE) && (v9fs_extended(v9ses))
111 && (v9ses->nodev == 0)) 111 && (v9ses->nodev == 0))
112 res |= S_IFBLK; 112 res |= S_IFBLK;
113 else 113 else
114 res |= S_IFREG; 114 res |= S_IFREG;
115 115
116 if (v9ses->extended) { 116 if (v9fs_extended(v9ses)) {
117 if ((mode & P9_DMSETUID) == P9_DMSETUID) 117 if ((mode & P9_DMSETUID) == P9_DMSETUID)
118 res |= S_ISUID; 118 res |= S_ISUID;
119 119
@@ -214,7 +214,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
214 case S_IFBLK: 214 case S_IFBLK:
215 case S_IFCHR: 215 case S_IFCHR:
216 case S_IFSOCK: 216 case S_IFSOCK:
217 if(!v9ses->extended) { 217 if (!v9fs_extended(v9ses)) {
218 P9_DPRINTK(P9_DEBUG_ERROR, 218 P9_DPRINTK(P9_DEBUG_ERROR,
219 "special files without extended mode\n"); 219 "special files without extended mode\n");
220 return ERR_PTR(-EINVAL); 220 return ERR_PTR(-EINVAL);
@@ -227,7 +227,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
227 inode->i_fop = &v9fs_file_operations; 227 inode->i_fop = &v9fs_file_operations;
228 break; 228 break;
229 case S_IFLNK: 229 case S_IFLNK:
230 if(!v9ses->extended) { 230 if (!v9fs_extended(v9ses)) {
231 P9_DPRINTK(P9_DEBUG_ERROR, 231 P9_DPRINTK(P9_DEBUG_ERROR,
232 "extended modes used w/o 9P2000.u\n"); 232 "extended modes used w/o 9P2000.u\n");
233 return ERR_PTR(-EINVAL); 233 return ERR_PTR(-EINVAL);
@@ -236,7 +236,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
236 break; 236 break;
237 case S_IFDIR: 237 case S_IFDIR:
238 inc_nlink(inode); 238 inc_nlink(inode);
239 if(v9ses->extended) 239 if (v9fs_extended(v9ses))
240 inode->i_op = &v9fs_dir_inode_operations_ext; 240 inode->i_op = &v9fs_dir_inode_operations_ext;
241 else 241 else
242 inode->i_op = &v9fs_dir_inode_operations; 242 inode->i_op = &v9fs_dir_inode_operations;
@@ -364,7 +364,7 @@ static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
364 file_inode = file->d_inode; 364 file_inode = file->d_inode;
365 v9ses = v9fs_inode2v9ses(file_inode); 365 v9ses = v9fs_inode2v9ses(file_inode);
366 v9fid = v9fs_fid_clone(file); 366 v9fid = v9fs_fid_clone(file);
367 if(IS_ERR(v9fid)) 367 if (IS_ERR(v9fid))
368 return PTR_ERR(v9fid); 368 return PTR_ERR(v9fid);
369 369
370 return p9_client_remove(v9fid); 370 return p9_client_remove(v9fid);
@@ -398,7 +398,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
398 fid = NULL; 398 fid = NULL;
399 name = (char *) dentry->d_name.name; 399 name = (char *) dentry->d_name.name;
400 dfid = v9fs_fid_clone(dentry->d_parent); 400 dfid = v9fs_fid_clone(dentry->d_parent);
401 if(IS_ERR(dfid)) { 401 if (IS_ERR(dfid)) {
402 err = PTR_ERR(dfid); 402 err = PTR_ERR(dfid);
403 dfid = NULL; 403 dfid = NULL;
404 goto error; 404 goto error;
@@ -432,7 +432,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
432 goto error; 432 goto error;
433 } 433 }
434 434
435 if(v9ses->cache) 435 if (v9ses->cache)
436 dentry->d_op = &v9fs_cached_dentry_operations; 436 dentry->d_op = &v9fs_cached_dentry_operations;
437 else 437 else
438 dentry->d_op = &v9fs_dentry_operations; 438 dentry->d_op = &v9fs_dentry_operations;
@@ -593,7 +593,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
593 if (result < 0) 593 if (result < 0)
594 goto error; 594 goto error;
595 595
596 if((fid->qid.version)&&(v9ses->cache)) 596 if ((fid->qid.version) && (v9ses->cache))
597 dentry->d_op = &v9fs_cached_dentry_operations; 597 dentry->d_op = &v9fs_cached_dentry_operations;
598 else 598 else
599 dentry->d_op = &v9fs_dentry_operations; 599 dentry->d_op = &v9fs_dentry_operations;
@@ -658,17 +658,17 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
658 old_inode = old_dentry->d_inode; 658 old_inode = old_dentry->d_inode;
659 v9ses = v9fs_inode2v9ses(old_inode); 659 v9ses = v9fs_inode2v9ses(old_inode);
660 oldfid = v9fs_fid_lookup(old_dentry); 660 oldfid = v9fs_fid_lookup(old_dentry);
661 if(IS_ERR(oldfid)) 661 if (IS_ERR(oldfid))
662 return PTR_ERR(oldfid); 662 return PTR_ERR(oldfid);
663 663
664 olddirfid = v9fs_fid_clone(old_dentry->d_parent); 664 olddirfid = v9fs_fid_clone(old_dentry->d_parent);
665 if(IS_ERR(olddirfid)) { 665 if (IS_ERR(olddirfid)) {
666 retval = PTR_ERR(olddirfid); 666 retval = PTR_ERR(olddirfid);
667 goto done; 667 goto done;
668 } 668 }
669 669
670 newdirfid = v9fs_fid_clone(new_dentry->d_parent); 670 newdirfid = v9fs_fid_clone(new_dentry->d_parent);
671 if(IS_ERR(newdirfid)) { 671 if (IS_ERR(newdirfid)) {
672 retval = PTR_ERR(newdirfid); 672 retval = PTR_ERR(newdirfid);
673 goto clunk_olddir; 673 goto clunk_olddir;
674 } 674 }
@@ -682,7 +682,7 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
682 } 682 }
683 683
684 v9fs_blank_wstat(&wstat); 684 v9fs_blank_wstat(&wstat);
685 wstat.muid = v9ses->name; 685 wstat.muid = v9ses->uname;
686 wstat.name = (char *) new_dentry->d_name.name; 686 wstat.name = (char *) new_dentry->d_name.name;
687 retval = p9_client_wstat(oldfid, &wstat); 687 retval = p9_client_wstat(oldfid, &wstat);
688 688
@@ -768,7 +768,7 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
768 if (iattr->ia_valid & ATTR_SIZE) 768 if (iattr->ia_valid & ATTR_SIZE)
769 wstat.length = iattr->ia_size; 769 wstat.length = iattr->ia_size;
770 770
771 if (v9ses->extended) { 771 if (v9fs_extended(v9ses)) {
772 if (iattr->ia_valid & ATTR_UID) 772 if (iattr->ia_valid & ATTR_UID)
773 wstat.n_uid = iattr->ia_uid; 773 wstat.n_uid = iattr->ia_uid;
774 774
@@ -805,10 +805,10 @@ v9fs_stat2inode(struct p9_stat *stat, struct inode *inode,
805 inode->i_mtime.tv_sec = stat->mtime; 805 inode->i_mtime.tv_sec = stat->mtime;
806 inode->i_ctime.tv_sec = stat->mtime; 806 inode->i_ctime.tv_sec = stat->mtime;
807 807
808 inode->i_uid = v9ses->uid; 808 inode->i_uid = v9ses->dfltuid;
809 inode->i_gid = v9ses->gid; 809 inode->i_gid = v9ses->dfltgid;
810 810
811 if (v9ses->extended) { 811 if (v9fs_extended(v9ses)) {
812 inode->i_uid = stat->n_uid; 812 inode->i_uid = stat->n_uid;
813 inode->i_gid = stat->n_gid; 813 inode->i_gid = stat->n_gid;
814 } 814 }
@@ -887,10 +887,10 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
887 retval = -EPERM; 887 retval = -EPERM;
888 v9ses = v9fs_inode2v9ses(dentry->d_inode); 888 v9ses = v9fs_inode2v9ses(dentry->d_inode);
889 fid = v9fs_fid_lookup(dentry); 889 fid = v9fs_fid_lookup(dentry);
890 if(IS_ERR(fid)) 890 if (IS_ERR(fid))
891 return PTR_ERR(fid); 891 return PTR_ERR(fid);
892 892
893 if (!v9ses->extended) 893 if (!v9fs_extended(v9ses))
894 return -EBADF; 894 return -EBADF;
895 895
896 st = p9_client_stat(fid); 896 st = p9_client_stat(fid);
@@ -1011,7 +1011,7 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1011 struct p9_fid *fid; 1011 struct p9_fid *fid;
1012 1012
1013 v9ses = v9fs_inode2v9ses(dir); 1013 v9ses = v9fs_inode2v9ses(dir);
1014 if (!v9ses->extended) { 1014 if (!v9fs_extended(v9ses)) {
1015 P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n"); 1015 P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n");
1016 return -EPERM; 1016 return -EPERM;
1017 } 1017 }
@@ -1070,7 +1070,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1070 old_dentry->d_name.name); 1070 old_dentry->d_name.name);
1071 1071
1072 oldfid = v9fs_fid_clone(old_dentry); 1072 oldfid = v9fs_fid_clone(old_dentry);
1073 if(IS_ERR(oldfid)) 1073 if (IS_ERR(oldfid))
1074 return PTR_ERR(oldfid); 1074 return PTR_ERR(oldfid);
1075 1075
1076 name = __getname(); 1076 name = __getname();
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index ba904371218b..bb0cef9a6b8a 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -216,24 +216,7 @@ static int v9fs_show_options(struct seq_file *m, struct vfsmount *mnt)
216{ 216{
217 struct v9fs_session_info *v9ses = mnt->mnt_sb->s_fs_info; 217 struct v9fs_session_info *v9ses = mnt->mnt_sb->s_fs_info;
218 218
219 if (v9ses->debug != 0) 219 seq_printf(m, "%s", v9ses->options);
220 seq_printf(m, ",debug=%x", v9ses->debug);
221 if (v9ses->port != V9FS_PORT)
222 seq_printf(m, ",port=%u", v9ses->port);
223 if (v9ses->maxdata != 9000)
224 seq_printf(m, ",msize=%u", v9ses->maxdata);
225 if (v9ses->afid != ~0)
226 seq_printf(m, ",afid=%u", v9ses->afid);
227 if (v9ses->proto == PROTO_UNIX)
228 seq_puts(m, ",proto=unix");
229 if (v9ses->extended == 0)
230 seq_puts(m, ",noextend");
231 if (v9ses->nodev == 1)
232 seq_puts(m, ",nodevmap");
233 seq_printf(m, ",name=%s", v9ses->name);
234 seq_printf(m, ",aname=%s", v9ses->remotename);
235 seq_printf(m, ",uid=%u", v9ses->uid);
236 seq_printf(m, ",gid=%u", v9ses->gid);
237 return 0; 220 return 0;
238} 221}
239 222