inode.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. /*
  2. FUSE: Filesystem in Userspace
  3. Copyright (C) 2001-2008 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/moduleparam.h>
  15. #include <linux/parser.h>
  16. #include <linux/statfs.h>
  17. #include <linux/random.h>
  18. #include <linux/sched.h>
  19. #include <linux/exportfs.h>
  20. MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
  21. MODULE_DESCRIPTION("Filesystem in Userspace");
  22. MODULE_LICENSE("GPL");
  23. static struct kmem_cache *fuse_inode_cachep;
  24. struct list_head fuse_conn_list;
  25. DEFINE_MUTEX(fuse_mutex);
  26. static int set_global_limit(const char *val, struct kernel_param *kp);
  27. unsigned max_user_bgreq;
  28. module_param_call(max_user_bgreq, set_global_limit, param_get_uint,
  29. &max_user_bgreq, 0644);
  30. __MODULE_PARM_TYPE(max_user_bgreq, "uint");
  31. MODULE_PARM_DESC(max_user_bgreq,
  32. "Global limit for the maximum number of backgrounded requests an "
  33. "unprivileged user can set");
  34. unsigned max_user_congthresh;
  35. module_param_call(max_user_congthresh, set_global_limit, param_get_uint,
  36. &max_user_congthresh, 0644);
  37. __MODULE_PARM_TYPE(max_user_congthresh, "uint");
  38. MODULE_PARM_DESC(max_user_congthresh,
  39. "Global limit for the maximum congestion threshold an "
  40. "unprivileged user can set");
  41. #define FUSE_SUPER_MAGIC 0x65735546
  42. #define FUSE_DEFAULT_BLKSIZE 512
  43. /** Maximum number of outstanding background requests */
  44. #define FUSE_DEFAULT_MAX_BACKGROUND 12
  45. /** Congestion starts at 75% of maximum */
  46. #define FUSE_DEFAULT_CONGESTION_THRESHOLD (FUSE_DEFAULT_MAX_BACKGROUND * 3 / 4)
  47. struct fuse_mount_data {
  48. int fd;
  49. unsigned rootmode;
  50. kuid_t user_id;
  51. kgid_t group_id;
  52. unsigned fd_present:1;
  53. unsigned rootmode_present:1;
  54. unsigned user_id_present:1;
  55. unsigned group_id_present:1;
  56. unsigned flags;
  57. unsigned max_read;
  58. unsigned blksize;
  59. };
  60. struct fuse_forget_link *fuse_alloc_forget(void)
  61. {
  62. return kzalloc(sizeof(struct fuse_forget_link), GFP_KERNEL);
  63. }
  64. static struct inode *fuse_alloc_inode(struct super_block *sb)
  65. {
  66. struct inode *inode;
  67. struct fuse_inode *fi;
  68. inode = kmem_cache_alloc(fuse_inode_cachep, GFP_KERNEL);
  69. if (!inode)
  70. return NULL;
  71. fi = get_fuse_inode(inode);
  72. fi->i_time = 0;
  73. fi->nodeid = 0;
  74. fi->nlookup = 0;
  75. fi->attr_version = 0;
  76. fi->writectr = 0;
  77. fi->orig_ino = 0;
  78. fi->state = 0;
  79. INIT_LIST_HEAD(&fi->write_files);
  80. INIT_LIST_HEAD(&fi->queued_writes);
  81. INIT_LIST_HEAD(&fi->writepages);
  82. init_waitqueue_head(&fi->page_waitq);
  83. fi->forget = fuse_alloc_forget();
  84. if (!fi->forget) {
  85. kmem_cache_free(fuse_inode_cachep, inode);
  86. return NULL;
  87. }
  88. return inode;
  89. }
  90. static void fuse_i_callback(struct rcu_head *head)
  91. {
  92. struct inode *inode = container_of(head, struct inode, i_rcu);
  93. kmem_cache_free(fuse_inode_cachep, inode);
  94. }
  95. static void fuse_destroy_inode(struct inode *inode)
  96. {
  97. struct fuse_inode *fi = get_fuse_inode(inode);
  98. BUG_ON(!list_empty(&fi->write_files));
  99. BUG_ON(!list_empty(&fi->queued_writes));
  100. kfree(fi->forget);
  101. call_rcu(&inode->i_rcu, fuse_i_callback);
  102. }
  103. static void fuse_evict_inode(struct inode *inode)
  104. {
  105. truncate_inode_pages(&inode->i_data, 0);
  106. clear_inode(inode);
  107. if (inode->i_sb->s_flags & MS_ACTIVE) {
  108. struct fuse_conn *fc = get_fuse_conn(inode);
  109. struct fuse_inode *fi = get_fuse_inode(inode);
  110. fuse_queue_forget(fc, fi->forget, fi->nodeid, fi->nlookup);
  111. fi->forget = NULL;
  112. }
  113. }
  114. static int fuse_remount_fs(struct super_block *sb, int *flags, char *data)
  115. {
  116. if (*flags & MS_MANDLOCK)
  117. return -EINVAL;
  118. return 0;
  119. }
  120. /*
  121. * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
  122. * so that it will fit.
  123. */
  124. static ino_t fuse_squash_ino(u64 ino64)
  125. {
  126. ino_t ino = (ino_t) ino64;
  127. if (sizeof(ino_t) < sizeof(u64))
  128. ino ^= ino64 >> (sizeof(u64) - sizeof(ino_t)) * 8;
  129. return ino;
  130. }
  131. void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
  132. u64 attr_valid)
  133. {
  134. struct fuse_conn *fc = get_fuse_conn(inode);
  135. struct fuse_inode *fi = get_fuse_inode(inode);
  136. fi->attr_version = ++fc->attr_version;
  137. fi->i_time = attr_valid;
  138. inode->i_ino = fuse_squash_ino(attr->ino);
  139. inode->i_mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777);
  140. set_nlink(inode, attr->nlink);
  141. inode->i_uid = make_kuid(&init_user_ns, attr->uid);
  142. inode->i_gid = make_kgid(&init_user_ns, attr->gid);
  143. inode->i_blocks = attr->blocks;
  144. inode->i_atime.tv_sec = attr->atime;
  145. inode->i_atime.tv_nsec = attr->atimensec;
  146. inode->i_mtime.tv_sec = attr->mtime;
  147. inode->i_mtime.tv_nsec = attr->mtimensec;
  148. inode->i_ctime.tv_sec = attr->ctime;
  149. inode->i_ctime.tv_nsec = attr->ctimensec;
  150. if (attr->blksize != 0)
  151. inode->i_blkbits = ilog2(attr->blksize);
  152. else
  153. inode->i_blkbits = inode->i_sb->s_blocksize_bits;
  154. /*
  155. * Don't set the sticky bit in i_mode, unless we want the VFS
  156. * to check permissions. This prevents failures due to the
  157. * check in may_delete().
  158. */
  159. fi->orig_i_mode = inode->i_mode;
  160. if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
  161. inode->i_mode &= ~S_ISVTX;
  162. fi->orig_ino = attr->ino;
  163. }
  164. void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
  165. u64 attr_valid, u64 attr_version)
  166. {
  167. struct fuse_conn *fc = get_fuse_conn(inode);
  168. struct fuse_inode *fi = get_fuse_inode(inode);
  169. loff_t oldsize;
  170. struct timespec old_mtime;
  171. spin_lock(&fc->lock);
  172. if (attr_version != 0 && fi->attr_version > attr_version) {
  173. spin_unlock(&fc->lock);
  174. return;
  175. }
  176. old_mtime = inode->i_mtime;
  177. fuse_change_attributes_common(inode, attr, attr_valid);
  178. oldsize = inode->i_size;
  179. i_size_write(inode, attr->size);
  180. spin_unlock(&fc->lock);
  181. if (S_ISREG(inode->i_mode)) {
  182. bool inval = false;
  183. if (oldsize != attr->size) {
  184. truncate_pagecache(inode, oldsize, attr->size);
  185. inval = true;
  186. } else if (fc->auto_inval_data) {
  187. struct timespec new_mtime = {
  188. .tv_sec = attr->mtime,
  189. .tv_nsec = attr->mtimensec,
  190. };
  191. /*
  192. * Auto inval mode also checks and invalidates if mtime
  193. * has changed.
  194. */
  195. if (!timespec_equal(&old_mtime, &new_mtime))
  196. inval = true;
  197. }
  198. if (inval)
  199. invalidate_inode_pages2(inode->i_mapping);
  200. }
  201. }
  202. static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
  203. {
  204. inode->i_mode = attr->mode & S_IFMT;
  205. inode->i_size = attr->size;
  206. if (S_ISREG(inode->i_mode)) {
  207. fuse_init_common(inode);
  208. fuse_init_file_inode(inode);
  209. } else if (S_ISDIR(inode->i_mode))
  210. fuse_init_dir(inode);
  211. else if (S_ISLNK(inode->i_mode))
  212. fuse_init_symlink(inode);
  213. else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
  214. S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
  215. fuse_init_common(inode);
  216. init_special_inode(inode, inode->i_mode,
  217. new_decode_dev(attr->rdev));
  218. } else
  219. BUG();
  220. }
  221. int fuse_inode_eq(struct inode *inode, void *_nodeidp)
  222. {
  223. u64 nodeid = *(u64 *) _nodeidp;
  224. if (get_node_id(inode) == nodeid)
  225. return 1;
  226. else
  227. return 0;
  228. }
  229. static int fuse_inode_set(struct inode *inode, void *_nodeidp)
  230. {
  231. u64 nodeid = *(u64 *) _nodeidp;
  232. get_fuse_inode(inode)->nodeid = nodeid;
  233. return 0;
  234. }
  235. struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
  236. int generation, struct fuse_attr *attr,
  237. u64 attr_valid, u64 attr_version)
  238. {
  239. struct inode *inode;
  240. struct fuse_inode *fi;
  241. struct fuse_conn *fc = get_fuse_conn_super(sb);
  242. retry:
  243. inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid);
  244. if (!inode)
  245. return NULL;
  246. if ((inode->i_state & I_NEW)) {
  247. inode->i_flags |= S_NOATIME|S_NOCMTIME;
  248. inode->i_generation = generation;
  249. inode->i_data.backing_dev_info = &fc->bdi;
  250. fuse_init_inode(inode, attr);
  251. unlock_new_inode(inode);
  252. } else if ((inode->i_mode ^ attr->mode) & S_IFMT) {
  253. /* Inode has changed type, any I/O on the old should fail */
  254. make_bad_inode(inode);
  255. iput(inode);
  256. goto retry;
  257. }
  258. fi = get_fuse_inode(inode);
  259. spin_lock(&fc->lock);
  260. fi->nlookup++;
  261. spin_unlock(&fc->lock);
  262. fuse_change_attributes(inode, attr, attr_valid, attr_version);
  263. return inode;
  264. }
  265. int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
  266. loff_t offset, loff_t len)
  267. {
  268. struct inode *inode;
  269. pgoff_t pg_start;
  270. pgoff_t pg_end;
  271. inode = ilookup5(sb, nodeid, fuse_inode_eq, &nodeid);
  272. if (!inode)
  273. return -ENOENT;
  274. fuse_invalidate_attr(inode);
  275. if (offset >= 0) {
  276. pg_start = offset >> PAGE_CACHE_SHIFT;
  277. if (len <= 0)
  278. pg_end = -1;
  279. else
  280. pg_end = (offset + len - 1) >> PAGE_CACHE_SHIFT;
  281. invalidate_inode_pages2_range(inode->i_mapping,
  282. pg_start, pg_end);
  283. }
  284. iput(inode);
  285. return 0;
  286. }
  287. static void fuse_umount_begin(struct super_block *sb)
  288. {
  289. fuse_abort_conn(get_fuse_conn_super(sb));
  290. }
  291. static void fuse_send_destroy(struct fuse_conn *fc)
  292. {
  293. struct fuse_req *req = fc->destroy_req;
  294. if (req && fc->conn_init) {
  295. fc->destroy_req = NULL;
  296. req->in.h.opcode = FUSE_DESTROY;
  297. req->force = 1;
  298. req->background = 0;
  299. fuse_request_send(fc, req);
  300. fuse_put_request(fc, req);
  301. }
  302. }
  303. static void fuse_bdi_destroy(struct fuse_conn *fc)
  304. {
  305. if (fc->bdi_initialized)
  306. bdi_destroy(&fc->bdi);
  307. }
  308. void fuse_conn_kill(struct fuse_conn *fc)
  309. {
  310. spin_lock(&fc->lock);
  311. fc->connected = 0;
  312. fc->blocked = 0;
  313. fc->initialized = 1;
  314. spin_unlock(&fc->lock);
  315. /* Flush all readers on this fs */
  316. kill_fasync(&fc->fasync, SIGIO, POLL_IN);
  317. wake_up_all(&fc->waitq);
  318. wake_up_all(&fc->blocked_waitq);
  319. wake_up_all(&fc->reserved_req_waitq);
  320. }
  321. EXPORT_SYMBOL_GPL(fuse_conn_kill);
  322. static void fuse_put_super(struct super_block *sb)
  323. {
  324. struct fuse_conn *fc = get_fuse_conn_super(sb);
  325. fuse_send_destroy(fc);
  326. fuse_conn_kill(fc);
  327. mutex_lock(&fuse_mutex);
  328. list_del(&fc->entry);
  329. fuse_ctl_remove_conn(fc);
  330. mutex_unlock(&fuse_mutex);
  331. fuse_bdi_destroy(fc);
  332. fuse_conn_put(fc);
  333. }
  334. static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr)
  335. {
  336. stbuf->f_type = FUSE_SUPER_MAGIC;
  337. stbuf->f_bsize = attr->bsize;
  338. stbuf->f_frsize = attr->frsize;
  339. stbuf->f_blocks = attr->blocks;
  340. stbuf->f_bfree = attr->bfree;
  341. stbuf->f_bavail = attr->bavail;
  342. stbuf->f_files = attr->files;
  343. stbuf->f_ffree = attr->ffree;
  344. stbuf->f_namelen = attr->namelen;
  345. /* fsid is left zero */
  346. }
  347. static int fuse_statfs(struct dentry *dentry, struct kstatfs *buf)
  348. {
  349. struct super_block *sb = dentry->d_sb;
  350. struct fuse_conn *fc = get_fuse_conn_super(sb);
  351. struct fuse_req *req;
  352. struct fuse_statfs_out outarg;
  353. int err;
  354. if (!fuse_allow_current_process(fc)) {
  355. buf->f_type = FUSE_SUPER_MAGIC;
  356. return 0;
  357. }
  358. req = fuse_get_req_nopages(fc);
  359. if (IS_ERR(req))
  360. return PTR_ERR(req);
  361. memset(&outarg, 0, sizeof(outarg));
  362. req->in.numargs = 0;
  363. req->in.h.opcode = FUSE_STATFS;
  364. req->in.h.nodeid = get_node_id(dentry->d_inode);
  365. req->out.numargs = 1;
  366. req->out.args[0].size =
  367. fc->minor < 4 ? FUSE_COMPAT_STATFS_SIZE : sizeof(outarg);
  368. req->out.args[0].value = &outarg;
  369. fuse_request_send(fc, req);
  370. err = req->out.h.error;
  371. if (!err)
  372. convert_fuse_statfs(buf, &outarg.st);
  373. fuse_put_request(fc, req);
  374. return err;
  375. }
  376. enum {
  377. OPT_FD,
  378. OPT_ROOTMODE,
  379. OPT_USER_ID,
  380. OPT_GROUP_ID,
  381. OPT_DEFAULT_PERMISSIONS,
  382. OPT_ALLOW_OTHER,
  383. OPT_MAX_READ,
  384. OPT_BLKSIZE,
  385. OPT_ERR
  386. };
  387. static const match_table_t tokens = {
  388. {OPT_FD, "fd=%u"},
  389. {OPT_ROOTMODE, "rootmode=%o"},
  390. {OPT_USER_ID, "user_id=%u"},
  391. {OPT_GROUP_ID, "group_id=%u"},
  392. {OPT_DEFAULT_PERMISSIONS, "default_permissions"},
  393. {OPT_ALLOW_OTHER, "allow_other"},
  394. {OPT_MAX_READ, "max_read=%u"},
  395. {OPT_BLKSIZE, "blksize=%u"},
  396. {OPT_ERR, NULL}
  397. };
  398. static int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev)
  399. {
  400. char *p;
  401. memset(d, 0, sizeof(struct fuse_mount_data));
  402. d->max_read = ~0;
  403. d->blksize = FUSE_DEFAULT_BLKSIZE;
  404. while ((p = strsep(&opt, ",")) != NULL) {
  405. int token;
  406. int value;
  407. substring_t args[MAX_OPT_ARGS];
  408. if (!*p)
  409. continue;
  410. token = match_token(p, tokens, args);
  411. switch (token) {
  412. case OPT_FD:
  413. if (match_int(&args[0], &value))
  414. return 0;
  415. d->fd = value;
  416. d->fd_present = 1;
  417. break;
  418. case OPT_ROOTMODE:
  419. if (match_octal(&args[0], &value))
  420. return 0;
  421. if (!fuse_valid_type(value))
  422. return 0;
  423. d->rootmode = value;
  424. d->rootmode_present = 1;
  425. break;
  426. case OPT_USER_ID:
  427. if (match_int(&args[0], &value))
  428. return 0;
  429. d->user_id = make_kuid(current_user_ns(), value);
  430. if (!uid_valid(d->user_id))
  431. return 0;
  432. d->user_id_present = 1;
  433. break;
  434. case OPT_GROUP_ID:
  435. if (match_int(&args[0], &value))
  436. return 0;
  437. d->group_id = make_kgid(current_user_ns(), value);
  438. if (!gid_valid(d->group_id))
  439. return 0;
  440. d->group_id_present = 1;
  441. break;
  442. case OPT_DEFAULT_PERMISSIONS:
  443. d->flags |= FUSE_DEFAULT_PERMISSIONS;
  444. break;
  445. case OPT_ALLOW_OTHER:
  446. d->flags |= FUSE_ALLOW_OTHER;
  447. break;
  448. case OPT_MAX_READ:
  449. if (match_int(&args[0], &value))
  450. return 0;
  451. d->max_read = value;
  452. break;
  453. case OPT_BLKSIZE:
  454. if (!is_bdev || match_int(&args[0], &value))
  455. return 0;
  456. d->blksize = value;
  457. break;
  458. default:
  459. return 0;
  460. }
  461. }
  462. if (!d->fd_present || !d->rootmode_present ||
  463. !d->user_id_present || !d->group_id_present)
  464. return 0;
  465. return 1;
  466. }
  467. static int fuse_show_options(struct seq_file *m, struct dentry *root)
  468. {
  469. struct super_block *sb = root->d_sb;
  470. struct fuse_conn *fc = get_fuse_conn_super(sb);
  471. seq_printf(m, ",user_id=%u", from_kuid_munged(&init_user_ns, fc->user_id));
  472. seq_printf(m, ",group_id=%u", from_kgid_munged(&init_user_ns, fc->group_id));
  473. if (fc->flags & FUSE_DEFAULT_PERMISSIONS)
  474. seq_puts(m, ",default_permissions");
  475. if (fc->flags & FUSE_ALLOW_OTHER)
  476. seq_puts(m, ",allow_other");
  477. if (fc->max_read != ~0)
  478. seq_printf(m, ",max_read=%u", fc->max_read);
  479. if (sb->s_bdev && sb->s_blocksize != FUSE_DEFAULT_BLKSIZE)
  480. seq_printf(m, ",blksize=%lu", sb->s_blocksize);
  481. return 0;
  482. }
  483. void fuse_conn_init(struct fuse_conn *fc)
  484. {
  485. memset(fc, 0, sizeof(*fc));
  486. spin_lock_init(&fc->lock);
  487. mutex_init(&fc->inst_mutex);
  488. init_rwsem(&fc->killsb);
  489. atomic_set(&fc->count, 1);
  490. init_waitqueue_head(&fc->waitq);
  491. init_waitqueue_head(&fc->blocked_waitq);
  492. init_waitqueue_head(&fc->reserved_req_waitq);
  493. INIT_LIST_HEAD(&fc->pending);
  494. INIT_LIST_HEAD(&fc->processing);
  495. INIT_LIST_HEAD(&fc->io);
  496. INIT_LIST_HEAD(&fc->interrupts);
  497. INIT_LIST_HEAD(&fc->bg_queue);
  498. INIT_LIST_HEAD(&fc->entry);
  499. fc->forget_list_tail = &fc->forget_list_head;
  500. atomic_set(&fc->num_waiting, 0);
  501. fc->max_background = FUSE_DEFAULT_MAX_BACKGROUND;
  502. fc->congestion_threshold = FUSE_DEFAULT_CONGESTION_THRESHOLD;
  503. fc->khctr = 0;
  504. fc->polled_files = RB_ROOT;
  505. fc->reqctr = 0;
  506. fc->blocked = 0;
  507. fc->initialized = 0;
  508. fc->attr_version = 1;
  509. get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
  510. }
  511. EXPORT_SYMBOL_GPL(fuse_conn_init);
  512. void fuse_conn_put(struct fuse_conn *fc)
  513. {
  514. if (atomic_dec_and_test(&fc->count)) {
  515. if (fc->destroy_req)
  516. fuse_request_free(fc->destroy_req);
  517. mutex_destroy(&fc->inst_mutex);
  518. fc->release(fc);
  519. }
  520. }
  521. EXPORT_SYMBOL_GPL(fuse_conn_put);
  522. struct fuse_conn *fuse_conn_get(struct fuse_conn *fc)
  523. {
  524. atomic_inc(&fc->count);
  525. return fc;
  526. }
  527. EXPORT_SYMBOL_GPL(fuse_conn_get);
  528. static struct inode *fuse_get_root_inode(struct super_block *sb, unsigned mode)
  529. {
  530. struct fuse_attr attr;
  531. memset(&attr, 0, sizeof(attr));
  532. attr.mode = mode;
  533. attr.ino = FUSE_ROOT_ID;
  534. attr.nlink = 1;
  535. return fuse_iget(sb, 1, 0, &attr, 0, 0);
  536. }
  537. struct fuse_inode_handle {
  538. u64 nodeid;
  539. u32 generation;
  540. };
  541. static struct dentry *fuse_get_dentry(struct super_block *sb,
  542. struct fuse_inode_handle *handle)
  543. {
  544. struct fuse_conn *fc = get_fuse_conn_super(sb);
  545. struct inode *inode;
  546. struct dentry *entry;
  547. int err = -ESTALE;
  548. if (handle->nodeid == 0)
  549. goto out_err;
  550. inode = ilookup5(sb, handle->nodeid, fuse_inode_eq, &handle->nodeid);
  551. if (!inode) {
  552. struct fuse_entry_out outarg;
  553. struct qstr name;
  554. if (!fc->export_support)
  555. goto out_err;
  556. name.len = 1;
  557. name.name = ".";
  558. err = fuse_lookup_name(sb, handle->nodeid, &name, &outarg,
  559. &inode);
  560. if (err && err != -ENOENT)
  561. goto out_err;
  562. if (err || !inode) {
  563. err = -ESTALE;
  564. goto out_err;
  565. }
  566. err = -EIO;
  567. if (get_node_id(inode) != handle->nodeid)
  568. goto out_iput;
  569. }
  570. err = -ESTALE;
  571. if (inode->i_generation != handle->generation)
  572. goto out_iput;
  573. entry = d_obtain_alias(inode);
  574. if (!IS_ERR(entry) && get_node_id(inode) != FUSE_ROOT_ID)
  575. fuse_invalidate_entry_cache(entry);
  576. return entry;
  577. out_iput:
  578. iput(inode);
  579. out_err:
  580. return ERR_PTR(err);
  581. }
  582. static int fuse_encode_fh(struct inode *inode, u32 *fh, int *max_len,
  583. struct inode *parent)
  584. {
  585. int len = parent ? 6 : 3;
  586. u64 nodeid;
  587. u32 generation;
  588. if (*max_len < len) {
  589. *max_len = len;
  590. return FILEID_INVALID;
  591. }
  592. nodeid = get_fuse_inode(inode)->nodeid;
  593. generation = inode->i_generation;
  594. fh[0] = (u32)(nodeid >> 32);
  595. fh[1] = (u32)(nodeid & 0xffffffff);
  596. fh[2] = generation;
  597. if (parent) {
  598. nodeid = get_fuse_inode(parent)->nodeid;
  599. generation = parent->i_generation;
  600. fh[3] = (u32)(nodeid >> 32);
  601. fh[4] = (u32)(nodeid & 0xffffffff);
  602. fh[5] = generation;
  603. }
  604. *max_len = len;
  605. return parent ? 0x82 : 0x81;
  606. }
  607. static struct dentry *fuse_fh_to_dentry(struct super_block *sb,
  608. struct fid *fid, int fh_len, int fh_type)
  609. {
  610. struct fuse_inode_handle handle;
  611. if ((fh_type != 0x81 && fh_type != 0x82) || fh_len < 3)
  612. return NULL;
  613. handle.nodeid = (u64) fid->raw[0] << 32;
  614. handle.nodeid |= (u64) fid->raw[1];
  615. handle.generation = fid->raw[2];
  616. return fuse_get_dentry(sb, &handle);
  617. }
  618. static struct dentry *fuse_fh_to_parent(struct super_block *sb,
  619. struct fid *fid, int fh_len, int fh_type)
  620. {
  621. struct fuse_inode_handle parent;
  622. if (fh_type != 0x82 || fh_len < 6)
  623. return NULL;
  624. parent.nodeid = (u64) fid->raw[3] << 32;
  625. parent.nodeid |= (u64) fid->raw[4];
  626. parent.generation = fid->raw[5];
  627. return fuse_get_dentry(sb, &parent);
  628. }
  629. static struct dentry *fuse_get_parent(struct dentry *child)
  630. {
  631. struct inode *child_inode = child->d_inode;
  632. struct fuse_conn *fc = get_fuse_conn(child_inode);
  633. struct inode *inode;
  634. struct dentry *parent;
  635. struct fuse_entry_out outarg;
  636. struct qstr name;
  637. int err;
  638. if (!fc->export_support)
  639. return ERR_PTR(-ESTALE);
  640. name.len = 2;
  641. name.name = "..";
  642. err = fuse_lookup_name(child_inode->i_sb, get_node_id(child_inode),
  643. &name, &outarg, &inode);
  644. if (err) {
  645. if (err == -ENOENT)
  646. return ERR_PTR(-ESTALE);
  647. return ERR_PTR(err);
  648. }
  649. parent = d_obtain_alias(inode);
  650. if (!IS_ERR(parent) && get_node_id(inode) != FUSE_ROOT_ID)
  651. fuse_invalidate_entry_cache(parent);
  652. return parent;
  653. }
  654. static const struct export_operations fuse_export_operations = {
  655. .fh_to_dentry = fuse_fh_to_dentry,
  656. .fh_to_parent = fuse_fh_to_parent,
  657. .encode_fh = fuse_encode_fh,
  658. .get_parent = fuse_get_parent,
  659. };
  660. static const struct super_operations fuse_super_operations = {
  661. .alloc_inode = fuse_alloc_inode,
  662. .destroy_inode = fuse_destroy_inode,
  663. .evict_inode = fuse_evict_inode,
  664. .drop_inode = generic_delete_inode,
  665. .remount_fs = fuse_remount_fs,
  666. .put_super = fuse_put_super,
  667. .umount_begin = fuse_umount_begin,
  668. .statfs = fuse_statfs,
  669. .show_options = fuse_show_options,
  670. };
  671. static void sanitize_global_limit(unsigned *limit)
  672. {
  673. if (*limit == 0)
  674. *limit = ((totalram_pages << PAGE_SHIFT) >> 13) /
  675. sizeof(struct fuse_req);
  676. if (*limit >= 1 << 16)
  677. *limit = (1 << 16) - 1;
  678. }
  679. static int set_global_limit(const char *val, struct kernel_param *kp)
  680. {
  681. int rv;
  682. rv = param_set_uint(val, kp);
  683. if (rv)
  684. return rv;
  685. sanitize_global_limit((unsigned *)kp->arg);
  686. return 0;
  687. }
  688. static void process_init_limits(struct fuse_conn *fc, struct fuse_init_out *arg)
  689. {
  690. int cap_sys_admin = capable(CAP_SYS_ADMIN);
  691. if (arg->minor < 13)
  692. return;
  693. sanitize_global_limit(&max_user_bgreq);
  694. sanitize_global_limit(&max_user_congthresh);
  695. if (arg->max_background) {
  696. fc->max_background = arg->max_background;
  697. if (!cap_sys_admin && fc->max_background > max_user_bgreq)
  698. fc->max_background = max_user_bgreq;
  699. }
  700. if (arg->congestion_threshold) {
  701. fc->congestion_threshold = arg->congestion_threshold;
  702. if (!cap_sys_admin &&
  703. fc->congestion_threshold > max_user_congthresh)
  704. fc->congestion_threshold = max_user_congthresh;
  705. }
  706. }
  707. static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
  708. {
  709. struct fuse_init_out *arg = &req->misc.init_out;
  710. if (req->out.h.error || arg->major != FUSE_KERNEL_VERSION)
  711. fc->conn_error = 1;
  712. else {
  713. unsigned long ra_pages;
  714. process_init_limits(fc, arg);
  715. if (arg->minor >= 6) {
  716. ra_pages = arg->max_readahead / PAGE_CACHE_SIZE;
  717. if (arg->flags & FUSE_ASYNC_READ)
  718. fc->async_read = 1;
  719. if (!(arg->flags & FUSE_POSIX_LOCKS))
  720. fc->no_lock = 1;
  721. if (arg->minor >= 17) {
  722. if (!(arg->flags & FUSE_FLOCK_LOCKS))
  723. fc->no_flock = 1;
  724. } else {
  725. if (!(arg->flags & FUSE_POSIX_LOCKS))
  726. fc->no_flock = 1;
  727. }
  728. if (arg->flags & FUSE_ATOMIC_O_TRUNC)
  729. fc->atomic_o_trunc = 1;
  730. if (arg->minor >= 9) {
  731. /* LOOKUP has dependency on proto version */
  732. if (arg->flags & FUSE_EXPORT_SUPPORT)
  733. fc->export_support = 1;
  734. }
  735. if (arg->flags & FUSE_BIG_WRITES)
  736. fc->big_writes = 1;
  737. if (arg->flags & FUSE_DONT_MASK)
  738. fc->dont_mask = 1;
  739. if (arg->flags & FUSE_AUTO_INVAL_DATA)
  740. fc->auto_inval_data = 1;
  741. if (arg->flags & FUSE_DO_READDIRPLUS) {
  742. fc->do_readdirplus = 1;
  743. if (arg->flags & FUSE_READDIRPLUS_AUTO)
  744. fc->readdirplus_auto = 1;
  745. }
  746. if (arg->flags & FUSE_ASYNC_DIO)
  747. fc->async_dio = 1;
  748. } else {
  749. ra_pages = fc->max_read / PAGE_CACHE_SIZE;
  750. fc->no_lock = 1;
  751. fc->no_flock = 1;
  752. }
  753. fc->bdi.ra_pages = min(fc->bdi.ra_pages, ra_pages);
  754. fc->minor = arg->minor;
  755. fc->max_write = arg->minor < 5 ? 4096 : arg->max_write;
  756. fc->max_write = max_t(unsigned, 4096, fc->max_write);
  757. fc->conn_init = 1;
  758. }
  759. fc->initialized = 1;
  760. wake_up_all(&fc->blocked_waitq);
  761. }
  762. static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req)
  763. {
  764. struct fuse_init_in *arg = &req->misc.init_in;
  765. arg->major = FUSE_KERNEL_VERSION;
  766. arg->minor = FUSE_KERNEL_MINOR_VERSION;
  767. arg->max_readahead = fc->bdi.ra_pages * PAGE_CACHE_SIZE;
  768. arg->flags |= FUSE_ASYNC_READ | FUSE_POSIX_LOCKS | FUSE_ATOMIC_O_TRUNC |
  769. FUSE_EXPORT_SUPPORT | FUSE_BIG_WRITES | FUSE_DONT_MASK |
  770. FUSE_SPLICE_WRITE | FUSE_SPLICE_MOVE | FUSE_SPLICE_READ |
  771. FUSE_FLOCK_LOCKS | FUSE_IOCTL_DIR | FUSE_AUTO_INVAL_DATA |
  772. FUSE_DO_READDIRPLUS | FUSE_READDIRPLUS_AUTO | FUSE_ASYNC_DIO;
  773. req->in.h.opcode = FUSE_INIT;
  774. req->in.numargs = 1;
  775. req->in.args[0].size = sizeof(*arg);
  776. req->in.args[0].value = arg;
  777. req->out.numargs = 1;
  778. /* Variable length argument used for backward compatibility
  779. with interface version < 7.5. Rest of init_out is zeroed
  780. by do_get_request(), so a short reply is not a problem */
  781. req->out.argvar = 1;
  782. req->out.args[0].size = sizeof(struct fuse_init_out);
  783. req->out.args[0].value = &req->misc.init_out;
  784. req->end = process_init_reply;
  785. fuse_request_send_background(fc, req);
  786. }
  787. static void fuse_free_conn(struct fuse_conn *fc)
  788. {
  789. kfree(fc);
  790. }
  791. static int fuse_bdi_init(struct fuse_conn *fc, struct super_block *sb)
  792. {
  793. int err;
  794. fc->bdi.name = "fuse";
  795. fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
  796. /* fuse does it's own writeback accounting */
  797. fc->bdi.capabilities = BDI_CAP_NO_ACCT_WB;
  798. err = bdi_init(&fc->bdi);
  799. if (err)
  800. return err;
  801. fc->bdi_initialized = 1;
  802. if (sb->s_bdev) {
  803. err = bdi_register(&fc->bdi, NULL, "%u:%u-fuseblk",
  804. MAJOR(fc->dev), MINOR(fc->dev));
  805. } else {
  806. err = bdi_register_dev(&fc->bdi, fc->dev);
  807. }
  808. if (err)
  809. return err;
  810. /*
  811. * For a single fuse filesystem use max 1% of dirty +
  812. * writeback threshold.
  813. *
  814. * This gives about 1M of write buffer for memory maps on a
  815. * machine with 1G and 10% dirty_ratio, which should be more
  816. * than enough.
  817. *
  818. * Privileged users can raise it by writing to
  819. *
  820. * /sys/class/bdi/<bdi>/max_ratio
  821. */
  822. bdi_set_max_ratio(&fc->bdi, 1);
  823. return 0;
  824. }
  825. static int fuse_fill_super(struct super_block *sb, void *data, int silent)
  826. {
  827. struct fuse_conn *fc;
  828. struct inode *root;
  829. struct fuse_mount_data d;
  830. struct file *file;
  831. struct dentry *root_dentry;
  832. struct fuse_req *init_req;
  833. int err;
  834. int is_bdev = sb->s_bdev != NULL;
  835. err = -EINVAL;
  836. if (sb->s_flags & MS_MANDLOCK)
  837. goto err;
  838. sb->s_flags &= ~MS_NOSEC;
  839. if (!parse_fuse_opt((char *) data, &d, is_bdev))
  840. goto err;
  841. if (is_bdev) {
  842. #ifdef CONFIG_BLOCK
  843. err = -EINVAL;
  844. if (!sb_set_blocksize(sb, d.blksize))
  845. goto err;
  846. #endif
  847. } else {
  848. sb->s_blocksize = PAGE_CACHE_SIZE;
  849. sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
  850. }
  851. sb->s_magic = FUSE_SUPER_MAGIC;
  852. sb->s_op = &fuse_super_operations;
  853. sb->s_maxbytes = MAX_LFS_FILESIZE;
  854. sb->s_time_gran = 1;
  855. sb->s_export_op = &fuse_export_operations;
  856. file = fget(d.fd);
  857. err = -EINVAL;
  858. if (!file)
  859. goto err;
  860. if ((file->f_op != &fuse_dev_operations) ||
  861. (file->f_cred->user_ns != &init_user_ns))
  862. goto err_fput;
  863. fc = kmalloc(sizeof(*fc), GFP_KERNEL);
  864. err = -ENOMEM;
  865. if (!fc)
  866. goto err_fput;
  867. fuse_conn_init(fc);
  868. fc->dev = sb->s_dev;
  869. fc->sb = sb;
  870. err = fuse_bdi_init(fc, sb);
  871. if (err)
  872. goto err_put_conn;
  873. sb->s_bdi = &fc->bdi;
  874. /* Handle umasking inside the fuse code */
  875. if (sb->s_flags & MS_POSIXACL)
  876. fc->dont_mask = 1;
  877. sb->s_flags |= MS_POSIXACL;
  878. fc->release = fuse_free_conn;
  879. fc->flags = d.flags;
  880. fc->user_id = d.user_id;
  881. fc->group_id = d.group_id;
  882. fc->max_read = max_t(unsigned, 4096, d.max_read);
  883. /* Used by get_root_inode() */
  884. sb->s_fs_info = fc;
  885. err = -ENOMEM;
  886. root = fuse_get_root_inode(sb, d.rootmode);
  887. root_dentry = d_make_root(root);
  888. if (!root_dentry)
  889. goto err_put_conn;
  890. /* only now - we want root dentry with NULL ->d_op */
  891. sb->s_d_op = &fuse_dentry_operations;
  892. init_req = fuse_request_alloc(0);
  893. if (!init_req)
  894. goto err_put_root;
  895. init_req->background = 1;
  896. if (is_bdev) {
  897. fc->destroy_req = fuse_request_alloc(0);
  898. if (!fc->destroy_req)
  899. goto err_free_init_req;
  900. }
  901. mutex_lock(&fuse_mutex);
  902. err = -EINVAL;
  903. if (file->private_data)
  904. goto err_unlock;
  905. err = fuse_ctl_add_conn(fc);
  906. if (err)
  907. goto err_unlock;
  908. list_add_tail(&fc->entry, &fuse_conn_list);
  909. sb->s_root = root_dentry;
  910. fc->connected = 1;
  911. file->private_data = fuse_conn_get(fc);
  912. mutex_unlock(&fuse_mutex);
  913. /*
  914. * atomic_dec_and_test() in fput() provides the necessary
  915. * memory barrier for file->private_data to be visible on all
  916. * CPUs after this
  917. */
  918. fput(file);
  919. fuse_send_init(fc, init_req);
  920. return 0;
  921. err_unlock:
  922. mutex_unlock(&fuse_mutex);
  923. err_free_init_req:
  924. fuse_request_free(init_req);
  925. err_put_root:
  926. dput(root_dentry);
  927. err_put_conn:
  928. fuse_bdi_destroy(fc);
  929. fuse_conn_put(fc);
  930. err_fput:
  931. fput(file);
  932. err:
  933. return err;
  934. }
  935. static struct dentry *fuse_mount(struct file_system_type *fs_type,
  936. int flags, const char *dev_name,
  937. void *raw_data)
  938. {
  939. return mount_nodev(fs_type, flags, raw_data, fuse_fill_super);
  940. }
  941. static void fuse_kill_sb_anon(struct super_block *sb)
  942. {
  943. struct fuse_conn *fc = get_fuse_conn_super(sb);
  944. if (fc) {
  945. down_write(&fc->killsb);
  946. fc->sb = NULL;
  947. up_write(&fc->killsb);
  948. }
  949. kill_anon_super(sb);
  950. }
  951. static struct file_system_type fuse_fs_type = {
  952. .owner = THIS_MODULE,
  953. .name = "fuse",
  954. .fs_flags = FS_HAS_SUBTYPE,
  955. .mount = fuse_mount,
  956. .kill_sb = fuse_kill_sb_anon,
  957. };
  958. MODULE_ALIAS_FS("fuse");
  959. #ifdef CONFIG_BLOCK
  960. static struct dentry *fuse_mount_blk(struct file_system_type *fs_type,
  961. int flags, const char *dev_name,
  962. void *raw_data)
  963. {
  964. return mount_bdev(fs_type, flags, dev_name, raw_data, fuse_fill_super);
  965. }
  966. static void fuse_kill_sb_blk(struct super_block *sb)
  967. {
  968. struct fuse_conn *fc = get_fuse_conn_super(sb);
  969. if (fc) {
  970. down_write(&fc->killsb);
  971. fc->sb = NULL;
  972. up_write(&fc->killsb);
  973. }
  974. kill_block_super(sb);
  975. }
  976. static struct file_system_type fuseblk_fs_type = {
  977. .owner = THIS_MODULE,
  978. .name = "fuseblk",
  979. .mount = fuse_mount_blk,
  980. .kill_sb = fuse_kill_sb_blk,
  981. .fs_flags = FS_REQUIRES_DEV | FS_HAS_SUBTYPE,
  982. };
  983. MODULE_ALIAS_FS("fuseblk");
  984. static inline int register_fuseblk(void)
  985. {
  986. return register_filesystem(&fuseblk_fs_type);
  987. }
  988. static inline void unregister_fuseblk(void)
  989. {
  990. unregister_filesystem(&fuseblk_fs_type);
  991. }
  992. #else
  993. static inline int register_fuseblk(void)
  994. {
  995. return 0;
  996. }
  997. static inline void unregister_fuseblk(void)
  998. {
  999. }
  1000. #endif
  1001. static void fuse_inode_init_once(void *foo)
  1002. {
  1003. struct inode *inode = foo;
  1004. inode_init_once(inode);
  1005. }
  1006. static int __init fuse_fs_init(void)
  1007. {
  1008. int err;
  1009. fuse_inode_cachep = kmem_cache_create("fuse_inode",
  1010. sizeof(struct fuse_inode),
  1011. 0, SLAB_HWCACHE_ALIGN,
  1012. fuse_inode_init_once);
  1013. err = -ENOMEM;
  1014. if (!fuse_inode_cachep)
  1015. goto out;
  1016. err = register_fuseblk();
  1017. if (err)
  1018. goto out2;
  1019. err = register_filesystem(&fuse_fs_type);
  1020. if (err)
  1021. goto out3;
  1022. return 0;
  1023. out3:
  1024. unregister_fuseblk();
  1025. out2:
  1026. kmem_cache_destroy(fuse_inode_cachep);
  1027. out:
  1028. return err;
  1029. }
  1030. static void fuse_fs_cleanup(void)
  1031. {
  1032. unregister_filesystem(&fuse_fs_type);
  1033. unregister_fuseblk();
  1034. /*
  1035. * Make sure all delayed rcu free inodes are flushed before we
  1036. * destroy cache.
  1037. */
  1038. rcu_barrier();
  1039. kmem_cache_destroy(fuse_inode_cachep);
  1040. }
  1041. static struct kobject *fuse_kobj;
  1042. static struct kobject *connections_kobj;
  1043. static int fuse_sysfs_init(void)
  1044. {
  1045. int err;
  1046. fuse_kobj = kobject_create_and_add("fuse", fs_kobj);
  1047. if (!fuse_kobj) {
  1048. err = -ENOMEM;
  1049. goto out_err;
  1050. }
  1051. connections_kobj = kobject_create_and_add("connections", fuse_kobj);
  1052. if (!connections_kobj) {
  1053. err = -ENOMEM;
  1054. goto out_fuse_unregister;
  1055. }
  1056. return 0;
  1057. out_fuse_unregister:
  1058. kobject_put(fuse_kobj);
  1059. out_err:
  1060. return err;
  1061. }
  1062. static void fuse_sysfs_cleanup(void)
  1063. {
  1064. kobject_put(connections_kobj);
  1065. kobject_put(fuse_kobj);
  1066. }
  1067. static int __init fuse_init(void)
  1068. {
  1069. int res;
  1070. printk(KERN_INFO "fuse init (API version %i.%i)\n",
  1071. FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
  1072. INIT_LIST_HEAD(&fuse_conn_list);
  1073. res = fuse_fs_init();
  1074. if (res)
  1075. goto err;
  1076. res = fuse_dev_init();
  1077. if (res)
  1078. goto err_fs_cleanup;
  1079. res = fuse_sysfs_init();
  1080. if (res)
  1081. goto err_dev_cleanup;
  1082. res = fuse_ctl_init();
  1083. if (res)
  1084. goto err_sysfs_cleanup;
  1085. sanitize_global_limit(&max_user_bgreq);
  1086. sanitize_global_limit(&max_user_congthresh);
  1087. return 0;
  1088. err_sysfs_cleanup:
  1089. fuse_sysfs_cleanup();
  1090. err_dev_cleanup:
  1091. fuse_dev_cleanup();
  1092. err_fs_cleanup:
  1093. fuse_fs_cleanup();
  1094. err:
  1095. return res;
  1096. }
  1097. static void __exit fuse_exit(void)
  1098. {
  1099. printk(KERN_DEBUG "fuse exit\n");
  1100. fuse_ctl_cleanup();
  1101. fuse_sysfs_cleanup();
  1102. fuse_fs_cleanup();
  1103. fuse_dev_cleanup();
  1104. }
  1105. module_init(fuse_init);
  1106. module_exit(fuse_exit);