2 * Copyright (C) 2007 Oracle. All rights reserved.
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.
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.
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.
19 #include <linux/blkdev.h>
20 #include <linux/module.h>
21 #include <linux/buffer_head.h>
23 #include <linux/pagemap.h>
24 #include <linux/highmem.h>
25 #include <linux/time.h>
26 #include <linux/init.h>
27 #include <linux/seq_file.h>
28 #include <linux/string.h>
29 #include <linux/backing-dev.h>
30 #include <linux/mount.h>
31 #include <linux/mpage.h>
32 #include <linux/swap.h>
33 #include <linux/writeback.h>
34 #include <linux/statfs.h>
35 #include <linux/compat.h>
36 #include <linux/parser.h>
37 #include <linux/ctype.h>
38 #include <linux/namei.h>
39 #include <linux/miscdevice.h>
40 #include <linux/magic.h>
41 #include <linux/slab.h>
42 #include <linux/cleancache.h>
43 #include <linux/ratelimit.h>
44 #include <linux/btrfs.h>
45 #include "delayed-inode.h"
48 #include "transaction.h"
49 #include "btrfs_inode.h"
50 #include "print-tree.h"
56 #include "compression.h"
57 #include "rcu-string.h"
58 #include "dev-replace.h"
59 #include "free-space-cache.h"
61 #include "tests/btrfs-tests.h"
64 #define CREATE_TRACE_POINTS
65 #include <trace/events/btrfs.h>
67 static const struct super_operations btrfs_super_ops;
70 * Types for mounting the default subvolume and a subvolume explicitly
71 * requested by subvol=/path. That way the callchain is straightforward and we
72 * don't have to play tricks with the mount options and recursive calls to
75 * The new btrfs_root_fs_type also servers as a tag for the bdev_holder.
77 static struct file_system_type btrfs_fs_type;
78 static struct file_system_type btrfs_root_fs_type;
80 static int btrfs_remount(struct super_block *sb, int *flags, char *data);
82 const char *btrfs_decode_error(int errno)
84 char *errstr = "unknown";
88 errstr = "IO failure";
91 errstr = "Out of memory";
94 errstr = "Readonly filesystem";
97 errstr = "Object already exists";
100 errstr = "No space left";
103 errstr = "No such entry";
110 /* btrfs handle error by forcing the filesystem readonly */
111 static void btrfs_handle_error(struct btrfs_fs_info *fs_info)
113 struct super_block *sb = fs_info->sb;
118 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
119 sb->s_flags |= SB_RDONLY;
120 btrfs_info(fs_info, "forced readonly");
122 * Note that a running device replace operation is not
123 * canceled here although there is no way to update
124 * the progress. It would add the risk of a deadlock,
125 * therefore the canceling is omitted. The only penalty
126 * is that some I/O remains active until the procedure
127 * completes. The next time when the filesystem is
128 * mounted writeable again, the device replace
129 * operation continues.
135 * __btrfs_handle_fs_error decodes expected errors from the caller and
136 * invokes the approciate error response.
139 void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
140 unsigned int line, int errno, const char *fmt, ...)
142 struct super_block *sb = fs_info->sb;
148 * Special case: if the error is EROFS, and we're already
149 * under SB_RDONLY, then it is safe here.
151 if (errno == -EROFS && sb_rdonly(sb))
155 errstr = btrfs_decode_error(errno);
157 struct va_format vaf;
164 pr_crit("BTRFS: error (device %s) in %s:%d: errno=%d %s (%pV)\n",
165 sb->s_id, function, line, errno, errstr, &vaf);
168 pr_crit("BTRFS: error (device %s) in %s:%d: errno=%d %s\n",
169 sb->s_id, function, line, errno, errstr);
174 * Today we only save the error info to memory. Long term we'll
175 * also send it down to the disk
177 set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state);
179 /* Don't go through full error handling during mount */
180 if (sb->s_flags & SB_BORN)
181 btrfs_handle_error(fs_info);
185 static const char * const logtypes[] = {
198 * Use one ratelimit state per log level so that a flood of less important
199 * messages doesn't cause more important ones to be dropped.
201 static struct ratelimit_state printk_limits[] = {
202 RATELIMIT_STATE_INIT(printk_limits[0], DEFAULT_RATELIMIT_INTERVAL, 100),
203 RATELIMIT_STATE_INIT(printk_limits[1], DEFAULT_RATELIMIT_INTERVAL, 100),
204 RATELIMIT_STATE_INIT(printk_limits[2], DEFAULT_RATELIMIT_INTERVAL, 100),
205 RATELIMIT_STATE_INIT(printk_limits[3], DEFAULT_RATELIMIT_INTERVAL, 100),
206 RATELIMIT_STATE_INIT(printk_limits[4], DEFAULT_RATELIMIT_INTERVAL, 100),
207 RATELIMIT_STATE_INIT(printk_limits[5], DEFAULT_RATELIMIT_INTERVAL, 100),
208 RATELIMIT_STATE_INIT(printk_limits[6], DEFAULT_RATELIMIT_INTERVAL, 100),
209 RATELIMIT_STATE_INIT(printk_limits[7], DEFAULT_RATELIMIT_INTERVAL, 100),
212 void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
214 char lvl[PRINTK_MAX_SINGLE_HEADER_LEN + 1] = "\0";
215 struct va_format vaf;
218 const char *type = logtypes[4];
219 struct ratelimit_state *ratelimit = &printk_limits[4];
223 while ((kern_level = printk_get_level(fmt)) != 0) {
224 size_t size = printk_skip_level(fmt) - fmt;
226 if (kern_level >= '0' && kern_level <= '7') {
227 memcpy(lvl, fmt, size);
229 type = logtypes[kern_level - '0'];
230 ratelimit = &printk_limits[kern_level - '0'];
238 if (__ratelimit(ratelimit))
239 printk("%sBTRFS %s (device %s): %pV\n", lvl, type,
240 fs_info ? fs_info->sb->s_id : "<unknown>", &vaf);
247 * We only mark the transaction aborted and then set the file system read-only.
248 * This will prevent new transactions from starting or trying to join this
251 * This means that error recovery at the call site is limited to freeing
252 * any local memory allocations and passing the error code up without
253 * further cleanup. The transaction should complete as it normally would
254 * in the call path but will return -EIO.
256 * We'll complete the cleanup in btrfs_end_transaction and
257 * btrfs_commit_transaction.
260 void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
261 const char *function,
262 unsigned int line, int errno)
264 struct btrfs_fs_info *fs_info = trans->fs_info;
266 trans->aborted = errno;
267 /* Nothing used. The other threads that have joined this
268 * transaction may be able to continue. */
269 if (!trans->dirty && list_empty(&trans->new_bgs)) {
272 errstr = btrfs_decode_error(errno);
274 "%s:%d: Aborting unused transaction(%s).",
275 function, line, errstr);
278 WRITE_ONCE(trans->transaction->aborted, errno);
279 /* Wake up anybody who may be waiting on this transaction */
280 wake_up(&fs_info->transaction_wait);
281 wake_up(&fs_info->transaction_blocked_wait);
282 __btrfs_handle_fs_error(fs_info, function, line, errno, NULL);
285 * __btrfs_panic decodes unexpected, fatal errors from the caller,
286 * issues an alert, and either panics or BUGs, depending on mount options.
289 void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
290 unsigned int line, int errno, const char *fmt, ...)
292 char *s_id = "<unknown>";
294 struct va_format vaf = { .fmt = fmt };
298 s_id = fs_info->sb->s_id;
303 errstr = btrfs_decode_error(errno);
304 if (fs_info && (btrfs_test_opt(fs_info, PANIC_ON_FATAL_ERROR)))
305 panic(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (errno=%d %s)\n",
306 s_id, function, line, &vaf, errno, errstr);
308 btrfs_crit(fs_info, "panic in %s:%d: %pV (errno=%d %s)",
309 function, line, &vaf, errno, errstr);
311 /* Caller calls BUG() */
314 static void btrfs_put_super(struct super_block *sb)
316 close_ctree(btrfs_sb(sb));
320 Opt_degraded, Opt_subvol, Opt_subvolid, Opt_device, Opt_nodatasum,
321 Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd,
322 Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
323 Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
324 Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
325 Opt_space_cache, Opt_space_cache_version, Opt_clear_cache,
326 Opt_user_subvol_rm_allowed, Opt_enospc_debug, Opt_subvolrootid,
327 Opt_defrag, Opt_inode_cache, Opt_no_space_cache, Opt_recovery,
328 Opt_skip_balance, Opt_check_integrity,
329 Opt_check_integrity_including_extent_data,
330 Opt_check_integrity_print_mask, Opt_fatal_errors, Opt_rescan_uuid_tree,
331 Opt_commit_interval, Opt_barrier, Opt_nodefrag, Opt_nodiscard,
332 Opt_noenospc_debug, Opt_noflushoncommit, Opt_acl, Opt_datacow,
333 Opt_datasum, Opt_treelog, Opt_noinode_cache, Opt_usebackuproot,
334 Opt_nologreplay, Opt_norecovery,
335 #ifdef CONFIG_BTRFS_DEBUG
336 Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all,
338 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
344 static const match_table_t tokens = {
345 {Opt_degraded, "degraded"},
346 {Opt_subvol, "subvol=%s"},
347 {Opt_subvolid, "subvolid=%s"},
348 {Opt_device, "device=%s"},
349 {Opt_nodatasum, "nodatasum"},
350 {Opt_datasum, "datasum"},
351 {Opt_nodatacow, "nodatacow"},
352 {Opt_datacow, "datacow"},
353 {Opt_nobarrier, "nobarrier"},
354 {Opt_barrier, "barrier"},
355 {Opt_max_inline, "max_inline=%s"},
356 {Opt_alloc_start, "alloc_start=%s"},
357 {Opt_thread_pool, "thread_pool=%d"},
358 {Opt_compress, "compress"},
359 {Opt_compress_type, "compress=%s"},
360 {Opt_compress_force, "compress-force"},
361 {Opt_compress_force_type, "compress-force=%s"},
363 {Opt_ssd_spread, "ssd_spread"},
364 {Opt_nossd, "nossd"},
366 {Opt_noacl, "noacl"},
367 {Opt_notreelog, "notreelog"},
368 {Opt_treelog, "treelog"},
369 {Opt_nologreplay, "nologreplay"},
370 {Opt_norecovery, "norecovery"},
371 {Opt_flushoncommit, "flushoncommit"},
372 {Opt_noflushoncommit, "noflushoncommit"},
373 {Opt_ratio, "metadata_ratio=%d"},
374 {Opt_discard, "discard"},
375 {Opt_nodiscard, "nodiscard"},
376 {Opt_space_cache, "space_cache"},
377 {Opt_space_cache_version, "space_cache=%s"},
378 {Opt_clear_cache, "clear_cache"},
379 {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
380 {Opt_enospc_debug, "enospc_debug"},
381 {Opt_noenospc_debug, "noenospc_debug"},
382 {Opt_subvolrootid, "subvolrootid=%d"},
383 {Opt_defrag, "autodefrag"},
384 {Opt_nodefrag, "noautodefrag"},
385 {Opt_inode_cache, "inode_cache"},
386 {Opt_noinode_cache, "noinode_cache"},
387 {Opt_no_space_cache, "nospace_cache"},
388 {Opt_recovery, "recovery"}, /* deprecated */
389 {Opt_usebackuproot, "usebackuproot"},
390 {Opt_skip_balance, "skip_balance"},
391 {Opt_check_integrity, "check_int"},
392 {Opt_check_integrity_including_extent_data, "check_int_data"},
393 {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
394 {Opt_rescan_uuid_tree, "rescan_uuid_tree"},
395 {Opt_fatal_errors, "fatal_errors=%s"},
396 {Opt_commit_interval, "commit=%d"},
397 #ifdef CONFIG_BTRFS_DEBUG
398 {Opt_fragment_data, "fragment=data"},
399 {Opt_fragment_metadata, "fragment=metadata"},
400 {Opt_fragment_all, "fragment=all"},
402 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
403 {Opt_ref_verify, "ref_verify"},
409 * Regular mount options parser. Everything that is needed only when
410 * reading in a new superblock is parsed here.
411 * XXX JDM: This needs to be cleaned up for remount.
413 int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
414 unsigned long new_flags)
416 substring_t args[MAX_OPT_ARGS];
417 char *p, *num, *orig = NULL;
422 bool compress_force = false;
423 enum btrfs_compression_type saved_compress_type;
424 bool saved_compress_force;
427 cache_gen = btrfs_super_cache_generation(info->super_copy);
428 if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE))
429 btrfs_set_opt(info->mount_opt, FREE_SPACE_TREE);
431 btrfs_set_opt(info->mount_opt, SPACE_CACHE);
434 * Even the options are empty, we still need to do extra check
441 * strsep changes the string, duplicate it because parse_options
444 options = kstrdup(options, GFP_KERNEL);
450 while ((p = strsep(&options, ",")) != NULL) {
455 token = match_token(p, tokens, args);
458 btrfs_info(info, "allowing degraded mounts");
459 btrfs_set_opt(info->mount_opt, DEGRADED);
463 case Opt_subvolrootid:
466 * These are parsed by btrfs_parse_subvol_options
467 * and btrfs_parse_early_options
468 * and can be happily ignored here.
472 btrfs_set_and_info(info, NODATASUM,
473 "setting nodatasum");
476 if (btrfs_test_opt(info, NODATASUM)) {
477 if (btrfs_test_opt(info, NODATACOW))
479 "setting datasum, datacow enabled");
481 btrfs_info(info, "setting datasum");
483 btrfs_clear_opt(info->mount_opt, NODATACOW);
484 btrfs_clear_opt(info->mount_opt, NODATASUM);
487 if (!btrfs_test_opt(info, NODATACOW)) {
488 if (!btrfs_test_opt(info, COMPRESS) ||
489 !btrfs_test_opt(info, FORCE_COMPRESS)) {
491 "setting nodatacow, compression disabled");
493 btrfs_info(info, "setting nodatacow");
496 btrfs_clear_opt(info->mount_opt, COMPRESS);
497 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS);
498 btrfs_set_opt(info->mount_opt, NODATACOW);
499 btrfs_set_opt(info->mount_opt, NODATASUM);
502 btrfs_clear_and_info(info, NODATACOW,
505 case Opt_compress_force:
506 case Opt_compress_force_type:
507 compress_force = true;
510 case Opt_compress_type:
511 saved_compress_type = btrfs_test_opt(info,
513 info->compress_type : BTRFS_COMPRESS_NONE;
514 saved_compress_force =
515 btrfs_test_opt(info, FORCE_COMPRESS);
516 if (token == Opt_compress ||
517 token == Opt_compress_force ||
518 strncmp(args[0].from, "zlib", 4) == 0) {
519 compress_type = "zlib";
521 info->compress_type = BTRFS_COMPRESS_ZLIB;
522 info->compress_level = BTRFS_ZLIB_DEFAULT_LEVEL;
524 * args[0] contains uninitialized data since
525 * for these tokens we don't expect any
528 if (token != Opt_compress &&
529 token != Opt_compress_force)
530 info->compress_level =
531 btrfs_compress_str2level(args[0].from);
532 btrfs_set_opt(info->mount_opt, COMPRESS);
533 btrfs_clear_opt(info->mount_opt, NODATACOW);
534 btrfs_clear_opt(info->mount_opt, NODATASUM);
536 } else if (strncmp(args[0].from, "lzo", 3) == 0) {
537 compress_type = "lzo";
538 info->compress_type = BTRFS_COMPRESS_LZO;
539 btrfs_set_opt(info->mount_opt, COMPRESS);
540 btrfs_clear_opt(info->mount_opt, NODATACOW);
541 btrfs_clear_opt(info->mount_opt, NODATASUM);
542 btrfs_set_fs_incompat(info, COMPRESS_LZO);
544 } else if (strcmp(args[0].from, "zstd") == 0) {
545 compress_type = "zstd";
546 info->compress_type = BTRFS_COMPRESS_ZSTD;
547 btrfs_set_opt(info->mount_opt, COMPRESS);
548 btrfs_clear_opt(info->mount_opt, NODATACOW);
549 btrfs_clear_opt(info->mount_opt, NODATASUM);
550 btrfs_set_fs_incompat(info, COMPRESS_ZSTD);
552 } else if (strncmp(args[0].from, "no", 2) == 0) {
553 compress_type = "no";
554 btrfs_clear_opt(info->mount_opt, COMPRESS);
555 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS);
556 compress_force = false;
563 if (compress_force) {
564 btrfs_set_opt(info->mount_opt, FORCE_COMPRESS);
567 * If we remount from compress-force=xxx to
568 * compress=xxx, we need clear FORCE_COMPRESS
569 * flag, otherwise, there is no way for users
570 * to disable forcible compression separately.
572 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS);
574 if ((btrfs_test_opt(info, COMPRESS) &&
575 (info->compress_type != saved_compress_type ||
576 compress_force != saved_compress_force)) ||
577 (!btrfs_test_opt(info, COMPRESS) &&
579 btrfs_info(info, "%s %s compression, level %d",
580 (compress_force) ? "force" : "use",
581 compress_type, info->compress_level);
583 compress_force = false;
586 btrfs_set_and_info(info, SSD,
587 "enabling ssd optimizations");
588 btrfs_clear_opt(info->mount_opt, NOSSD);
591 btrfs_set_and_info(info, SSD,
592 "enabling ssd optimizations");
593 btrfs_set_and_info(info, SSD_SPREAD,
594 "using spread ssd allocation scheme");
595 btrfs_clear_opt(info->mount_opt, NOSSD);
598 btrfs_set_opt(info->mount_opt, NOSSD);
599 btrfs_clear_and_info(info, SSD,
600 "not using ssd optimizations");
601 btrfs_clear_and_info(info, SSD_SPREAD,
602 "not using spread ssd allocation scheme");
605 btrfs_clear_and_info(info, NOBARRIER,
606 "turning on barriers");
609 btrfs_set_and_info(info, NOBARRIER,
610 "turning off barriers");
612 case Opt_thread_pool:
613 ret = match_int(&args[0], &intarg);
616 } else if (intarg > 0) {
617 info->thread_pool_size = intarg;
624 num = match_strdup(&args[0]);
626 info->max_inline = memparse(num, NULL);
629 if (info->max_inline) {
630 info->max_inline = min_t(u64,
634 btrfs_info(info, "max_inline at %llu",
641 case Opt_alloc_start:
643 "option alloc_start is obsolete, ignored");
646 #ifdef CONFIG_BTRFS_FS_POSIX_ACL
647 info->sb->s_flags |= SB_POSIXACL;
650 btrfs_err(info, "support for ACL not compiled in!");
655 info->sb->s_flags &= ~SB_POSIXACL;
658 btrfs_set_and_info(info, NOTREELOG,
659 "disabling tree log");
662 btrfs_clear_and_info(info, NOTREELOG,
663 "enabling tree log");
666 case Opt_nologreplay:
667 btrfs_set_and_info(info, NOLOGREPLAY,
668 "disabling log replay at mount time");
670 case Opt_flushoncommit:
671 btrfs_set_and_info(info, FLUSHONCOMMIT,
672 "turning on flush-on-commit");
674 case Opt_noflushoncommit:
675 btrfs_clear_and_info(info, FLUSHONCOMMIT,
676 "turning off flush-on-commit");
679 ret = match_int(&args[0], &intarg);
682 } else if (intarg >= 0) {
683 info->metadata_ratio = intarg;
684 btrfs_info(info, "metadata ratio %d",
685 info->metadata_ratio);
692 btrfs_set_and_info(info, DISCARD,
693 "turning on discard");
696 btrfs_clear_and_info(info, DISCARD,
697 "turning off discard");
699 case Opt_space_cache:
700 case Opt_space_cache_version:
701 if (token == Opt_space_cache ||
702 strcmp(args[0].from, "v1") == 0) {
703 btrfs_clear_opt(info->mount_opt,
705 btrfs_set_and_info(info, SPACE_CACHE,
706 "enabling disk space caching");
707 } else if (strcmp(args[0].from, "v2") == 0) {
708 btrfs_clear_opt(info->mount_opt,
710 btrfs_set_and_info(info, FREE_SPACE_TREE,
711 "enabling free space tree");
717 case Opt_rescan_uuid_tree:
718 btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE);
720 case Opt_no_space_cache:
721 if (btrfs_test_opt(info, SPACE_CACHE)) {
722 btrfs_clear_and_info(info, SPACE_CACHE,
723 "disabling disk space caching");
725 if (btrfs_test_opt(info, FREE_SPACE_TREE)) {
726 btrfs_clear_and_info(info, FREE_SPACE_TREE,
727 "disabling free space tree");
730 case Opt_inode_cache:
731 btrfs_set_pending_and_info(info, INODE_MAP_CACHE,
732 "enabling inode map caching");
734 case Opt_noinode_cache:
735 btrfs_clear_pending_and_info(info, INODE_MAP_CACHE,
736 "disabling inode map caching");
738 case Opt_clear_cache:
739 btrfs_set_and_info(info, CLEAR_CACHE,
740 "force clearing of disk cache");
742 case Opt_user_subvol_rm_allowed:
743 btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED);
745 case Opt_enospc_debug:
746 btrfs_set_opt(info->mount_opt, ENOSPC_DEBUG);
748 case Opt_noenospc_debug:
749 btrfs_clear_opt(info->mount_opt, ENOSPC_DEBUG);
752 btrfs_set_and_info(info, AUTO_DEFRAG,
753 "enabling auto defrag");
756 btrfs_clear_and_info(info, AUTO_DEFRAG,
757 "disabling auto defrag");
761 "'recovery' is deprecated, use 'usebackuproot' instead");
762 case Opt_usebackuproot:
764 "trying to use backup root at mount time");
765 btrfs_set_opt(info->mount_opt, USEBACKUPROOT);
767 case Opt_skip_balance:
768 btrfs_set_opt(info->mount_opt, SKIP_BALANCE);
770 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
771 case Opt_check_integrity_including_extent_data:
773 "enabling check integrity including extent data");
774 btrfs_set_opt(info->mount_opt,
775 CHECK_INTEGRITY_INCLUDING_EXTENT_DATA);
776 btrfs_set_opt(info->mount_opt, CHECK_INTEGRITY);
778 case Opt_check_integrity:
779 btrfs_info(info, "enabling check integrity");
780 btrfs_set_opt(info->mount_opt, CHECK_INTEGRITY);
782 case Opt_check_integrity_print_mask:
783 ret = match_int(&args[0], &intarg);
786 } else if (intarg >= 0) {
787 info->check_integrity_print_mask = intarg;
789 "check_integrity_print_mask 0x%x",
790 info->check_integrity_print_mask);
797 case Opt_check_integrity_including_extent_data:
798 case Opt_check_integrity:
799 case Opt_check_integrity_print_mask:
801 "support for check_integrity* not compiled in!");
805 case Opt_fatal_errors:
806 if (strcmp(args[0].from, "panic") == 0)
807 btrfs_set_opt(info->mount_opt,
808 PANIC_ON_FATAL_ERROR);
809 else if (strcmp(args[0].from, "bug") == 0)
810 btrfs_clear_opt(info->mount_opt,
811 PANIC_ON_FATAL_ERROR);
817 case Opt_commit_interval:
819 ret = match_int(&args[0], &intarg);
821 btrfs_err(info, "invalid commit interval");
828 "excessive commit interval %d",
831 info->commit_interval = intarg;
834 "using default commit interval %ds",
835 BTRFS_DEFAULT_COMMIT_INTERVAL);
836 info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
839 #ifdef CONFIG_BTRFS_DEBUG
840 case Opt_fragment_all:
841 btrfs_info(info, "fragmenting all space");
842 btrfs_set_opt(info->mount_opt, FRAGMENT_DATA);
843 btrfs_set_opt(info->mount_opt, FRAGMENT_METADATA);
845 case Opt_fragment_metadata:
846 btrfs_info(info, "fragmenting metadata");
847 btrfs_set_opt(info->mount_opt,
850 case Opt_fragment_data:
851 btrfs_info(info, "fragmenting data");
852 btrfs_set_opt(info->mount_opt, FRAGMENT_DATA);
855 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
857 btrfs_info(info, "doing ref verification");
858 btrfs_set_opt(info->mount_opt, REF_VERIFY);
862 btrfs_info(info, "unrecognized mount option '%s'", p);
871 * Extra check for current option against current flag
873 if (btrfs_test_opt(info, NOLOGREPLAY) && !(new_flags & SB_RDONLY)) {
875 "nologreplay must be used with ro mount option");
879 if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE) &&
880 !btrfs_test_opt(info, FREE_SPACE_TREE) &&
881 !btrfs_test_opt(info, CLEAR_CACHE)) {
882 btrfs_err(info, "cannot disable free space tree");
886 if (!ret && btrfs_test_opt(info, SPACE_CACHE))
887 btrfs_info(info, "disk space caching is enabled");
888 if (!ret && btrfs_test_opt(info, FREE_SPACE_TREE))
889 btrfs_info(info, "using free space tree");
895 * Parse mount options that are required early in the mount process.
897 * All other options will be parsed on much later in the mount process and
898 * only when we need to allocate a new super block.
900 static int btrfs_parse_early_options(const char *options, fmode_t flags,
901 void *holder, struct btrfs_fs_devices **fs_devices)
903 substring_t args[MAX_OPT_ARGS];
904 char *device_name, *opts, *orig, *p;
911 * strsep changes the string, duplicate it because btrfs_parse_options
914 opts = kstrdup(options, GFP_KERNEL);
919 while ((p = strsep(&opts, ",")) != NULL) {
925 token = match_token(p, tokens, args);
926 if (token == Opt_device) {
927 device_name = match_strdup(&args[0]);
932 error = btrfs_scan_one_device(device_name,
933 flags, holder, fs_devices);
946 * Parse mount options that are related to subvolume id
948 * The value is later passed to mount_subvol()
950 static int btrfs_parse_subvol_options(const char *options, fmode_t flags,
951 void *holder, char **subvol_name, u64 *subvol_objectid)
953 substring_t args[MAX_OPT_ARGS];
954 char *opts, *orig, *p;
962 * strsep changes the string, duplicate it because
963 * btrfs_parse_early_options gets called later
965 opts = kstrdup(options, GFP_KERNEL);
970 while ((p = strsep(&opts, ",")) != NULL) {
975 token = match_token(p, tokens, args);
979 *subvol_name = match_strdup(&args[0]);
986 num = match_strdup(&args[0]);
988 *subvol_objectid = memparse(num, NULL);
990 /* we want the original fs_tree */
991 if (!*subvol_objectid)
993 BTRFS_FS_TREE_OBJECTID;
999 case Opt_subvolrootid:
1000 pr_warn("BTRFS: 'subvolrootid' mount option is deprecated and has no effect\n");
1012 static char *get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info,
1013 u64 subvol_objectid)
1015 struct btrfs_root *root = fs_info->tree_root;
1016 struct btrfs_root *fs_root;
1017 struct btrfs_root_ref *root_ref;
1018 struct btrfs_inode_ref *inode_ref;
1019 struct btrfs_key key;
1020 struct btrfs_path *path = NULL;
1021 char *name = NULL, *ptr;
1026 path = btrfs_alloc_path();
1031 path->leave_spinning = 1;
1033 name = kmalloc(PATH_MAX, GFP_KERNEL);
1038 ptr = name + PATH_MAX - 1;
1042 * Walk up the subvolume trees in the tree of tree roots by root
1043 * backrefs until we hit the top-level subvolume.
1045 while (subvol_objectid != BTRFS_FS_TREE_OBJECTID) {
1046 key.objectid = subvol_objectid;
1047 key.type = BTRFS_ROOT_BACKREF_KEY;
1048 key.offset = (u64)-1;
1050 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
1053 } else if (ret > 0) {
1054 ret = btrfs_previous_item(root, path, subvol_objectid,
1055 BTRFS_ROOT_BACKREF_KEY);
1058 } else if (ret > 0) {
1064 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
1065 subvol_objectid = key.offset;
1067 root_ref = btrfs_item_ptr(path->nodes[0], path->slots[0],
1068 struct btrfs_root_ref);
1069 len = btrfs_root_ref_name_len(path->nodes[0], root_ref);
1072 ret = -ENAMETOOLONG;
1075 read_extent_buffer(path->nodes[0], ptr + 1,
1076 (unsigned long)(root_ref + 1), len);
1078 dirid = btrfs_root_ref_dirid(path->nodes[0], root_ref);
1079 btrfs_release_path(path);
1081 key.objectid = subvol_objectid;
1082 key.type = BTRFS_ROOT_ITEM_KEY;
1083 key.offset = (u64)-1;
1084 fs_root = btrfs_read_fs_root_no_name(fs_info, &key);
1085 if (IS_ERR(fs_root)) {
1086 ret = PTR_ERR(fs_root);
1091 * Walk up the filesystem tree by inode refs until we hit the
1094 while (dirid != BTRFS_FIRST_FREE_OBJECTID) {
1095 key.objectid = dirid;
1096 key.type = BTRFS_INODE_REF_KEY;
1097 key.offset = (u64)-1;
1099 ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0);
1102 } else if (ret > 0) {
1103 ret = btrfs_previous_item(fs_root, path, dirid,
1104 BTRFS_INODE_REF_KEY);
1107 } else if (ret > 0) {
1113 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
1116 inode_ref = btrfs_item_ptr(path->nodes[0],
1118 struct btrfs_inode_ref);
1119 len = btrfs_inode_ref_name_len(path->nodes[0],
1123 ret = -ENAMETOOLONG;
1126 read_extent_buffer(path->nodes[0], ptr + 1,
1127 (unsigned long)(inode_ref + 1), len);
1129 btrfs_release_path(path);
1133 btrfs_free_path(path);
1134 if (ptr == name + PATH_MAX - 1) {
1138 memmove(name, ptr, name + PATH_MAX - ptr);
1143 btrfs_free_path(path);
1145 return ERR_PTR(ret);
1148 static int get_default_subvol_objectid(struct btrfs_fs_info *fs_info, u64 *objectid)
1150 struct btrfs_root *root = fs_info->tree_root;
1151 struct btrfs_dir_item *di;
1152 struct btrfs_path *path;
1153 struct btrfs_key location;
1156 path = btrfs_alloc_path();
1159 path->leave_spinning = 1;
1162 * Find the "default" dir item which points to the root item that we
1163 * will mount by default if we haven't been given a specific subvolume
1166 dir_id = btrfs_super_root_dir(fs_info->super_copy);
1167 di = btrfs_lookup_dir_item(NULL, root, path, dir_id, "default", 7, 0);
1169 btrfs_free_path(path);
1174 * Ok the default dir item isn't there. This is weird since
1175 * it's always been there, but don't freak out, just try and
1176 * mount the top-level subvolume.
1178 btrfs_free_path(path);
1179 *objectid = BTRFS_FS_TREE_OBJECTID;
1183 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location);
1184 btrfs_free_path(path);
1185 *objectid = location.objectid;
1189 static int btrfs_fill_super(struct super_block *sb,
1190 struct btrfs_fs_devices *fs_devices,
1193 struct inode *inode;
1194 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
1195 struct btrfs_key key;
1198 sb->s_maxbytes = MAX_LFS_FILESIZE;
1199 sb->s_magic = BTRFS_SUPER_MAGIC;
1200 sb->s_op = &btrfs_super_ops;
1201 sb->s_d_op = &btrfs_dentry_operations;
1202 sb->s_export_op = &btrfs_export_ops;
1203 sb->s_xattr = btrfs_xattr_handlers;
1204 sb->s_time_gran = 1;
1205 #ifdef CONFIG_BTRFS_FS_POSIX_ACL
1206 sb->s_flags |= SB_POSIXACL;
1208 sb->s_flags |= SB_I_VERSION;
1209 sb->s_iflags |= SB_I_CGROUPWB;
1211 err = super_setup_bdi(sb);
1213 btrfs_err(fs_info, "super_setup_bdi failed");
1217 err = open_ctree(sb, fs_devices, (char *)data);
1219 btrfs_err(fs_info, "open_ctree failed");
1223 key.objectid = BTRFS_FIRST_FREE_OBJECTID;
1224 key.type = BTRFS_INODE_ITEM_KEY;
1226 inode = btrfs_iget(sb, &key, fs_info->fs_root, NULL);
1227 if (IS_ERR(inode)) {
1228 err = PTR_ERR(inode);
1232 sb->s_root = d_make_root(inode);
1238 cleancache_init_fs(sb);
1239 sb->s_flags |= SB_ACTIVE;
1243 close_ctree(fs_info);
1247 int btrfs_sync_fs(struct super_block *sb, int wait)
1249 struct btrfs_trans_handle *trans;
1250 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
1251 struct btrfs_root *root = fs_info->tree_root;
1253 trace_btrfs_sync_fs(fs_info, wait);
1256 filemap_flush(fs_info->btree_inode->i_mapping);
1260 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
1262 trans = btrfs_attach_transaction_barrier(root);
1263 if (IS_ERR(trans)) {
1264 /* no transaction, don't bother */
1265 if (PTR_ERR(trans) == -ENOENT) {
1267 * Exit unless we have some pending changes
1268 * that need to go through commit
1270 if (fs_info->pending_changes == 0)
1273 * A non-blocking test if the fs is frozen. We must not
1274 * start a new transaction here otherwise a deadlock
1275 * happens. The pending operations are delayed to the
1276 * next commit after thawing.
1278 if (sb_start_write_trylock(sb))
1282 trans = btrfs_start_transaction(root, 0);
1285 return PTR_ERR(trans);
1287 return btrfs_commit_transaction(trans);
1290 static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
1292 struct btrfs_fs_info *info = btrfs_sb(dentry->d_sb);
1293 const char *compress_type;
1295 if (btrfs_test_opt(info, DEGRADED))
1296 seq_puts(seq, ",degraded");
1297 if (btrfs_test_opt(info, NODATASUM))
1298 seq_puts(seq, ",nodatasum");
1299 if (btrfs_test_opt(info, NODATACOW))
1300 seq_puts(seq, ",nodatacow");
1301 if (btrfs_test_opt(info, NOBARRIER))
1302 seq_puts(seq, ",nobarrier");
1303 if (info->max_inline != BTRFS_DEFAULT_MAX_INLINE)
1304 seq_printf(seq, ",max_inline=%llu", info->max_inline);
1305 if (info->thread_pool_size != min_t(unsigned long,
1306 num_online_cpus() + 2, 8))
1307 seq_printf(seq, ",thread_pool=%d", info->thread_pool_size);
1308 if (btrfs_test_opt(info, COMPRESS)) {
1309 compress_type = btrfs_compress_type2str(info->compress_type);
1310 if (btrfs_test_opt(info, FORCE_COMPRESS))
1311 seq_printf(seq, ",compress-force=%s", compress_type);
1313 seq_printf(seq, ",compress=%s", compress_type);
1314 if (info->compress_level)
1315 seq_printf(seq, ":%d", info->compress_level);
1317 if (btrfs_test_opt(info, NOSSD))
1318 seq_puts(seq, ",nossd");
1319 if (btrfs_test_opt(info, SSD_SPREAD))
1320 seq_puts(seq, ",ssd_spread");
1321 else if (btrfs_test_opt(info, SSD))
1322 seq_puts(seq, ",ssd");
1323 if (btrfs_test_opt(info, NOTREELOG))
1324 seq_puts(seq, ",notreelog");
1325 if (btrfs_test_opt(info, NOLOGREPLAY))
1326 seq_puts(seq, ",nologreplay");
1327 if (btrfs_test_opt(info, FLUSHONCOMMIT))
1328 seq_puts(seq, ",flushoncommit");
1329 if (btrfs_test_opt(info, DISCARD))
1330 seq_puts(seq, ",discard");
1331 if (!(info->sb->s_flags & SB_POSIXACL))
1332 seq_puts(seq, ",noacl");
1333 if (btrfs_test_opt(info, SPACE_CACHE))
1334 seq_puts(seq, ",space_cache");
1335 else if (btrfs_test_opt(info, FREE_SPACE_TREE))
1336 seq_puts(seq, ",space_cache=v2");
1338 seq_puts(seq, ",nospace_cache");
1339 if (btrfs_test_opt(info, RESCAN_UUID_TREE))
1340 seq_puts(seq, ",rescan_uuid_tree");
1341 if (btrfs_test_opt(info, CLEAR_CACHE))
1342 seq_puts(seq, ",clear_cache");
1343 if (btrfs_test_opt(info, USER_SUBVOL_RM_ALLOWED))
1344 seq_puts(seq, ",user_subvol_rm_allowed");
1345 if (btrfs_test_opt(info, ENOSPC_DEBUG))
1346 seq_puts(seq, ",enospc_debug");
1347 if (btrfs_test_opt(info, AUTO_DEFRAG))
1348 seq_puts(seq, ",autodefrag");
1349 if (btrfs_test_opt(info, INODE_MAP_CACHE))
1350 seq_puts(seq, ",inode_cache");
1351 if (btrfs_test_opt(info, SKIP_BALANCE))
1352 seq_puts(seq, ",skip_balance");
1353 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
1354 if (btrfs_test_opt(info, CHECK_INTEGRITY_INCLUDING_EXTENT_DATA))
1355 seq_puts(seq, ",check_int_data");
1356 else if (btrfs_test_opt(info, CHECK_INTEGRITY))
1357 seq_puts(seq, ",check_int");
1358 if (info->check_integrity_print_mask)
1359 seq_printf(seq, ",check_int_print_mask=%d",
1360 info->check_integrity_print_mask);
1362 if (info->metadata_ratio)
1363 seq_printf(seq, ",metadata_ratio=%d",
1364 info->metadata_ratio);
1365 if (btrfs_test_opt(info, PANIC_ON_FATAL_ERROR))
1366 seq_puts(seq, ",fatal_errors=panic");
1367 if (info->commit_interval != BTRFS_DEFAULT_COMMIT_INTERVAL)
1368 seq_printf(seq, ",commit=%d", info->commit_interval);
1369 #ifdef CONFIG_BTRFS_DEBUG
1370 if (btrfs_test_opt(info, FRAGMENT_DATA))
1371 seq_puts(seq, ",fragment=data");
1372 if (btrfs_test_opt(info, FRAGMENT_METADATA))
1373 seq_puts(seq, ",fragment=metadata");
1375 if (btrfs_test_opt(info, REF_VERIFY))
1376 seq_puts(seq, ",ref_verify");
1377 seq_printf(seq, ",subvolid=%llu",
1378 BTRFS_I(d_inode(dentry))->root->root_key.objectid);
1379 seq_puts(seq, ",subvol=");
1380 seq_dentry(seq, dentry, " \t\n\\");
1384 static int btrfs_test_super(struct super_block *s, void *data)
1386 struct btrfs_fs_info *p = data;
1387 struct btrfs_fs_info *fs_info = btrfs_sb(s);
1389 return fs_info->fs_devices == p->fs_devices;
1392 static int btrfs_set_super(struct super_block *s, void *data)
1394 int err = set_anon_super(s, data);
1396 s->s_fs_info = data;
1401 * subvolumes are identified by ino 256
1403 static inline int is_subvolume_inode(struct inode *inode)
1405 if (inode && inode->i_ino == BTRFS_FIRST_FREE_OBJECTID)
1411 * This will add subvolid=0 to the argument string while removing any subvol=
1412 * and subvolid= arguments to make sure we get the top-level root for path
1413 * walking to the subvol we want.
1415 static char *setup_root_args(char *args)
1417 char *buf, *dst, *sep;
1420 return kstrdup("subvolid=0", GFP_KERNEL);
1422 /* The worst case is that we add ",subvolid=0" to the end. */
1423 buf = dst = kmalloc(strlen(args) + strlen(",subvolid=0") + 1,
1429 sep = strchrnul(args, ',');
1430 if (!strstarts(args, "subvol=") &&
1431 !strstarts(args, "subvolid=")) {
1432 memcpy(dst, args, sep - args);
1441 strcpy(dst, "subvolid=0");
1446 static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,
1447 int flags, const char *device_name,
1448 char *data, struct vfsmount *mnt)
1450 struct dentry *root;
1454 if (!subvol_objectid) {
1455 ret = get_default_subvol_objectid(btrfs_sb(mnt->mnt_sb),
1458 root = ERR_PTR(ret);
1462 subvol_name = get_subvol_name_from_objectid(btrfs_sb(mnt->mnt_sb),
1464 if (IS_ERR(subvol_name)) {
1465 root = ERR_CAST(subvol_name);
1472 root = mount_subtree(mnt, subvol_name);
1473 /* mount_subtree() drops our reference on the vfsmount. */
1476 if (!IS_ERR(root)) {
1477 struct super_block *s = root->d_sb;
1478 struct btrfs_fs_info *fs_info = btrfs_sb(s);
1479 struct inode *root_inode = d_inode(root);
1480 u64 root_objectid = BTRFS_I(root_inode)->root->root_key.objectid;
1483 if (!is_subvolume_inode(root_inode)) {
1484 btrfs_err(fs_info, "'%s' is not a valid subvolume",
1488 if (subvol_objectid && root_objectid != subvol_objectid) {
1490 * This will also catch a race condition where a
1491 * subvolume which was passed by ID is renamed and
1492 * another subvolume is renamed over the old location.
1495 "subvol '%s' does not match subvolid %llu",
1496 subvol_name, subvol_objectid);
1501 root = ERR_PTR(ret);
1502 deactivate_locked_super(s);
1512 static int parse_security_options(char *orig_opts,
1513 struct security_mnt_opts *sec_opts)
1515 char *secdata = NULL;
1518 secdata = alloc_secdata();
1521 ret = security_sb_copy_data(orig_opts, secdata);
1523 free_secdata(secdata);
1526 ret = security_sb_parse_opts_str(secdata, sec_opts);
1527 free_secdata(secdata);
1531 static int setup_security_options(struct btrfs_fs_info *fs_info,
1532 struct super_block *sb,
1533 struct security_mnt_opts *sec_opts)
1538 * Call security_sb_set_mnt_opts() to check whether new sec_opts
1541 ret = security_sb_set_mnt_opts(sb, sec_opts, 0, NULL);
1545 #ifdef CONFIG_SECURITY
1546 if (!fs_info->security_opts.num_mnt_opts) {
1547 /* first time security setup, copy sec_opts to fs_info */
1548 memcpy(&fs_info->security_opts, sec_opts, sizeof(*sec_opts));
1551 * Since SELinux (the only one supporting security_mnt_opts)
1552 * does NOT support changing context during remount/mount of
1553 * the same sb, this must be the same or part of the same
1554 * security options, just free it.
1556 security_free_mnt_opts(sec_opts);
1563 * Find a superblock for the given device / mount point.
1565 * Note: This is based on mount_bdev from fs/super.c with a few additions
1566 * for multiple device setup. Make sure to keep it in sync.
1568 static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
1569 int flags, const char *device_name, void *data)
1571 struct block_device *bdev = NULL;
1572 struct super_block *s;
1573 struct btrfs_fs_devices *fs_devices = NULL;
1574 struct btrfs_fs_info *fs_info = NULL;
1575 struct security_mnt_opts new_sec_opts;
1576 fmode_t mode = FMODE_READ;
1579 if (!(flags & SB_RDONLY))
1580 mode |= FMODE_WRITE;
1582 error = btrfs_parse_early_options(data, mode, fs_type,
1585 return ERR_PTR(error);
1588 security_init_mnt_opts(&new_sec_opts);
1590 error = parse_security_options(data, &new_sec_opts);
1592 return ERR_PTR(error);
1595 error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices);
1597 goto error_sec_opts;
1600 * Setup a dummy root and fs_info for test/set super. This is because
1601 * we don't actually fill this stuff out until open_ctree, but we need
1602 * it for searching for existing supers, so this lets us do that and
1603 * then open_ctree will properly initialize everything later.
1605 fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_KERNEL);
1608 goto error_sec_opts;
1611 fs_info->fs_devices = fs_devices;
1613 fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL);
1614 fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL);
1615 security_init_mnt_opts(&fs_info->security_opts);
1616 if (!fs_info->super_copy || !fs_info->super_for_commit) {
1621 error = btrfs_open_devices(fs_devices, mode, fs_type);
1625 if (!(flags & SB_RDONLY) && fs_devices->rw_devices == 0) {
1627 goto error_close_devices;
1630 bdev = fs_devices->latest_bdev;
1631 s = sget(fs_type, btrfs_test_super, btrfs_set_super, flags | SB_NOSEC,
1635 goto error_close_devices;
1639 btrfs_close_devices(fs_devices);
1640 free_fs_info(fs_info);
1641 if ((flags ^ s->s_flags) & SB_RDONLY)
1644 snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev);
1645 btrfs_sb(s)->bdev_holder = fs_type;
1646 error = btrfs_fill_super(s, fs_devices, data);
1649 deactivate_locked_super(s);
1650 goto error_sec_opts;
1653 fs_info = btrfs_sb(s);
1654 error = setup_security_options(fs_info, s, &new_sec_opts);
1656 deactivate_locked_super(s);
1657 goto error_sec_opts;
1660 return dget(s->s_root);
1662 error_close_devices:
1663 btrfs_close_devices(fs_devices);
1665 free_fs_info(fs_info);
1667 security_free_mnt_opts(&new_sec_opts);
1668 return ERR_PTR(error);
1672 * Mount function which is called by VFS layer.
1674 * In order to allow mounting a subvolume directly, btrfs uses mount_subtree()
1675 * which needs vfsmount* of device's root (/). This means device's root has to
1676 * be mounted internally in any case.
1679 * 1. Parse subvol id related options for later use in mount_subvol().
1681 * 2. Mount device's root (/) by calling vfs_kern_mount().
1683 * NOTE: vfs_kern_mount() is used by VFS to call btrfs_mount() in the
1684 * first place. In order to avoid calling btrfs_mount() again, we use
1685 * different file_system_type which is not registered to VFS by
1686 * register_filesystem() (btrfs_root_fs_type). As a result,
1687 * btrfs_mount_root() is called. The return value will be used by
1688 * mount_subtree() in mount_subvol().
1690 * 3. Call mount_subvol() to get the dentry of subvolume. Since there is
1691 * "btrfs subvolume set-default", mount_subvol() is called always.
1693 static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
1694 const char *device_name, void *data)
1696 struct vfsmount *mnt_root;
1697 struct dentry *root;
1698 fmode_t mode = FMODE_READ;
1699 char *subvol_name = NULL;
1700 u64 subvol_objectid = 0;
1703 if (!(flags & SB_RDONLY))
1704 mode |= FMODE_WRITE;
1706 error = btrfs_parse_subvol_options(data, mode, fs_type,
1707 &subvol_name, &subvol_objectid);
1710 return ERR_PTR(error);
1713 /* mount device's root (/) */
1714 mnt_root = vfs_kern_mount(&btrfs_root_fs_type, flags, device_name, data);
1715 if (PTR_ERR_OR_ZERO(mnt_root) == -EBUSY) {
1716 if (flags & SB_RDONLY) {
1717 mnt_root = vfs_kern_mount(&btrfs_root_fs_type,
1718 flags & ~SB_RDONLY, device_name, data);
1720 mnt_root = vfs_kern_mount(&btrfs_root_fs_type,
1721 flags | SB_RDONLY, device_name, data);
1722 if (IS_ERR(mnt_root)) {
1723 root = ERR_CAST(mnt_root);
1727 down_write(&mnt_root->mnt_sb->s_umount);
1728 error = btrfs_remount(mnt_root->mnt_sb, &flags, NULL);
1729 up_write(&mnt_root->mnt_sb->s_umount);
1731 root = ERR_PTR(error);
1737 if (IS_ERR(mnt_root)) {
1738 root = ERR_CAST(mnt_root);
1742 /* mount_subvol() will free subvol_name and mnt_root */
1743 root = mount_subvol(subvol_name, subvol_objectid, flags, device_name,
1750 static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info,
1751 int new_pool_size, int old_pool_size)
1753 if (new_pool_size == old_pool_size)
1756 fs_info->thread_pool_size = new_pool_size;
1758 btrfs_info(fs_info, "resize thread pool %d -> %d",
1759 old_pool_size, new_pool_size);
1761 btrfs_workqueue_set_max(fs_info->workers, new_pool_size);
1762 btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size);
1763 btrfs_workqueue_set_max(fs_info->submit_workers, new_pool_size);
1764 btrfs_workqueue_set_max(fs_info->caching_workers, new_pool_size);
1765 btrfs_workqueue_set_max(fs_info->endio_workers, new_pool_size);
1766 btrfs_workqueue_set_max(fs_info->endio_meta_workers, new_pool_size);
1767 btrfs_workqueue_set_max(fs_info->endio_meta_write_workers,
1769 btrfs_workqueue_set_max(fs_info->endio_write_workers, new_pool_size);
1770 btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size);
1771 btrfs_workqueue_set_max(fs_info->delayed_workers, new_pool_size);
1772 btrfs_workqueue_set_max(fs_info->readahead_workers, new_pool_size);
1773 btrfs_workqueue_set_max(fs_info->scrub_wr_completion_workers,
1777 static inline void btrfs_remount_prepare(struct btrfs_fs_info *fs_info)
1779 set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state);
1782 static inline void btrfs_remount_begin(struct btrfs_fs_info *fs_info,
1783 unsigned long old_opts, int flags)
1785 if (btrfs_raw_test_opt(old_opts, AUTO_DEFRAG) &&
1786 (!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) ||
1787 (flags & SB_RDONLY))) {
1788 /* wait for any defraggers to finish */
1789 wait_event(fs_info->transaction_wait,
1790 (atomic_read(&fs_info->defrag_running) == 0));
1791 if (flags & SB_RDONLY)
1792 sync_filesystem(fs_info->sb);
1796 static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info,
1797 unsigned long old_opts)
1800 * We need to cleanup all defragable inodes if the autodefragment is
1801 * close or the filesystem is read only.
1803 if (btrfs_raw_test_opt(old_opts, AUTO_DEFRAG) &&
1804 (!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) || sb_rdonly(fs_info->sb))) {
1805 btrfs_cleanup_defrag_inodes(fs_info);
1808 clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state);
1811 static int btrfs_remount(struct super_block *sb, int *flags, char *data)
1813 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
1814 struct btrfs_root *root = fs_info->tree_root;
1815 unsigned old_flags = sb->s_flags;
1816 unsigned long old_opts = fs_info->mount_opt;
1817 unsigned long old_compress_type = fs_info->compress_type;
1818 u64 old_max_inline = fs_info->max_inline;
1819 int old_thread_pool_size = fs_info->thread_pool_size;
1820 unsigned int old_metadata_ratio = fs_info->metadata_ratio;
1823 sync_filesystem(sb);
1824 btrfs_remount_prepare(fs_info);
1827 struct security_mnt_opts new_sec_opts;
1829 security_init_mnt_opts(&new_sec_opts);
1830 ret = parse_security_options(data, &new_sec_opts);
1833 ret = setup_security_options(fs_info, sb,
1836 security_free_mnt_opts(&new_sec_opts);
1841 ret = btrfs_parse_options(fs_info, data, *flags);
1847 btrfs_remount_begin(fs_info, old_opts, *flags);
1848 btrfs_resize_thread_pool(fs_info,
1849 fs_info->thread_pool_size, old_thread_pool_size);
1851 if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
1854 if (*flags & SB_RDONLY) {
1856 * this also happens on 'umount -rf' or on shutdown, when
1857 * the filesystem is busy.
1859 cancel_work_sync(&fs_info->async_reclaim_work);
1861 /* wait for the uuid_scan task to finish */
1862 down(&fs_info->uuid_tree_rescan_sem);
1863 /* avoid complains from lockdep et al. */
1864 up(&fs_info->uuid_tree_rescan_sem);
1866 sb->s_flags |= SB_RDONLY;
1869 * Setting SB_RDONLY will put the cleaner thread to
1870 * sleep at the next loop if it's already active.
1871 * If it's already asleep, we'll leave unused block
1872 * groups on disk until we're mounted read-write again
1873 * unless we clean them up here.
1875 btrfs_delete_unused_bgs(fs_info);
1877 btrfs_dev_replace_suspend_for_unmount(fs_info);
1878 btrfs_scrub_cancel(fs_info);
1879 btrfs_pause_balance(fs_info);
1881 ret = btrfs_commit_super(fs_info);
1885 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
1887 "Remounting read-write after error is not allowed");
1891 if (fs_info->fs_devices->rw_devices == 0) {
1896 if (!btrfs_check_rw_degradable(fs_info)) {
1898 "too many missing devices, writeable remount is not allowed");
1903 if (btrfs_super_log_root(fs_info->super_copy) != 0) {
1908 ret = btrfs_cleanup_fs_roots(fs_info);
1912 /* recover relocation */
1913 mutex_lock(&fs_info->cleaner_mutex);
1914 ret = btrfs_recover_relocation(root);
1915 mutex_unlock(&fs_info->cleaner_mutex);
1919 ret = btrfs_resume_balance_async(fs_info);
1923 ret = btrfs_resume_dev_replace_async(fs_info);
1925 btrfs_warn(fs_info, "failed to resume dev_replace");
1929 btrfs_qgroup_rescan_resume(fs_info);
1931 if (!fs_info->uuid_root) {
1932 btrfs_info(fs_info, "creating UUID tree");
1933 ret = btrfs_create_uuid_tree(fs_info);
1936 "failed to create the UUID tree %d",
1941 sb->s_flags &= ~SB_RDONLY;
1943 set_bit(BTRFS_FS_OPEN, &fs_info->flags);
1946 wake_up_process(fs_info->transaction_kthread);
1947 btrfs_remount_cleanup(fs_info, old_opts);
1951 /* We've hit an error - don't reset SB_RDONLY */
1953 old_flags |= SB_RDONLY;
1954 sb->s_flags = old_flags;
1955 fs_info->mount_opt = old_opts;
1956 fs_info->compress_type = old_compress_type;
1957 fs_info->max_inline = old_max_inline;
1958 btrfs_resize_thread_pool(fs_info,
1959 old_thread_pool_size, fs_info->thread_pool_size);
1960 fs_info->metadata_ratio = old_metadata_ratio;
1961 btrfs_remount_cleanup(fs_info, old_opts);
1965 /* Used to sort the devices by max_avail(descending sort) */
1966 static int btrfs_cmp_device_free_bytes(const void *dev_info1,
1967 const void *dev_info2)
1969 if (((struct btrfs_device_info *)dev_info1)->max_avail >
1970 ((struct btrfs_device_info *)dev_info2)->max_avail)
1972 else if (((struct btrfs_device_info *)dev_info1)->max_avail <
1973 ((struct btrfs_device_info *)dev_info2)->max_avail)
1980 * sort the devices by max_avail, in which max free extent size of each device
1981 * is stored.(Descending Sort)
1983 static inline void btrfs_descending_sort_devices(
1984 struct btrfs_device_info *devices,
1987 sort(devices, nr_devices, sizeof(struct btrfs_device_info),
1988 btrfs_cmp_device_free_bytes, NULL);
1992 * The helper to calc the free space on the devices that can be used to store
1995 static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
1998 struct btrfs_device_info *devices_info;
1999 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
2000 struct btrfs_device *device;
2004 u64 min_stripe_size;
2005 int min_stripes = 1, num_stripes = 1;
2006 int i = 0, nr_devices;
2009 * We aren't under the device list lock, so this is racy-ish, but good
2010 * enough for our purposes.
2012 nr_devices = fs_info->fs_devices->open_devices;
2015 nr_devices = fs_info->fs_devices->open_devices;
2023 devices_info = kmalloc_array(nr_devices, sizeof(*devices_info),
2028 /* calc min stripe number for data space allocation */
2029 type = btrfs_data_alloc_profile(fs_info);
2030 if (type & BTRFS_BLOCK_GROUP_RAID0) {
2032 num_stripes = nr_devices;
2033 } else if (type & BTRFS_BLOCK_GROUP_RAID1) {
2036 } else if (type & BTRFS_BLOCK_GROUP_RAID10) {
2041 if (type & BTRFS_BLOCK_GROUP_DUP)
2042 min_stripe_size = 2 * BTRFS_STRIPE_LEN;
2044 min_stripe_size = BTRFS_STRIPE_LEN;
2047 list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
2048 if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
2049 &device->dev_state) ||
2051 test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
2054 if (i >= nr_devices)
2057 avail_space = device->total_bytes - device->bytes_used;
2059 /* align with stripe_len */
2060 avail_space = div_u64(avail_space, BTRFS_STRIPE_LEN);
2061 avail_space *= BTRFS_STRIPE_LEN;
2064 * In order to avoid overwriting the superblock on the drive,
2065 * btrfs starts at an offset of at least 1MB when doing chunk
2071 * we can use the free space in [0, skip_space - 1], subtract
2072 * it from the total.
2074 if (avail_space && avail_space >= skip_space)
2075 avail_space -= skip_space;
2079 if (avail_space < min_stripe_size)
2082 devices_info[i].dev = device;
2083 devices_info[i].max_avail = avail_space;
2091 btrfs_descending_sort_devices(devices_info, nr_devices);
2095 while (nr_devices >= min_stripes) {
2096 if (num_stripes > nr_devices)
2097 num_stripes = nr_devices;
2099 if (devices_info[i].max_avail >= min_stripe_size) {
2103 avail_space += devices_info[i].max_avail * num_stripes;
2104 alloc_size = devices_info[i].max_avail;
2105 for (j = i + 1 - num_stripes; j <= i; j++)
2106 devices_info[j].max_avail -= alloc_size;
2112 kfree(devices_info);
2113 *free_bytes = avail_space;
2118 * Calculate numbers for 'df', pessimistic in case of mixed raid profiles.
2120 * If there's a redundant raid level at DATA block groups, use the respective
2121 * multiplier to scale the sizes.
2123 * Unused device space usage is based on simulating the chunk allocator
2124 * algorithm that respects the device sizes and order of allocations. This is
2125 * a close approximation of the actual use but there are other factors that may
2126 * change the result (like a new metadata chunk).
2128 * If metadata is exhausted, f_bavail will be 0.
2130 static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
2132 struct btrfs_fs_info *fs_info = btrfs_sb(dentry->d_sb);
2133 struct btrfs_super_block *disk_super = fs_info->super_copy;
2134 struct list_head *head = &fs_info->space_info;
2135 struct btrfs_space_info *found;
2137 u64 total_free_data = 0;
2138 u64 total_free_meta = 0;
2139 int bits = dentry->d_sb->s_blocksize_bits;
2140 __be32 *fsid = (__be32 *)fs_info->fsid;
2141 unsigned factor = 1;
2142 struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
2148 list_for_each_entry_rcu(found, head, list) {
2149 if (found->flags & BTRFS_BLOCK_GROUP_DATA) {
2152 total_free_data += found->disk_total - found->disk_used;
2154 btrfs_account_ro_block_groups_free_space(found);
2156 for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
2157 if (!list_empty(&found->block_groups[i])) {
2159 case BTRFS_RAID_DUP:
2160 case BTRFS_RAID_RAID1:
2161 case BTRFS_RAID_RAID10:
2169 * Metadata in mixed block goup profiles are accounted in data
2171 if (!mixed && found->flags & BTRFS_BLOCK_GROUP_METADATA) {
2172 if (found->flags & BTRFS_BLOCK_GROUP_DATA)
2175 total_free_meta += found->disk_total -
2179 total_used += found->disk_used;
2184 buf->f_blocks = div_u64(btrfs_super_total_bytes(disk_super), factor);
2185 buf->f_blocks >>= bits;
2186 buf->f_bfree = buf->f_blocks - (div_u64(total_used, factor) >> bits);
2188 /* Account global block reserve as used, it's in logical size already */
2189 spin_lock(&block_rsv->lock);
2190 /* Mixed block groups accounting is not byte-accurate, avoid overflow */
2191 if (buf->f_bfree >= block_rsv->size >> bits)
2192 buf->f_bfree -= block_rsv->size >> bits;
2195 spin_unlock(&block_rsv->lock);
2197 buf->f_bavail = div_u64(total_free_data, factor);
2198 ret = btrfs_calc_avail_data_space(fs_info, &total_free_data);
2201 buf->f_bavail += div_u64(total_free_data, factor);
2202 buf->f_bavail = buf->f_bavail >> bits;
2205 * We calculate the remaining metadata space minus global reserve. If
2206 * this is (supposedly) smaller than zero, there's no space. But this
2207 * does not hold in practice, the exhausted state happens where's still
2208 * some positive delta. So we apply some guesswork and compare the
2209 * delta to a 4M threshold. (Practically observed delta was ~2M.)
2211 * We probably cannot calculate the exact threshold value because this
2212 * depends on the internal reservations requested by various
2213 * operations, so some operations that consume a few metadata will
2214 * succeed even if the Avail is zero. But this is better than the other
2219 if (!mixed && total_free_meta - thresh < block_rsv->size)
2222 buf->f_type = BTRFS_SUPER_MAGIC;
2223 buf->f_bsize = dentry->d_sb->s_blocksize;
2224 buf->f_namelen = BTRFS_NAME_LEN;
2226 /* We treat it as constant endianness (it doesn't matter _which_)
2227 because we want the fsid to come out the same whether mounted
2228 on a big-endian or little-endian host */
2229 buf->f_fsid.val[0] = be32_to_cpu(fsid[0]) ^ be32_to_cpu(fsid[2]);
2230 buf->f_fsid.val[1] = be32_to_cpu(fsid[1]) ^ be32_to_cpu(fsid[3]);
2231 /* Mask in the root object ID too, to disambiguate subvols */
2232 buf->f_fsid.val[0] ^= BTRFS_I(d_inode(dentry))->root->objectid >> 32;
2233 buf->f_fsid.val[1] ^= BTRFS_I(d_inode(dentry))->root->objectid;
2238 static void btrfs_kill_super(struct super_block *sb)
2240 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
2241 kill_anon_super(sb);
2242 free_fs_info(fs_info);
2245 static struct file_system_type btrfs_fs_type = {
2246 .owner = THIS_MODULE,
2248 .mount = btrfs_mount,
2249 .kill_sb = btrfs_kill_super,
2250 .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA,
2253 static struct file_system_type btrfs_root_fs_type = {
2254 .owner = THIS_MODULE,
2256 .mount = btrfs_mount_root,
2257 .kill_sb = btrfs_kill_super,
2258 .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA,
2261 MODULE_ALIAS_FS("btrfs");
2263 static int btrfs_control_open(struct inode *inode, struct file *file)
2266 * The control file's private_data is used to hold the
2267 * transaction when it is started and is used to keep
2268 * track of whether a transaction is already in progress.
2270 file->private_data = NULL;
2275 * used by btrfsctl to scan devices when no FS is mounted
2277 static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
2280 struct btrfs_ioctl_vol_args *vol;
2281 struct btrfs_fs_devices *fs_devices;
2284 if (!capable(CAP_SYS_ADMIN))
2287 vol = memdup_user((void __user *)arg, sizeof(*vol));
2289 return PTR_ERR(vol);
2292 case BTRFS_IOC_SCAN_DEV:
2293 ret = btrfs_scan_one_device(vol->name, FMODE_READ,
2294 &btrfs_root_fs_type, &fs_devices);
2296 case BTRFS_IOC_DEVICES_READY:
2297 ret = btrfs_scan_one_device(vol->name, FMODE_READ,
2298 &btrfs_root_fs_type, &fs_devices);
2301 ret = !(fs_devices->num_devices == fs_devices->total_devices);
2303 case BTRFS_IOC_GET_SUPPORTED_FEATURES:
2304 ret = btrfs_ioctl_get_supported_features((void __user*)arg);
2312 static int btrfs_freeze(struct super_block *sb)
2314 struct btrfs_trans_handle *trans;
2315 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
2316 struct btrfs_root *root = fs_info->tree_root;
2318 set_bit(BTRFS_FS_FROZEN, &fs_info->flags);
2320 * We don't need a barrier here, we'll wait for any transaction that
2321 * could be in progress on other threads (and do delayed iputs that
2322 * we want to avoid on a frozen filesystem), or do the commit
2325 trans = btrfs_attach_transaction_barrier(root);
2326 if (IS_ERR(trans)) {
2327 /* no transaction, don't bother */
2328 if (PTR_ERR(trans) == -ENOENT)
2330 return PTR_ERR(trans);
2332 return btrfs_commit_transaction(trans);
2335 static int btrfs_unfreeze(struct super_block *sb)
2337 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
2339 clear_bit(BTRFS_FS_FROZEN, &fs_info->flags);
2343 static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
2345 struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb);
2346 struct btrfs_fs_devices *cur_devices;
2347 struct btrfs_device *dev, *first_dev = NULL;
2348 struct list_head *head;
2349 struct rcu_string *name;
2351 mutex_lock(&fs_info->fs_devices->device_list_mutex);
2352 cur_devices = fs_info->fs_devices;
2353 while (cur_devices) {
2354 head = &cur_devices->devices;
2355 list_for_each_entry(dev, head, dev_list) {
2356 if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state))
2360 if (!first_dev || dev->devid < first_dev->devid)
2363 cur_devices = cur_devices->seed;
2368 name = rcu_dereference(first_dev->name);
2369 seq_escape(m, name->str, " \t\n\\");
2374 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
2378 static const struct super_operations btrfs_super_ops = {
2379 .drop_inode = btrfs_drop_inode,
2380 .evict_inode = btrfs_evict_inode,
2381 .put_super = btrfs_put_super,
2382 .sync_fs = btrfs_sync_fs,
2383 .show_options = btrfs_show_options,
2384 .show_devname = btrfs_show_devname,
2385 .write_inode = btrfs_write_inode,
2386 .alloc_inode = btrfs_alloc_inode,
2387 .destroy_inode = btrfs_destroy_inode,
2388 .statfs = btrfs_statfs,
2389 .remount_fs = btrfs_remount,
2390 .freeze_fs = btrfs_freeze,
2391 .unfreeze_fs = btrfs_unfreeze,
2394 static const struct file_operations btrfs_ctl_fops = {
2395 .open = btrfs_control_open,
2396 .unlocked_ioctl = btrfs_control_ioctl,
2397 .compat_ioctl = btrfs_control_ioctl,
2398 .owner = THIS_MODULE,
2399 .llseek = noop_llseek,
2402 static struct miscdevice btrfs_misc = {
2403 .minor = BTRFS_MINOR,
2404 .name = "btrfs-control",
2405 .fops = &btrfs_ctl_fops
2408 MODULE_ALIAS_MISCDEV(BTRFS_MINOR);
2409 MODULE_ALIAS("devname:btrfs-control");
2411 static int __init btrfs_interface_init(void)
2413 return misc_register(&btrfs_misc);
2416 static void btrfs_interface_exit(void)
2418 misc_deregister(&btrfs_misc);
2421 static void __init btrfs_print_mod_info(void)
2423 pr_info("Btrfs loaded, crc32c=%s"
2424 #ifdef CONFIG_BTRFS_DEBUG
2427 #ifdef CONFIG_BTRFS_ASSERT
2430 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
2431 ", integrity-checker=on"
2433 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
2437 btrfs_crc32c_impl());
2440 static int __init init_btrfs_fs(void)
2444 err = btrfs_hash_init();
2450 err = btrfs_init_sysfs();
2454 btrfs_init_compress();
2456 err = btrfs_init_cachep();
2460 err = extent_io_init();
2464 err = extent_map_init();
2466 goto free_extent_io;
2468 err = ordered_data_init();
2470 goto free_extent_map;
2472 err = btrfs_delayed_inode_init();
2474 goto free_ordered_data;
2476 err = btrfs_auto_defrag_init();
2478 goto free_delayed_inode;
2480 err = btrfs_delayed_ref_init();
2482 goto free_auto_defrag;
2484 err = btrfs_prelim_ref_init();
2486 goto free_delayed_ref;
2488 err = btrfs_end_io_wq_init();
2490 goto free_prelim_ref;
2492 err = btrfs_interface_init();
2494 goto free_end_io_wq;
2496 btrfs_init_lockdep();
2498 btrfs_print_mod_info();
2500 err = btrfs_run_sanity_tests();
2502 goto unregister_ioctl;
2504 err = register_filesystem(&btrfs_fs_type);
2506 goto unregister_ioctl;
2511 btrfs_interface_exit();
2513 btrfs_end_io_wq_exit();
2515 btrfs_prelim_ref_exit();
2517 btrfs_delayed_ref_exit();
2519 btrfs_auto_defrag_exit();
2521 btrfs_delayed_inode_exit();
2523 ordered_data_exit();
2529 btrfs_destroy_cachep();
2531 btrfs_exit_compress();
2538 static void __exit exit_btrfs_fs(void)
2540 btrfs_destroy_cachep();
2541 btrfs_delayed_ref_exit();
2542 btrfs_auto_defrag_exit();
2543 btrfs_delayed_inode_exit();
2544 btrfs_prelim_ref_exit();
2545 ordered_data_exit();
2548 btrfs_interface_exit();
2549 btrfs_end_io_wq_exit();
2550 unregister_filesystem(&btrfs_fs_type);
2552 btrfs_cleanup_fs_uuids();
2553 btrfs_exit_compress();
2557 late_initcall(init_btrfs_fs);
2558 module_exit(exit_btrfs_fs)
2560 MODULE_LICENSE("GPL");