]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/9p/v9fs.c
9p: Fix the incorrect update of inode size in v9fs_file_write()
[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 *
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 32#include <net/9p/9p.h>
bd238fb4 33#include <net/9p/client.h>
8b81ef58 34#include <net/9p/transport.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
43enum {
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
a447c093 58static const 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 *
ab31267d 76 * Return 0 upon success, -ERRNO upon failure.
9e82cf6a
EVH
77 */
78
4b53e4b5 79static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
9e82cf6a 80{
8999e04f 81 char *options;
9e82cf6a 82 substring_t args[MAX_OPT_ARGS];
a80d923e 83 char *p;
8a0dc95f 84 int option = 0;
ba17674f 85 char *s, *e;
ab31267d 86 int ret = 0;
9e82cf6a
EVH
87
88 /* setup defaults */
9e82cf6a
EVH
89 v9ses->afid = ~0;
90 v9ses->debug = 0;
e03abc0c 91 v9ses->cache = 0;
9e82cf6a 92
4b53e4b5 93 if (!opts)
ab31267d 94 return 0;
9e82cf6a 95
4b53e4b5 96 options = kstrdup(opts, GFP_KERNEL);
ab31267d
JM
97 if (!options) {
98 P9_DPRINTK(P9_DEBUG_ERROR,
99 "failed to allocate copy of option string\n");
100 return -ENOMEM;
101 }
102
9e82cf6a
EVH
103 while ((p = strsep(&options, ",")) != NULL) {
104 int token;
105 if (!*p)
106 continue;
107 token = match_token(p, tokens, args);
67543e50 108 if (token < Opt_uname) {
ab31267d
JM
109 int r = match_int(&args[0], &option);
110 if (r < 0) {
bd238fb4 111 P9_DPRINTK(P9_DEBUG_ERROR,
9e82cf6a 112 "integer field, but no integer?\n");
ab31267d 113 ret = r;
9e82cf6a
EVH
114 continue;
115 }
9e82cf6a
EVH
116 }
117 switch (token) {
9e2f6688
EVH
118 case Opt_debug:
119 v9ses->debug = option;
10fa16e7 120#ifdef CONFIG_NET_9P_DEBUG
9e2f6688 121 p9_debug_level = option;
10fa16e7 122#endif
9e2f6688 123 break;
8a0dc95f 124
bd32b82d
LI
125 case Opt_dfltuid:
126 v9ses->dfltuid = option;
9e82cf6a 127 break;
bd32b82d
LI
128 case Opt_dfltgid:
129 v9ses->dfltgid = option;
9e82cf6a
EVH
130 break;
131 case Opt_afid:
132 v9ses->afid = option;
133 break;
67543e50 134 case Opt_uname:
b32a09db 135 match_strlcpy(v9ses->uname, &args[0], PATH_MAX);
9e82cf6a
EVH
136 break;
137 case Opt_remotename:
b32a09db 138 match_strlcpy(v9ses->aname, &args[0], PATH_MAX);
9e82cf6a 139 break;
9e82cf6a
EVH
140 case Opt_nodevmap:
141 v9ses->nodev = 1;
142 break;
e03abc0c
EVH
143 case Opt_cache_loose:
144 v9ses->cache = CACHE_LOOSE;
145 break;
ba17674f
LI
146
147 case Opt_access:
148 s = match_strdup(&args[0]);
ab31267d
JM
149 if (!s) {
150 P9_DPRINTK(P9_DEBUG_ERROR,
151 "failed to allocate copy"
152 " of option argument\n");
153 ret = -ENOMEM;
154 break;
155 }
ba17674f
LI
156 v9ses->flags &= ~V9FS_ACCESS_MASK;
157 if (strcmp(s, "user") == 0)
158 v9ses->flags |= V9FS_ACCESS_USER;
159 else if (strcmp(s, "any") == 0)
160 v9ses->flags |= V9FS_ACCESS_ANY;
161 else {
162 v9ses->flags |= V9FS_ACCESS_SINGLE;
f1d9e458 163 v9ses->uid = simple_strtoul(s, &e, 10);
ba17674f
LI
164 if (*e != '\0')
165 v9ses->uid = ~0;
166 }
0a976297 167 kfree(s);
ba17674f
LI
168 break;
169
9e82cf6a
EVH
170 default:
171 continue;
172 }
173 }
8999e04f 174 kfree(options);
ab31267d 175 return ret;
9e82cf6a
EVH
176}
177
9e82cf6a
EVH
178/**
179 * v9fs_session_init - initialize session
180 * @v9ses: session information structure
181 * @dev_name: device being mounted
182 * @data: options
183 *
184 */
185
bd238fb4 186struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
9e82cf6a
EVH
187 const char *dev_name, char *data)
188{
9e82cf6a 189 int retval = -EINVAL;
bd238fb4 190 struct p9_fid *fid;
ab31267d 191 int rc;
9e82cf6a 192
ba17674f
LI
193 v9ses->uname = __getname();
194 if (!v9ses->uname)
bd238fb4 195 return ERR_PTR(-ENOMEM);
9e82cf6a 196
ba17674f
LI
197 v9ses->aname = __getname();
198 if (!v9ses->aname) {
199 __putname(v9ses->uname);
bd238fb4 200 return ERR_PTR(-ENOMEM);
9e82cf6a
EVH
201 }
202
ba17674f
LI
203 v9ses->flags = V9FS_EXTENDED | V9FS_ACCESS_USER;
204 strcpy(v9ses->uname, V9FS_DEFUSER);
205 strcpy(v9ses->aname, V9FS_DEFANAME);
206 v9ses->uid = ~0;
bd32b82d
LI
207 v9ses->dfltuid = V9FS_DEFUID;
208 v9ses->dfltgid = V9FS_DEFGID;
ab31267d 209
4b53e4b5 210 rc = v9fs_parse_options(v9ses, data);
ab31267d
JM
211 if (rc < 0) {
212 retval = rc;
213 goto error;
214 }
a80d923e 215
4b53e4b5 216 v9ses->clnt = p9_client_create(dev_name, data);
bd238fb4
LI
217 if (IS_ERR(v9ses->clnt)) {
218 retval = PTR_ERR(v9ses->clnt);
219 v9ses->clnt = NULL;
220 P9_DPRINTK(P9_DEBUG_ERROR, "problem initializing 9p client\n");
221 goto error;
9e82cf6a
EVH
222 }
223
ba17674f
LI
224 if (!v9ses->clnt->dotu)
225 v9ses->flags &= ~V9FS_EXTENDED;
226
fbedadc1 227 v9ses->maxdata = v9ses->clnt->msize - P9_IOHDRSZ;
8a0dc95f 228
ba17674f
LI
229 /* for legacy mode, fall back to V9FS_ACCESS_ANY */
230 if (!v9fs_extended(v9ses) &&
231 ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) {
232
233 v9ses->flags &= ~V9FS_ACCESS_MASK;
234 v9ses->flags |= V9FS_ACCESS_ANY;
235 v9ses->uid = ~0;
236 }
237
238 fid = p9_client_attach(v9ses->clnt, NULL, v9ses->uname, ~0,
239 v9ses->aname);
bd238fb4
LI
240 if (IS_ERR(fid)) {
241 retval = PTR_ERR(fid);
242 fid = NULL;
243 P9_DPRINTK(P9_DEBUG_ERROR, "cannot attach\n");
244 goto error;
9e82cf6a
EVH
245 }
246
ba17674f
LI
247 if ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_SINGLE)
248 fid->uid = v9ses->uid;
249 else
250 fid->uid = ~0;
251
bd238fb4 252 return fid;
9e82cf6a 253
bd238fb4 254error:
bd238fb4 255 return ERR_PTR(retval);
9e82cf6a
EVH
256}
257
258/**
259 * v9fs_session_close - shutdown a session
260 * @v9ses: session information structure
261 *
262 */
263
264void v9fs_session_close(struct v9fs_session_info *v9ses)
265{
bd238fb4
LI
266 if (v9ses->clnt) {
267 p9_client_destroy(v9ses->clnt);
268 v9ses->clnt = NULL;
3cf6429a 269 }
9e82cf6a 270
ba17674f
LI
271 __putname(v9ses->uname);
272 __putname(v9ses->aname);
9e82cf6a
EVH
273}
274
322b329a 275/**
ee443996
EVH
276 * v9fs_session_cancel - terminate a session
277 * @v9ses: session to terminate
278 *
279 * mark transport as disconnected and cancel all pending requests.
322b329a 280 */
ee443996 281
322b329a 282void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
bd238fb4
LI
283 P9_DPRINTK(P9_DEBUG_ERROR, "cancel session %p\n", v9ses);
284 p9_client_disconnect(v9ses->clnt);
322b329a
EVH
285}
286
9e82cf6a
EVH
287extern int v9fs_error_init(void);
288
289/**
290 * v9fs_init - Initialize module
291 *
292 */
293
294static int __init init_v9fs(void)
295{
f94b3470 296 printk(KERN_INFO "Installing v9fs 9p2000 file system support\n");
a80d923e 297 /* TODO: Setup list of registered trasnport modules */
bd238fb4 298 return register_filesystem(&v9fs_fs_type);
9e82cf6a
EVH
299}
300
301/**
302 * v9fs_init - shutdown module
303 *
304 */
305
306static void __exit exit_v9fs(void)
307{
308 unregister_filesystem(&v9fs_fs_type);
309}
310
311module_init(init_v9fs)
312module_exit(exit_v9fs)
313
bd238fb4 314MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
9e82cf6a
EVH
315MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
316MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
317MODULE_LICENSE("GPL");