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