Blame view

fs/9p/v9fs.c 13.8 KB
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
1
2
3
4
5
  /*
   *  linux/fs/9p/v9fs.c
   *
   *  This file contains functions assisting in mapping VFS to 9P2000
   *
8a0dc95fd   Eric Van Hensbergen   9p: transport API...
6
   *  Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
7
8
9
   *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
   *
   *  This program is free software; you can redistribute it and/or modify
42e8c509c   Eric Van Hensbergen   [PATCH] v9fs: upd...
10
11
   *  it under the terms of the GNU General Public License version 2
   *  as published by the Free Software Foundation.
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
12
13
14
15
16
17
18
19
20
21
22
23
24
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, write to:
   *  Free Software Foundation
   *  51 Franklin Street, Fifth Floor
   *  Boston, MA  02111-1301  USA
   *
   */
5d3851530   Joe Perches   9p: Reduce object...
25
  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
26
27
28
  #include <linux/module.h>
  #include <linux/errno.h>
  #include <linux/fs.h>
914e26379   Al Viro   [PATCH] severing ...
29
  #include <linux/sched.h>
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
30
31
  #include <linux/parser.h>
  #include <linux/idr.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
32
  #include <linux/slab.h>
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
33
  #include <net/9p/9p.h>
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
34
  #include <net/9p/client.h>
8b81ef589   Eric Van Hensbergen   9p: consolidate t...
35
  #include <net/9p/transport.h>
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
36
  #include "v9fs.h"
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
37
  #include "v9fs_vfs.h"
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
38
39
40
41
  #include "cache.h"
  
  static DEFINE_SPINLOCK(v9fs_sessionlist_lock);
  static LIST_HEAD(v9fs_sessionlist);
a78ce05d5   Aneesh Kumar K.V   fs/9p: Add v9fs_i...
42
  struct kmem_cache *v9fs_inode_cache;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
43
44
  
  /*
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
45
46
47
   * Option Parsing (code inspired by NFS code)
   *  NOTE: each transport will parse its own options
   */
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
48
49
50
  
  enum {
  	/* Options that take integer arguments */
8a0dc95fd   Eric Van Hensbergen   9p: transport API...
51
  	Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid,
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
52
  	/* String options */
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
53
  	Opt_uname, Opt_remotename, Opt_trans, Opt_cache, Opt_cachetag,
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
54
  	/* Options that take no arguments */
8a0dc95fd   Eric Van Hensbergen   9p: transport API...
55
  	Opt_nodevmap,
e03abc0c9   Eric Van Hensbergen   9p: implement opt...
56
  	/* Cache options */
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
57
  	Opt_cache_loose, Opt_fscache,
ba17674fe   Latchesar Ionkov   9p: attach-per-user
58
  	/* Access options */
e782ef710   Venkateswararao Jujjuri (JV)   [fs/9P] Add posix...
59
  	Opt_access, Opt_posixacl,
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
60
61
62
  	/* Error token */
  	Opt_err
  };
a447c0932   Steven Whitehouse   vfs: Use const fo...
63
  static const match_table_t tokens = {
9e2f6688c   Eric Van Hensbergen   9p: re-enable mou...
64
  	{Opt_debug, "debug=%x"},
bd32b82df   Latchesar Ionkov   9p: rename uid an...
65
66
  	{Opt_dfltuid, "dfltuid=%u"},
  	{Opt_dfltgid, "dfltgid=%u"},
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
67
  	{Opt_afid, "afid=%u"},
67543e508   Eric Van Hensbergen   [PATCH] 9p: fix n...
68
  	{Opt_uname, "uname=%s"},
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
69
  	{Opt_remotename, "aname=%s"},
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
70
  	{Opt_nodevmap, "nodevmap"},
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
71
  	{Opt_cache, "cache=%s"},
e03abc0c9   Eric Van Hensbergen   9p: implement opt...
72
  	{Opt_cache_loose, "loose"},
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
73
74
  	{Opt_fscache, "fscache"},
  	{Opt_cachetag, "cachetag=%s"},
ba17674fe   Latchesar Ionkov   9p: attach-per-user
75
  	{Opt_access, "access=%s"},
e782ef710   Venkateswararao Jujjuri (JV)   [fs/9P] Add posix...
76
  	{Opt_posixacl, "posixacl"},
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
77
78
  	{Opt_err, NULL}
  };
a2dd43bb0   Prem Karat   fs/9p: Fix invali...
79
80
81
82
83
84
85
  /* Interpret mount options for cache mode */
  static int get_cache_mode(char *s)
  {
  	int version = -EINVAL;
  
  	if (!strcmp(s, "loose")) {
  		version = CACHE_LOOSE;
5d3851530   Joe Perches   9p: Reduce object...
86
87
  		p9_debug(P9_DEBUG_9P, "Cache mode: loose
  ");
a2dd43bb0   Prem Karat   fs/9p: Fix invali...
88
89
  	} else if (!strcmp(s, "fscache")) {
  		version = CACHE_FSCACHE;
5d3851530   Joe Perches   9p: Reduce object...
90
91
  		p9_debug(P9_DEBUG_9P, "Cache mode: fscache
  ");
a2dd43bb0   Prem Karat   fs/9p: Fix invali...
92
93
  	} else if (!strcmp(s, "none")) {
  		version = CACHE_NONE;
5d3851530   Joe Perches   9p: Reduce object...
94
95
  		p9_debug(P9_DEBUG_9P, "Cache mode: none
  ");
a2dd43bb0   Prem Karat   fs/9p: Fix invali...
96
  	} else
5d3851530   Joe Perches   9p: Reduce object...
97
98
  		pr_info("Unknown Cache mode %s
  ", s);
a2dd43bb0   Prem Karat   fs/9p: Fix invali...
99
100
  	return version;
  }
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
101
102
  /**
   * v9fs_parse_options - parse mount options into session structure
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
103
104
   * @v9ses: existing v9fs session information
   *
ab31267df   Jim Meyering   fs/9p/v9fs.c (v9f...
105
   * Return 0 upon success, -ERRNO upon failure.
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
106
   */
4b53e4b50   Abhishek Kulkarni   9p: remove unnece...
107
  static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
108
  {
d8c8a9e36   Eric Van Hensbergen   9p: fix option pa...
109
  	char *options, *tmp_options;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
110
  	substring_t args[MAX_OPT_ARGS];
a80d923e1   Eric Van Hensbergen   9p: Make transpor...
111
  	char *p;
8a0dc95fd   Eric Van Hensbergen   9p: transport API...
112
  	int option = 0;
ba17674fe   Latchesar Ionkov   9p: attach-per-user
113
  	char *s, *e;
ab31267df   Jim Meyering   fs/9p/v9fs.c (v9f...
114
  	int ret = 0;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
115
116
  
  	/* setup defaults */
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
117
118
  	v9ses->afid = ~0;
  	v9ses->debug = 0;
a2dd43bb0   Prem Karat   fs/9p: Fix invali...
119
  	v9ses->cache = CACHE_NONE;
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
120
121
122
  #ifdef CONFIG_9P_FSCACHE
  	v9ses->cachetag = NULL;
  #endif
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
123

4b53e4b50   Abhishek Kulkarni   9p: remove unnece...
124
  	if (!opts)
ab31267df   Jim Meyering   fs/9p/v9fs.c (v9f...
125
  		return 0;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
126

d8c8a9e36   Eric Van Hensbergen   9p: fix option pa...
127
  	tmp_options = kstrdup(opts, GFP_KERNEL);
bf2d29c64   Eric Van Hensbergen   9p: fix memory le...
128
129
  	if (!tmp_options) {
  		ret = -ENOMEM;
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
130
  		goto fail_option_alloc;
bf2d29c64   Eric Van Hensbergen   9p: fix memory le...
131
  	}
d8c8a9e36   Eric Van Hensbergen   9p: fix option pa...
132
  	options = tmp_options;
ab31267df   Jim Meyering   fs/9p/v9fs.c (v9f...
133

9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
134
  	while ((p = strsep(&options, ",")) != NULL) {
4d5077f1b   Aneesh Kumar K.V   fs/9p: Cleanup op...
135
  		int token, r;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
136
137
138
  		if (!*p)
  			continue;
  		token = match_token(p, tokens, args);
4d5077f1b   Aneesh Kumar K.V   fs/9p: Cleanup op...
139
140
141
  		switch (token) {
  		case Opt_debug:
  			r = match_int(&args[0], &option);
ab31267df   Jim Meyering   fs/9p/v9fs.c (v9f...
142
  			if (r < 0) {
5d3851530   Joe Perches   9p: Reduce object...
143
144
145
  				p9_debug(P9_DEBUG_ERROR,
  					 "integer field, but no integer?
  ");
ab31267df   Jim Meyering   fs/9p/v9fs.c (v9f...
146
  				ret = r;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
147
148
  				continue;
  			}
9e2f6688c   Eric Van Hensbergen   9p: re-enable mou...
149
  			v9ses->debug = option;
10fa16e75   Eric Van Hensbergen   9p: fix debug com...
150
  #ifdef CONFIG_NET_9P_DEBUG
9e2f6688c   Eric Van Hensbergen   9p: re-enable mou...
151
  			p9_debug_level = option;
10fa16e75   Eric Van Hensbergen   9p: fix debug com...
152
  #endif
9e2f6688c   Eric Van Hensbergen   9p: re-enable mou...
153
  			break;
8a0dc95fd   Eric Van Hensbergen   9p: transport API...
154

bd32b82df   Latchesar Ionkov   9p: rename uid an...
155
  		case Opt_dfltuid:
4d5077f1b   Aneesh Kumar K.V   fs/9p: Cleanup op...
156
157
  			r = match_int(&args[0], &option);
  			if (r < 0) {
5d3851530   Joe Perches   9p: Reduce object...
158
159
160
  				p9_debug(P9_DEBUG_ERROR,
  					 "integer field, but no integer?
  ");
4d5077f1b   Aneesh Kumar K.V   fs/9p: Cleanup op...
161
162
163
  				ret = r;
  				continue;
  			}
bd32b82df   Latchesar Ionkov   9p: rename uid an...
164
  			v9ses->dfltuid = option;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
165
  			break;
bd32b82df   Latchesar Ionkov   9p: rename uid an...
166
  		case Opt_dfltgid:
4d5077f1b   Aneesh Kumar K.V   fs/9p: Cleanup op...
167
168
  			r = match_int(&args[0], &option);
  			if (r < 0) {
5d3851530   Joe Perches   9p: Reduce object...
169
170
171
  				p9_debug(P9_DEBUG_ERROR,
  					 "integer field, but no integer?
  ");
4d5077f1b   Aneesh Kumar K.V   fs/9p: Cleanup op...
172
173
174
  				ret = r;
  				continue;
  			}
bd32b82df   Latchesar Ionkov   9p: rename uid an...
175
  			v9ses->dfltgid = option;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
176
177
  			break;
  		case Opt_afid:
4d5077f1b   Aneesh Kumar K.V   fs/9p: Cleanup op...
178
179
  			r = match_int(&args[0], &option);
  			if (r < 0) {
5d3851530   Joe Perches   9p: Reduce object...
180
181
182
  				p9_debug(P9_DEBUG_ERROR,
  					 "integer field, but no integer?
  ");
4d5077f1b   Aneesh Kumar K.V   fs/9p: Cleanup op...
183
184
185
  				ret = r;
  				continue;
  			}
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
186
187
  			v9ses->afid = option;
  			break;
67543e508   Eric Van Hensbergen   [PATCH] 9p: fix n...
188
  		case Opt_uname:
b32a09db4   Markus Armbruster   add match_strlcpy...
189
  			match_strlcpy(v9ses->uname, &args[0], PATH_MAX);
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
190
191
  			break;
  		case Opt_remotename:
b32a09db4   Markus Armbruster   add match_strlcpy...
192
  			match_strlcpy(v9ses->aname, &args[0], PATH_MAX);
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
193
  			break;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
194
195
196
  		case Opt_nodevmap:
  			v9ses->nodev = 1;
  			break;
e03abc0c9   Eric Van Hensbergen   9p: implement opt...
197
198
199
  		case Opt_cache_loose:
  			v9ses->cache = CACHE_LOOSE;
  			break;
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
200
201
202
203
204
205
206
207
208
209
  		case Opt_fscache:
  			v9ses->cache = CACHE_FSCACHE;
  			break;
  		case Opt_cachetag:
  #ifdef CONFIG_9P_FSCACHE
  			v9ses->cachetag = match_strdup(&args[0]);
  #endif
  			break;
  		case Opt_cache:
  			s = match_strdup(&args[0]);
bf2d29c64   Eric Van Hensbergen   9p: fix memory le...
210
211
  			if (!s) {
  				ret = -ENOMEM;
5d3851530   Joe Perches   9p: Reduce object...
212
213
214
  				p9_debug(P9_DEBUG_ERROR,
  					 "problem allocating copy of cache arg
  ");
bf2d29c64   Eric Van Hensbergen   9p: fix memory le...
215
216
  				goto free_and_return;
  			}
a2dd43bb0   Prem Karat   fs/9p: Fix invali...
217
218
219
220
221
  			ret = get_cache_mode(s);
  			if (ret == -EINVAL) {
  				kfree(s);
  				goto free_and_return;
  			}
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
222

a2dd43bb0   Prem Karat   fs/9p: Fix invali...
223
  			v9ses->cache = ret;
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
224
225
  			kfree(s);
  			break;
ba17674fe   Latchesar Ionkov   9p: attach-per-user
226
227
228
  
  		case Opt_access:
  			s = match_strdup(&args[0]);
bf2d29c64   Eric Van Hensbergen   9p: fix memory le...
229
230
  			if (!s) {
  				ret = -ENOMEM;
5d3851530   Joe Perches   9p: Reduce object...
231
232
233
  				p9_debug(P9_DEBUG_ERROR,
  					 "problem allocating copy of access arg
  ");
bf2d29c64   Eric Van Hensbergen   9p: fix memory le...
234
235
  				goto free_and_return;
  			}
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
236

ba17674fe   Latchesar Ionkov   9p: attach-per-user
237
238
239
240
241
  			v9ses->flags &= ~V9FS_ACCESS_MASK;
  			if (strcmp(s, "user") == 0)
  				v9ses->flags |= V9FS_ACCESS_USER;
  			else if (strcmp(s, "any") == 0)
  				v9ses->flags |= V9FS_ACCESS_ANY;
76381a42e   Aneesh Kumar K.V   fs/9p: Add access...
242
  			else if (strcmp(s, "client") == 0) {
76381a42e   Aneesh Kumar K.V   fs/9p: Add access...
243
  				v9ses->flags |= V9FS_ACCESS_CLIENT;
76381a42e   Aneesh Kumar K.V   fs/9p: Add access...
244
  			} else {
ba17674fe   Latchesar Ionkov   9p: attach-per-user
245
  				v9ses->flags |= V9FS_ACCESS_SINGLE;
f1d9e4586   Julia Lawall   fs/9p: change sim...
246
  				v9ses->uid = simple_strtoul(s, &e, 10);
a2dd43bb0   Prem Karat   fs/9p: Fix invali...
247
248
  				if (*e != '\0') {
  					ret = -EINVAL;
5d3851530   Joe Perches   9p: Reduce object...
249
250
251
  					pr_info("Unknown access argument %s
  ",
  						s);
a2dd43bb0   Prem Karat   fs/9p: Fix invali...
252
253
254
  					kfree(s);
  					goto free_and_return;
  				}
ba17674fe   Latchesar Ionkov   9p: attach-per-user
255
  			}
a2dd43bb0   Prem Karat   fs/9p: Fix invali...
256

0a976297e   Adrian Bunk   9p: fix memleak i...
257
  			kfree(s);
ba17674fe   Latchesar Ionkov   9p: attach-per-user
258
  			break;
e782ef710   Venkateswararao Jujjuri (JV)   [fs/9P] Add posix...
259
260
261
262
  		case Opt_posixacl:
  #ifdef CONFIG_9P_FS_POSIX_ACL
  			v9ses->flags |= V9FS_POSIX_ACL;
  #else
5d3851530   Joe Perches   9p: Reduce object...
263
264
265
  			p9_debug(P9_DEBUG_ERROR,
  				 "Not defined CONFIG_9P_FS_POSIX_ACL. Ignoring posixacl option
  ");
e782ef710   Venkateswararao Jujjuri (JV)   [fs/9P] Add posix...
266
267
  #endif
  			break;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
268
269
270
271
  		default:
  			continue;
  		}
  	}
d8c8a9e36   Eric Van Hensbergen   9p: fix option pa...
272

bf2d29c64   Eric Van Hensbergen   9p: fix memory le...
273
  free_and_return:
d8c8a9e36   Eric Van Hensbergen   9p: fix option pa...
274
  	kfree(tmp_options);
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
275
  fail_option_alloc:
bf2d29c64   Eric Van Hensbergen   9p: fix memory le...
276
  	return ret;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
277
278
279
  }
  
  /**
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
280
281
282
283
284
285
   * v9fs_session_init - initialize session
   * @v9ses: session information structure
   * @dev_name: device being mounted
   * @data: options
   *
   */
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
286
  struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
287
288
  		  const char *dev_name, char *data)
  {
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
289
  	int retval = -EINVAL;
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
290
  	struct p9_fid *fid;
ab31267df   Jim Meyering   fs/9p/v9fs.c (v9f...
291
  	int rc;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
292

ba17674fe   Latchesar Ionkov   9p: attach-per-user
293
294
  	v9ses->uname = __getname();
  	if (!v9ses->uname)
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
295
  		return ERR_PTR(-ENOMEM);
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
296

ba17674fe   Latchesar Ionkov   9p: attach-per-user
297
298
299
  	v9ses->aname = __getname();
  	if (!v9ses->aname) {
  		__putname(v9ses->uname);
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
300
  		return ERR_PTR(-ENOMEM);
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
301
  	}
a534c8d15   Aneesh Kumar K.V   fs/9p: Prevent pa...
302
  	init_rwsem(&v9ses->rename_sem);
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
303

0ed07ddb5   Jens Axboe   9p: add bdi backi...
304
305
306
307
308
309
  	rc = bdi_setup_and_register(&v9ses->bdi, "9p", BDI_CAP_MAP_COPY);
  	if (rc) {
  		__putname(v9ses->aname);
  		__putname(v9ses->uname);
  		return ERR_PTR(rc);
  	}
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
310
311
312
  	spin_lock(&v9fs_sessionlist_lock);
  	list_add(&v9ses->slist, &v9fs_sessionlist);
  	spin_unlock(&v9fs_sessionlist_lock);
ba17674fe   Latchesar Ionkov   9p: attach-per-user
313
314
315
  	strcpy(v9ses->uname, V9FS_DEFUSER);
  	strcpy(v9ses->aname, V9FS_DEFANAME);
  	v9ses->uid = ~0;
bd32b82df   Latchesar Ionkov   9p: rename uid an...
316
317
  	v9ses->dfltuid = V9FS_DEFUID;
  	v9ses->dfltgid = V9FS_DEFGID;
ab31267df   Jim Meyering   fs/9p/v9fs.c (v9f...
318

4b53e4b50   Abhishek Kulkarni   9p: remove unnece...
319
  	v9ses->clnt = p9_client_create(dev_name, data);
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
320
321
322
  	if (IS_ERR(v9ses->clnt)) {
  		retval = PTR_ERR(v9ses->clnt);
  		v9ses->clnt = NULL;
5d3851530   Joe Perches   9p: Reduce object...
323
324
  		p9_debug(P9_DEBUG_ERROR, "problem initializing 9p client
  ");
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
325
  		goto error;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
326
  	}
6752a1ebd   Venkateswararao Jujjuri (JV)   [fs/9p] Make acce...
327
328
329
330
  	v9ses->flags = V9FS_ACCESS_USER;
  
  	if (p9_is_proto_dotl(v9ses->clnt)) {
  		v9ses->flags = V9FS_ACCESS_CLIENT;
476ada043   Sripathi Kodi   9p: Fix setting o...
331
  		v9ses->flags |= V9FS_PROTO_2000L;
6752a1ebd   Venkateswararao Jujjuri (JV)   [fs/9p] Make acce...
332
  	} else if (p9_is_proto_dotu(v9ses->clnt)) {
476ada043   Sripathi Kodi   9p: Fix setting o...
333
  		v9ses->flags |= V9FS_PROTO_2000U;
6752a1ebd   Venkateswararao Jujjuri (JV)   [fs/9p] Make acce...
334
335
336
337
338
339
340
  	}
  
  	rc = v9fs_parse_options(v9ses, data);
  	if (rc < 0) {
  		retval = rc;
  		goto error;
  	}
ba17674fe   Latchesar Ionkov   9p: attach-per-user
341

fbedadc16   Eric Van Hensbergen   9p: move readn me...
342
  	v9ses->maxdata = v9ses->clnt->msize - P9_IOHDRSZ;
8a0dc95fd   Eric Van Hensbergen   9p: transport API...
343

76381a42e   Aneesh Kumar K.V   fs/9p: Add access...
344
345
346
347
348
349
350
351
352
353
  	if (!v9fs_proto_dotl(v9ses) &&
  	    ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_CLIENT)) {
  		/*
  		 * We support ACCESS_CLIENT only for dotl.
  		 * Fall back to ACCESS_USER
  		 */
  		v9ses->flags &= ~V9FS_ACCESS_MASK;
  		v9ses->flags |= V9FS_ACCESS_USER;
  	}
  	/*FIXME !! */
ba17674fe   Latchesar Ionkov   9p: attach-per-user
354
  	/* for legacy mode, fall back to V9FS_ACCESS_ANY */
9ffaf63e3   Aneesh Kumar K.V   fs/9p: Pass the c...
355
  	if (!(v9fs_proto_dotu(v9ses) || v9fs_proto_dotl(v9ses)) &&
ba17674fe   Latchesar Ionkov   9p: attach-per-user
356
357
358
359
360
361
  		((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) {
  
  		v9ses->flags &= ~V9FS_ACCESS_MASK;
  		v9ses->flags |= V9FS_ACCESS_ANY;
  		v9ses->uid = ~0;
  	}
e782ef710   Venkateswararao Jujjuri (JV)   [fs/9P] Add posix...
362
363
364
365
366
367
368
369
  	if (!v9fs_proto_dotl(v9ses) ||
  		!((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_CLIENT)) {
  		/*
  		 * We support ACL checks on clinet only if the protocol is
  		 * 9P2000.L and access is V9FS_ACCESS_CLIENT.
  		 */
  		v9ses->flags &= ~V9FS_ACL_MASK;
  	}
ba17674fe   Latchesar Ionkov   9p: attach-per-user
370
371
372
  
  	fid = p9_client_attach(v9ses->clnt, NULL, v9ses->uname, ~0,
  							v9ses->aname);
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
373
374
375
  	if (IS_ERR(fid)) {
  		retval = PTR_ERR(fid);
  		fid = NULL;
5d3851530   Joe Perches   9p: Reduce object...
376
377
  		p9_debug(P9_DEBUG_ERROR, "cannot attach
  ");
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
378
  		goto error;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
379
  	}
ba17674fe   Latchesar Ionkov   9p: attach-per-user
380
381
382
383
  	if ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_SINGLE)
  		fid->uid = v9ses->uid;
  	else
  		fid->uid = ~0;
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
384
385
386
387
  #ifdef CONFIG_9P_FSCACHE
  	/* register the session for caching */
  	v9fs_cache_session_get_cookie(v9ses);
  #endif
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
388
  	return fid;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
389

bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
390
  error:
0ed07ddb5   Jens Axboe   9p: add bdi backi...
391
  	bdi_destroy(&v9ses->bdi);
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
392
  	return ERR_PTR(retval);
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
393
394
395
396
397
398
399
400
401
402
  }
  
  /**
   * v9fs_session_close - shutdown a session
   * @v9ses: session information structure
   *
   */
  
  void v9fs_session_close(struct v9fs_session_info *v9ses)
  {
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
403
404
405
  	if (v9ses->clnt) {
  		p9_client_destroy(v9ses->clnt);
  		v9ses->clnt = NULL;
3cf6429a2   Latchesar Ionkov   [PATCH] v9fs: new...
406
  	}
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
407

60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
408
409
410
411
412
413
  #ifdef CONFIG_9P_FSCACHE
  	if (v9ses->fscache) {
  		v9fs_cache_session_put_cookie(v9ses);
  		kfree(v9ses->cachetag);
  	}
  #endif
ba17674fe   Latchesar Ionkov   9p: attach-per-user
414
415
  	__putname(v9ses->uname);
  	__putname(v9ses->aname);
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
416

0ed07ddb5   Jens Axboe   9p: add bdi backi...
417
  	bdi_destroy(&v9ses->bdi);
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
418
419
420
  	spin_lock(&v9fs_sessionlist_lock);
  	list_del(&v9ses->slist);
  	spin_unlock(&v9fs_sessionlist_lock);
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
421
  }
322b329ab   Eric Van Hensbergen   [PATCH] v9fs: Sup...
422
  /**
ee443996a   Eric Van Hensbergen   9p: Documentation...
423
424
425
426
   * v9fs_session_cancel - terminate a session
   * @v9ses: session to terminate
   *
   * mark transport as disconnected and cancel all pending requests.
322b329ab   Eric Van Hensbergen   [PATCH] v9fs: Sup...
427
   */
ee443996a   Eric Van Hensbergen   9p: Documentation...
428

322b329ab   Eric Van Hensbergen   [PATCH] v9fs: Sup...
429
  void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
5d3851530   Joe Perches   9p: Reduce object...
430
431
  	p9_debug(P9_DEBUG_ERROR, "cancel session %p
  ", v9ses);
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
432
  	p9_client_disconnect(v9ses->clnt);
322b329ab   Eric Van Hensbergen   [PATCH] v9fs: Sup...
433
  }
6d96d3ab7   Aneesh Kumar K.V   9p: Make sure we ...
434
435
436
437
438
439
440
441
442
  /**
   * v9fs_session_begin_cancel - Begin terminate of a session
   * @v9ses: session to terminate
   *
   * After this call we don't allow any request other than clunk.
   */
  
  void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses)
  {
5d3851530   Joe Perches   9p: Reduce object...
443
444
  	p9_debug(P9_DEBUG_ERROR, "begin cancel session %p
  ", v9ses);
6d96d3ab7   Aneesh Kumar K.V   9p: Make sure we ...
445
446
  	p9_client_begin_disconnect(v9ses->clnt);
  }
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
447
  extern int v9fs_error_init(void);
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
448
449
450
  static struct kobject *v9fs_kobj;
  
  #ifdef CONFIG_9P_FSCACHE
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
451
  /**
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
   * caches_show - list caches associated with a session
   *
   * Returns the size of buffer written.
   */
  
  static ssize_t caches_show(struct kobject *kobj,
  			   struct kobj_attribute *attr,
  			   char *buf)
  {
  	ssize_t n = 0, count = 0, limit = PAGE_SIZE;
  	struct v9fs_session_info *v9ses;
  
  	spin_lock(&v9fs_sessionlist_lock);
  	list_for_each_entry(v9ses, &v9fs_sessionlist, slist) {
  		if (v9ses->cachetag) {
  			n = snprintf(buf, limit, "%s
  ", v9ses->cachetag);
  			if (n < 0) {
  				count = n;
  				break;
  			}
  
  			count += n;
  			limit -= n;
  		}
  	}
  
  	spin_unlock(&v9fs_sessionlist_lock);
  	return count;
  }
  
  static struct kobj_attribute v9fs_attr_cache = __ATTR_RO(caches);
  #endif /* CONFIG_9P_FSCACHE */
  
  static struct attribute *v9fs_attrs[] = {
  #ifdef CONFIG_9P_FSCACHE
  	&v9fs_attr_cache.attr,
  #endif
  	NULL,
  };
  
  static struct attribute_group v9fs_attr_group = {
  	.attrs = v9fs_attrs,
  };
  
  /**
   * v9fs_sysfs_init - Initialize the v9fs sysfs interface
   *
   */
  
  static int v9fs_sysfs_init(void)
  {
  	v9fs_kobj = kobject_create_and_add("9p", fs_kobj);
  	if (!v9fs_kobj)
  		return -ENOMEM;
  
  	if (sysfs_create_group(v9fs_kobj, &v9fs_attr_group)) {
  		kobject_put(v9fs_kobj);
  		return -ENOMEM;
  	}
  
  	return 0;
  }
  
  /**
   * v9fs_sysfs_cleanup - Unregister the v9fs sysfs interface
   *
   */
  
  static void v9fs_sysfs_cleanup(void)
  {
  	sysfs_remove_group(v9fs_kobj, &v9fs_attr_group);
  	kobject_put(v9fs_kobj);
  }
a78ce05d5   Aneesh Kumar K.V   fs/9p: Add v9fs_i...
526
527
528
529
530
  static void v9fs_inode_init_once(void *foo)
  {
  	struct v9fs_inode *v9inode = (struct v9fs_inode *)foo;
  #ifdef CONFIG_9P_FSCACHE
  	v9inode->fscache = NULL;
a78ce05d5   Aneesh Kumar K.V   fs/9p: Add v9fs_i...
531
  #endif
fd2421f54   Aneesh Kumar K.V   fs/9p: When doing...
532
  	memset(&v9inode->qid, 0, sizeof(v9inode->qid));
a78ce05d5   Aneesh Kumar K.V   fs/9p: Add v9fs_i...
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
  	inode_init_once(&v9inode->vfs_inode);
  }
  
  /**
   * v9fs_init_inode_cache - initialize a cache for 9P
   * Returns 0 on success.
   */
  static int v9fs_init_inode_cache(void)
  {
  	v9fs_inode_cache = kmem_cache_create("v9fs_inode_cache",
  					  sizeof(struct v9fs_inode),
  					  0, (SLAB_RECLAIM_ACCOUNT|
  					      SLAB_MEM_SPREAD),
  					  v9fs_inode_init_once);
  	if (!v9fs_inode_cache)
  		return -ENOMEM;
  
  	return 0;
  }
  
  /**
   * v9fs_destroy_inode_cache - destroy the cache of 9P inode
   *
   */
  static void v9fs_destroy_inode_cache(void)
  {
  	kmem_cache_destroy(v9fs_inode_cache);
  }
  
  static int v9fs_cache_register(void)
  {
  	int ret;
  	ret = v9fs_init_inode_cache();
  	if (ret < 0)
  		return ret;
  #ifdef CONFIG_9P_FSCACHE
  	return fscache_register_netfs(&v9fs_cache_netfs);
  #else
  	return ret;
  #endif
  }
  
  static void v9fs_cache_unregister(void)
  {
  	v9fs_destroy_inode_cache();
  #ifdef CONFIG_9P_FSCACHE
  	fscache_unregister_netfs(&v9fs_cache_netfs);
  #endif
  }
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
582
583
  /**
   * init_v9fs - Initialize module
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
584
585
586
587
588
   *
   */
  
  static int __init init_v9fs(void)
  {
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
589
  	int err;
5d3851530   Joe Perches   9p: Reduce object...
590
591
  	pr_info("Installing v9fs 9p2000 file system support
  ");
a80d923e1   Eric Van Hensbergen   9p: Make transpor...
592
  	/* TODO: Setup list of registered trasnport modules */
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
593
594
  	err = register_filesystem(&v9fs_fs_type);
  	if (err < 0) {
5d3851530   Joe Perches   9p: Reduce object...
595
596
  		pr_err("Failed to register filesystem
  ");
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
597
598
599
600
601
  		return err;
  	}
  
  	err = v9fs_cache_register();
  	if (err < 0) {
5d3851530   Joe Perches   9p: Reduce object...
602
603
  		pr_err("Failed to register v9fs for caching
  ");
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
604
605
606
607
608
  		goto out_fs_unreg;
  	}
  
  	err = v9fs_sysfs_init();
  	if (err < 0) {
5d3851530   Joe Perches   9p: Reduce object...
609
610
  		pr_err("Failed to register with sysfs
  ");
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
611
612
613
614
615
616
617
618
619
620
621
622
  		goto out_sysfs_cleanup;
  	}
  
  	return 0;
  
  out_sysfs_cleanup:
  	v9fs_sysfs_cleanup();
  
  out_fs_unreg:
  	unregister_filesystem(&v9fs_fs_type);
  
  	return err;
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
623
624
625
  }
  
  /**
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
626
   * exit_v9fs - shutdown module
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
627
628
629
630
631
   *
   */
  
  static void __exit exit_v9fs(void)
  {
60e78d2c9   Abhishek Kulkarni   9p: Add fscache s...
632
633
  	v9fs_sysfs_cleanup();
  	v9fs_cache_unregister();
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
634
635
636
637
638
  	unregister_filesystem(&v9fs_fs_type);
  }
  
  module_init(init_v9fs)
  module_exit(exit_v9fs)
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
639
  MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
9e82cf6a8   Eric Van Hensbergen   [PATCH] v9fs: VFS...
640
641
642
  MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
  MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
  MODULE_LICENSE("GPL");