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)
45 /* Options that take integer arguments */
46 Opt_debug
, Opt_port
, Opt_msize
, Opt_uid
, Opt_gid
, Opt_afid
,
49 Opt_uname
, Opt_remotename
,
50 /* Options that take no arguments */
51 Opt_legacy
, Opt_nodevmap
, Opt_unix
, Opt_tcp
, Opt_fd
, Opt_pci
,
58 static match_table_t tokens
= {
59 {Opt_debug
, "debug=%x"},
60 {Opt_port
, "port=%u"},
61 {Opt_msize
, "msize=%u"},
64 {Opt_afid
, "afid=%u"},
65 {Opt_rfdno
, "rfdno=%u"},
66 {Opt_wfdno
, "wfdno=%u"},
67 {Opt_uname
, "uname=%s"},
68 {Opt_remotename
, "aname=%s"},
69 {Opt_unix
, "proto=unix"},
70 {Opt_tcp
, "proto=tcp"},
73 {Opt_pci
, "proto=pci"},
78 {Opt_legacy
, "noextend"},
79 {Opt_nodevmap
, "nodevmap"},
80 {Opt_cache_loose
, "cache=loose"},
81 {Opt_cache_loose
, "loose"},
85 extern struct p9_transport
*p9pci_trans_create(void);
88 * Parse option string.
92 * v9fs_parse_options - parse mount options into session structure
93 * @options: options string passed from mount
94 * @v9ses: existing v9fs session information
98 static void v9fs_parse_options(char *options
, struct v9fs_session_info
*v9ses
)
101 substring_t args
[MAX_OPT_ARGS
];
106 v9ses
->port
= V9FS_PORT
;
107 v9ses
->maxdata
= 9000;
108 v9ses
->proto
= PROTO_TCP
;
119 while ((p
= strsep(&options
, ",")) != NULL
) {
123 token
= match_token(p
, tokens
, args
);
124 if (token
< Opt_uname
) {
125 if ((ret
= match_int(&args
[0], &option
)) < 0) {
126 P9_DPRINTK(P9_DEBUG_ERROR
,
127 "integer field, but no integer?\n");
133 v9ses
->debug
= option
;
134 p9_debug_level
= option
;
137 v9ses
->port
= option
;
140 v9ses
->maxdata
= option
;
149 v9ses
->afid
= option
;
152 v9ses
->rfdno
= option
;
155 v9ses
->wfdno
= option
;
158 v9ses
->proto
= PROTO_TCP
;
161 v9ses
->proto
= PROTO_UNIX
;
164 v9ses
->proto
= PROTO_PCI
;
167 v9ses
->proto
= PROTO_FD
;
170 match_strcpy(v9ses
->name
, &args
[0]);
173 match_strcpy(v9ses
->remotename
, &args
[0]);
181 case Opt_cache_loose
:
182 v9ses
->cache
= CACHE_LOOSE
;
191 * v9fs_session_init - initialize session
192 * @v9ses: session information structure
193 * @dev_name: device being mounted
198 struct p9_fid
*v9fs_session_init(struct v9fs_session_info
*v9ses
,
199 const char *dev_name
, char *data
)
201 int retval
= -EINVAL
;
202 struct p9_transport
*trans
;
205 v9ses
->name
= __getname();
207 return ERR_PTR(-ENOMEM
);
209 v9ses
->remotename
= __getname();
210 if (!v9ses
->remotename
) {
211 __putname(v9ses
->name
);
212 return ERR_PTR(-ENOMEM
);
215 strcpy(v9ses
->name
, V9FS_DEFUSER
);
216 strcpy(v9ses
->remotename
, V9FS_DEFANAME
);
218 v9fs_parse_options(data
, v9ses
);
220 switch (v9ses
->proto
) {
222 trans
= p9_trans_create_tcp(dev_name
, v9ses
->port
);
225 trans
= p9_trans_create_unix(dev_name
);
226 *v9ses
->remotename
= 0;
229 trans
= p9_trans_create_fd(v9ses
->rfdno
, v9ses
->wfdno
);
230 *v9ses
->remotename
= 0;
234 trans
= p9pci_trans_create();
235 *v9ses
->remotename
= 0;
239 printk(KERN_ERR
"v9fs: Bad mount protocol %d\n", v9ses
->proto
);
240 retval
= -ENOPROTOOPT
;
245 retval
= PTR_ERR(trans
);
250 v9ses
->clnt
= p9_client_create(trans
, v9ses
->maxdata
+ P9_IOHDRSZ
,
253 if (IS_ERR(v9ses
->clnt
)) {
254 retval
= PTR_ERR(v9ses
->clnt
);
256 P9_DPRINTK(P9_DEBUG_ERROR
, "problem initializing 9p client\n");
260 fid
= p9_client_attach(v9ses
->clnt
, NULL
, v9ses
->name
,
263 retval
= PTR_ERR(fid
);
265 P9_DPRINTK(P9_DEBUG_ERROR
, "cannot attach\n");
272 v9fs_session_close(v9ses
);
273 return ERR_PTR(retval
);
277 * v9fs_session_close - shutdown a session
278 * @v9ses: session information structure
282 void v9fs_session_close(struct v9fs_session_info
*v9ses
)
285 p9_client_destroy(v9ses
->clnt
);
289 __putname(v9ses
->name
);
290 __putname(v9ses
->remotename
);
294 * v9fs_session_cancel - mark transport as disconnected
295 * and cancel all pending requests.
297 void v9fs_session_cancel(struct v9fs_session_info
*v9ses
) {
298 P9_DPRINTK(P9_DEBUG_ERROR
, "cancel session %p\n", v9ses
);
299 p9_client_disconnect(v9ses
->clnt
);
302 extern int v9fs_error_init(void);
305 * v9fs_init - Initialize module
309 static int __init
init_v9fs(void)
311 printk(KERN_INFO
"Installing v9fs 9p2000 file system support\n");
313 return register_filesystem(&v9fs_fs_type
);
317 * v9fs_init - shutdown module
321 static void __exit
exit_v9fs(void)
323 unregister_filesystem(&v9fs_fs_type
);
326 module_init(init_v9fs
)
327 module_exit(exit_v9fs
)
329 MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
330 MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
331 MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
332 MODULE_LICENSE("GPL");