super.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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/string.h>
  27. #include <linux/smp_lock.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/version.h>
  40. #include "compat.h"
  41. #include "ctree.h"
  42. #include "disk-io.h"
  43. #include "transaction.h"
  44. #include "btrfs_inode.h"
  45. #include "ioctl.h"
  46. #include "print-tree.h"
  47. #include "xattr.h"
  48. #include "volumes.h"
  49. #include "version.h"
  50. #include "export.h"
  51. #include "compression.h"
  52. #define BTRFS_SUPER_MAGIC 0x9123683E
  53. static struct super_operations btrfs_super_ops;
  54. static void btrfs_put_super (struct super_block * sb)
  55. {
  56. struct btrfs_root *root = btrfs_sb(sb);
  57. struct btrfs_fs_info *fs = root->fs_info;
  58. int ret;
  59. ret = close_ctree(root);
  60. if (ret) {
  61. printk("close ctree returns %d\n", ret);
  62. }
  63. btrfs_sysfs_del_super(fs);
  64. sb->s_fs_info = NULL;
  65. }
  66. enum {
  67. Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow,
  68. Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier,
  69. Opt_ssd, Opt_thread_pool, Opt_noacl, Opt_compress, Opt_err,
  70. };
  71. static match_table_t tokens = {
  72. {Opt_degraded, "degraded"},
  73. {Opt_subvol, "subvol=%s"},
  74. {Opt_device, "device=%s"},
  75. {Opt_nodatasum, "nodatasum"},
  76. {Opt_nodatacow, "nodatacow"},
  77. {Opt_nobarrier, "nobarrier"},
  78. {Opt_max_extent, "max_extent=%s"},
  79. {Opt_max_inline, "max_inline=%s"},
  80. {Opt_alloc_start, "alloc_start=%s"},
  81. {Opt_thread_pool, "thread_pool=%d"},
  82. {Opt_compress, "compress"},
  83. {Opt_ssd, "ssd"},
  84. {Opt_noacl, "noacl"},
  85. {Opt_err, NULL},
  86. };
  87. u64 btrfs_parse_size(char *str)
  88. {
  89. u64 res;
  90. int mult = 1;
  91. char *end;
  92. char last;
  93. res = simple_strtoul(str, &end, 10);
  94. last = end[0];
  95. if (isalpha(last)) {
  96. last = tolower(last);
  97. switch (last) {
  98. case 'g':
  99. mult *= 1024;
  100. case 'm':
  101. mult *= 1024;
  102. case 'k':
  103. mult *= 1024;
  104. }
  105. res = res * mult;
  106. }
  107. return res;
  108. }
  109. /*
  110. * Regular mount options parser. Everything that is needed only when
  111. * reading in a new superblock is parsed here.
  112. */
  113. int btrfs_parse_options(struct btrfs_root *root, char *options)
  114. {
  115. struct btrfs_fs_info *info = root->fs_info;
  116. substring_t args[MAX_OPT_ARGS];
  117. char *p, *num;
  118. int intarg;
  119. if (!options)
  120. return 0;
  121. /*
  122. * strsep changes the string, duplicate it because parse_options
  123. * gets called twice
  124. */
  125. options = kstrdup(options, GFP_NOFS);
  126. if (!options)
  127. return -ENOMEM;
  128. while ((p = strsep(&options, ",")) != NULL) {
  129. int token;
  130. if (!*p)
  131. continue;
  132. token = match_token(p, tokens, args);
  133. switch (token) {
  134. case Opt_degraded:
  135. printk(KERN_INFO "btrfs: allowing degraded mounts\n");
  136. btrfs_set_opt(info->mount_opt, DEGRADED);
  137. break;
  138. case Opt_subvol:
  139. case Opt_device:
  140. /*
  141. * These are parsed by btrfs_parse_early_options
  142. * and can be happily ignored here.
  143. */
  144. break;
  145. case Opt_nodatasum:
  146. printk(KERN_INFO "btrfs: setting nodatacsum\n");
  147. btrfs_set_opt(info->mount_opt, NODATASUM);
  148. break;
  149. case Opt_nodatacow:
  150. printk(KERN_INFO "btrfs: setting nodatacow\n");
  151. btrfs_set_opt(info->mount_opt, NODATACOW);
  152. btrfs_set_opt(info->mount_opt, NODATASUM);
  153. break;
  154. case Opt_compress:
  155. printk(KERN_INFO "btrfs: use compression\n");
  156. btrfs_set_opt(info->mount_opt, COMPRESS);
  157. break;
  158. case Opt_ssd:
  159. printk(KERN_INFO "btrfs: use ssd allocation scheme\n");
  160. btrfs_set_opt(info->mount_opt, SSD);
  161. break;
  162. case Opt_nobarrier:
  163. printk(KERN_INFO "btrfs: turning off barriers\n");
  164. btrfs_set_opt(info->mount_opt, NOBARRIER);
  165. break;
  166. case Opt_thread_pool:
  167. intarg = 0;
  168. match_int(&args[0], &intarg);
  169. if (intarg) {
  170. info->thread_pool_size = intarg;
  171. printk(KERN_INFO "btrfs: thread pool %d\n",
  172. info->thread_pool_size);
  173. }
  174. break;
  175. case Opt_max_extent:
  176. num = match_strdup(&args[0]);
  177. if (num) {
  178. info->max_extent = btrfs_parse_size(num);
  179. kfree(num);
  180. info->max_extent = max_t(u64,
  181. info->max_extent, root->sectorsize);
  182. printk(KERN_INFO "btrfs: max_extent at %llu\n",
  183. info->max_extent);
  184. }
  185. break;
  186. case Opt_max_inline:
  187. num = match_strdup(&args[0]);
  188. if (num) {
  189. info->max_inline = btrfs_parse_size(num);
  190. kfree(num);
  191. if (info->max_inline) {
  192. info->max_inline = max_t(u64,
  193. info->max_inline,
  194. root->sectorsize);
  195. }
  196. printk(KERN_INFO "btrfs: max_inline at %llu\n",
  197. info->max_inline);
  198. }
  199. break;
  200. case Opt_alloc_start:
  201. num = match_strdup(&args[0]);
  202. if (num) {
  203. info->alloc_start = btrfs_parse_size(num);
  204. kfree(num);
  205. printk(KERN_INFO
  206. "btrfs: allocations start at %llu\n",
  207. info->alloc_start);
  208. }
  209. break;
  210. case Opt_noacl:
  211. root->fs_info->sb->s_flags &= ~MS_POSIXACL;
  212. break;
  213. default:
  214. break;
  215. }
  216. }
  217. kfree(options);
  218. return 0;
  219. }
  220. /*
  221. * Parse mount options that are required early in the mount process.
  222. *
  223. * All other options will be parsed on much later in the mount process and
  224. * only when we need to allocate a new super block.
  225. */
  226. static int btrfs_parse_early_options(const char *options, fmode_t flags,
  227. void *holder, char **subvol_name,
  228. struct btrfs_fs_devices **fs_devices)
  229. {
  230. substring_t args[MAX_OPT_ARGS];
  231. char *opts, *p;
  232. int error = 0;
  233. if (!options)
  234. goto out;
  235. /*
  236. * strsep changes the string, duplicate it because parse_options
  237. * gets called twice
  238. */
  239. opts = kstrdup(options, GFP_KERNEL);
  240. if (!opts)
  241. return -ENOMEM;
  242. while ((p = strsep(&opts, ",")) != NULL) {
  243. int token;
  244. if (!*p)
  245. continue;
  246. token = match_token(p, tokens, args);
  247. switch (token) {
  248. case Opt_subvol:
  249. *subvol_name = match_strdup(&args[0]);
  250. break;
  251. case Opt_device:
  252. error = btrfs_scan_one_device(match_strdup(&args[0]),
  253. flags, holder, fs_devices);
  254. if (error)
  255. goto out_free_opts;
  256. break;
  257. default:
  258. break;
  259. }
  260. }
  261. out_free_opts:
  262. kfree(opts);
  263. out:
  264. /*
  265. * If no subvolume name is specified we use the default one. Allocate
  266. * a copy of the string "." here so that code later in the
  267. * mount path doesn't care if it's the default volume or another one.
  268. */
  269. if (!*subvol_name) {
  270. *subvol_name = kstrdup(".", GFP_KERNEL);
  271. if (!*subvol_name)
  272. return -ENOMEM;
  273. }
  274. return error;
  275. }
  276. static int btrfs_fill_super(struct super_block * sb,
  277. struct btrfs_fs_devices *fs_devices,
  278. void * data, int silent)
  279. {
  280. struct inode * inode;
  281. struct dentry * root_dentry;
  282. struct btrfs_super_block *disk_super;
  283. struct btrfs_root *tree_root;
  284. struct btrfs_inode *bi;
  285. int err;
  286. sb->s_maxbytes = MAX_LFS_FILESIZE;
  287. sb->s_magic = BTRFS_SUPER_MAGIC;
  288. sb->s_op = &btrfs_super_ops;
  289. sb->s_export_op = &btrfs_export_ops;
  290. sb->s_xattr = btrfs_xattr_handlers;
  291. sb->s_time_gran = 1;
  292. sb->s_flags |= MS_POSIXACL;
  293. tree_root = open_ctree(sb, fs_devices, (char *)data);
  294. if (IS_ERR(tree_root)) {
  295. printk("btrfs: open_ctree failed\n");
  296. return PTR_ERR(tree_root);
  297. }
  298. sb->s_fs_info = tree_root;
  299. disk_super = &tree_root->fs_info->super_copy;
  300. inode = btrfs_iget_locked(sb, BTRFS_FIRST_FREE_OBJECTID,
  301. tree_root->fs_info->fs_root);
  302. bi = BTRFS_I(inode);
  303. bi->location.objectid = inode->i_ino;
  304. bi->location.offset = 0;
  305. bi->root = tree_root->fs_info->fs_root;
  306. btrfs_set_key_type(&bi->location, BTRFS_INODE_ITEM_KEY);
  307. if (!inode) {
  308. err = -ENOMEM;
  309. goto fail_close;
  310. }
  311. if (inode->i_state & I_NEW) {
  312. btrfs_read_locked_inode(inode);
  313. unlock_new_inode(inode);
  314. }
  315. root_dentry = d_alloc_root(inode);
  316. if (!root_dentry) {
  317. iput(inode);
  318. err = -ENOMEM;
  319. goto fail_close;
  320. }
  321. /* this does the super kobj at the same time */
  322. err = btrfs_sysfs_add_super(tree_root->fs_info);
  323. if (err)
  324. goto fail_close;
  325. sb->s_root = root_dentry;
  326. save_mount_options(sb, data);
  327. return 0;
  328. fail_close:
  329. close_ctree(tree_root);
  330. return err;
  331. }
  332. int btrfs_sync_fs(struct super_block *sb, int wait)
  333. {
  334. struct btrfs_trans_handle *trans;
  335. struct btrfs_root *root;
  336. int ret;
  337. root = btrfs_sb(sb);
  338. if (sb->s_flags & MS_RDONLY)
  339. return 0;
  340. sb->s_dirt = 0;
  341. if (!wait) {
  342. filemap_flush(root->fs_info->btree_inode->i_mapping);
  343. return 0;
  344. }
  345. btrfs_start_delalloc_inodes(root);
  346. btrfs_wait_ordered_extents(root, 0);
  347. btrfs_clean_old_snapshots(root);
  348. trans = btrfs_start_transaction(root, 1);
  349. ret = btrfs_commit_transaction(trans, root);
  350. sb->s_dirt = 0;
  351. return ret;
  352. }
  353. static void btrfs_write_super(struct super_block *sb)
  354. {
  355. sb->s_dirt = 0;
  356. }
  357. static int btrfs_test_super(struct super_block *s, void *data)
  358. {
  359. struct btrfs_fs_devices *test_fs_devices = data;
  360. struct btrfs_root *root = btrfs_sb(s);
  361. return root->fs_info->fs_devices == test_fs_devices;
  362. }
  363. /*
  364. * Find a superblock for the given device / mount point.
  365. *
  366. * Note: This is based on get_sb_bdev from fs/super.c with a few additions
  367. * for multiple device setup. Make sure to keep it in sync.
  368. */
  369. static int btrfs_get_sb(struct file_system_type *fs_type, int flags,
  370. const char *dev_name, void *data, struct vfsmount *mnt)
  371. {
  372. char *subvol_name = NULL;
  373. struct block_device *bdev = NULL;
  374. struct super_block *s;
  375. struct dentry *root;
  376. struct btrfs_fs_devices *fs_devices = NULL;
  377. fmode_t mode = FMODE_READ;
  378. int error = 0;
  379. if (!(flags & MS_RDONLY))
  380. mode |= FMODE_WRITE;
  381. error = btrfs_parse_early_options(data, mode, fs_type,
  382. &subvol_name, &fs_devices);
  383. if (error)
  384. goto error;
  385. error = btrfs_scan_one_device(dev_name, mode, fs_type, &fs_devices);
  386. if (error)
  387. goto error_free_subvol_name;
  388. error = btrfs_open_devices(fs_devices, mode, fs_type);
  389. if (error)
  390. goto error_free_subvol_name;
  391. if (!(flags & MS_RDONLY) && fs_devices->rw_devices == 0) {
  392. error = -EACCES;
  393. goto error_close_devices;
  394. }
  395. bdev = fs_devices->latest_bdev;
  396. s = sget(fs_type, btrfs_test_super, set_anon_super, fs_devices);
  397. if (IS_ERR(s))
  398. goto error_s;
  399. if (s->s_root) {
  400. if ((flags ^ s->s_flags) & MS_RDONLY) {
  401. up_write(&s->s_umount);
  402. deactivate_super(s);
  403. error = -EBUSY;
  404. goto error_close_devices;
  405. }
  406. btrfs_close_devices(fs_devices);
  407. } else {
  408. char b[BDEVNAME_SIZE];
  409. s->s_flags = flags;
  410. strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
  411. error = btrfs_fill_super(s, fs_devices, data,
  412. flags & MS_SILENT ? 1 : 0);
  413. if (error) {
  414. up_write(&s->s_umount);
  415. deactivate_super(s);
  416. goto error;
  417. }
  418. btrfs_sb(s)->fs_info->bdev_holder = fs_type;
  419. s->s_flags |= MS_ACTIVE;
  420. }
  421. if (!strcmp(subvol_name, "."))
  422. root = dget(s->s_root);
  423. else {
  424. mutex_lock(&s->s_root->d_inode->i_mutex);
  425. root = lookup_one_len(subvol_name, s->s_root, strlen(subvol_name));
  426. mutex_unlock(&s->s_root->d_inode->i_mutex);
  427. if (IS_ERR(root)) {
  428. up_write(&s->s_umount);
  429. deactivate_super(s);
  430. error = PTR_ERR(root);
  431. goto error;
  432. }
  433. if (!root->d_inode) {
  434. dput(root);
  435. up_write(&s->s_umount);
  436. deactivate_super(s);
  437. error = -ENXIO;
  438. goto error;
  439. }
  440. }
  441. mnt->mnt_sb = s;
  442. mnt->mnt_root = root;
  443. kfree(subvol_name);
  444. return 0;
  445. error_s:
  446. error = PTR_ERR(s);
  447. error_close_devices:
  448. btrfs_close_devices(fs_devices);
  449. error_free_subvol_name:
  450. kfree(subvol_name);
  451. error:
  452. return error;
  453. }
  454. static int btrfs_remount(struct super_block *sb, int *flags, char *data)
  455. {
  456. struct btrfs_root *root = btrfs_sb(sb);
  457. int ret;
  458. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  459. return 0;
  460. if (*flags & MS_RDONLY) {
  461. sb->s_flags |= MS_RDONLY;
  462. ret = btrfs_commit_super(root);
  463. WARN_ON(ret);
  464. } else {
  465. if (root->fs_info->fs_devices->rw_devices == 0)
  466. return -EACCES;
  467. if (btrfs_super_log_root(&root->fs_info->super_copy) != 0)
  468. return -EINVAL;
  469. ret = btrfs_cleanup_reloc_trees(root);
  470. WARN_ON(ret);
  471. ret = btrfs_cleanup_fs_roots(root->fs_info);
  472. WARN_ON(ret);
  473. sb->s_flags &= ~MS_RDONLY;
  474. }
  475. return 0;
  476. }
  477. static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  478. {
  479. struct btrfs_root *root = btrfs_sb(dentry->d_sb);
  480. struct btrfs_super_block *disk_super = &root->fs_info->super_copy;
  481. int bits = dentry->d_sb->s_blocksize_bits;
  482. __be32 *fsid = (__be32 *)root->fs_info->fsid;
  483. buf->f_namelen = BTRFS_NAME_LEN;
  484. buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits;
  485. buf->f_bfree = buf->f_blocks -
  486. (btrfs_super_bytes_used(disk_super) >> bits);
  487. buf->f_bavail = buf->f_bfree;
  488. buf->f_bsize = dentry->d_sb->s_blocksize;
  489. buf->f_type = BTRFS_SUPER_MAGIC;
  490. /* We treat it as constant endianness (it doesn't matter _which_)
  491. because we want the fsid to come out the same whether mounted
  492. on a big-endian or little-endian host */
  493. buf->f_fsid.val[0] = be32_to_cpu(fsid[0]) ^ be32_to_cpu(fsid[2]);
  494. buf->f_fsid.val[1] = be32_to_cpu(fsid[1]) ^ be32_to_cpu(fsid[3]);
  495. /* Mask in the root object ID too, to disambiguate subvols */
  496. buf->f_fsid.val[0] ^= BTRFS_I(dentry->d_inode)->root->objectid >> 32;
  497. buf->f_fsid.val[1] ^= BTRFS_I(dentry->d_inode)->root->objectid;
  498. return 0;
  499. }
  500. static struct file_system_type btrfs_fs_type = {
  501. .owner = THIS_MODULE,
  502. .name = "btrfs",
  503. .get_sb = btrfs_get_sb,
  504. .kill_sb = kill_anon_super,
  505. .fs_flags = FS_REQUIRES_DEV,
  506. };
  507. /*
  508. * used by btrfsctl to scan devices when no FS is mounted
  509. */
  510. static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
  511. unsigned long arg)
  512. {
  513. struct btrfs_ioctl_vol_args *vol;
  514. struct btrfs_fs_devices *fs_devices;
  515. int ret = 0;
  516. int len;
  517. vol = kmalloc(sizeof(*vol), GFP_KERNEL);
  518. if (copy_from_user(vol, (void __user *)arg, sizeof(*vol))) {
  519. ret = -EFAULT;
  520. goto out;
  521. }
  522. len = strnlen(vol->name, BTRFS_PATH_NAME_MAX);
  523. switch (cmd) {
  524. case BTRFS_IOC_SCAN_DEV:
  525. ret = btrfs_scan_one_device(vol->name, FMODE_READ,
  526. &btrfs_fs_type, &fs_devices);
  527. break;
  528. }
  529. out:
  530. kfree(vol);
  531. return ret;
  532. }
  533. static void btrfs_write_super_lockfs(struct super_block *sb)
  534. {
  535. struct btrfs_root *root = btrfs_sb(sb);
  536. mutex_lock(&root->fs_info->transaction_kthread_mutex);
  537. mutex_lock(&root->fs_info->cleaner_mutex);
  538. }
  539. static void btrfs_unlockfs(struct super_block *sb)
  540. {
  541. struct btrfs_root *root = btrfs_sb(sb);
  542. mutex_unlock(&root->fs_info->cleaner_mutex);
  543. mutex_unlock(&root->fs_info->transaction_kthread_mutex);
  544. }
  545. static struct super_operations btrfs_super_ops = {
  546. .delete_inode = btrfs_delete_inode,
  547. .put_super = btrfs_put_super,
  548. .write_super = btrfs_write_super,
  549. .sync_fs = btrfs_sync_fs,
  550. .show_options = generic_show_options,
  551. .write_inode = btrfs_write_inode,
  552. .dirty_inode = btrfs_dirty_inode,
  553. .alloc_inode = btrfs_alloc_inode,
  554. .destroy_inode = btrfs_destroy_inode,
  555. .statfs = btrfs_statfs,
  556. .remount_fs = btrfs_remount,
  557. .write_super_lockfs = btrfs_write_super_lockfs,
  558. .unlockfs = btrfs_unlockfs,
  559. };
  560. static const struct file_operations btrfs_ctl_fops = {
  561. .unlocked_ioctl = btrfs_control_ioctl,
  562. .compat_ioctl = btrfs_control_ioctl,
  563. .owner = THIS_MODULE,
  564. };
  565. static struct miscdevice btrfs_misc = {
  566. .minor = MISC_DYNAMIC_MINOR,
  567. .name = "btrfs-control",
  568. .fops = &btrfs_ctl_fops
  569. };
  570. static int btrfs_interface_init(void)
  571. {
  572. return misc_register(&btrfs_misc);
  573. }
  574. static void btrfs_interface_exit(void)
  575. {
  576. if (misc_deregister(&btrfs_misc) < 0)
  577. printk("misc_deregister failed for control device");
  578. }
  579. static int __init init_btrfs_fs(void)
  580. {
  581. int err;
  582. err = btrfs_init_sysfs();
  583. if (err)
  584. return err;
  585. err = btrfs_init_cachep();
  586. if (err)
  587. goto free_sysfs;
  588. err = extent_io_init();
  589. if (err)
  590. goto free_cachep;
  591. err = extent_map_init();
  592. if (err)
  593. goto free_extent_io;
  594. err = btrfs_interface_init();
  595. if (err)
  596. goto free_extent_map;
  597. err = register_filesystem(&btrfs_fs_type);
  598. if (err)
  599. goto unregister_ioctl;
  600. printk(KERN_INFO "%s loaded\n", BTRFS_BUILD_VERSION);
  601. return 0;
  602. unregister_ioctl:
  603. btrfs_interface_exit();
  604. free_extent_map:
  605. extent_map_exit();
  606. free_extent_io:
  607. extent_io_exit();
  608. free_cachep:
  609. btrfs_destroy_cachep();
  610. free_sysfs:
  611. btrfs_exit_sysfs();
  612. return err;
  613. }
  614. static void __exit exit_btrfs_fs(void)
  615. {
  616. btrfs_destroy_cachep();
  617. extent_map_exit();
  618. extent_io_exit();
  619. btrfs_interface_exit();
  620. unregister_filesystem(&btrfs_fs_type);
  621. btrfs_exit_sysfs();
  622. btrfs_cleanup_fs_uuids();
  623. btrfs_zlib_exit();
  624. }
  625. module_init(init_btrfs_fs)
  626. module_exit(exit_btrfs_fs)
  627. MODULE_LICENSE("GPL");