]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/9p/v9fs.c
9p: define session flags
[net-next-2.6.git] / fs / 9p / v9fs.c
CommitLineData
9e82cf6a
EVH
1/*
2 * linux/fs/9p/v9fs.c
3 *
4 * This file contains functions assisting in mapping VFS to 9P2000
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
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>
34#include <net/9p/conn.h>
35#include <net/9p/client.h>
9e82cf6a 36#include "v9fs.h"
9e82cf6a 37#include "v9fs_vfs.h"
9e82cf6a 38
a80d923e
EVH
39/*
40 * Dynamic Transport Registration Routines
41 *
42 */
43
44static LIST_HEAD(v9fs_trans_list);
45static struct p9_trans_module *v9fs_default_trans;
46
47/**
48 * v9fs_register_trans - register a new transport with 9p
49 * @m - structure describing the transport module and entry points
50 *
51 */
52void v9fs_register_trans(struct p9_trans_module *m)
53{
54 list_add_tail(&m->list, &v9fs_trans_list);
55 if (m->def)
56 v9fs_default_trans = m;
57}
58EXPORT_SYMBOL(v9fs_register_trans);
59
60/**
61 * v9fs_match_trans - match transport versus registered transports
62 * @arg: string identifying transport
63 *
64 */
65static struct p9_trans_module *v9fs_match_trans(const substring_t *name)
66{
67 struct list_head *p;
68 struct p9_trans_module *t = NULL;
69
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);
74 break;
75 }
76 }
77 return t;
78}
79
9e82cf6a
EVH
80/*
81 * Option Parsing (code inspired by NFS code)
a80d923e 82 * NOTE: each transport will parse its own options
9e82cf6a
EVH
83 */
84
85enum {
86 /* Options that take integer arguments */
a80d923e 87 Opt_debug, Opt_msize, Opt_uid, Opt_gid, Opt_afid,
9e82cf6a 88 /* String options */
a80d923e 89 Opt_uname, Opt_remotename, Opt_trans,
9e82cf6a 90 /* Options that take no arguments */
a80d923e 91 Opt_legacy, Opt_nodevmap,
e03abc0c
EVH
92 /* Cache options */
93 Opt_cache_loose,
9e82cf6a
EVH
94 /* Error token */
95 Opt_err
96};
97
98static match_table_t tokens = {
9e2f6688 99 {Opt_debug, "debug=%x"},
9e82cf6a
EVH
100 {Opt_msize, "msize=%u"},
101 {Opt_uid, "uid=%u"},
102 {Opt_gid, "gid=%u"},
103 {Opt_afid, "afid=%u"},
67543e50 104 {Opt_uname, "uname=%s"},
9e82cf6a 105 {Opt_remotename, "aname=%s"},
a80d923e 106 {Opt_trans, "trans=%s"},
9e82cf6a
EVH
107 {Opt_legacy, "noextend"},
108 {Opt_nodevmap, "nodevmap"},
e03abc0c
EVH
109 {Opt_cache_loose, "cache=loose"},
110 {Opt_cache_loose, "loose"},
9e82cf6a
EVH
111 {Opt_err, NULL}
112};
113
9e82cf6a
EVH
114/**
115 * v9fs_parse_options - parse mount options into session structure
116 * @options: options string passed from mount
117 * @v9ses: existing v9fs session information
118 *
119 */
120
a80d923e 121static void v9fs_parse_options(struct v9fs_session_info *v9ses)
9e82cf6a 122{
a80d923e 123 char *options = v9ses->options;
9e82cf6a 124 substring_t args[MAX_OPT_ARGS];
a80d923e 125 char *p;
9e82cf6a
EVH
126 int option;
127 int ret;
128
129 /* setup defaults */
a80d923e 130 v9ses->maxdata = 8192;
2405669b 131 v9ses->flags = V9FS_EXTENDED;
9e82cf6a
EVH
132 v9ses->afid = ~0;
133 v9ses->debug = 0;
e03abc0c 134 v9ses->cache = 0;
a80d923e 135 v9ses->trans = v9fs_default_trans;
9e82cf6a
EVH
136
137 if (!options)
138 return;
139
140 while ((p = strsep(&options, ",")) != NULL) {
141 int token;
142 if (!*p)
143 continue;
144 token = match_token(p, tokens, args);
67543e50 145 if (token < Opt_uname) {
9e82cf6a 146 if ((ret = match_int(&args[0], &option)) < 0) {
bd238fb4 147 P9_DPRINTK(P9_DEBUG_ERROR,
9e82cf6a
EVH
148 "integer field, but no integer?\n");
149 continue;
150 }
9e82cf6a
EVH
151 }
152 switch (token) {
9e2f6688
EVH
153 case Opt_debug:
154 v9ses->debug = option;
10fa16e7 155#ifdef CONFIG_NET_9P_DEBUG
9e2f6688 156 p9_debug_level = option;
10fa16e7 157#endif
9e2f6688 158 break;
9e82cf6a
EVH
159 case Opt_msize:
160 v9ses->maxdata = option;
161 break;
162 case Opt_uid:
163 v9ses->uid = option;
164 break;
165 case Opt_gid:
166 v9ses->gid = option;
167 break;
168 case Opt_afid:
169 v9ses->afid = option;
170 break;
a80d923e
EVH
171 case Opt_trans:
172 v9ses->trans = v9fs_match_trans(&args[0]);
9e82cf6a 173 break;
67543e50 174 case Opt_uname:
9e82cf6a
EVH
175 match_strcpy(v9ses->name, &args[0]);
176 break;
177 case Opt_remotename:
178 match_strcpy(v9ses->remotename, &args[0]);
179 break;
180 case Opt_legacy:
2405669b 181 v9ses->flags &= ~V9FS_EXTENDED;
9e82cf6a
EVH
182 break;
183 case Opt_nodevmap:
184 v9ses->nodev = 1;
185 break;
e03abc0c
EVH
186 case Opt_cache_loose:
187 v9ses->cache = CACHE_LOOSE;
188 break;
9e82cf6a
EVH
189 default:
190 continue;
191 }
192 }
193}
194
9e82cf6a
EVH
195/**
196 * v9fs_session_init - initialize session
197 * @v9ses: session information structure
198 * @dev_name: device being mounted
199 * @data: options
200 *
201 */
202
bd238fb4 203struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
9e82cf6a
EVH
204 const char *dev_name, char *data)
205{
9e82cf6a 206 int retval = -EINVAL;
a80d923e 207 struct p9_trans *trans = NULL;
bd238fb4 208 struct p9_fid *fid;
9e82cf6a
EVH
209
210 v9ses->name = __getname();
211 if (!v9ses->name)
bd238fb4 212 return ERR_PTR(-ENOMEM);
9e82cf6a
EVH
213
214 v9ses->remotename = __getname();
215 if (!v9ses->remotename) {
ce44eeb6 216 __putname(v9ses->name);
bd238fb4 217 return ERR_PTR(-ENOMEM);
9e82cf6a
EVH
218 }
219
220 strcpy(v9ses->name, V9FS_DEFUSER);
221 strcpy(v9ses->remotename, V9FS_DEFANAME);
222
a80d923e
EVH
223 v9ses->options = kstrdup(data, GFP_KERNEL);
224 v9fs_parse_options(v9ses);
225
226 if ((v9ses->trans == NULL) && !list_empty(&v9fs_trans_list))
227 v9ses->trans = list_first_entry(&v9fs_trans_list,
228 struct p9_trans_module, list);
229
230 if (v9ses->trans == NULL) {
231 retval = -EPROTONOSUPPORT;
232 P9_DPRINTK(P9_DEBUG_ERROR,
233 "No transport defined or default transport\n");
bd238fb4 234 goto error;
a80d923e 235 }
9e82cf6a 236
a80d923e 237 trans = v9ses->trans->create(dev_name, v9ses->options);
bd238fb4
LI
238 if (IS_ERR(trans)) {
239 retval = PTR_ERR(trans);
240 trans = NULL;
241 goto error;
a8e63bff 242 }
a80d923e
EVH
243 if ((v9ses->maxdata+P9_IOHDRSZ) > v9ses->trans->maxsize)
244 v9ses->maxdata = v9ses->trans->maxsize-P9_IOHDRSZ;
a8e63bff 245
a80d923e 246 v9ses->clnt = p9_client_create(trans, v9ses->maxdata+P9_IOHDRSZ,
2405669b 247 v9fs_extended(v9ses));
9e82cf6a 248
bd238fb4
LI
249 if (IS_ERR(v9ses->clnt)) {
250 retval = PTR_ERR(v9ses->clnt);
251 v9ses->clnt = NULL;
252 P9_DPRINTK(P9_DEBUG_ERROR, "problem initializing 9p client\n");
253 goto error;
9e82cf6a
EVH
254 }
255
bd238fb4
LI
256 fid = p9_client_attach(v9ses->clnt, NULL, v9ses->name,
257 v9ses->remotename);
258 if (IS_ERR(fid)) {
259 retval = PTR_ERR(fid);
260 fid = NULL;
261 P9_DPRINTK(P9_DEBUG_ERROR, "cannot attach\n");
262 goto error;
9e82cf6a
EVH
263 }
264
bd238fb4 265 return fid;
9e82cf6a 266
bd238fb4 267error:
9e82cf6a 268 v9fs_session_close(v9ses);
bd238fb4 269 return ERR_PTR(retval);
9e82cf6a
EVH
270}
271
272/**
273 * v9fs_session_close - shutdown a session
274 * @v9ses: session information structure
275 *
276 */
277
278void v9fs_session_close(struct v9fs_session_info *v9ses)
279{
bd238fb4
LI
280 if (v9ses->clnt) {
281 p9_client_destroy(v9ses->clnt);
282 v9ses->clnt = NULL;
3cf6429a 283 }
9e82cf6a 284
ce44eeb6
DA
285 __putname(v9ses->name);
286 __putname(v9ses->remotename);
a80d923e 287 kfree(v9ses->options);
9e82cf6a
EVH
288}
289
322b329a
EVH
290/**
291 * v9fs_session_cancel - mark transport as disconnected
292 * and cancel all pending requests.
293 */
294void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
bd238fb4
LI
295 P9_DPRINTK(P9_DEBUG_ERROR, "cancel session %p\n", v9ses);
296 p9_client_disconnect(v9ses->clnt);
322b329a
EVH
297}
298
9e82cf6a
EVH
299extern int v9fs_error_init(void);
300
301/**
302 * v9fs_init - Initialize module
303 *
304 */
305
306static int __init init_v9fs(void)
307{
f94b3470 308 printk(KERN_INFO "Installing v9fs 9p2000 file system support\n");
a80d923e 309 /* TODO: Setup list of registered trasnport modules */
bd238fb4 310 return register_filesystem(&v9fs_fs_type);
9e82cf6a
EVH
311}
312
313/**
314 * v9fs_init - shutdown module
315 *
316 */
317
318static void __exit exit_v9fs(void)
319{
320 unregister_filesystem(&v9fs_fs_type);
321}
322
323module_init(init_v9fs)
324module_exit(exit_v9fs)
325
bd238fb4 326MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
9e82cf6a
EVH
327MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
328MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
329MODULE_LICENSE("GPL");