xref: /openbmc/linux/fs/9p/v9fs.c (revision 2fa5ebe3)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *  This file contains functions assisting in mapping VFS to 9P2000
4  *
5  *  Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
6  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
7  */
8 
9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 
11 #include <linux/module.h>
12 #include <linux/errno.h>
13 #include <linux/fs.h>
14 #include <linux/sched.h>
15 #include <linux/cred.h>
16 #include <linux/parser.h>
17 #include <linux/slab.h>
18 #include <linux/seq_file.h>
19 #include <net/9p/9p.h>
20 #include <net/9p/client.h>
21 #include <net/9p/transport.h>
22 #include "v9fs.h"
23 #include "v9fs_vfs.h"
24 #include "cache.h"
25 
26 static DEFINE_SPINLOCK(v9fs_sessionlist_lock);
27 static LIST_HEAD(v9fs_sessionlist);
28 struct kmem_cache *v9fs_inode_cache;
29 
30 /*
31  * Option Parsing (code inspired by NFS code)
32  *  NOTE: each transport will parse its own options
33  */
34 
35 enum {
36 	/* Options that take integer arguments */
37 	Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid,
38 	/* String options */
39 	Opt_uname, Opt_remotename, Opt_cache, Opt_cachetag,
40 	/* Options that take no arguments */
41 	Opt_nodevmap,
42 	/* Cache options */
43 	Opt_cache_loose, Opt_fscache, Opt_mmap,
44 	/* Access options */
45 	Opt_access, Opt_posixacl,
46 	/* Lock timeout option */
47 	Opt_locktimeout,
48 	/* Error token */
49 	Opt_err
50 };
51 
52 static const match_table_t tokens = {
53 	{Opt_debug, "debug=%x"},
54 	{Opt_dfltuid, "dfltuid=%u"},
55 	{Opt_dfltgid, "dfltgid=%u"},
56 	{Opt_afid, "afid=%u"},
57 	{Opt_uname, "uname=%s"},
58 	{Opt_remotename, "aname=%s"},
59 	{Opt_nodevmap, "nodevmap"},
60 	{Opt_cache, "cache=%s"},
61 	{Opt_cache_loose, "loose"},
62 	{Opt_fscache, "fscache"},
63 	{Opt_mmap, "mmap"},
64 	{Opt_cachetag, "cachetag=%s"},
65 	{Opt_access, "access=%s"},
66 	{Opt_posixacl, "posixacl"},
67 	{Opt_locktimeout, "locktimeout=%u"},
68 	{Opt_err, NULL}
69 };
70 
71 static const char *const v9fs_cache_modes[nr__p9_cache_modes] = {
72 	[CACHE_NONE]	= "none",
73 	[CACHE_MMAP]	= "mmap",
74 	[CACHE_LOOSE]	= "loose",
75 	[CACHE_FSCACHE]	= "fscache",
76 };
77 
78 /* Interpret mount options for cache mode */
79 static int get_cache_mode(char *s)
80 {
81 	int version = -EINVAL;
82 
83 	if (!strcmp(s, "loose")) {
84 		version = CACHE_LOOSE;
85 		p9_debug(P9_DEBUG_9P, "Cache mode: loose\n");
86 	} else if (!strcmp(s, "fscache")) {
87 		version = CACHE_FSCACHE;
88 		p9_debug(P9_DEBUG_9P, "Cache mode: fscache\n");
89 	} else if (!strcmp(s, "mmap")) {
90 		version = CACHE_MMAP;
91 		p9_debug(P9_DEBUG_9P, "Cache mode: mmap\n");
92 	} else if (!strcmp(s, "none")) {
93 		version = CACHE_NONE;
94 		p9_debug(P9_DEBUG_9P, "Cache mode: none\n");
95 	} else
96 		pr_info("Unknown Cache mode %s\n", s);
97 	return version;
98 }
99 
100 /*
101  * Display the mount options in /proc/mounts.
102  */
103 int v9fs_show_options(struct seq_file *m, struct dentry *root)
104 {
105 	struct v9fs_session_info *v9ses = root->d_sb->s_fs_info;
106 
107 	if (v9ses->debug)
108 		seq_printf(m, ",debug=%x", v9ses->debug);
109 	if (!uid_eq(v9ses->dfltuid, V9FS_DEFUID))
110 		seq_printf(m, ",dfltuid=%u",
111 			   from_kuid_munged(&init_user_ns, v9ses->dfltuid));
112 	if (!gid_eq(v9ses->dfltgid, V9FS_DEFGID))
113 		seq_printf(m, ",dfltgid=%u",
114 			   from_kgid_munged(&init_user_ns, v9ses->dfltgid));
115 	if (v9ses->afid != ~0)
116 		seq_printf(m, ",afid=%u", v9ses->afid);
117 	if (strcmp(v9ses->uname, V9FS_DEFUSER) != 0)
118 		seq_printf(m, ",uname=%s", v9ses->uname);
119 	if (strcmp(v9ses->aname, V9FS_DEFANAME) != 0)
120 		seq_printf(m, ",aname=%s", v9ses->aname);
121 	if (v9ses->nodev)
122 		seq_puts(m, ",nodevmap");
123 	if (v9ses->cache)
124 		seq_printf(m, ",%s", v9fs_cache_modes[v9ses->cache]);
125 #ifdef CONFIG_9P_FSCACHE
126 	if (v9ses->cachetag && v9ses->cache == CACHE_FSCACHE)
127 		seq_printf(m, ",cachetag=%s", v9ses->cachetag);
128 #endif
129 
130 	switch (v9ses->flags & V9FS_ACCESS_MASK) {
131 	case V9FS_ACCESS_USER:
132 		seq_puts(m, ",access=user");
133 		break;
134 	case V9FS_ACCESS_ANY:
135 		seq_puts(m, ",access=any");
136 		break;
137 	case V9FS_ACCESS_CLIENT:
138 		seq_puts(m, ",access=client");
139 		break;
140 	case V9FS_ACCESS_SINGLE:
141 		seq_printf(m, ",access=%u",
142 			   from_kuid_munged(&init_user_ns, v9ses->uid));
143 		break;
144 	}
145 
146 	if (v9ses->flags & V9FS_POSIX_ACL)
147 		seq_puts(m, ",posixacl");
148 
149 	return p9_show_client_options(m, v9ses->clnt);
150 }
151 
152 /**
153  * v9fs_parse_options - parse mount options into session structure
154  * @v9ses: existing v9fs session information
155  * @opts: The mount option string
156  *
157  * Return 0 upon success, -ERRNO upon failure.
158  */
159 
160 static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
161 {
162 	char *options, *tmp_options;
163 	substring_t args[MAX_OPT_ARGS];
164 	char *p;
165 	int option = 0;
166 	char *s;
167 	int ret = 0;
168 
169 	/* setup defaults */
170 	v9ses->afid = ~0;
171 	v9ses->debug = 0;
172 	v9ses->cache = CACHE_NONE;
173 #ifdef CONFIG_9P_FSCACHE
174 	v9ses->cachetag = NULL;
175 #endif
176 	v9ses->session_lock_timeout = P9_LOCK_TIMEOUT;
177 
178 	if (!opts)
179 		return 0;
180 
181 	tmp_options = kstrdup(opts, GFP_KERNEL);
182 	if (!tmp_options) {
183 		ret = -ENOMEM;
184 		goto fail_option_alloc;
185 	}
186 	options = tmp_options;
187 
188 	while ((p = strsep(&options, ",")) != NULL) {
189 		int token, r;
190 
191 		if (!*p)
192 			continue;
193 
194 		token = match_token(p, tokens, args);
195 		switch (token) {
196 		case Opt_debug:
197 			r = match_int(&args[0], &option);
198 			if (r < 0) {
199 				p9_debug(P9_DEBUG_ERROR,
200 					 "integer field, but no integer?\n");
201 				ret = r;
202 			} else {
203 				v9ses->debug = option;
204 #ifdef CONFIG_NET_9P_DEBUG
205 				p9_debug_level = option;
206 #endif
207 			}
208 			break;
209 
210 		case Opt_dfltuid:
211 			r = match_int(&args[0], &option);
212 			if (r < 0) {
213 				p9_debug(P9_DEBUG_ERROR,
214 					 "integer field, but no integer?\n");
215 				ret = r;
216 				continue;
217 			}
218 			v9ses->dfltuid = make_kuid(current_user_ns(), option);
219 			if (!uid_valid(v9ses->dfltuid)) {
220 				p9_debug(P9_DEBUG_ERROR,
221 					 "uid field, but not a uid?\n");
222 				ret = -EINVAL;
223 			}
224 			break;
225 		case Opt_dfltgid:
226 			r = match_int(&args[0], &option);
227 			if (r < 0) {
228 				p9_debug(P9_DEBUG_ERROR,
229 					 "integer field, but no integer?\n");
230 				ret = r;
231 				continue;
232 			}
233 			v9ses->dfltgid = make_kgid(current_user_ns(), option);
234 			if (!gid_valid(v9ses->dfltgid)) {
235 				p9_debug(P9_DEBUG_ERROR,
236 					 "gid field, but not a gid?\n");
237 				ret = -EINVAL;
238 			}
239 			break;
240 		case Opt_afid:
241 			r = match_int(&args[0], &option);
242 			if (r < 0) {
243 				p9_debug(P9_DEBUG_ERROR,
244 					 "integer field, but no integer?\n");
245 				ret = r;
246 			} else {
247 				v9ses->afid = option;
248 			}
249 			break;
250 		case Opt_uname:
251 			kfree(v9ses->uname);
252 			v9ses->uname = match_strdup(&args[0]);
253 			if (!v9ses->uname) {
254 				ret = -ENOMEM;
255 				goto free_and_return;
256 			}
257 			break;
258 		case Opt_remotename:
259 			kfree(v9ses->aname);
260 			v9ses->aname = match_strdup(&args[0]);
261 			if (!v9ses->aname) {
262 				ret = -ENOMEM;
263 				goto free_and_return;
264 			}
265 			break;
266 		case Opt_nodevmap:
267 			v9ses->nodev = 1;
268 			break;
269 		case Opt_cache_loose:
270 			v9ses->cache = CACHE_LOOSE;
271 			break;
272 		case Opt_fscache:
273 			v9ses->cache = CACHE_FSCACHE;
274 			break;
275 		case Opt_mmap:
276 			v9ses->cache = CACHE_MMAP;
277 			break;
278 		case Opt_cachetag:
279 #ifdef CONFIG_9P_FSCACHE
280 			kfree(v9ses->cachetag);
281 			v9ses->cachetag = match_strdup(&args[0]);
282 			if (!v9ses->cachetag) {
283 				ret = -ENOMEM;
284 				goto free_and_return;
285 			}
286 #endif
287 			break;
288 		case Opt_cache:
289 			s = match_strdup(&args[0]);
290 			if (!s) {
291 				ret = -ENOMEM;
292 				p9_debug(P9_DEBUG_ERROR,
293 					 "problem allocating copy of cache arg\n");
294 				goto free_and_return;
295 			}
296 			r = get_cache_mode(s);
297 			if (r < 0)
298 				ret = r;
299 			else
300 				v9ses->cache = r;
301 
302 			kfree(s);
303 			break;
304 
305 		case Opt_access:
306 			s = match_strdup(&args[0]);
307 			if (!s) {
308 				ret = -ENOMEM;
309 				p9_debug(P9_DEBUG_ERROR,
310 					 "problem allocating copy of access arg\n");
311 				goto free_and_return;
312 			}
313 
314 			v9ses->flags &= ~V9FS_ACCESS_MASK;
315 			if (strcmp(s, "user") == 0)
316 				v9ses->flags |= V9FS_ACCESS_USER;
317 			else if (strcmp(s, "any") == 0)
318 				v9ses->flags |= V9FS_ACCESS_ANY;
319 			else if (strcmp(s, "client") == 0) {
320 				v9ses->flags |= V9FS_ACCESS_CLIENT;
321 			} else {
322 				uid_t uid;
323 
324 				v9ses->flags |= V9FS_ACCESS_SINGLE;
325 				r = kstrtouint(s, 10, &uid);
326 				if (r) {
327 					ret = r;
328 					pr_info("Unknown access argument %s: %d\n",
329 						s, r);
330 					kfree(s);
331 					continue;
332 				}
333 				v9ses->uid = make_kuid(current_user_ns(), uid);
334 				if (!uid_valid(v9ses->uid)) {
335 					ret = -EINVAL;
336 					pr_info("Unknown uid %s\n", s);
337 				}
338 			}
339 
340 			kfree(s);
341 			break;
342 
343 		case Opt_posixacl:
344 #ifdef CONFIG_9P_FS_POSIX_ACL
345 			v9ses->flags |= V9FS_POSIX_ACL;
346 #else
347 			p9_debug(P9_DEBUG_ERROR,
348 				 "Not defined CONFIG_9P_FS_POSIX_ACL. Ignoring posixacl option\n");
349 #endif
350 			break;
351 
352 		case Opt_locktimeout:
353 			r = match_int(&args[0], &option);
354 			if (r < 0) {
355 				p9_debug(P9_DEBUG_ERROR,
356 					 "integer field, but no integer?\n");
357 				ret = r;
358 				continue;
359 			}
360 			if (option < 1) {
361 				p9_debug(P9_DEBUG_ERROR,
362 					 "locktimeout must be a greater than zero integer.\n");
363 				ret = -EINVAL;
364 				continue;
365 			}
366 			v9ses->session_lock_timeout = (long)option * HZ;
367 			break;
368 
369 		default:
370 			continue;
371 		}
372 	}
373 
374 free_and_return:
375 	kfree(tmp_options);
376 fail_option_alloc:
377 	return ret;
378 }
379 
380 /**
381  * v9fs_session_init - initialize session
382  * @v9ses: session information structure
383  * @dev_name: device being mounted
384  * @data: options
385  *
386  */
387 
388 struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
389 		  const char *dev_name, char *data)
390 {
391 	struct p9_fid *fid;
392 	int rc = -ENOMEM;
393 
394 	v9ses->uname = kstrdup(V9FS_DEFUSER, GFP_KERNEL);
395 	if (!v9ses->uname)
396 		goto err_names;
397 
398 	v9ses->aname = kstrdup(V9FS_DEFANAME, GFP_KERNEL);
399 	if (!v9ses->aname)
400 		goto err_names;
401 	init_rwsem(&v9ses->rename_sem);
402 
403 	v9ses->uid = INVALID_UID;
404 	v9ses->dfltuid = V9FS_DEFUID;
405 	v9ses->dfltgid = V9FS_DEFGID;
406 
407 	v9ses->clnt = p9_client_create(dev_name, data);
408 	if (IS_ERR(v9ses->clnt)) {
409 		rc = PTR_ERR(v9ses->clnt);
410 		p9_debug(P9_DEBUG_ERROR, "problem initializing 9p client\n");
411 		goto err_names;
412 	}
413 
414 	v9ses->flags = V9FS_ACCESS_USER;
415 
416 	if (p9_is_proto_dotl(v9ses->clnt)) {
417 		v9ses->flags = V9FS_ACCESS_CLIENT;
418 		v9ses->flags |= V9FS_PROTO_2000L;
419 	} else if (p9_is_proto_dotu(v9ses->clnt)) {
420 		v9ses->flags |= V9FS_PROTO_2000U;
421 	}
422 
423 	rc = v9fs_parse_options(v9ses, data);
424 	if (rc < 0)
425 		goto err_clnt;
426 
427 	v9ses->maxdata = v9ses->clnt->msize - P9_IOHDRSZ;
428 
429 	if (!v9fs_proto_dotl(v9ses) &&
430 	    ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_CLIENT)) {
431 		/*
432 		 * We support ACCESS_CLIENT only for dotl.
433 		 * Fall back to ACCESS_USER
434 		 */
435 		v9ses->flags &= ~V9FS_ACCESS_MASK;
436 		v9ses->flags |= V9FS_ACCESS_USER;
437 	}
438 	/*FIXME !! */
439 	/* for legacy mode, fall back to V9FS_ACCESS_ANY */
440 	if (!(v9fs_proto_dotu(v9ses) || v9fs_proto_dotl(v9ses)) &&
441 		((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) {
442 
443 		v9ses->flags &= ~V9FS_ACCESS_MASK;
444 		v9ses->flags |= V9FS_ACCESS_ANY;
445 		v9ses->uid = INVALID_UID;
446 	}
447 	if (!v9fs_proto_dotl(v9ses) ||
448 		!((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_CLIENT)) {
449 		/*
450 		 * We support ACL checks on clinet only if the protocol is
451 		 * 9P2000.L and access is V9FS_ACCESS_CLIENT.
452 		 */
453 		v9ses->flags &= ~V9FS_ACL_MASK;
454 	}
455 
456 	fid = p9_client_attach(v9ses->clnt, NULL, v9ses->uname, INVALID_UID,
457 							v9ses->aname);
458 	if (IS_ERR(fid)) {
459 		rc = PTR_ERR(fid);
460 		p9_debug(P9_DEBUG_ERROR, "cannot attach\n");
461 		goto err_clnt;
462 	}
463 
464 	if ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_SINGLE)
465 		fid->uid = v9ses->uid;
466 	else
467 		fid->uid = INVALID_UID;
468 
469 #ifdef CONFIG_9P_FSCACHE
470 	/* register the session for caching */
471 	if (v9ses->cache == CACHE_FSCACHE) {
472 		rc = v9fs_cache_session_get_cookie(v9ses, dev_name);
473 		if (rc < 0)
474 			goto err_clnt;
475 	}
476 #endif
477 	spin_lock(&v9fs_sessionlist_lock);
478 	list_add(&v9ses->slist, &v9fs_sessionlist);
479 	spin_unlock(&v9fs_sessionlist_lock);
480 
481 	return fid;
482 
483 err_clnt:
484 #ifdef CONFIG_9P_FSCACHE
485 	kfree(v9ses->cachetag);
486 #endif
487 	p9_client_destroy(v9ses->clnt);
488 err_names:
489 	kfree(v9ses->uname);
490 	kfree(v9ses->aname);
491 	return ERR_PTR(rc);
492 }
493 
494 /**
495  * v9fs_session_close - shutdown a session
496  * @v9ses: session information structure
497  *
498  */
499 
500 void v9fs_session_close(struct v9fs_session_info *v9ses)
501 {
502 	if (v9ses->clnt) {
503 		p9_client_destroy(v9ses->clnt);
504 		v9ses->clnt = NULL;
505 	}
506 
507 #ifdef CONFIG_9P_FSCACHE
508 	fscache_relinquish_volume(v9fs_session_cache(v9ses), NULL, false);
509 	kfree(v9ses->cachetag);
510 #endif
511 	kfree(v9ses->uname);
512 	kfree(v9ses->aname);
513 
514 	spin_lock(&v9fs_sessionlist_lock);
515 	list_del(&v9ses->slist);
516 	spin_unlock(&v9fs_sessionlist_lock);
517 }
518 
519 /**
520  * v9fs_session_cancel - terminate a session
521  * @v9ses: session to terminate
522  *
523  * mark transport as disconnected and cancel all pending requests.
524  */
525 
526 void v9fs_session_cancel(struct v9fs_session_info *v9ses)
527 {
528 	p9_debug(P9_DEBUG_ERROR, "cancel session %p\n", v9ses);
529 	p9_client_disconnect(v9ses->clnt);
530 }
531 
532 /**
533  * v9fs_session_begin_cancel - Begin terminate of a session
534  * @v9ses: session to terminate
535  *
536  * After this call we don't allow any request other than clunk.
537  */
538 
539 void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses)
540 {
541 	p9_debug(P9_DEBUG_ERROR, "begin cancel session %p\n", v9ses);
542 	p9_client_begin_disconnect(v9ses->clnt);
543 }
544 
545 extern int v9fs_error_init(void);
546 
547 static struct kobject *v9fs_kobj;
548 
549 #ifdef CONFIG_9P_FSCACHE
550 /*
551  * List caches associated with a session
552  */
553 static ssize_t caches_show(struct kobject *kobj,
554 			   struct kobj_attribute *attr,
555 			   char *buf)
556 {
557 	ssize_t n = 0, count = 0, limit = PAGE_SIZE;
558 	struct v9fs_session_info *v9ses;
559 
560 	spin_lock(&v9fs_sessionlist_lock);
561 	list_for_each_entry(v9ses, &v9fs_sessionlist, slist) {
562 		if (v9ses->cachetag) {
563 			n = snprintf(buf, limit, "%s\n", v9ses->cachetag);
564 			if (n < 0) {
565 				count = n;
566 				break;
567 			}
568 
569 			count += n;
570 			limit -= n;
571 		}
572 	}
573 
574 	spin_unlock(&v9fs_sessionlist_lock);
575 	return count;
576 }
577 
578 static struct kobj_attribute v9fs_attr_cache = __ATTR_RO(caches);
579 #endif /* CONFIG_9P_FSCACHE */
580 
581 static struct attribute *v9fs_attrs[] = {
582 #ifdef CONFIG_9P_FSCACHE
583 	&v9fs_attr_cache.attr,
584 #endif
585 	NULL,
586 };
587 
588 static const struct attribute_group v9fs_attr_group = {
589 	.attrs = v9fs_attrs,
590 };
591 
592 /**
593  * v9fs_sysfs_init - Initialize the v9fs sysfs interface
594  *
595  */
596 
597 static int __init v9fs_sysfs_init(void)
598 {
599 	v9fs_kobj = kobject_create_and_add("9p", fs_kobj);
600 	if (!v9fs_kobj)
601 		return -ENOMEM;
602 
603 	if (sysfs_create_group(v9fs_kobj, &v9fs_attr_group)) {
604 		kobject_put(v9fs_kobj);
605 		return -ENOMEM;
606 	}
607 
608 	return 0;
609 }
610 
611 /**
612  * v9fs_sysfs_cleanup - Unregister the v9fs sysfs interface
613  *
614  */
615 
616 static void v9fs_sysfs_cleanup(void)
617 {
618 	sysfs_remove_group(v9fs_kobj, &v9fs_attr_group);
619 	kobject_put(v9fs_kobj);
620 }
621 
622 static void v9fs_inode_init_once(void *foo)
623 {
624 	struct v9fs_inode *v9inode = (struct v9fs_inode *)foo;
625 
626 	memset(&v9inode->qid, 0, sizeof(v9inode->qid));
627 	inode_init_once(&v9inode->netfs.inode);
628 }
629 
630 /**
631  * v9fs_init_inode_cache - initialize a cache for 9P
632  * Returns 0 on success.
633  */
634 static int v9fs_init_inode_cache(void)
635 {
636 	v9fs_inode_cache = kmem_cache_create("v9fs_inode_cache",
637 					  sizeof(struct v9fs_inode),
638 					  0, (SLAB_RECLAIM_ACCOUNT|
639 					      SLAB_MEM_SPREAD|SLAB_ACCOUNT),
640 					  v9fs_inode_init_once);
641 	if (!v9fs_inode_cache)
642 		return -ENOMEM;
643 
644 	return 0;
645 }
646 
647 /**
648  * v9fs_destroy_inode_cache - destroy the cache of 9P inode
649  *
650  */
651 static void v9fs_destroy_inode_cache(void)
652 {
653 	/*
654 	 * Make sure all delayed rcu free inodes are flushed before we
655 	 * destroy cache.
656 	 */
657 	rcu_barrier();
658 	kmem_cache_destroy(v9fs_inode_cache);
659 }
660 
661 static int v9fs_cache_register(void)
662 {
663 	int ret;
664 
665 	ret = v9fs_init_inode_cache();
666 	if (ret < 0)
667 		return ret;
668 	return ret;
669 }
670 
671 static void v9fs_cache_unregister(void)
672 {
673 	v9fs_destroy_inode_cache();
674 }
675 
676 /**
677  * init_v9fs - Initialize module
678  *
679  */
680 
681 static int __init init_v9fs(void)
682 {
683 	int err;
684 
685 	pr_info("Installing v9fs 9p2000 file system support\n");
686 	/* TODO: Setup list of registered trasnport modules */
687 
688 	err = v9fs_cache_register();
689 	if (err < 0) {
690 		pr_err("Failed to register v9fs for caching\n");
691 		return err;
692 	}
693 
694 	err = v9fs_sysfs_init();
695 	if (err < 0) {
696 		pr_err("Failed to register with sysfs\n");
697 		goto out_cache;
698 	}
699 	err = register_filesystem(&v9fs_fs_type);
700 	if (err < 0) {
701 		pr_err("Failed to register filesystem\n");
702 		goto out_sysfs_cleanup;
703 	}
704 
705 	return 0;
706 
707 out_sysfs_cleanup:
708 	v9fs_sysfs_cleanup();
709 
710 out_cache:
711 	v9fs_cache_unregister();
712 
713 	return err;
714 }
715 
716 /**
717  * exit_v9fs - shutdown module
718  *
719  */
720 
721 static void __exit exit_v9fs(void)
722 {
723 	v9fs_sysfs_cleanup();
724 	v9fs_cache_unregister();
725 	unregister_filesystem(&v9fs_fs_type);
726 }
727 
728 module_init(init_v9fs)
729 module_exit(exit_v9fs)
730 
731 MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
732 MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
733 MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
734 MODULE_LICENSE("GPL");
735