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 * Dynamic Transport Registration Routines
44 static LIST_HEAD(v9fs_trans_list);
45 static struct p9_trans_module *v9fs_default_trans;
48 * v9fs_register_trans - register a new transport with 9p
49 * @m - structure describing the transport module and entry points
52 void v9fs_register_trans(struct p9_trans_module *m)
54 list_add_tail(&m->list, &v9fs_trans_list);
56 v9fs_default_trans = m;
58 EXPORT_SYMBOL(v9fs_register_trans);
61 * v9fs_match_trans - match transport versus registered transports
62 * @arg: string identifying transport
65 static struct p9_trans_module *v9fs_match_trans(const substring_t *name)
68 struct p9_trans_module *t = NULL;
70 list_for_each(p, &v9fs_trans_list) {
71 t = list_entry(p, struct p9_trans_module, list);
72 if (strncmp(t->name, name->from, name->to-name->from) == 0) {
73 P9_DPRINTK(P9_DEBUG_TRANS, "trans=%s\n", t->name);
81 * Option Parsing (code inspired by NFS code)
82 * NOTE: each transport will parse its own options
86 /* Options that take integer arguments */
87 Opt_debug, Opt_msize, Opt_dfltuid, Opt_dfltgid, Opt_afid,
89 Opt_uname, Opt_remotename, Opt_trans,
90 /* Options that take no arguments */
91 Opt_legacy, Opt_nodevmap,
98 static match_table_t tokens = {
99 {Opt_debug, "debug=%x"},
100 {Opt_msize, "msize=%u"},
101 {Opt_dfltuid, "dfltuid=%u"},
102 {Opt_dfltgid, "dfltgid=%u"},
103 {Opt_afid, "afid=%u"},
104 {Opt_uname, "uname=%s"},
105 {Opt_remotename, "aname=%s"},
106 {Opt_trans, "trans=%s"},
107 {Opt_legacy, "noextend"},
108 {Opt_nodevmap, "nodevmap"},
109 {Opt_cache_loose, "cache=loose"},
110 {Opt_cache_loose, "loose"},
115 * v9fs_parse_options - parse mount options into session structure
116 * @options: options string passed from mount
117 * @v9ses: existing v9fs session information
121 static void v9fs_parse_options(struct v9fs_session_info *v9ses)
123 char *options = v9ses->options;
124 substring_t args[MAX_OPT_ARGS];
130 v9ses->maxdata = 8192;
131 v9ses->flags = V9FS_EXTENDED;
135 v9ses->trans = v9fs_default_trans;
140 while ((p = strsep(&options, ",")) != NULL) {
144 token = match_token(p, tokens, args);
145 if (token < Opt_uname) {
146 if ((ret = match_int(&args[0], &option)) < 0) {
147 P9_DPRINTK(P9_DEBUG_ERROR,
148 "integer field, but no integer?\n");
154 v9ses->debug = option;
155 #ifdef CONFIG_NET_9P_DEBUG
156 p9_debug_level = option;
160 v9ses->maxdata = option;
163 v9ses->dfltuid = option;
166 v9ses->dfltgid = option;
169 v9ses->afid = option;
172 v9ses->trans = v9fs_match_trans(&args[0]);
175 match_strcpy(v9ses->name, &args[0]);
178 match_strcpy(v9ses->remotename, &args[0]);
181 v9ses->flags &= ~V9FS_EXTENDED;
186 case Opt_cache_loose:
187 v9ses->cache = CACHE_LOOSE;
196 * v9fs_session_init - initialize session
197 * @v9ses: session information structure
198 * @dev_name: device being mounted
203 struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
204 const char *dev_name, char *data)
206 int retval = -EINVAL;
207 struct p9_trans *trans = NULL;
210 v9ses->name = __getname();
212 return ERR_PTR(-ENOMEM);
214 v9ses->remotename = __getname();
215 if (!v9ses->remotename) {
216 __putname(v9ses->name);
217 return ERR_PTR(-ENOMEM);
220 strcpy(v9ses->name, V9FS_DEFUSER);
221 strcpy(v9ses->remotename, V9FS_DEFANAME);
222 v9ses->dfltuid = V9FS_DEFUID;
223 v9ses->dfltgid = V9FS_DEFGID;
225 v9ses->options = kstrdup(data, GFP_KERNEL);
226 v9fs_parse_options(v9ses);
228 if ((v9ses->trans == NULL) && !list_empty(&v9fs_trans_list))
229 v9ses->trans = list_first_entry(&v9fs_trans_list,
230 struct p9_trans_module, list);
232 if (v9ses->trans == NULL) {
233 retval = -EPROTONOSUPPORT;
234 P9_DPRINTK(P9_DEBUG_ERROR,
235 "No transport defined or default transport\n");
239 trans = v9ses->trans->create(dev_name, v9ses->options);
241 retval = PTR_ERR(trans);
245 if ((v9ses->maxdata+P9_IOHDRSZ) > v9ses->trans->maxsize)
246 v9ses->maxdata = v9ses->trans->maxsize-P9_IOHDRSZ;
248 v9ses->clnt = p9_client_create(trans, v9ses->maxdata+P9_IOHDRSZ,
249 v9fs_extended(v9ses));
251 if (IS_ERR(v9ses->clnt)) {
252 retval = PTR_ERR(v9ses->clnt);
254 P9_DPRINTK(P9_DEBUG_ERROR, "problem initializing 9p client\n");
258 fid = p9_client_attach(v9ses->clnt, NULL, v9ses->name,
261 retval = PTR_ERR(fid);
263 P9_DPRINTK(P9_DEBUG_ERROR, "cannot attach\n");
270 v9fs_session_close(v9ses);
271 return ERR_PTR(retval);
275 * v9fs_session_close - shutdown a session
276 * @v9ses: session information structure
280 void v9fs_session_close(struct v9fs_session_info *v9ses)
283 p9_client_destroy(v9ses->clnt);
287 __putname(v9ses->name);
288 __putname(v9ses->remotename);
289 kfree(v9ses->options);
293 * v9fs_session_cancel - mark transport as disconnected
294 * and cancel all pending requests.
296 void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
297 P9_DPRINTK(P9_DEBUG_ERROR, "cancel session %p\n", v9ses);
298 p9_client_disconnect(v9ses->clnt);
301 extern int v9fs_error_init(void);
304 * v9fs_init - Initialize module
308 static int __init init_v9fs(void)
310 printk(KERN_INFO "Installing v9fs 9p2000 file system support\n");
311 /* TODO: Setup list of registered trasnport modules */
312 return register_filesystem(&v9fs_fs_type);
316 * v9fs_init - shutdown module
320 static void __exit exit_v9fs(void)
322 unregister_filesystem(&v9fs_fs_type);
325 module_init(init_v9fs)
326 module_exit(exit_v9fs)
328 MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
329 MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
330 MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
331 MODULE_LICENSE("GPL");