super.c 32 KB

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