super.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. /*
  2. * Copyright (C) 2007 Oracle. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #include <linux/blkdev.h>
  19. #include <linux/module.h>
  20. #include <linux/buffer_head.h>
  21. #include <linux/fs.h>
  22. #include <linux/pagemap.h>
  23. #include <linux/highmem.h>
  24. #include <linux/time.h>
  25. #include <linux/init.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/string.h>
  28. #include <linux/backing-dev.h>
  29. #include <linux/mount.h>
  30. #include <linux/mpage.h>
  31. #include <linux/swap.h>
  32. #include <linux/writeback.h>
  33. #include <linux/statfs.h>
  34. #include <linux/compat.h>
  35. #include <linux/parser.h>
  36. #include <linux/ctype.h>
  37. #include <linux/namei.h>
  38. #include <linux/miscdevice.h>
  39. #include <linux/magic.h>
  40. #include <linux/slab.h>
  41. #include "compat.h"
  42. #include "delayed-inode.h"
  43. #include "ctree.h"
  44. #include "disk-io.h"
  45. #include "transaction.h"
  46. #include "btrfs_inode.h"
  47. #include "ioctl.h"
  48. #include "print-tree.h"
  49. #include "xattr.h"
  50. #include "volumes.h"
  51. #include "version.h"
  52. #include "export.h"
  53. #include "compression.h"
  54. #define CREATE_TRACE_POINTS
  55. #include <trace/events/btrfs.h>
  56. static const struct super_operations btrfs_super_ops;
  57. static const char *btrfs_decode_error(struct btrfs_fs_info *fs_info, int errno,
  58. char nbuf[16])
  59. {
  60. char *errstr = NULL;
  61. switch (errno) {
  62. case -EIO:
  63. errstr = "IO failure";
  64. break;
  65. case -ENOMEM:
  66. errstr = "Out of memory";
  67. break;
  68. case -EROFS:
  69. errstr = "Readonly filesystem";
  70. break;
  71. default:
  72. if (nbuf) {
  73. if (snprintf(nbuf, 16, "error %d", -errno) >= 0)
  74. errstr = nbuf;
  75. }
  76. break;
  77. }
  78. return errstr;
  79. }
  80. static void __save_error_info(struct btrfs_fs_info *fs_info)
  81. {
  82. /*
  83. * today we only save the error info into ram. Long term we'll
  84. * also send it down to the disk
  85. */
  86. fs_info->fs_state = BTRFS_SUPER_FLAG_ERROR;
  87. }
  88. /* NOTE:
  89. * We move write_super stuff at umount in order to avoid deadlock
  90. * for umount hold all lock.
  91. */
  92. static void save_error_info(struct btrfs_fs_info *fs_info)
  93. {
  94. __save_error_info(fs_info);
  95. }
  96. /* btrfs handle error by forcing the filesystem readonly */
  97. static void btrfs_handle_error(struct btrfs_fs_info *fs_info)
  98. {
  99. struct super_block *sb = fs_info->sb;
  100. if (sb->s_flags & MS_RDONLY)
  101. return;
  102. if (fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) {
  103. sb->s_flags |= MS_RDONLY;
  104. printk(KERN_INFO "btrfs is forced readonly\n");
  105. }
  106. }
  107. /*
  108. * __btrfs_std_error decodes expected errors from the caller and
  109. * invokes the approciate error response.
  110. */
  111. void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
  112. unsigned int line, int errno)
  113. {
  114. struct super_block *sb = fs_info->sb;
  115. char nbuf[16];
  116. const char *errstr;
  117. /*
  118. * Special case: if the error is EROFS, and we're already
  119. * under MS_RDONLY, then it is safe here.
  120. */
  121. if (errno == -EROFS && (sb->s_flags & MS_RDONLY))
  122. return;
  123. errstr = btrfs_decode_error(fs_info, errno, nbuf);
  124. printk(KERN_CRIT "BTRFS error (device %s) in %s:%d: %s\n",
  125. sb->s_id, function, line, errstr);
  126. save_error_info(fs_info);
  127. btrfs_handle_error(fs_info);
  128. }
  129. static void btrfs_put_super(struct super_block *sb)
  130. {
  131. struct btrfs_root *root = btrfs_sb(sb);
  132. int ret;
  133. ret = close_ctree(root);
  134. sb->s_fs_info = NULL;
  135. (void)ret; /* FIXME: need to fix VFS to return error? */
  136. }
  137. enum {
  138. Opt_degraded, Opt_subvol, Opt_subvolid, Opt_device, Opt_nodatasum,
  139. Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd,
  140. Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
  141. Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
  142. Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
  143. Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
  144. Opt_enospc_debug, Opt_subvolrootid, Opt_defrag, Opt_err,
  145. };
  146. static match_table_t tokens = {
  147. {Opt_degraded, "degraded"},
  148. {Opt_subvol, "subvol=%s"},
  149. {Opt_subvolid, "subvolid=%d"},
  150. {Opt_device, "device=%s"},
  151. {Opt_nodatasum, "nodatasum"},
  152. {Opt_nodatacow, "nodatacow"},
  153. {Opt_nobarrier, "nobarrier"},
  154. {Opt_max_inline, "max_inline=%s"},
  155. {Opt_alloc_start, "alloc_start=%s"},
  156. {Opt_thread_pool, "thread_pool=%d"},
  157. {Opt_compress, "compress"},
  158. {Opt_compress_type, "compress=%s"},
  159. {Opt_compress_force, "compress-force"},
  160. {Opt_compress_force_type, "compress-force=%s"},
  161. {Opt_ssd, "ssd"},
  162. {Opt_ssd_spread, "ssd_spread"},
  163. {Opt_nossd, "nossd"},
  164. {Opt_noacl, "noacl"},
  165. {Opt_notreelog, "notreelog"},
  166. {Opt_flushoncommit, "flushoncommit"},
  167. {Opt_ratio, "metadata_ratio=%d"},
  168. {Opt_discard, "discard"},
  169. {Opt_space_cache, "space_cache"},
  170. {Opt_clear_cache, "clear_cache"},
  171. {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
  172. {Opt_enospc_debug, "enospc_debug"},
  173. {Opt_subvolrootid, "subvolrootid=%d"},
  174. {Opt_defrag, "autodefrag"},
  175. {Opt_err, NULL},
  176. };
  177. /*
  178. * Regular mount options parser. Everything that is needed only when
  179. * reading in a new superblock is parsed here.
  180. */
  181. int btrfs_parse_options(struct btrfs_root *root, char *options)
  182. {
  183. struct btrfs_fs_info *info = root->fs_info;
  184. substring_t args[MAX_OPT_ARGS];
  185. char *p, *num, *orig;
  186. int intarg;
  187. int ret = 0;
  188. char *compress_type;
  189. bool compress_force = false;
  190. if (!options)
  191. return 0;
  192. /*
  193. * strsep changes the string, duplicate it because parse_options
  194. * gets called twice
  195. */
  196. options = kstrdup(options, GFP_NOFS);
  197. if (!options)
  198. return -ENOMEM;
  199. orig = options;
  200. while ((p = strsep(&options, ",")) != NULL) {
  201. int token;
  202. if (!*p)
  203. continue;
  204. token = match_token(p, tokens, args);
  205. switch (token) {
  206. case Opt_degraded:
  207. printk(KERN_INFO "btrfs: allowing degraded mounts\n");
  208. btrfs_set_opt(info->mount_opt, DEGRADED);
  209. break;
  210. case Opt_subvol:
  211. case Opt_subvolid:
  212. case Opt_subvolrootid:
  213. case Opt_device:
  214. /*
  215. * These are parsed by btrfs_parse_early_options
  216. * and can be happily ignored here.
  217. */
  218. break;
  219. case Opt_nodatasum:
  220. printk(KERN_INFO "btrfs: setting nodatasum\n");
  221. btrfs_set_opt(info->mount_opt, NODATASUM);
  222. break;
  223. case Opt_nodatacow:
  224. printk(KERN_INFO "btrfs: setting nodatacow\n");
  225. btrfs_set_opt(info->mount_opt, NODATACOW);
  226. btrfs_set_opt(info->mount_opt, NODATASUM);
  227. break;
  228. case Opt_compress_force:
  229. case Opt_compress_force_type:
  230. compress_force = true;
  231. case Opt_compress:
  232. case Opt_compress_type:
  233. if (token == Opt_compress ||
  234. token == Opt_compress_force ||
  235. strcmp(args[0].from, "zlib") == 0) {
  236. compress_type = "zlib";
  237. info->compress_type = BTRFS_COMPRESS_ZLIB;
  238. } else if (strcmp(args[0].from, "lzo") == 0) {
  239. compress_type = "lzo";
  240. info->compress_type = BTRFS_COMPRESS_LZO;
  241. } else {
  242. ret = -EINVAL;
  243. goto out;
  244. }
  245. btrfs_set_opt(info->mount_opt, COMPRESS);
  246. if (compress_force) {
  247. btrfs_set_opt(info->mount_opt, FORCE_COMPRESS);
  248. pr_info("btrfs: force %s compression\n",
  249. compress_type);
  250. } else
  251. pr_info("btrfs: use %s compression\n",
  252. compress_type);
  253. break;
  254. case Opt_ssd:
  255. printk(KERN_INFO "btrfs: use ssd allocation scheme\n");
  256. btrfs_set_opt(info->mount_opt, SSD);
  257. break;
  258. case Opt_ssd_spread:
  259. printk(KERN_INFO "btrfs: use spread ssd "
  260. "allocation scheme\n");
  261. btrfs_set_opt(info->mount_opt, SSD);
  262. btrfs_set_opt(info->mount_opt, SSD_SPREAD);
  263. break;
  264. case Opt_nossd:
  265. printk(KERN_INFO "btrfs: not using ssd allocation "
  266. "scheme\n");
  267. btrfs_set_opt(info->mount_opt, NOSSD);
  268. btrfs_clear_opt(info->mount_opt, SSD);
  269. btrfs_clear_opt(info->mount_opt, SSD_SPREAD);
  270. break;
  271. case Opt_nobarrier:
  272. printk(KERN_INFO "btrfs: turning off barriers\n");
  273. btrfs_set_opt(info->mount_opt, NOBARRIER);
  274. break;
  275. case Opt_thread_pool:
  276. intarg = 0;
  277. match_int(&args[0], &intarg);
  278. if (intarg) {
  279. info->thread_pool_size = intarg;
  280. printk(KERN_INFO "btrfs: thread pool %d\n",
  281. info->thread_pool_size);
  282. }
  283. break;
  284. case Opt_max_inline:
  285. num = match_strdup(&args[0]);
  286. if (num) {
  287. info->max_inline = memparse(num, NULL);
  288. kfree(num);
  289. if (info->max_inline) {
  290. info->max_inline = max_t(u64,
  291. info->max_inline,
  292. root->sectorsize);
  293. }
  294. printk(KERN_INFO "btrfs: max_inline at %llu\n",
  295. (unsigned long long)info->max_inline);
  296. }
  297. break;
  298. case Opt_alloc_start:
  299. num = match_strdup(&args[0]);
  300. if (num) {
  301. info->alloc_start = memparse(num, NULL);
  302. kfree(num);
  303. printk(KERN_INFO
  304. "btrfs: allocations start at %llu\n",
  305. (unsigned long long)info->alloc_start);
  306. }
  307. break;
  308. case Opt_noacl:
  309. root->fs_info->sb->s_flags &= ~MS_POSIXACL;
  310. break;
  311. case Opt_notreelog:
  312. printk(KERN_INFO "btrfs: disabling tree log\n");
  313. btrfs_set_opt(info->mount_opt, NOTREELOG);
  314. break;
  315. case Opt_flushoncommit:
  316. printk(KERN_INFO "btrfs: turning on flush-on-commit\n");
  317. btrfs_set_opt(info->mount_opt, FLUSHONCOMMIT);
  318. break;
  319. case Opt_ratio:
  320. intarg = 0;
  321. match_int(&args[0], &intarg);
  322. if (intarg) {
  323. info->metadata_ratio = intarg;
  324. printk(KERN_INFO "btrfs: metadata ratio %d\n",
  325. info->metadata_ratio);
  326. }
  327. break;
  328. case Opt_discard:
  329. btrfs_set_opt(info->mount_opt, DISCARD);
  330. break;
  331. case Opt_space_cache:
  332. printk(KERN_INFO "btrfs: enabling disk space caching\n");
  333. btrfs_set_opt(info->mount_opt, SPACE_CACHE);
  334. break;
  335. case Opt_clear_cache:
  336. printk(KERN_INFO "btrfs: force clearing of disk cache\n");
  337. btrfs_set_opt(info->mount_opt, CLEAR_CACHE);
  338. break;
  339. case Opt_user_subvol_rm_allowed:
  340. btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED);
  341. break;
  342. case Opt_enospc_debug:
  343. btrfs_set_opt(info->mount_opt, ENOSPC_DEBUG);
  344. break;
  345. case Opt_defrag:
  346. printk(KERN_INFO "btrfs: enabling auto defrag");
  347. btrfs_set_opt(info->mount_opt, AUTO_DEFRAG);
  348. break;
  349. case Opt_err:
  350. printk(KERN_INFO "btrfs: unrecognized mount option "
  351. "'%s'\n", p);
  352. ret = -EINVAL;
  353. goto out;
  354. default:
  355. break;
  356. }
  357. }
  358. out:
  359. kfree(orig);
  360. return ret;
  361. }
  362. /*
  363. * Parse mount options that are required early in the mount process.
  364. *
  365. * All other options will be parsed on much later in the mount process and
  366. * only when we need to allocate a new super block.
  367. */
  368. static int btrfs_parse_early_options(const char *options, fmode_t flags,
  369. void *holder, char **subvol_name, u64 *subvol_objectid,
  370. u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
  371. {
  372. substring_t args[MAX_OPT_ARGS];
  373. char *opts, *orig, *p;
  374. int error = 0;
  375. int intarg;
  376. if (!options)
  377. goto out;
  378. /*
  379. * strsep changes the string, duplicate it because parse_options
  380. * gets called twice
  381. */
  382. opts = kstrdup(options, GFP_KERNEL);
  383. if (!opts)
  384. return -ENOMEM;
  385. orig = opts;
  386. while ((p = strsep(&opts, ",")) != NULL) {
  387. int token;
  388. if (!*p)
  389. continue;
  390. token = match_token(p, tokens, args);
  391. switch (token) {
  392. case Opt_subvol:
  393. *subvol_name = match_strdup(&args[0]);
  394. break;
  395. case Opt_subvolid:
  396. intarg = 0;
  397. error = match_int(&args[0], &intarg);
  398. if (!error) {
  399. /* we want the original fs_tree */
  400. if (!intarg)
  401. *subvol_objectid =
  402. BTRFS_FS_TREE_OBJECTID;
  403. else
  404. *subvol_objectid = intarg;
  405. }
  406. break;
  407. case Opt_subvolrootid:
  408. intarg = 0;
  409. error = match_int(&args[0], &intarg);
  410. if (!error) {
  411. /* we want the original fs_tree */
  412. if (!intarg)
  413. *subvol_rootid =
  414. BTRFS_FS_TREE_OBJECTID;
  415. else
  416. *subvol_rootid = intarg;
  417. }
  418. break;
  419. case Opt_device:
  420. error = btrfs_scan_one_device(match_strdup(&args[0]),
  421. flags, holder, fs_devices);
  422. if (error)
  423. goto out_free_opts;
  424. break;
  425. default:
  426. break;
  427. }
  428. }
  429. out_free_opts:
  430. kfree(orig);
  431. out:
  432. /*
  433. * If no subvolume name is specified we use the default one. Allocate
  434. * a copy of the string "." here so that code later in the
  435. * mount path doesn't care if it's the default volume or another one.
  436. */
  437. if (!*subvol_name) {
  438. *subvol_name = kstrdup(".", GFP_KERNEL);
  439. if (!*subvol_name)
  440. return -ENOMEM;
  441. }
  442. return error;
  443. }
  444. static struct dentry *get_default_root(struct super_block *sb,
  445. u64 subvol_objectid)
  446. {
  447. struct btrfs_root *root = sb->s_fs_info;
  448. struct btrfs_root *new_root;
  449. struct btrfs_dir_item *di;
  450. struct btrfs_path *path;
  451. struct btrfs_key location;
  452. struct inode *inode;
  453. struct dentry *dentry;
  454. u64 dir_id;
  455. int new = 0;
  456. /*
  457. * We have a specific subvol we want to mount, just setup location and
  458. * go look up the root.
  459. */
  460. if (subvol_objectid) {
  461. location.objectid = subvol_objectid;
  462. location.type = BTRFS_ROOT_ITEM_KEY;
  463. location.offset = (u64)-1;
  464. goto find_root;
  465. }
  466. path = btrfs_alloc_path();
  467. if (!path)
  468. return ERR_PTR(-ENOMEM);
  469. path->leave_spinning = 1;
  470. /*
  471. * Find the "default" dir item which points to the root item that we
  472. * will mount by default if we haven't been given a specific subvolume
  473. * to mount.
  474. */
  475. dir_id = btrfs_super_root_dir(&root->fs_info->super_copy);
  476. di = btrfs_lookup_dir_item(NULL, root, path, dir_id, "default", 7, 0);
  477. if (IS_ERR(di)) {
  478. btrfs_free_path(path);
  479. return ERR_CAST(di);
  480. }
  481. if (!di) {
  482. /*
  483. * Ok the default dir item isn't there. This is weird since
  484. * it's always been there, but don't freak out, just try and
  485. * mount to root most subvolume.
  486. */
  487. btrfs_free_path(path);
  488. dir_id = BTRFS_FIRST_FREE_OBJECTID;
  489. new_root = root->fs_info->fs_root;
  490. goto setup_root;
  491. }
  492. btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location);
  493. btrfs_free_path(path);
  494. find_root:
  495. new_root = btrfs_read_fs_root_no_name(root->fs_info, &location);
  496. if (IS_ERR(new_root))
  497. return ERR_CAST(new_root);
  498. if (btrfs_root_refs(&new_root->root_item) == 0)
  499. return ERR_PTR(-ENOENT);
  500. dir_id = btrfs_root_dirid(&new_root->root_item);
  501. setup_root:
  502. location.objectid = dir_id;
  503. location.type = BTRFS_INODE_ITEM_KEY;
  504. location.offset = 0;
  505. inode = btrfs_iget(sb, &location, new_root, &new);
  506. if (IS_ERR(inode))
  507. return ERR_CAST(inode);
  508. /*
  509. * If we're just mounting the root most subvol put the inode and return
  510. * a reference to the dentry. We will have already gotten a reference
  511. * to the inode in btrfs_fill_super so we're good to go.
  512. */
  513. if (!new && sb->s_root->d_inode == inode) {
  514. iput(inode);
  515. return dget(sb->s_root);
  516. }
  517. if (new) {
  518. const struct qstr name = { .name = "/", .len = 1 };
  519. /*
  520. * New inode, we need to make the dentry a sibling of s_root so
  521. * everything gets cleaned up properly on unmount.
  522. */
  523. dentry = d_alloc(sb->s_root, &name);
  524. if (!dentry) {
  525. iput(inode);
  526. return ERR_PTR(-ENOMEM);
  527. }
  528. d_splice_alias(inode, dentry);
  529. } else {
  530. /*
  531. * We found the inode in cache, just find a dentry for it and
  532. * put the reference to the inode we just got.
  533. */
  534. dentry = d_find_alias(inode);
  535. iput(inode);
  536. }
  537. return dentry;
  538. }
  539. static int btrfs_fill_super(struct super_block *sb,
  540. struct btrfs_fs_devices *fs_devices,
  541. void *data, int silent)
  542. {
  543. struct inode *inode;
  544. struct dentry *root_dentry;
  545. struct btrfs_root *tree_root;
  546. struct btrfs_key key;
  547. int err;
  548. sb->s_maxbytes = MAX_LFS_FILESIZE;
  549. sb->s_magic = BTRFS_SUPER_MAGIC;
  550. sb->s_op = &btrfs_super_ops;
  551. sb->s_d_op = &btrfs_dentry_operations;
  552. sb->s_export_op = &btrfs_export_ops;
  553. sb->s_xattr = btrfs_xattr_handlers;
  554. sb->s_time_gran = 1;
  555. #ifdef CONFIG_BTRFS_FS_POSIX_ACL
  556. sb->s_flags |= MS_POSIXACL;
  557. #endif
  558. tree_root = open_ctree(sb, fs_devices, (char *)data);
  559. if (IS_ERR(tree_root)) {
  560. printk("btrfs: open_ctree failed\n");
  561. return PTR_ERR(tree_root);
  562. }
  563. sb->s_fs_info = tree_root;
  564. key.objectid = BTRFS_FIRST_FREE_OBJECTID;
  565. key.type = BTRFS_INODE_ITEM_KEY;
  566. key.offset = 0;
  567. inode = btrfs_iget(sb, &key, tree_root->fs_info->fs_root, NULL);
  568. if (IS_ERR(inode)) {
  569. err = PTR_ERR(inode);
  570. goto fail_close;
  571. }
  572. root_dentry = d_alloc_root(inode);
  573. if (!root_dentry) {
  574. iput(inode);
  575. err = -ENOMEM;
  576. goto fail_close;
  577. }
  578. sb->s_root = root_dentry;
  579. save_mount_options(sb, data);
  580. return 0;
  581. fail_close:
  582. close_ctree(tree_root);
  583. return err;
  584. }
  585. int btrfs_sync_fs(struct super_block *sb, int wait)
  586. {
  587. struct btrfs_trans_handle *trans;
  588. struct btrfs_root *root = btrfs_sb(sb);
  589. int ret;
  590. trace_btrfs_sync_fs(wait);
  591. if (!wait) {
  592. filemap_flush(root->fs_info->btree_inode->i_mapping);
  593. return 0;
  594. }
  595. btrfs_start_delalloc_inodes(root, 0);
  596. btrfs_wait_ordered_extents(root, 0, 0);
  597. trans = btrfs_start_transaction(root, 0);
  598. if (IS_ERR(trans))
  599. return PTR_ERR(trans);
  600. ret = btrfs_commit_transaction(trans, root);
  601. return ret;
  602. }
  603. static int btrfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
  604. {
  605. struct btrfs_root *root = btrfs_sb(vfs->mnt_sb);
  606. struct btrfs_fs_info *info = root->fs_info;
  607. char *compress_type;
  608. if (btrfs_test_opt(root, DEGRADED))
  609. seq_puts(seq, ",degraded");
  610. if (btrfs_test_opt(root, NODATASUM))
  611. seq_puts(seq, ",nodatasum");
  612. if (btrfs_test_opt(root, NODATACOW))
  613. seq_puts(seq, ",nodatacow");
  614. if (btrfs_test_opt(root, NOBARRIER))
  615. seq_puts(seq, ",nobarrier");
  616. if (info->max_inline != 8192 * 1024)
  617. seq_printf(seq, ",max_inline=%llu",
  618. (unsigned long long)info->max_inline);
  619. if (info->alloc_start != 0)
  620. seq_printf(seq, ",alloc_start=%llu",
  621. (unsigned long long)info->alloc_start);
  622. if (info->thread_pool_size != min_t(unsigned long,
  623. num_online_cpus() + 2, 8))
  624. seq_printf(seq, ",thread_pool=%d", info->thread_pool_size);
  625. if (btrfs_test_opt(root, COMPRESS)) {
  626. if (info->compress_type == BTRFS_COMPRESS_ZLIB)
  627. compress_type = "zlib";
  628. else
  629. compress_type = "lzo";
  630. if (btrfs_test_opt(root, FORCE_COMPRESS))
  631. seq_printf(seq, ",compress-force=%s", compress_type);
  632. else
  633. seq_printf(seq, ",compress=%s", compress_type);
  634. }
  635. if (btrfs_test_opt(root, NOSSD))
  636. seq_puts(seq, ",nossd");
  637. if (btrfs_test_opt(root, SSD_SPREAD))
  638. seq_puts(seq, ",ssd_spread");
  639. else if (btrfs_test_opt(root, SSD))
  640. seq_puts(seq, ",ssd");
  641. if (btrfs_test_opt(root, NOTREELOG))
  642. seq_puts(seq, ",notreelog");
  643. if (btrfs_test_opt(root, FLUSHONCOMMIT))
  644. seq_puts(seq, ",flushoncommit");
  645. if (btrfs_test_opt(root, DISCARD))
  646. seq_puts(seq, ",discard");
  647. if (!(root->fs_info->sb->s_flags & MS_POSIXACL))
  648. seq_puts(seq, ",noacl");
  649. if (btrfs_test_opt(root, SPACE_CACHE))
  650. seq_puts(seq, ",space_cache");
  651. if (btrfs_test_opt(root, CLEAR_CACHE))
  652. seq_puts(seq, ",clear_cache");
  653. if (btrfs_test_opt(root, USER_SUBVOL_RM_ALLOWED))
  654. seq_puts(seq, ",user_subvol_rm_allowed");
  655. return 0;
  656. }
  657. static int btrfs_test_super(struct super_block *s, void *data)
  658. {
  659. struct btrfs_root *test_root = data;
  660. struct btrfs_root *root = btrfs_sb(s);
  661. /*
  662. * If this super block is going away, return false as it
  663. * can't match as an existing super block.
  664. */
  665. if (!atomic_read(&s->s_active))
  666. return 0;
  667. return root->fs_info->fs_devices == test_root->fs_info->fs_devices;
  668. }
  669. static int btrfs_set_super(struct super_block *s, void *data)
  670. {
  671. s->s_fs_info = data;
  672. return set_anon_super(s, data);
  673. }
  674. /*
  675. * Find a superblock for the given device / mount point.
  676. *
  677. * Note: This is based on get_sb_bdev from fs/super.c with a few additions
  678. * for multiple device setup. Make sure to keep it in sync.
  679. */
  680. static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
  681. const char *device_name, void *data)
  682. {
  683. struct block_device *bdev = NULL;
  684. struct super_block *s;
  685. struct dentry *root;
  686. struct btrfs_fs_devices *fs_devices = NULL;
  687. struct btrfs_root *tree_root = NULL;
  688. struct btrfs_fs_info *fs_info = NULL;
  689. fmode_t mode = FMODE_READ;
  690. char *subvol_name = NULL;
  691. u64 subvol_objectid = 0;
  692. u64 subvol_rootid = 0;
  693. int error = 0;
  694. if (!(flags & MS_RDONLY))
  695. mode |= FMODE_WRITE;
  696. error = btrfs_parse_early_options(data, mode, fs_type,
  697. &subvol_name, &subvol_objectid,
  698. &subvol_rootid, &fs_devices);
  699. if (error)
  700. return ERR_PTR(error);
  701. error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices);
  702. if (error)
  703. goto error_free_subvol_name;
  704. error = btrfs_open_devices(fs_devices, mode, fs_type);
  705. if (error)
  706. goto error_free_subvol_name;
  707. if (!(flags & MS_RDONLY) && fs_devices->rw_devices == 0) {
  708. error = -EACCES;
  709. goto error_close_devices;
  710. }
  711. /*
  712. * Setup a dummy root and fs_info for test/set super. This is because
  713. * we don't actually fill this stuff out until open_ctree, but we need
  714. * it for searching for existing supers, so this lets us do that and
  715. * then open_ctree will properly initialize everything later.
  716. */
  717. fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_NOFS);
  718. tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
  719. if (!fs_info || !tree_root) {
  720. error = -ENOMEM;
  721. goto error_close_devices;
  722. }
  723. fs_info->tree_root = tree_root;
  724. fs_info->fs_devices = fs_devices;
  725. tree_root->fs_info = fs_info;
  726. bdev = fs_devices->latest_bdev;
  727. s = sget(fs_type, btrfs_test_super, btrfs_set_super, tree_root);
  728. if (IS_ERR(s))
  729. goto error_s;
  730. if (s->s_root) {
  731. if ((flags ^ s->s_flags) & MS_RDONLY) {
  732. deactivate_locked_super(s);
  733. error = -EBUSY;
  734. goto error_close_devices;
  735. }
  736. btrfs_close_devices(fs_devices);
  737. kfree(fs_info);
  738. kfree(tree_root);
  739. } else {
  740. char b[BDEVNAME_SIZE];
  741. s->s_flags = flags;
  742. strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
  743. error = btrfs_fill_super(s, fs_devices, data,
  744. flags & MS_SILENT ? 1 : 0);
  745. if (error) {
  746. deactivate_locked_super(s);
  747. goto error_free_subvol_name;
  748. }
  749. btrfs_sb(s)->fs_info->bdev_holder = fs_type;
  750. s->s_flags |= MS_ACTIVE;
  751. }
  752. /* if they gave us a subvolume name bind mount into that */
  753. if (strcmp(subvol_name, ".")) {
  754. struct dentry *new_root;
  755. root = get_default_root(s, subvol_rootid);
  756. if (IS_ERR(root)) {
  757. error = PTR_ERR(root);
  758. deactivate_locked_super(s);
  759. goto error_free_subvol_name;
  760. }
  761. mutex_lock(&root->d_inode->i_mutex);
  762. new_root = lookup_one_len(subvol_name, root,
  763. strlen(subvol_name));
  764. mutex_unlock(&root->d_inode->i_mutex);
  765. if (IS_ERR(new_root)) {
  766. dput(root);
  767. deactivate_locked_super(s);
  768. error = PTR_ERR(new_root);
  769. goto error_free_subvol_name;
  770. }
  771. if (!new_root->d_inode) {
  772. dput(root);
  773. dput(new_root);
  774. deactivate_locked_super(s);
  775. error = -ENXIO;
  776. goto error_free_subvol_name;
  777. }
  778. dput(root);
  779. root = new_root;
  780. } else {
  781. root = get_default_root(s, subvol_objectid);
  782. if (IS_ERR(root)) {
  783. error = PTR_ERR(root);
  784. deactivate_locked_super(s);
  785. goto error_free_subvol_name;
  786. }
  787. }
  788. kfree(subvol_name);
  789. return root;
  790. error_s:
  791. error = PTR_ERR(s);
  792. error_close_devices:
  793. btrfs_close_devices(fs_devices);
  794. kfree(fs_info);
  795. kfree(tree_root);
  796. error_free_subvol_name:
  797. kfree(subvol_name);
  798. return ERR_PTR(error);
  799. }
  800. static int btrfs_remount(struct super_block *sb, int *flags, char *data)
  801. {
  802. struct btrfs_root *root = btrfs_sb(sb);
  803. int ret;
  804. ret = btrfs_parse_options(root, data);
  805. if (ret)
  806. return -EINVAL;
  807. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  808. return 0;
  809. if (*flags & MS_RDONLY) {
  810. sb->s_flags |= MS_RDONLY;
  811. ret = btrfs_commit_super(root);
  812. WARN_ON(ret);
  813. } else {
  814. if (root->fs_info->fs_devices->rw_devices == 0)
  815. return -EACCES;
  816. if (btrfs_super_log_root(&root->fs_info->super_copy) != 0)
  817. return -EINVAL;
  818. ret = btrfs_cleanup_fs_roots(root->fs_info);
  819. WARN_ON(ret);
  820. /* recover relocation */
  821. ret = btrfs_recover_relocation(root);
  822. WARN_ON(ret);
  823. sb->s_flags &= ~MS_RDONLY;
  824. }
  825. return 0;
  826. }
  827. /* Used to sort the devices by max_avail(descending sort) */
  828. static int btrfs_cmp_device_free_bytes(const void *dev_info1,
  829. const void *dev_info2)
  830. {
  831. if (((struct btrfs_device_info *)dev_info1)->max_avail >
  832. ((struct btrfs_device_info *)dev_info2)->max_avail)
  833. return -1;
  834. else if (((struct btrfs_device_info *)dev_info1)->max_avail <
  835. ((struct btrfs_device_info *)dev_info2)->max_avail)
  836. return 1;
  837. else
  838. return 0;
  839. }
  840. /*
  841. * sort the devices by max_avail, in which max free extent size of each device
  842. * is stored.(Descending Sort)
  843. */
  844. static inline void btrfs_descending_sort_devices(
  845. struct btrfs_device_info *devices,
  846. size_t nr_devices)
  847. {
  848. sort(devices, nr_devices, sizeof(struct btrfs_device_info),
  849. btrfs_cmp_device_free_bytes, NULL);
  850. }
  851. /*
  852. * The helper to calc the free space on the devices that can be used to store
  853. * file data.
  854. */
  855. static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
  856. {
  857. struct btrfs_fs_info *fs_info = root->fs_info;
  858. struct btrfs_device_info *devices_info;
  859. struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
  860. struct btrfs_device *device;
  861. u64 skip_space;
  862. u64 type;
  863. u64 avail_space;
  864. u64 used_space;
  865. u64 min_stripe_size;
  866. int min_stripes = 1;
  867. int i = 0, nr_devices;
  868. int ret;
  869. nr_devices = fs_info->fs_devices->rw_devices;
  870. BUG_ON(!nr_devices);
  871. devices_info = kmalloc(sizeof(*devices_info) * nr_devices,
  872. GFP_NOFS);
  873. if (!devices_info)
  874. return -ENOMEM;
  875. /* calc min stripe number for data space alloction */
  876. type = btrfs_get_alloc_profile(root, 1);
  877. if (type & BTRFS_BLOCK_GROUP_RAID0)
  878. min_stripes = 2;
  879. else if (type & BTRFS_BLOCK_GROUP_RAID1)
  880. min_stripes = 2;
  881. else if (type & BTRFS_BLOCK_GROUP_RAID10)
  882. min_stripes = 4;
  883. if (type & BTRFS_BLOCK_GROUP_DUP)
  884. min_stripe_size = 2 * BTRFS_STRIPE_LEN;
  885. else
  886. min_stripe_size = BTRFS_STRIPE_LEN;
  887. list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list) {
  888. if (!device->in_fs_metadata)
  889. continue;
  890. avail_space = device->total_bytes - device->bytes_used;
  891. /* align with stripe_len */
  892. do_div(avail_space, BTRFS_STRIPE_LEN);
  893. avail_space *= BTRFS_STRIPE_LEN;
  894. /*
  895. * In order to avoid overwritting the superblock on the drive,
  896. * btrfs starts at an offset of at least 1MB when doing chunk
  897. * allocation.
  898. */
  899. skip_space = 1024 * 1024;
  900. /* user can set the offset in fs_info->alloc_start. */
  901. if (fs_info->alloc_start + BTRFS_STRIPE_LEN <=
  902. device->total_bytes)
  903. skip_space = max(fs_info->alloc_start, skip_space);
  904. /*
  905. * btrfs can not use the free space in [0, skip_space - 1],
  906. * we must subtract it from the total. In order to implement
  907. * it, we account the used space in this range first.
  908. */
  909. ret = btrfs_account_dev_extents_size(device, 0, skip_space - 1,
  910. &used_space);
  911. if (ret) {
  912. kfree(devices_info);
  913. return ret;
  914. }
  915. /* calc the free space in [0, skip_space - 1] */
  916. skip_space -= used_space;
  917. /*
  918. * we can use the free space in [0, skip_space - 1], subtract
  919. * it from the total.
  920. */
  921. if (avail_space && avail_space >= skip_space)
  922. avail_space -= skip_space;
  923. else
  924. avail_space = 0;
  925. if (avail_space < min_stripe_size)
  926. continue;
  927. devices_info[i].dev = device;
  928. devices_info[i].max_avail = avail_space;
  929. i++;
  930. }
  931. nr_devices = i;
  932. btrfs_descending_sort_devices(devices_info, nr_devices);
  933. i = nr_devices - 1;
  934. avail_space = 0;
  935. while (nr_devices >= min_stripes) {
  936. if (devices_info[i].max_avail >= min_stripe_size) {
  937. int j;
  938. u64 alloc_size;
  939. avail_space += devices_info[i].max_avail * min_stripes;
  940. alloc_size = devices_info[i].max_avail;
  941. for (j = i + 1 - min_stripes; j <= i; j++)
  942. devices_info[j].max_avail -= alloc_size;
  943. }
  944. i--;
  945. nr_devices--;
  946. }
  947. kfree(devices_info);
  948. *free_bytes = avail_space;
  949. return 0;
  950. }
  951. static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  952. {
  953. struct btrfs_root *root = btrfs_sb(dentry->d_sb);
  954. struct btrfs_super_block *disk_super = &root->fs_info->super_copy;
  955. struct list_head *head = &root->fs_info->space_info;
  956. struct btrfs_space_info *found;
  957. u64 total_used = 0;
  958. u64 total_free_data = 0;
  959. int bits = dentry->d_sb->s_blocksize_bits;
  960. __be32 *fsid = (__be32 *)root->fs_info->fsid;
  961. int ret;
  962. /* holding chunk_muext to avoid allocating new chunks */
  963. mutex_lock(&root->fs_info->chunk_mutex);
  964. rcu_read_lock();
  965. list_for_each_entry_rcu(found, head, list) {
  966. if (found->flags & BTRFS_BLOCK_GROUP_DATA) {
  967. total_free_data += found->disk_total - found->disk_used;
  968. total_free_data -=
  969. btrfs_account_ro_block_groups_free_space(found);
  970. }
  971. total_used += found->disk_used;
  972. }
  973. rcu_read_unlock();
  974. buf->f_namelen = BTRFS_NAME_LEN;
  975. buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits;
  976. buf->f_bfree = buf->f_blocks - (total_used >> bits);
  977. buf->f_bsize = dentry->d_sb->s_blocksize;
  978. buf->f_type = BTRFS_SUPER_MAGIC;
  979. buf->f_bavail = total_free_data;
  980. ret = btrfs_calc_avail_data_space(root, &total_free_data);
  981. if (ret) {
  982. mutex_unlock(&root->fs_info->chunk_mutex);
  983. return ret;
  984. }
  985. buf->f_bavail += total_free_data;
  986. buf->f_bavail = buf->f_bavail >> bits;
  987. mutex_unlock(&root->fs_info->chunk_mutex);
  988. /* We treat it as constant endianness (it doesn't matter _which_)
  989. because we want the fsid to come out the same whether mounted
  990. on a big-endian or little-endian host */
  991. buf->f_fsid.val[0] = be32_to_cpu(fsid[0]) ^ be32_to_cpu(fsid[2]);
  992. buf->f_fsid.val[1] = be32_to_cpu(fsid[1]) ^ be32_to_cpu(fsid[3]);
  993. /* Mask in the root object ID too, to disambiguate subvols */
  994. buf->f_fsid.val[0] ^= BTRFS_I(dentry->d_inode)->root->objectid >> 32;
  995. buf->f_fsid.val[1] ^= BTRFS_I(dentry->d_inode)->root->objectid;
  996. return 0;
  997. }
  998. static struct file_system_type btrfs_fs_type = {
  999. .owner = THIS_MODULE,
  1000. .name = "btrfs",
  1001. .mount = btrfs_mount,
  1002. .kill_sb = kill_anon_super,
  1003. .fs_flags = FS_REQUIRES_DEV,
  1004. };
  1005. /*
  1006. * used by btrfsctl to scan devices when no FS is mounted
  1007. */
  1008. static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
  1009. unsigned long arg)
  1010. {
  1011. struct btrfs_ioctl_vol_args *vol;
  1012. struct btrfs_fs_devices *fs_devices;
  1013. int ret = -ENOTTY;
  1014. if (!capable(CAP_SYS_ADMIN))
  1015. return -EPERM;
  1016. vol = memdup_user((void __user *)arg, sizeof(*vol));
  1017. if (IS_ERR(vol))
  1018. return PTR_ERR(vol);
  1019. switch (cmd) {
  1020. case BTRFS_IOC_SCAN_DEV:
  1021. ret = btrfs_scan_one_device(vol->name, FMODE_READ,
  1022. &btrfs_fs_type, &fs_devices);
  1023. break;
  1024. }
  1025. kfree(vol);
  1026. return ret;
  1027. }
  1028. static int btrfs_freeze(struct super_block *sb)
  1029. {
  1030. struct btrfs_root *root = btrfs_sb(sb);
  1031. mutex_lock(&root->fs_info->transaction_kthread_mutex);
  1032. mutex_lock(&root->fs_info->cleaner_mutex);
  1033. return 0;
  1034. }
  1035. static int btrfs_unfreeze(struct super_block *sb)
  1036. {
  1037. struct btrfs_root *root = btrfs_sb(sb);
  1038. mutex_unlock(&root->fs_info->cleaner_mutex);
  1039. mutex_unlock(&root->fs_info->transaction_kthread_mutex);
  1040. return 0;
  1041. }
  1042. static const struct super_operations btrfs_super_ops = {
  1043. .drop_inode = btrfs_drop_inode,
  1044. .evict_inode = btrfs_evict_inode,
  1045. .put_super = btrfs_put_super,
  1046. .sync_fs = btrfs_sync_fs,
  1047. .show_options = btrfs_show_options,
  1048. .write_inode = btrfs_write_inode,
  1049. .dirty_inode = btrfs_dirty_inode,
  1050. .alloc_inode = btrfs_alloc_inode,
  1051. .destroy_inode = btrfs_destroy_inode,
  1052. .statfs = btrfs_statfs,
  1053. .remount_fs = btrfs_remount,
  1054. .freeze_fs = btrfs_freeze,
  1055. .unfreeze_fs = btrfs_unfreeze,
  1056. };
  1057. static const struct file_operations btrfs_ctl_fops = {
  1058. .unlocked_ioctl = btrfs_control_ioctl,
  1059. .compat_ioctl = btrfs_control_ioctl,
  1060. .owner = THIS_MODULE,
  1061. .llseek = noop_llseek,
  1062. };
  1063. static struct miscdevice btrfs_misc = {
  1064. .minor = BTRFS_MINOR,
  1065. .name = "btrfs-control",
  1066. .fops = &btrfs_ctl_fops
  1067. };
  1068. MODULE_ALIAS_MISCDEV(BTRFS_MINOR);
  1069. MODULE_ALIAS("devname:btrfs-control");
  1070. static int btrfs_interface_init(void)
  1071. {
  1072. return misc_register(&btrfs_misc);
  1073. }
  1074. static void btrfs_interface_exit(void)
  1075. {
  1076. if (misc_deregister(&btrfs_misc) < 0)
  1077. printk(KERN_INFO "misc_deregister failed for control device");
  1078. }
  1079. static int __init init_btrfs_fs(void)
  1080. {
  1081. int err;
  1082. err = btrfs_init_sysfs();
  1083. if (err)
  1084. return err;
  1085. err = btrfs_init_compress();
  1086. if (err)
  1087. goto free_sysfs;
  1088. err = btrfs_init_cachep();
  1089. if (err)
  1090. goto free_compress;
  1091. err = extent_io_init();
  1092. if (err)
  1093. goto free_cachep;
  1094. err = extent_map_init();
  1095. if (err)
  1096. goto free_extent_io;
  1097. err = btrfs_delayed_inode_init();
  1098. if (err)
  1099. goto free_extent_map;
  1100. err = btrfs_interface_init();
  1101. if (err)
  1102. goto free_delayed_inode;
  1103. err = register_filesystem(&btrfs_fs_type);
  1104. if (err)
  1105. goto unregister_ioctl;
  1106. printk(KERN_INFO "%s loaded\n", BTRFS_BUILD_VERSION);
  1107. return 0;
  1108. unregister_ioctl:
  1109. btrfs_interface_exit();
  1110. free_delayed_inode:
  1111. btrfs_delayed_inode_exit();
  1112. free_extent_map:
  1113. extent_map_exit();
  1114. free_extent_io:
  1115. extent_io_exit();
  1116. free_cachep:
  1117. btrfs_destroy_cachep();
  1118. free_compress:
  1119. btrfs_exit_compress();
  1120. free_sysfs:
  1121. btrfs_exit_sysfs();
  1122. return err;
  1123. }
  1124. static void __exit exit_btrfs_fs(void)
  1125. {
  1126. btrfs_destroy_cachep();
  1127. btrfs_delayed_inode_exit();
  1128. extent_map_exit();
  1129. extent_io_exit();
  1130. btrfs_interface_exit();
  1131. unregister_filesystem(&btrfs_fs_type);
  1132. btrfs_exit_sysfs();
  1133. btrfs_cleanup_fs_uuids();
  1134. btrfs_exit_compress();
  1135. }
  1136. module_init(init_btrfs_fs)
  1137. module_exit(exit_btrfs_fs)
  1138. MODULE_LICENSE("GPL");