aboutsummaryrefslogtreecommitdiffstats
path: root/fs/9p/v9fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/9p/v9fs.c')
-rw-r--r--fs/9p/v9fs.c295
1 files changed, 65 insertions, 230 deletions
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index 6ad6f192b6e4..0a7068e30ecb 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -29,16 +29,12 @@
29#include <linux/sched.h> 29#include <linux/sched.h>
30#include <linux/parser.h> 30#include <linux/parser.h>
31#include <linux/idr.h> 31#include <linux/idr.h>
32 32#include <net/9p/9p.h>
33#include "debug.h" 33#include <net/9p/transport.h>
34#include <net/9p/conn.h>
35#include <net/9p/client.h>
34#include "v9fs.h" 36#include "v9fs.h"
35#include "9p.h"
36#include "v9fs_vfs.h" 37#include "v9fs_vfs.h"
37#include "transport.h"
38#include "mux.h"
39
40/* TODO: sysfs or debugfs interface */
41int v9fs_debug_level = 0; /* feature-rific global debug level */
42 38
43/* 39/*
44 * Option Parsing (code inspired by NFS code) 40 * Option Parsing (code inspired by NFS code)
@@ -47,12 +43,12 @@ int v9fs_debug_level = 0; /* feature-rific global debug level */
47 43
48enum { 44enum {
49 /* Options that take integer arguments */ 45 /* Options that take integer arguments */
50 Opt_port, Opt_msize, Opt_uid, Opt_gid, Opt_afid, Opt_debug, 46 Opt_debug, Opt_port, Opt_msize, Opt_uid, Opt_gid, Opt_afid,
51 Opt_rfdno, Opt_wfdno, 47 Opt_rfdno, Opt_wfdno,
52 /* String options */ 48 /* String options */
53 Opt_uname, Opt_remotename, 49 Opt_uname, Opt_remotename,
54 /* Options that take no arguments */ 50 /* Options that take no arguments */
55 Opt_legacy, Opt_nodevmap, Opt_unix, Opt_tcp, Opt_fd, 51 Opt_legacy, Opt_nodevmap, Opt_unix, Opt_tcp, Opt_fd, Opt_pci,
56 /* Cache options */ 52 /* Cache options */
57 Opt_cache_loose, 53 Opt_cache_loose,
58 /* Error token */ 54 /* Error token */
@@ -60,6 +56,7 @@ enum {
60}; 56};
61 57
62static match_table_t tokens = { 58static match_table_t tokens = {
59 {Opt_debug, "debug=%x"},
63 {Opt_port, "port=%u"}, 60 {Opt_port, "port=%u"},
64 {Opt_msize, "msize=%u"}, 61 {Opt_msize, "msize=%u"},
65 {Opt_uid, "uid=%u"}, 62 {Opt_uid, "uid=%u"},
@@ -67,12 +64,14 @@ static match_table_t tokens = {
67 {Opt_afid, "afid=%u"}, 64 {Opt_afid, "afid=%u"},
68 {Opt_rfdno, "rfdno=%u"}, 65 {Opt_rfdno, "rfdno=%u"},
69 {Opt_wfdno, "wfdno=%u"}, 66 {Opt_wfdno, "wfdno=%u"},
70 {Opt_debug, "debug=%x"},
71 {Opt_uname, "uname=%s"}, 67 {Opt_uname, "uname=%s"},
72 {Opt_remotename, "aname=%s"}, 68 {Opt_remotename, "aname=%s"},
73 {Opt_unix, "proto=unix"}, 69 {Opt_unix, "proto=unix"},
74 {Opt_tcp, "proto=tcp"}, 70 {Opt_tcp, "proto=tcp"},
75 {Opt_fd, "proto=fd"}, 71 {Opt_fd, "proto=fd"},
72#ifdef CONFIG_PCI_9P
73 {Opt_pci, "proto=pci"},
74#endif
76 {Opt_tcp, "tcp"}, 75 {Opt_tcp, "tcp"},
77 {Opt_unix, "unix"}, 76 {Opt_unix, "unix"},
78 {Opt_fd, "fd"}, 77 {Opt_fd, "fd"},
@@ -83,6 +82,8 @@ static match_table_t tokens = {
83 {Opt_err, NULL} 82 {Opt_err, NULL}
84}; 83};
85 84
85extern struct p9_transport *p9pci_trans_create(void);
86
86/* 87/*
87 * Parse option string. 88 * Parse option string.
88 */ 89 */
@@ -122,12 +123,18 @@ static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses)
122 token = match_token(p, tokens, args); 123 token = match_token(p, tokens, args);
123 if (token < Opt_uname) { 124 if (token < Opt_uname) {
124 if ((ret = match_int(&args[0], &option)) < 0) { 125 if ((ret = match_int(&args[0], &option)) < 0) {
125 dprintk(DEBUG_ERROR, 126 P9_DPRINTK(P9_DEBUG_ERROR,
126 "integer field, but no integer?\n"); 127 "integer field, but no integer?\n");
127 continue; 128 continue;
128 } 129 }
129 } 130 }
130 switch (token) { 131 switch (token) {
132 case Opt_debug:
133 v9ses->debug = option;
134#ifdef CONFIG_NET_9P_DEBUG
135 p9_debug_level = option;
136#endif
137 break;
131 case Opt_port: 138 case Opt_port:
132 v9ses->port = option; 139 v9ses->port = option;
133 break; 140 break;
@@ -149,15 +156,15 @@ static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses)
149 case Opt_wfdno: 156 case Opt_wfdno:
150 v9ses->wfdno = option; 157 v9ses->wfdno = option;
151 break; 158 break;
152 case Opt_debug:
153 v9ses->debug = option;
154 break;
155 case Opt_tcp: 159 case Opt_tcp:
156 v9ses->proto = PROTO_TCP; 160 v9ses->proto = PROTO_TCP;
157 break; 161 break;
158 case Opt_unix: 162 case Opt_unix:
159 v9ses->proto = PROTO_UNIX; 163 v9ses->proto = PROTO_UNIX;
160 break; 164 break;
165 case Opt_pci:
166 v9ses->proto = PROTO_PCI;
167 break;
161 case Opt_fd: 168 case Opt_fd:
162 v9ses->proto = PROTO_FD; 169 v9ses->proto = PROTO_FD;
163 break; 170 break;
@@ -183,82 +190,6 @@ static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses)
183} 190}
184 191
185/** 192/**
186 * v9fs_inode2v9ses - safely extract v9fs session info from super block
187 * @inode: inode to extract information from
188 *
189 * Paranoid function to extract v9ses information from superblock,
190 * if anything is missing it will report an error.
191 *
192 */
193
194struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)
195{
196 return (inode->i_sb->s_fs_info);
197}
198
199/**
200 * v9fs_get_idpool - allocate numeric id from pool
201 * @p - pool to allocate from
202 *
203 * XXX - This seems to be an awful generic function, should it be in idr.c with
204 * the lock included in struct idr?
205 */
206
207int v9fs_get_idpool(struct v9fs_idpool *p)
208{
209 int i = 0;
210 int error;
211
212retry:
213 if (idr_pre_get(&p->pool, GFP_KERNEL) == 0)
214 return 0;
215
216 if (down_interruptible(&p->lock) == -EINTR) {
217 eprintk(KERN_WARNING, "Interrupted while locking\n");
218 return -1;
219 }
220
221 /* no need to store exactly p, we just need something non-null */
222 error = idr_get_new(&p->pool, p, &i);
223 up(&p->lock);
224
225 if (error == -EAGAIN)
226 goto retry;
227 else if (error)
228 return -1;
229
230 return i;
231}
232
233/**
234 * v9fs_put_idpool - release numeric id from pool
235 * @p - pool to allocate from
236 *
237 * XXX - This seems to be an awful generic function, should it be in idr.c with
238 * the lock included in struct idr?
239 */
240
241void v9fs_put_idpool(int id, struct v9fs_idpool *p)
242{
243 if (down_interruptible(&p->lock) == -EINTR) {
244 eprintk(KERN_WARNING, "Interrupted while locking\n");
245 return;
246 }
247 idr_remove(&p->pool, id);
248 up(&p->lock);
249}
250
251/**
252 * v9fs_check_idpool - check if the specified id is available
253 * @id - id to check
254 * @p - pool
255 */
256int v9fs_check_idpool(int id, struct v9fs_idpool *p)
257{
258 return idr_find(&p->pool, id) != NULL;
259}
260
261/**
262 * v9fs_session_init - initialize session 193 * v9fs_session_init - initialize session
263 * @v9ses: session information structure 194 * @v9ses: session information structure
264 * @dev_name: device being mounted 195 * @dev_name: device being mounted
@@ -266,25 +197,21 @@ int v9fs_check_idpool(int id, struct v9fs_idpool *p)
266 * 197 *
267 */ 198 */
268 199
269int 200struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
270v9fs_session_init(struct v9fs_session_info *v9ses,
271 const char *dev_name, char *data) 201 const char *dev_name, char *data)
272{ 202{
273 struct v9fs_fcall *fcall = NULL;
274 struct v9fs_transport *trans_proto;
275 int n = 0;
276 int newfid = -1;
277 int retval = -EINVAL; 203 int retval = -EINVAL;
278 struct v9fs_str *version; 204 struct p9_transport *trans;
205 struct p9_fid *fid;
279 206
280 v9ses->name = __getname(); 207 v9ses->name = __getname();
281 if (!v9ses->name) 208 if (!v9ses->name)
282 return -ENOMEM; 209 return ERR_PTR(-ENOMEM);
283 210
284 v9ses->remotename = __getname(); 211 v9ses->remotename = __getname();
285 if (!v9ses->remotename) { 212 if (!v9ses->remotename) {
286 __putname(v9ses->name); 213 __putname(v9ses->name);
287 return -ENOMEM; 214 return ERR_PTR(-ENOMEM);
288 } 215 }
289 216
290 strcpy(v9ses->name, V9FS_DEFUSER); 217 strcpy(v9ses->name, V9FS_DEFUSER);
@@ -292,130 +219,60 @@ v9fs_session_init(struct v9fs_session_info *v9ses,
292 219
293 v9fs_parse_options(data, v9ses); 220 v9fs_parse_options(data, v9ses);
294 221
295 /* set global debug level */
296 v9fs_debug_level = v9ses->debug;
297
298 /* id pools that are session-dependent: fids and tags */
299 idr_init(&v9ses->fidpool.pool);
300 init_MUTEX(&v9ses->fidpool.lock);
301
302 switch (v9ses->proto) { 222 switch (v9ses->proto) {
303 case PROTO_TCP: 223 case PROTO_TCP:
304 trans_proto = &v9fs_trans_tcp; 224 trans = p9_trans_create_tcp(dev_name, v9ses->port);
305 break; 225 break;
306 case PROTO_UNIX: 226 case PROTO_UNIX:
307 trans_proto = &v9fs_trans_unix; 227 trans = p9_trans_create_unix(dev_name);
308 *v9ses->remotename = 0; 228 *v9ses->remotename = 0;
309 break; 229 break;
310 case PROTO_FD: 230 case PROTO_FD:
311 trans_proto = &v9fs_trans_fd; 231 trans = p9_trans_create_fd(v9ses->rfdno, v9ses->wfdno);
312 *v9ses->remotename = 0; 232 *v9ses->remotename = 0;
313 break; 233 break;
234#ifdef CONFIG_PCI_9P
235 case PROTO_PCI:
236 trans = p9pci_trans_create();
237 *v9ses->remotename = 0;
238 break;
239#endif
314 default: 240 default:
315 printk(KERN_ERR "v9fs: Bad mount protocol %d\n", v9ses->proto); 241 printk(KERN_ERR "v9fs: Bad mount protocol %d\n", v9ses->proto);
316 retval = -ENOPROTOOPT; 242 retval = -ENOPROTOOPT;
317 goto SessCleanUp; 243 goto error;
318 }; 244 };
319 245
320 v9ses->transport = kmalloc(sizeof(*v9ses->transport), GFP_KERNEL); 246 if (IS_ERR(trans)) {
321 if (!v9ses->transport) { 247 retval = PTR_ERR(trans);
322 retval = -ENOMEM; 248 trans = NULL;
323 goto SessCleanUp; 249 goto error;
324 } 250 }
325 251
326 memmove(v9ses->transport, trans_proto, sizeof(*v9ses->transport)); 252 v9ses->clnt = p9_client_create(trans, v9ses->maxdata + P9_IOHDRSZ,
253 v9ses->extended);
327 254
328 if ((retval = v9ses->transport->init(v9ses, dev_name, data)) < 0) { 255 if (IS_ERR(v9ses->clnt)) {
329 eprintk(KERN_ERR, "problem initializing transport\n"); 256 retval = PTR_ERR(v9ses->clnt);
330 goto SessCleanUp; 257 v9ses->clnt = NULL;
258 P9_DPRINTK(P9_DEBUG_ERROR, "problem initializing 9p client\n");
259 goto error;
331 } 260 }
332 261
333 v9ses->inprogress = 0; 262 fid = p9_client_attach(v9ses->clnt, NULL, v9ses->name,
334 v9ses->shutdown = 0; 263 v9ses->remotename);
335 v9ses->session_hung = 0; 264 if (IS_ERR(fid)) {
336 265 retval = PTR_ERR(fid);
337 v9ses->mux = v9fs_mux_init(v9ses->transport, v9ses->maxdata + V9FS_IOHDRSZ, 266 fid = NULL;
338 &v9ses->extended); 267 P9_DPRINTK(P9_DEBUG_ERROR, "cannot attach\n");
339 268 goto error;
340 if (IS_ERR(v9ses->mux)) {
341 retval = PTR_ERR(v9ses->mux);
342 v9ses->mux = NULL;
343 dprintk(DEBUG_ERROR, "problem initializing mux\n");
344 goto SessCleanUp;
345 } 269 }
346 270
347 if (v9ses->afid == ~0) { 271 return fid;
348 if (v9ses->extended)
349 retval =
350 v9fs_t_version(v9ses, v9ses->maxdata, "9P2000.u",
351 &fcall);
352 else
353 retval = v9fs_t_version(v9ses, v9ses->maxdata, "9P2000",
354 &fcall);
355
356 if (retval < 0) {
357 dprintk(DEBUG_ERROR, "v9fs_t_version failed\n");
358 goto FreeFcall;
359 }
360
361 version = &fcall->params.rversion.version;
362 if (version->len==8 && !memcmp(version->str, "9P2000.u", 8)) {
363 dprintk(DEBUG_9P, "9P2000 UNIX extensions enabled\n");
364 v9ses->extended = 1;
365 } else if (version->len==6 && !memcmp(version->str, "9P2000", 6)) {
366 dprintk(DEBUG_9P, "9P2000 legacy mode enabled\n");
367 v9ses->extended = 0;
368 } else {
369 retval = -EREMOTEIO;
370 goto FreeFcall;
371 }
372 272
373 n = fcall->params.rversion.msize; 273error:
374 kfree(fcall);
375
376 if (n < v9ses->maxdata)
377 v9ses->maxdata = n;
378 }
379
380 newfid = v9fs_get_idpool(&v9ses->fidpool);
381 if (newfid < 0) {
382 eprintk(KERN_WARNING, "couldn't allocate FID\n");
383 retval = -ENOMEM;
384 goto SessCleanUp;
385 }
386 /* it is a little bit ugly, but we have to prevent newfid */
387 /* being the same as afid, so if it is, get a new fid */
388 if (v9ses->afid != ~0 && newfid == v9ses->afid) {
389 newfid = v9fs_get_idpool(&v9ses->fidpool);
390 if (newfid < 0) {
391 eprintk(KERN_WARNING, "couldn't allocate FID\n");
392 retval = -ENOMEM;
393 goto SessCleanUp;
394 }
395 }
396
397 if ((retval =
398 v9fs_t_attach(v9ses, v9ses->name, v9ses->remotename, newfid,
399 v9ses->afid, NULL))
400 < 0) {
401 dprintk(DEBUG_ERROR, "cannot attach\n");
402 goto SessCleanUp;
403 }
404
405 if (v9ses->afid != ~0) {
406 dprintk(DEBUG_ERROR, "afid not equal to ~0\n");
407 if (v9fs_t_clunk(v9ses, v9ses->afid))
408 dprintk(DEBUG_ERROR, "clunk failed\n");
409 }
410
411 return newfid;
412
413 FreeFcall:
414 kfree(fcall);
415
416 SessCleanUp:
417 v9fs_session_close(v9ses); 274 v9fs_session_close(v9ses);
418 return retval; 275 return ERR_PTR(retval);
419} 276}
420 277
421/** 278/**
@@ -426,15 +283,9 @@ v9fs_session_init(struct v9fs_session_info *v9ses,
426 283
427void v9fs_session_close(struct v9fs_session_info *v9ses) 284void v9fs_session_close(struct v9fs_session_info *v9ses)
428{ 285{
429 if (v9ses->mux) { 286 if (v9ses->clnt) {
430 v9fs_mux_destroy(v9ses->mux); 287 p9_client_destroy(v9ses->clnt);
431 v9ses->mux = NULL; 288 v9ses->clnt = NULL;
432 }
433
434 if (v9ses->transport) {
435 v9ses->transport->close(v9ses->transport);
436 kfree(v9ses->transport);
437 v9ses->transport = NULL;
438 } 289 }
439 290
440 __putname(v9ses->name); 291 __putname(v9ses->name);
@@ -446,9 +297,8 @@ void v9fs_session_close(struct v9fs_session_info *v9ses)
446 * and cancel all pending requests. 297 * and cancel all pending requests.
447 */ 298 */
448void v9fs_session_cancel(struct v9fs_session_info *v9ses) { 299void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
449 dprintk(DEBUG_ERROR, "cancel session %p\n", v9ses); 300 P9_DPRINTK(P9_DEBUG_ERROR, "cancel session %p\n", v9ses);
450 v9ses->transport->status = Disconnected; 301 p9_client_disconnect(v9ses->clnt);
451 v9fs_mux_cancel(v9ses->mux, -EIO);
452} 302}
453 303
454extern int v9fs_error_init(void); 304extern int v9fs_error_init(void);
@@ -460,24 +310,9 @@ extern int v9fs_error_init(void);
460 310
461static int __init init_v9fs(void) 311static int __init init_v9fs(void)
462{ 312{
463 int ret;
464
465 v9fs_error_init();
466
467 printk(KERN_INFO "Installing v9fs 9p2000 file system support\n"); 313 printk(KERN_INFO "Installing v9fs 9p2000 file system support\n");
468 314
469 ret = v9fs_mux_global_init(); 315 return register_filesystem(&v9fs_fs_type);
470 if (ret) {
471 printk(KERN_WARNING "v9fs: starting mux failed\n");
472 return ret;
473 }
474 ret = register_filesystem(&v9fs_fs_type);
475 if (ret) {
476 printk(KERN_WARNING "v9fs: registering file system failed\n");
477 v9fs_mux_global_exit();
478 }
479
480 return ret;
481} 316}
482 317
483/** 318/**
@@ -487,13 +322,13 @@ static int __init init_v9fs(void)
487 322
488static void __exit exit_v9fs(void) 323static void __exit exit_v9fs(void)
489{ 324{
490 v9fs_mux_global_exit();
491 unregister_filesystem(&v9fs_fs_type); 325 unregister_filesystem(&v9fs_fs_type);
492} 326}
493 327
494module_init(init_v9fs) 328module_init(init_v9fs)
495module_exit(exit_v9fs) 329module_exit(exit_v9fs)
496 330
331MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
497MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>"); 332MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
498MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>"); 333MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
499MODULE_LICENSE("GPL"); 334MODULE_LICENSE("GPL");