4 * This file contains functions assisting in mapping VFS to 9P2000
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
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.
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
26 #include <linux/module.h>
27 #include <linux/errno.h>
29 #include <linux/sched.h>
30 #include <linux/parser.h>
31 #include <linux/idr.h>
32 #include <net/9p/9p.h>
33 #include <net/9p/transport.h>
34 #include <net/9p/conn.h>
35 #include <net/9p/client.h>
40 * Option Parsing (code inspired by NFS code)
41 * NOTE: each transport will parse its own options
45 /* Options that take integer arguments */
46 Opt_debug, Opt_msize, Opt_dfltuid, Opt_dfltgid, Opt_afid,
48 Opt_uname, Opt_remotename, Opt_trans,
49 /* Options that take no arguments */
50 Opt_legacy, Opt_nodevmap,
59 static match_table_t tokens = {
60 {Opt_debug, "debug=%x"},
61 {Opt_msize, "msize=%u"},
62 {Opt_dfltuid, "dfltuid=%u"},
63 {Opt_dfltgid, "dfltgid=%u"},
64 {Opt_afid, "afid=%u"},
65 {Opt_uname, "uname=%s"},
66 {Opt_remotename, "aname=%s"},
67 {Opt_trans, "trans=%s"},
68 {Opt_legacy, "noextend"},
69 {Opt_nodevmap, "nodevmap"},
70 {Opt_cache_loose, "cache=loose"},
71 {Opt_cache_loose, "loose"},
72 {Opt_access, "access=%s"},
77 * v9fs_parse_options - parse mount options into session structure
78 * @options: options string passed from mount
79 * @v9ses: existing v9fs session information
83 static void v9fs_parse_options(struct v9fs_session_info *v9ses)
85 char *options = v9ses->options;
86 substring_t args[MAX_OPT_ARGS];
93 v9ses->maxdata = 8192;
97 v9ses->trans = v9fs_default_trans();
102 while ((p = strsep(&options, ",")) != NULL) {
106 token = match_token(p, tokens, args);
107 if (token < Opt_uname) {
108 if ((ret = match_int(&args[0], &option)) < 0) {
109 P9_DPRINTK(P9_DEBUG_ERROR,
110 "integer field, but no integer?\n");
116 v9ses->debug = option;
117 #ifdef CONFIG_NET_9P_DEBUG
118 p9_debug_level = option;
122 v9ses->maxdata = option;
125 v9ses->dfltuid = option;
128 v9ses->dfltgid = option;
131 v9ses->afid = option;
134 v9ses->trans = v9fs_match_trans(&args[0]);
137 match_strcpy(v9ses->uname, &args[0]);
140 match_strcpy(v9ses->aname, &args[0]);
143 v9ses->flags &= ~V9FS_EXTENDED;
148 case Opt_cache_loose:
149 v9ses->cache = CACHE_LOOSE;
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;
160 v9ses->flags |= V9FS_ACCESS_SINGLE;
161 v9ses->uid = simple_strtol(s, &e, 10);
174 * v9fs_session_init - initialize session
175 * @v9ses: session information structure
176 * @dev_name: device being mounted
181 struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
182 const char *dev_name, char *data)
184 int retval = -EINVAL;
185 struct p9_trans *trans = NULL;
188 v9ses->uname = __getname();
190 return ERR_PTR(-ENOMEM);
192 v9ses->aname = __getname();
194 __putname(v9ses->uname);
195 return ERR_PTR(-ENOMEM);
198 v9ses->flags = V9FS_EXTENDED | V9FS_ACCESS_USER;
199 strcpy(v9ses->uname, V9FS_DEFUSER);
200 strcpy(v9ses->aname, V9FS_DEFANAME);
202 v9ses->dfltuid = V9FS_DEFUID;
203 v9ses->dfltgid = V9FS_DEFGID;
204 v9ses->options = kstrdup(data, GFP_KERNEL);
205 v9fs_parse_options(v9ses);
207 if (v9ses->trans == NULL) {
208 retval = -EPROTONOSUPPORT;
209 P9_DPRINTK(P9_DEBUG_ERROR,
210 "No transport defined or default transport\n");
214 trans = v9ses->trans->create(dev_name, v9ses->options);
216 retval = PTR_ERR(trans);
220 if ((v9ses->maxdata+P9_IOHDRSZ) > v9ses->trans->maxsize)
221 v9ses->maxdata = v9ses->trans->maxsize-P9_IOHDRSZ;
223 v9ses->clnt = p9_client_create(trans, v9ses->maxdata+P9_IOHDRSZ,
224 v9fs_extended(v9ses));
226 if (IS_ERR(v9ses->clnt)) {
227 retval = PTR_ERR(v9ses->clnt);
229 P9_DPRINTK(P9_DEBUG_ERROR, "problem initializing 9p client\n");
233 if (!v9ses->clnt->dotu)
234 v9ses->flags &= ~V9FS_EXTENDED;
236 /* for legacy mode, fall back to V9FS_ACCESS_ANY */
237 if (!v9fs_extended(v9ses) &&
238 ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) {
240 v9ses->flags &= ~V9FS_ACCESS_MASK;
241 v9ses->flags |= V9FS_ACCESS_ANY;
245 fid = p9_client_attach(v9ses->clnt, NULL, v9ses->uname, ~0,
248 retval = PTR_ERR(fid);
250 P9_DPRINTK(P9_DEBUG_ERROR, "cannot attach\n");
254 if ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_SINGLE)
255 fid->uid = v9ses->uid;
262 v9fs_session_close(v9ses);
263 return ERR_PTR(retval);
267 * v9fs_session_close - shutdown a session
268 * @v9ses: session information structure
272 void v9fs_session_close(struct v9fs_session_info *v9ses)
275 p9_client_destroy(v9ses->clnt);
279 __putname(v9ses->uname);
280 __putname(v9ses->aname);
281 kfree(v9ses->options);
285 * v9fs_session_cancel - mark transport as disconnected
286 * and cancel all pending requests.
288 void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
289 P9_DPRINTK(P9_DEBUG_ERROR, "cancel session %p\n", v9ses);
290 p9_client_disconnect(v9ses->clnt);
293 extern int v9fs_error_init(void);
296 * v9fs_init - Initialize module
300 static int __init init_v9fs(void)
302 printk(KERN_INFO "Installing v9fs 9p2000 file system support\n");
303 /* TODO: Setup list of registered trasnport modules */
304 return register_filesystem(&v9fs_fs_type);
308 * v9fs_init - shutdown module
312 static void __exit exit_v9fs(void)
314 unregister_filesystem(&v9fs_fs_type);
317 module_init(init_v9fs)
318 module_exit(exit_v9fs)
320 MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
321 MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
322 MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
323 MODULE_LICENSE("GPL");