super.c 33 KB

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