]>
Commit | Line | Data |
---|---|---|
9e82cf6a EVH |
1 | /* |
2 | * linux/fs/9p/v9fs.c | |
3 | * | |
4 | * This file contains functions assisting in mapping VFS to 9P2000 | |
5 | * | |
8a0dc95f | 6 | * Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com> |
9e82cf6a EVH |
7 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
42e8c509 EVH |
10 | * it under the terms of the GNU General Public License version 2 |
11 | * as published by the Free Software Foundation. | |
9e82cf6a EVH |
12 | * |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to: | |
20 | * Free Software Foundation | |
21 | * 51 Franklin Street, Fifth Floor | |
22 | * Boston, MA 02111-1301 USA | |
23 | * | |
24 | */ | |
25 | ||
9e82cf6a EVH |
26 | #include <linux/module.h> |
27 | #include <linux/errno.h> | |
28 | #include <linux/fs.h> | |
914e2637 | 29 | #include <linux/sched.h> |
9e82cf6a EVH |
30 | #include <linux/parser.h> |
31 | #include <linux/idr.h> | |
bd238fb4 LI |
32 | #include <net/9p/9p.h> |
33 | #include <net/9p/transport.h> | |
bd238fb4 | 34 | #include <net/9p/client.h> |
9e82cf6a | 35 | #include "v9fs.h" |
9e82cf6a | 36 | #include "v9fs_vfs.h" |
9e82cf6a EVH |
37 | |
38 | /* | |
39 | * Option Parsing (code inspired by NFS code) | |
a80d923e | 40 | * NOTE: each transport will parse its own options |
9e82cf6a EVH |
41 | */ |
42 | ||
43 | enum { | |
44 | /* Options that take integer arguments */ | |
8a0dc95f | 45 | Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid, |
9e82cf6a | 46 | /* String options */ |
a80d923e | 47 | Opt_uname, Opt_remotename, Opt_trans, |
9e82cf6a | 48 | /* Options that take no arguments */ |
8a0dc95f | 49 | Opt_nodevmap, |
e03abc0c EVH |
50 | /* Cache options */ |
51 | Opt_cache_loose, | |
ba17674f LI |
52 | /* Access options */ |
53 | Opt_access, | |
9e82cf6a EVH |
54 | /* Error token */ |
55 | Opt_err | |
56 | }; | |
57 | ||
58 | static match_table_t tokens = { | |
9e2f6688 | 59 | {Opt_debug, "debug=%x"}, |
bd32b82d LI |
60 | {Opt_dfltuid, "dfltuid=%u"}, |
61 | {Opt_dfltgid, "dfltgid=%u"}, | |
9e82cf6a | 62 | {Opt_afid, "afid=%u"}, |
67543e50 | 63 | {Opt_uname, "uname=%s"}, |
9e82cf6a | 64 | {Opt_remotename, "aname=%s"}, |
9e82cf6a | 65 | {Opt_nodevmap, "nodevmap"}, |
e03abc0c EVH |
66 | {Opt_cache_loose, "cache=loose"}, |
67 | {Opt_cache_loose, "loose"}, | |
ba17674f | 68 | {Opt_access, "access=%s"}, |
9e82cf6a EVH |
69 | {Opt_err, NULL} |
70 | }; | |
71 | ||
9e82cf6a EVH |
72 | /** |
73 | * v9fs_parse_options - parse mount options into session structure | |
9e82cf6a EVH |
74 | * @v9ses: existing v9fs session information |
75 | * | |
76 | */ | |
77 | ||
a80d923e | 78 | static void v9fs_parse_options(struct v9fs_session_info *v9ses) |
9e82cf6a | 79 | { |
8999e04f | 80 | char *options; |
9e82cf6a | 81 | substring_t args[MAX_OPT_ARGS]; |
a80d923e | 82 | char *p; |
8a0dc95f | 83 | int option = 0; |
ba17674f | 84 | char *s, *e; |
8a0dc95f | 85 | int ret; |
9e82cf6a EVH |
86 | |
87 | /* setup defaults */ | |
9e82cf6a EVH |
88 | v9ses->afid = ~0; |
89 | v9ses->debug = 0; | |
e03abc0c | 90 | v9ses->cache = 0; |
9e82cf6a | 91 | |
8999e04f | 92 | if (!v9ses->options) |
9e82cf6a EVH |
93 | return; |
94 | ||
8999e04f | 95 | options = kstrdup(v9ses->options, GFP_KERNEL); |
9e82cf6a EVH |
96 | while ((p = strsep(&options, ",")) != NULL) { |
97 | int token; | |
98 | if (!*p) | |
99 | continue; | |
100 | token = match_token(p, tokens, args); | |
67543e50 | 101 | if (token < Opt_uname) { |
8a0dc95f EVH |
102 | ret = match_int(&args[0], &option); |
103 | if (ret < 0) { | |
bd238fb4 | 104 | P9_DPRINTK(P9_DEBUG_ERROR, |
9e82cf6a EVH |
105 | "integer field, but no integer?\n"); |
106 | continue; | |
107 | } | |
9e82cf6a EVH |
108 | } |
109 | switch (token) { | |
9e2f6688 EVH |
110 | case Opt_debug: |
111 | v9ses->debug = option; | |
10fa16e7 | 112 | #ifdef CONFIG_NET_9P_DEBUG |
9e2f6688 | 113 | p9_debug_level = option; |
10fa16e7 | 114 | #endif |
9e2f6688 | 115 | break; |
8a0dc95f | 116 | |
bd32b82d LI |
117 | case Opt_dfltuid: |
118 | v9ses->dfltuid = option; | |
9e82cf6a | 119 | break; |
bd32b82d LI |
120 | case Opt_dfltgid: |
121 | v9ses->dfltgid = option; | |
9e82cf6a EVH |
122 | break; |
123 | case Opt_afid: | |
124 | v9ses->afid = option; | |
125 | break; | |
67543e50 | 126 | case Opt_uname: |
b32a09db | 127 | match_strlcpy(v9ses->uname, &args[0], PATH_MAX); |
9e82cf6a EVH |
128 | break; |
129 | case Opt_remotename: | |
b32a09db | 130 | match_strlcpy(v9ses->aname, &args[0], PATH_MAX); |
9e82cf6a | 131 | break; |
9e82cf6a EVH |
132 | case Opt_nodevmap: |
133 | v9ses->nodev = 1; | |
134 | break; | |
e03abc0c EVH |
135 | case Opt_cache_loose: |
136 | v9ses->cache = CACHE_LOOSE; | |
137 | break; | |
ba17674f LI |
138 | |
139 | case Opt_access: | |
140 | s = match_strdup(&args[0]); | |
141 | v9ses->flags &= ~V9FS_ACCESS_MASK; | |
142 | if (strcmp(s, "user") == 0) | |
143 | v9ses->flags |= V9FS_ACCESS_USER; | |
144 | else if (strcmp(s, "any") == 0) | |
145 | v9ses->flags |= V9FS_ACCESS_ANY; | |
146 | else { | |
147 | v9ses->flags |= V9FS_ACCESS_SINGLE; | |
148 | v9ses->uid = simple_strtol(s, &e, 10); | |
149 | if (*e != '\0') | |
150 | v9ses->uid = ~0; | |
151 | } | |
0a976297 | 152 | kfree(s); |
ba17674f LI |
153 | break; |
154 | ||
9e82cf6a EVH |
155 | default: |
156 | continue; | |
157 | } | |
158 | } | |
8999e04f | 159 | kfree(options); |
9e82cf6a EVH |
160 | } |
161 | ||
9e82cf6a EVH |
162 | /** |
163 | * v9fs_session_init - initialize session | |
164 | * @v9ses: session information structure | |
165 | * @dev_name: device being mounted | |
166 | * @data: options | |
167 | * | |
168 | */ | |
169 | ||
bd238fb4 | 170 | struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses, |
9e82cf6a EVH |
171 | const char *dev_name, char *data) |
172 | { | |
9e82cf6a | 173 | int retval = -EINVAL; |
bd238fb4 | 174 | struct p9_fid *fid; |
9e82cf6a | 175 | |
ba17674f LI |
176 | v9ses->uname = __getname(); |
177 | if (!v9ses->uname) | |
bd238fb4 | 178 | return ERR_PTR(-ENOMEM); |
9e82cf6a | 179 | |
ba17674f LI |
180 | v9ses->aname = __getname(); |
181 | if (!v9ses->aname) { | |
182 | __putname(v9ses->uname); | |
bd238fb4 | 183 | return ERR_PTR(-ENOMEM); |
9e82cf6a EVH |
184 | } |
185 | ||
ba17674f LI |
186 | v9ses->flags = V9FS_EXTENDED | V9FS_ACCESS_USER; |
187 | strcpy(v9ses->uname, V9FS_DEFUSER); | |
188 | strcpy(v9ses->aname, V9FS_DEFANAME); | |
189 | v9ses->uid = ~0; | |
bd32b82d LI |
190 | v9ses->dfltuid = V9FS_DEFUID; |
191 | v9ses->dfltgid = V9FS_DEFGID; | |
a80d923e EVH |
192 | v9ses->options = kstrdup(data, GFP_KERNEL); |
193 | v9fs_parse_options(v9ses); | |
194 | ||
8a0dc95f | 195 | v9ses->clnt = p9_client_create(dev_name, v9ses->options); |
9e82cf6a | 196 | |
bd238fb4 LI |
197 | if (IS_ERR(v9ses->clnt)) { |
198 | retval = PTR_ERR(v9ses->clnt); | |
199 | v9ses->clnt = NULL; | |
200 | P9_DPRINTK(P9_DEBUG_ERROR, "problem initializing 9p client\n"); | |
201 | goto error; | |
9e82cf6a EVH |
202 | } |
203 | ||
ba17674f LI |
204 | if (!v9ses->clnt->dotu) |
205 | v9ses->flags &= ~V9FS_EXTENDED; | |
206 | ||
8a0dc95f EVH |
207 | v9ses->maxdata = v9ses->clnt->msize; |
208 | ||
ba17674f LI |
209 | /* for legacy mode, fall back to V9FS_ACCESS_ANY */ |
210 | if (!v9fs_extended(v9ses) && | |
211 | ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) { | |
212 | ||
213 | v9ses->flags &= ~V9FS_ACCESS_MASK; | |
214 | v9ses->flags |= V9FS_ACCESS_ANY; | |
215 | v9ses->uid = ~0; | |
216 | } | |
217 | ||
218 | fid = p9_client_attach(v9ses->clnt, NULL, v9ses->uname, ~0, | |
219 | v9ses->aname); | |
bd238fb4 LI |
220 | if (IS_ERR(fid)) { |
221 | retval = PTR_ERR(fid); | |
222 | fid = NULL; | |
223 | P9_DPRINTK(P9_DEBUG_ERROR, "cannot attach\n"); | |
224 | goto error; | |
9e82cf6a EVH |
225 | } |
226 | ||
ba17674f LI |
227 | if ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_SINGLE) |
228 | fid->uid = v9ses->uid; | |
229 | else | |
230 | fid->uid = ~0; | |
231 | ||
bd238fb4 | 232 | return fid; |
9e82cf6a | 233 | |
bd238fb4 | 234 | error: |
9e82cf6a | 235 | v9fs_session_close(v9ses); |
bd238fb4 | 236 | return ERR_PTR(retval); |
9e82cf6a EVH |
237 | } |
238 | ||
239 | /** | |
240 | * v9fs_session_close - shutdown a session | |
241 | * @v9ses: session information structure | |
242 | * | |
243 | */ | |
244 | ||
245 | void v9fs_session_close(struct v9fs_session_info *v9ses) | |
246 | { | |
bd238fb4 LI |
247 | if (v9ses->clnt) { |
248 | p9_client_destroy(v9ses->clnt); | |
249 | v9ses->clnt = NULL; | |
3cf6429a | 250 | } |
9e82cf6a | 251 | |
ba17674f LI |
252 | __putname(v9ses->uname); |
253 | __putname(v9ses->aname); | |
a80d923e | 254 | kfree(v9ses->options); |
9e82cf6a EVH |
255 | } |
256 | ||
322b329a | 257 | /** |
ee443996 EVH |
258 | * v9fs_session_cancel - terminate a session |
259 | * @v9ses: session to terminate | |
260 | * | |
261 | * mark transport as disconnected and cancel all pending requests. | |
322b329a | 262 | */ |
ee443996 | 263 | |
322b329a | 264 | void v9fs_session_cancel(struct v9fs_session_info *v9ses) { |
bd238fb4 LI |
265 | P9_DPRINTK(P9_DEBUG_ERROR, "cancel session %p\n", v9ses); |
266 | p9_client_disconnect(v9ses->clnt); | |
322b329a EVH |
267 | } |
268 | ||
9e82cf6a EVH |
269 | extern int v9fs_error_init(void); |
270 | ||
271 | /** | |
272 | * v9fs_init - Initialize module | |
273 | * | |
274 | */ | |
275 | ||
276 | static int __init init_v9fs(void) | |
277 | { | |
f94b3470 | 278 | printk(KERN_INFO "Installing v9fs 9p2000 file system support\n"); |
a80d923e | 279 | /* TODO: Setup list of registered trasnport modules */ |
bd238fb4 | 280 | return register_filesystem(&v9fs_fs_type); |
9e82cf6a EVH |
281 | } |
282 | ||
283 | /** | |
284 | * v9fs_init - shutdown module | |
285 | * | |
286 | */ | |
287 | ||
288 | static void __exit exit_v9fs(void) | |
289 | { | |
290 | unregister_filesystem(&v9fs_fs_type); | |
291 | } | |
292 | ||
293 | module_init(init_v9fs) | |
294 | module_exit(exit_v9fs) | |
295 | ||
bd238fb4 | 296 | MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>"); |
9e82cf6a EVH |
297 | MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>"); |
298 | MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>"); | |
299 | MODULE_LICENSE("GPL"); |