inode.c 16 KB

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