super.c 16 KB

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