super.c 16 KB

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