inode.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. FUSE: Filesystem in Userspace
  3. Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
  4. This program can be distributed under the terms of the GNU GPL.
  5. See the file COPYING.
  6. */
  7. #include "fuse_i.h"
  8. #include <linux/pagemap.h>
  9. #include <linux/slab.h>
  10. #include <linux/file.h>
  11. #include <linux/seq_file.h>
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/parser.h>
  15. #include <linux/statfs.h>
  16. #include <linux/random.h>
  17. MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
  18. MODULE_DESCRIPTION("Filesystem in Userspace");
  19. MODULE_LICENSE("GPL");
  20. static kmem_cache_t *fuse_inode_cachep;
  21. struct list_head fuse_conn_list;
  22. DEFINE_MUTEX(fuse_mutex);
  23. #define FUSE_SUPER_MAGIC 0x65735546
  24. struct fuse_mount_data {
  25. int fd;
  26. unsigned rootmode;
  27. unsigned user_id;
  28. unsigned group_id;
  29. unsigned fd_present : 1;
  30. unsigned rootmode_present : 1;
  31. unsigned user_id_present : 1;
  32. unsigned group_id_present : 1;
  33. unsigned flags;
  34. unsigned max_read;
  35. };
  36. static struct inode *fuse_alloc_inode(struct super_block *sb)
  37. {
  38. struct inode *inode;
  39. struct fuse_inode *fi;
  40. inode = kmem_cache_alloc(fuse_inode_cachep, SLAB_KERNEL);
  41. if (!inode)
  42. return NULL;
  43. fi = get_fuse_inode(inode);
  44. fi->i_time = 0;
  45. fi->nodeid = 0;
  46. fi->nlookup = 0;
  47. fi->forget_req = fuse_request_alloc();
  48. if (!fi->forget_req) {
  49. kmem_cache_free(fuse_inode_cachep, inode);
  50. return NULL;
  51. }
  52. return inode;
  53. }
  54. static void fuse_destroy_inode(struct inode *inode)
  55. {
  56. struct fuse_inode *fi = get_fuse_inode(inode);
  57. if (fi->forget_req)
  58. fuse_request_free(fi->forget_req);
  59. kmem_cache_free(fuse_inode_cachep, inode);
  60. }
  61. static void fuse_read_inode(struct inode *inode)
  62. {
  63. /* No op */
  64. }
  65. void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
  66. unsigned long nodeid, u64 nlookup)
  67. {
  68. struct fuse_forget_in *inarg = &req->misc.forget_in;
  69. inarg->nlookup = nlookup;
  70. req->in.h.opcode = FUSE_FORGET;
  71. req->in.h.nodeid = nodeid;
  72. req->in.numargs = 1;
  73. req->in.args[0].size = sizeof(struct fuse_forget_in);
  74. req->in.args[0].value = inarg;
  75. request_send_noreply(fc, req);
  76. }
  77. static void fuse_clear_inode(struct inode *inode)
  78. {
  79. if (inode->i_sb->s_flags & MS_ACTIVE) {
  80. struct fuse_conn *fc = get_fuse_conn(inode);
  81. struct fuse_inode *fi = get_fuse_inode(inode);
  82. fuse_send_forget(fc, fi->forget_req, fi->nodeid, fi->nlookup);
  83. fi->forget_req = NULL;
  84. }
  85. }
  86. static int fuse_remount_fs(struct super_block *sb, int *flags, char *data)
  87. {
  88. if (*flags & MS_MANDLOCK)
  89. return -EINVAL;
  90. return 0;
  91. }
  92. void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr)
  93. {
  94. struct fuse_conn *fc = get_fuse_conn(inode);
  95. if (S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size)
  96. invalidate_inode_pages(inode->i_mapping);
  97. inode->i_ino = attr->ino;
  98. inode->i_mode = (inode->i_mode & S_IFMT) + (attr->mode & 07777);
  99. inode->i_nlink = attr->nlink;
  100. inode->i_uid = attr->uid;
  101. inode->i_gid = attr->gid;
  102. spin_lock(&fc->lock);
  103. i_size_write(inode, attr->size);
  104. spin_unlock(&fc->lock);
  105. inode->i_blocks = attr->blocks;
  106. inode->i_atime.tv_sec = attr->atime;
  107. inode->i_atime.tv_nsec = attr->atimensec;
  108. inode->i_mtime.tv_sec = attr->mtime;
  109. inode->i_mtime.tv_nsec = attr->mtimensec;
  110. inode->i_ctime.tv_sec = attr->ctime;
  111. inode->i_ctime.tv_nsec = attr->ctimensec;
  112. }
  113. static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
  114. {
  115. inode->i_mode = attr->mode & S_IFMT;
  116. inode->i_size = attr->size;
  117. if (S_ISREG(inode->i_mode)) {
  118. fuse_init_common(inode);
  119. fuse_init_file_inode(inode);
  120. } else if (S_ISDIR(inode->i_mode))
  121. fuse_init_dir(inode);
  122. else if (S_ISLNK(inode->i_mode))
  123. fuse_init_symlink(inode);
  124. else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
  125. S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
  126. fuse_init_common(inode);
  127. init_special_inode(inode, inode->i_mode,
  128. new_decode_dev(attr->rdev));
  129. } else
  130. BUG();
  131. }
  132. static int fuse_inode_eq(struct inode *inode, void *_nodeidp)
  133. {
  134. unsigned long nodeid = *(unsigned long *) _nodeidp;
  135. if (get_node_id(inode) == nodeid)
  136. return 1;
  137. else
  138. return 0;
  139. }
  140. static int fuse_inode_set(struct inode *inode, void *_nodeidp)
  141. {
  142. unsigned long nodeid = *(unsigned long *) _nodeidp;
  143. get_fuse_inode(inode)->nodeid = nodeid;
  144. return 0;
  145. }
  146. struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
  147. int generation, struct fuse_attr *attr)
  148. {
  149. struct inode *inode;
  150. struct fuse_inode *fi;
  151. struct fuse_conn *fc = get_fuse_conn_super(sb);
  152. retry:
  153. inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid);
  154. if (!inode)
  155. return NULL;
  156. if ((inode->i_state & I_NEW)) {
  157. inode->i_flags |= S_NOATIME|S_NOCMTIME;
  158. inode->i_generation = generation;
  159. inode->i_data.backing_dev_info = &fc->bdi;
  160. fuse_init_inode(inode, attr);
  161. unlock_new_inode(inode);
  162. } else if ((inode->i_mode ^ attr->mode) & S_IFMT) {
  163. /* Inode has changed type, any I/O on the old should fail */
  164. make_bad_inode(inode);
  165. iput(inode);
  166. goto retry;
  167. }
  168. fi = get_fuse_inode(inode);
  169. spin_lock(&fc->lock);
  170. fi->nlookup ++;
  171. spin_unlock(&fc->lock);
  172. fuse_change_attributes(inode, attr);
  173. return inode;
  174. }
  175. static void fuse_umount_begin(struct vfsmount *vfsmnt, int flags)
  176. {
  177. if (flags & MNT_FORCE)
  178. fuse_abort_conn(get_fuse_conn_super(vfsmnt->mnt_sb));
  179. }
  180. static void fuse_put_super(struct super_block *sb)
  181. {
  182. struct fuse_conn *fc = get_fuse_conn_super(sb);
  183. spin_lock(&fc->lock);
  184. fc->connected = 0;
  185. fc->blocked = 0;
  186. spin_unlock(&fc->lock);
  187. /* Flush all readers on this fs */
  188. kill_fasync(&fc->fasync, SIGIO, POLL_IN);
  189. wake_up_all(&fc->waitq);
  190. wake_up_all(&fc->blocked_waitq);
  191. mutex_lock(&fuse_mutex);
  192. list_del(&fc->entry);
  193. fuse_ctl_remove_conn(fc);
  194. mutex_unlock(&fuse_mutex);
  195. fuse_conn_put(fc);
  196. }
  197. static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr)
  198. {
  199. stbuf->f_type = FUSE_SUPER_MAGIC;
  200. stbuf->f_bsize = attr->bsize;
  201. stbuf->f_frsize = attr->frsize;
  202. stbuf->f_blocks = attr->blocks;
  203. stbuf->f_bfree = attr->bfree;
  204. stbuf->f_bavail = attr->bavail;
  205. stbuf->f_files = attr->files;
  206. stbuf->f_ffree = attr->ffree;
  207. stbuf->f_namelen = attr->namelen;
  208. /* fsid is left zero */
  209. }
  210. static int fuse_statfs(struct dentry *dentry, struct kstatfs *buf)
  211. {
  212. struct super_block *sb = dentry->d_sb;
  213. struct fuse_conn *fc = get_fuse_conn_super(sb);
  214. struct fuse_req *req;
  215. struct fuse_statfs_out outarg;
  216. int err;
  217. req = fuse_get_req(fc);
  218. if (IS_ERR(req))
  219. return PTR_ERR(req);
  220. memset(&outarg, 0, sizeof(outarg));
  221. req->in.numargs = 0;
  222. req->in.h.opcode = FUSE_STATFS;
  223. req->in.h.nodeid = get_node_id(dentry->d_inode);
  224. req->out.numargs = 1;
  225. req->out.args[0].size =
  226. fc->minor < 4 ? FUSE_COMPAT_STATFS_SIZE : sizeof(outarg);
  227. req->out.args[0].value = &outarg;
  228. request_send(fc, req);
  229. err = req->out.h.error;
  230. if (!err)
  231. convert_fuse_statfs(buf, &outarg.st);
  232. fuse_put_request(fc, req);
  233. return err;
  234. }
  235. enum {
  236. OPT_FD,
  237. OPT_ROOTMODE,
  238. OPT_USER_ID,
  239. OPT_GROUP_ID,
  240. OPT_DEFAULT_PERMISSIONS,
  241. OPT_ALLOW_OTHER,
  242. OPT_MAX_READ,
  243. OPT_ERR
  244. };
  245. static match_table_t tokens = {
  246. {OPT_FD, "fd=%u"},
  247. {OPT_ROOTMODE, "rootmode=%o"},
  248. {OPT_USER_ID, "user_id=%u"},
  249. {OPT_GROUP_ID, "group_id=%u"},
  250. {OPT_DEFAULT_PERMISSIONS, "default_permissions"},
  251. {OPT_ALLOW_OTHER, "allow_other"},
  252. {OPT_MAX_READ, "max_read=%u"},
  253. {OPT_ERR, NULL}
  254. };
  255. static int parse_fuse_opt(char *opt, struct fuse_mount_data *d)
  256. {
  257. char *p;
  258. memset(d, 0, sizeof(struct fuse_mount_data));
  259. d->max_read = ~0;
  260. while ((p = strsep(&opt, ",")) != NULL) {
  261. int token;
  262. int value;
  263. substring_t args[MAX_OPT_ARGS];
  264. if (!*p)
  265. continue;
  266. token = match_token(p, tokens, args);
  267. switch (token) {
  268. case OPT_FD:
  269. if (match_int(&args[0], &value))
  270. return 0;
  271. d->fd = value;
  272. d->fd_present = 1;
  273. break;
  274. case OPT_ROOTMODE:
  275. if (match_octal(&args[0], &value))
  276. return 0;
  277. d->rootmode = value;
  278. d->rootmode_present = 1;
  279. break;
  280. case OPT_USER_ID:
  281. if (match_int(&args[0], &value))
  282. return 0;
  283. d->user_id = value;
  284. d->user_id_present = 1;
  285. break;
  286. case OPT_GROUP_ID:
  287. if (match_int(&args[0], &value))
  288. return 0;
  289. d->group_id = value;
  290. d->group_id_present = 1;
  291. break;
  292. case OPT_DEFAULT_PERMISSIONS:
  293. d->flags |= FUSE_DEFAULT_PERMISSIONS;
  294. break;
  295. case OPT_ALLOW_OTHER:
  296. d->flags |= FUSE_ALLOW_OTHER;
  297. break;
  298. case OPT_MAX_READ:
  299. if (match_int(&args[0], &value))
  300. return 0;
  301. d->max_read = value;
  302. break;
  303. default:
  304. return 0;
  305. }
  306. }
  307. if (!d->fd_present || !d->rootmode_present ||
  308. !d->user_id_present || !d->group_id_present)
  309. return 0;
  310. return 1;
  311. }
  312. static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt)
  313. {
  314. struct fuse_conn *fc = get_fuse_conn_super(mnt->mnt_sb);
  315. seq_printf(m, ",user_id=%u", fc->user_id);
  316. seq_printf(m, ",group_id=%u", fc->group_id);
  317. if (fc->flags & FUSE_DEFAULT_PERMISSIONS)
  318. seq_puts(m, ",default_permissions");
  319. if (fc->flags & FUSE_ALLOW_OTHER)
  320. seq_puts(m, ",allow_other");
  321. if (fc->max_read != ~0)
  322. seq_printf(m, ",max_read=%u", fc->max_read);
  323. return 0;
  324. }
  325. static struct fuse_conn *new_conn(void)
  326. {
  327. struct fuse_conn *fc;
  328. fc = kzalloc(sizeof(*fc), GFP_KERNEL);
  329. if (fc) {
  330. spin_lock_init(&fc->lock);
  331. mutex_init(&fc->inst_mutex);
  332. atomic_set(&fc->count, 1);
  333. init_waitqueue_head(&fc->waitq);
  334. init_waitqueue_head(&fc->blocked_waitq);
  335. INIT_LIST_HEAD(&fc->pending);
  336. INIT_LIST_HEAD(&fc->processing);
  337. INIT_LIST_HEAD(&fc->io);
  338. INIT_LIST_HEAD(&fc->interrupts);
  339. atomic_set(&fc->num_waiting, 0);
  340. fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
  341. fc->bdi.unplug_io_fn = default_unplug_io_fn;
  342. fc->reqctr = 0;
  343. fc->blocked = 1;
  344. get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
  345. }
  346. return fc;
  347. }
  348. void fuse_conn_put(struct fuse_conn *fc)
  349. {
  350. if (atomic_dec_and_test(&fc->count)) {
  351. mutex_destroy(&fc->inst_mutex);
  352. kfree(fc);
  353. }
  354. }
  355. struct fuse_conn *fuse_conn_get(struct fuse_conn *fc)
  356. {
  357. atomic_inc(&fc->count);
  358. return fc;
  359. }
  360. static struct inode *get_root_inode(struct super_block *sb, unsigned mode)
  361. {
  362. struct fuse_attr attr;
  363. memset(&attr, 0, sizeof(attr));
  364. attr.mode = mode;
  365. attr.ino = FUSE_ROOT_ID;
  366. return fuse_iget(sb, 1, 0, &attr);
  367. }
  368. static struct super_operations fuse_super_operations = {
  369. .alloc_inode = fuse_alloc_inode,
  370. .destroy_inode = fuse_destroy_inode,
  371. .read_inode = fuse_read_inode,
  372. .clear_inode = fuse_clear_inode,
  373. .remount_fs = fuse_remount_fs,
  374. .put_super = fuse_put_super,
  375. .umount_begin = fuse_umount_begin,
  376. .statfs = fuse_statfs,
  377. .show_options = fuse_show_options,
  378. };
  379. static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
  380. {
  381. struct fuse_init_out *arg = &req->misc.init_out;
  382. if (req->out.h.error || arg->major != FUSE_KERNEL_VERSION)
  383. fc->conn_error = 1;
  384. else {
  385. unsigned long ra_pages;
  386. if (arg->minor >= 6) {
  387. ra_pages = arg->max_readahead / PAGE_CACHE_SIZE;
  388. if (arg->flags & FUSE_ASYNC_READ)
  389. fc->async_read = 1;
  390. if (!(arg->flags & FUSE_POSIX_LOCKS))
  391. fc->no_lock = 1;
  392. } else {
  393. ra_pages = fc->max_read / PAGE_CACHE_SIZE;
  394. fc->no_lock = 1;
  395. }
  396. fc->bdi.ra_pages = min(fc->bdi.ra_pages, ra_pages);
  397. fc->minor = arg->minor;
  398. fc->max_write = arg->minor < 5 ? 4096 : arg->max_write;
  399. }
  400. fuse_put_request(fc, req);
  401. fc->blocked = 0;
  402. wake_up_all(&fc->blocked_waitq);
  403. }
  404. static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req)
  405. {
  406. struct fuse_init_in *arg = &req->misc.init_in;
  407. arg->major = FUSE_KERNEL_VERSION;
  408. arg->minor = FUSE_KERNEL_MINOR_VERSION;
  409. arg->max_readahead = fc->bdi.ra_pages * PAGE_CACHE_SIZE;
  410. arg->flags |= FUSE_ASYNC_READ | FUSE_POSIX_LOCKS;
  411. req->in.h.opcode = FUSE_INIT;
  412. req->in.numargs = 1;
  413. req->in.args[0].size = sizeof(*arg);
  414. req->in.args[0].value = arg;
  415. req->out.numargs = 1;
  416. /* Variable length arguement used for backward compatibility
  417. with interface version < 7.5. Rest of init_out is zeroed
  418. by do_get_request(), so a short reply is not a problem */
  419. req->out.argvar = 1;
  420. req->out.args[0].size = sizeof(struct fuse_init_out);
  421. req->out.args[0].value = &req->misc.init_out;
  422. req->end = process_init_reply;
  423. request_send_background(fc, req);
  424. }
  425. static u64 conn_id(void)
  426. {
  427. static u64 ctr = 1;
  428. return ctr++;
  429. }
  430. static int fuse_fill_super(struct super_block *sb, void *data, int silent)
  431. {
  432. struct fuse_conn *fc;
  433. struct inode *root;
  434. struct fuse_mount_data d;
  435. struct file *file;
  436. struct dentry *root_dentry;
  437. struct fuse_req *init_req;
  438. int err;
  439. if (sb->s_flags & MS_MANDLOCK)
  440. return -EINVAL;
  441. if (!parse_fuse_opt((char *) data, &d))
  442. return -EINVAL;
  443. sb->s_blocksize = PAGE_CACHE_SIZE;
  444. sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
  445. sb->s_magic = FUSE_SUPER_MAGIC;
  446. sb->s_op = &fuse_super_operations;
  447. sb->s_maxbytes = MAX_LFS_FILESIZE;
  448. file = fget(d.fd);
  449. if (!file)
  450. return -EINVAL;
  451. if (file->f_op != &fuse_dev_operations)
  452. return -EINVAL;
  453. fc = new_conn();
  454. if (!fc)
  455. return -ENOMEM;
  456. fc->flags = d.flags;
  457. fc->user_id = d.user_id;
  458. fc->group_id = d.group_id;
  459. fc->max_read = d.max_read;
  460. /* Used by get_root_inode() */
  461. sb->s_fs_info = fc;
  462. err = -ENOMEM;
  463. root = get_root_inode(sb, d.rootmode);
  464. if (!root)
  465. goto err;
  466. root_dentry = d_alloc_root(root);
  467. if (!root_dentry) {
  468. iput(root);
  469. goto err;
  470. }
  471. init_req = fuse_request_alloc();
  472. if (!init_req)
  473. goto err_put_root;
  474. mutex_lock(&fuse_mutex);
  475. err = -EINVAL;
  476. if (file->private_data)
  477. goto err_unlock;
  478. fc->id = conn_id();
  479. err = fuse_ctl_add_conn(fc);
  480. if (err)
  481. goto err_unlock;
  482. list_add_tail(&fc->entry, &fuse_conn_list);
  483. sb->s_root = root_dentry;
  484. fc->connected = 1;
  485. file->private_data = fuse_conn_get(fc);
  486. mutex_unlock(&fuse_mutex);
  487. /*
  488. * atomic_dec_and_test() in fput() provides the necessary
  489. * memory barrier for file->private_data to be visible on all
  490. * CPUs after this
  491. */
  492. fput(file);
  493. fuse_send_init(fc, init_req);
  494. return 0;
  495. err_unlock:
  496. mutex_unlock(&fuse_mutex);
  497. fuse_request_free(init_req);
  498. err_put_root:
  499. dput(root_dentry);
  500. err:
  501. fput(file);
  502. fuse_conn_put(fc);
  503. return err;
  504. }
  505. static int fuse_get_sb(struct file_system_type *fs_type,
  506. int flags, const char *dev_name,
  507. void *raw_data, struct vfsmount *mnt)
  508. {
  509. return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super, mnt);
  510. }
  511. static struct file_system_type fuse_fs_type = {
  512. .owner = THIS_MODULE,
  513. .name = "fuse",
  514. .get_sb = fuse_get_sb,
  515. .kill_sb = kill_anon_super,
  516. };
  517. static decl_subsys(fuse, NULL, NULL);
  518. static decl_subsys(connections, NULL, NULL);
  519. static void fuse_inode_init_once(void *foo, kmem_cache_t *cachep,
  520. unsigned long flags)
  521. {
  522. struct inode * inode = foo;
  523. if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
  524. SLAB_CTOR_CONSTRUCTOR)
  525. inode_init_once(inode);
  526. }
  527. static int __init fuse_fs_init(void)
  528. {
  529. int err;
  530. err = register_filesystem(&fuse_fs_type);
  531. if (err)
  532. printk("fuse: failed to register filesystem\n");
  533. else {
  534. fuse_inode_cachep = kmem_cache_create("fuse_inode",
  535. sizeof(struct fuse_inode),
  536. 0, SLAB_HWCACHE_ALIGN,
  537. fuse_inode_init_once, NULL);
  538. if (!fuse_inode_cachep) {
  539. unregister_filesystem(&fuse_fs_type);
  540. err = -ENOMEM;
  541. }
  542. }
  543. return err;
  544. }
  545. static void fuse_fs_cleanup(void)
  546. {
  547. unregister_filesystem(&fuse_fs_type);
  548. kmem_cache_destroy(fuse_inode_cachep);
  549. }
  550. static int fuse_sysfs_init(void)
  551. {
  552. int err;
  553. kset_set_kset_s(&fuse_subsys, fs_subsys);
  554. err = subsystem_register(&fuse_subsys);
  555. if (err)
  556. goto out_err;
  557. kset_set_kset_s(&connections_subsys, fuse_subsys);
  558. err = subsystem_register(&connections_subsys);
  559. if (err)
  560. goto out_fuse_unregister;
  561. return 0;
  562. out_fuse_unregister:
  563. subsystem_unregister(&fuse_subsys);
  564. out_err:
  565. return err;
  566. }
  567. static void fuse_sysfs_cleanup(void)
  568. {
  569. subsystem_unregister(&connections_subsys);
  570. subsystem_unregister(&fuse_subsys);
  571. }
  572. static int __init fuse_init(void)
  573. {
  574. int res;
  575. printk("fuse init (API version %i.%i)\n",
  576. FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
  577. INIT_LIST_HEAD(&fuse_conn_list);
  578. res = fuse_fs_init();
  579. if (res)
  580. goto err;
  581. res = fuse_dev_init();
  582. if (res)
  583. goto err_fs_cleanup;
  584. res = fuse_sysfs_init();
  585. if (res)
  586. goto err_dev_cleanup;
  587. res = fuse_ctl_init();
  588. if (res)
  589. goto err_sysfs_cleanup;
  590. return 0;
  591. err_sysfs_cleanup:
  592. fuse_sysfs_cleanup();
  593. err_dev_cleanup:
  594. fuse_dev_cleanup();
  595. err_fs_cleanup:
  596. fuse_fs_cleanup();
  597. err:
  598. return res;
  599. }
  600. static void __exit fuse_exit(void)
  601. {
  602. printk(KERN_DEBUG "fuse exit\n");
  603. fuse_ctl_cleanup();
  604. fuse_sysfs_cleanup();
  605. fuse_fs_cleanup();
  606. fuse_dev_cleanup();
  607. }
  608. module_init(fuse_init);
  609. module_exit(fuse_exit);