super.c 16 KB

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