1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2007 Oracle. All rights reserved.
6 #include <linux/blkdev.h>
7 #include <linux/module.h>
9 #include <linux/pagemap.h>
10 #include <linux/highmem.h>
11 #include <linux/time.h>
12 #include <linux/init.h>
13 #include <linux/seq_file.h>
14 #include <linux/string.h>
15 #include <linux/backing-dev.h>
16 #include <linux/mount.h>
17 #include <linux/writeback.h>
18 #include <linux/statfs.h>
19 #include <linux/compat.h>
20 #include <linux/parser.h>
21 #include <linux/ctype.h>
22 #include <linux/namei.h>
23 #include <linux/miscdevice.h>
24 #include <linux/magic.h>
25 #include <linux/slab.h>
26 #include <linux/cleancache.h>
27 #include <linux/ratelimit.h>
28 #include <linux/crc32c.h>
29 #include <linux/btrfs.h>
30 #include "delayed-inode.h"
33 #include "transaction.h"
34 #include "btrfs_inode.h"
35 #include "print-tree.h"
40 #include "compression.h"
41 #include "rcu-string.h"
42 #include "dev-replace.h"
43 #include "free-space-cache.h"
45 #include "space-info.h"
47 #include "tests/btrfs-tests.h"
48 #include "block-group.h"
52 #define CREATE_TRACE_POINTS
53 #include <trace/events/btrfs.h>
55 static const struct super_operations btrfs_super_ops;
58 * Types for mounting the default subvolume and a subvolume explicitly
59 * requested by subvol=/path. That way the callchain is straightforward and we
60 * don't have to play tricks with the mount options and recursive calls to
63 * The new btrfs_root_fs_type also servers as a tag for the bdev_holder.
65 static struct file_system_type btrfs_fs_type;
66 static struct file_system_type btrfs_root_fs_type;
68 static int btrfs_remount(struct super_block *sb, int *flags, char *data);
70 const char * __attribute_const__ btrfs_decode_error(int errno)
72 char *errstr = "unknown";
75 case -ENOENT: /* -2 */
76 errstr = "No such entry";
79 errstr = "IO failure";
81 case -ENOMEM: /* -12*/
82 errstr = "Out of memory";
84 case -EEXIST: /* -17 */
85 errstr = "Object already exists";
87 case -ENOSPC: /* -28 */
88 errstr = "No space left";
90 case -EROFS: /* -30 */
91 errstr = "Readonly filesystem";
93 case -EOPNOTSUPP: /* -95 */
94 errstr = "Operation not supported";
96 case -EUCLEAN: /* -117 */
97 errstr = "Filesystem corrupted";
99 case -EDQUOT: /* -122 */
100 errstr = "Quota exceeded";
108 * __btrfs_handle_fs_error decodes expected errors from the caller and
109 * invokes the appropriate error response.
112 void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
113 unsigned int line, int errno, const char *fmt, ...)
115 struct super_block *sb = fs_info->sb;
121 * Special case: if the error is EROFS, and we're already
122 * under SB_RDONLY, then it is safe here.
124 if (errno == -EROFS && sb_rdonly(sb))
128 errstr = btrfs_decode_error(errno);
130 struct va_format vaf;
137 pr_crit("BTRFS: error (device %s) in %s:%d: errno=%d %s (%pV)\n",
138 sb->s_id, function, line, errno, errstr, &vaf);
141 pr_crit("BTRFS: error (device %s) in %s:%d: errno=%d %s\n",
142 sb->s_id, function, line, errno, errstr);
147 * Today we only save the error info to memory. Long term we'll
148 * also send it down to the disk
150 set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state);
152 /* Don't go through full error handling during mount */
153 if (!(sb->s_flags & SB_BORN))
159 btrfs_discard_stop(fs_info);
161 /* btrfs handle error by forcing the filesystem readonly */
162 sb->s_flags |= SB_RDONLY;
163 btrfs_info(fs_info, "forced readonly");
165 * Note that a running device replace operation is not canceled here
166 * although there is no way to update the progress. It would add the
167 * risk of a deadlock, therefore the canceling is omitted. The only
168 * penalty is that some I/O remains active until the procedure
169 * completes. The next time when the filesystem is mounted writable
170 * again, the device replace operation continues.
175 static const char * const logtypes[] = {
188 * Use one ratelimit state per log level so that a flood of less important
189 * messages doesn't cause more important ones to be dropped.
191 static struct ratelimit_state printk_limits[] = {
192 RATELIMIT_STATE_INIT(printk_limits[0], DEFAULT_RATELIMIT_INTERVAL, 100),
193 RATELIMIT_STATE_INIT(printk_limits[1], DEFAULT_RATELIMIT_INTERVAL, 100),
194 RATELIMIT_STATE_INIT(printk_limits[2], DEFAULT_RATELIMIT_INTERVAL, 100),
195 RATELIMIT_STATE_INIT(printk_limits[3], DEFAULT_RATELIMIT_INTERVAL, 100),
196 RATELIMIT_STATE_INIT(printk_limits[4], DEFAULT_RATELIMIT_INTERVAL, 100),
197 RATELIMIT_STATE_INIT(printk_limits[5], DEFAULT_RATELIMIT_INTERVAL, 100),
198 RATELIMIT_STATE_INIT(printk_limits[6], DEFAULT_RATELIMIT_INTERVAL, 100),
199 RATELIMIT_STATE_INIT(printk_limits[7], DEFAULT_RATELIMIT_INTERVAL, 100),
202 void __cold btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
204 char lvl[PRINTK_MAX_SINGLE_HEADER_LEN + 1] = "\0";
205 struct va_format vaf;
208 const char *type = logtypes[4];
209 struct ratelimit_state *ratelimit = &printk_limits[4];
213 while ((kern_level = printk_get_level(fmt)) != 0) {
214 size_t size = printk_skip_level(fmt) - fmt;
216 if (kern_level >= '0' && kern_level <= '7') {
217 memcpy(lvl, fmt, size);
219 type = logtypes[kern_level - '0'];
220 ratelimit = &printk_limits[kern_level - '0'];
228 if (__ratelimit(ratelimit))
229 printk("%sBTRFS %s (device %s): %pV\n", lvl, type,
230 fs_info ? fs_info->sb->s_id : "<unknown>", &vaf);
237 * We only mark the transaction aborted and then set the file system read-only.
238 * This will prevent new transactions from starting or trying to join this
241 * This means that error recovery at the call site is limited to freeing
242 * any local memory allocations and passing the error code up without
243 * further cleanup. The transaction should complete as it normally would
244 * in the call path but will return -EIO.
246 * We'll complete the cleanup in btrfs_end_transaction and
247 * btrfs_commit_transaction.
250 void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
251 const char *function,
252 unsigned int line, int errno)
254 struct btrfs_fs_info *fs_info = trans->fs_info;
256 WRITE_ONCE(trans->aborted, errno);
257 /* Nothing used. The other threads that have joined this
258 * transaction may be able to continue. */
259 if (!trans->dirty && list_empty(&trans->new_bgs)) {
262 errstr = btrfs_decode_error(errno);
264 "%s:%d: Aborting unused transaction(%s).",
265 function, line, errstr);
268 WRITE_ONCE(trans->transaction->aborted, errno);
269 /* Wake up anybody who may be waiting on this transaction */
270 wake_up(&fs_info->transaction_wait);
271 wake_up(&fs_info->transaction_blocked_wait);
272 __btrfs_handle_fs_error(fs_info, function, line, errno, NULL);
275 * __btrfs_panic decodes unexpected, fatal errors from the caller,
276 * issues an alert, and either panics or BUGs, depending on mount options.
279 void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
280 unsigned int line, int errno, const char *fmt, ...)
282 char *s_id = "<unknown>";
284 struct va_format vaf = { .fmt = fmt };
288 s_id = fs_info->sb->s_id;
293 errstr = btrfs_decode_error(errno);
294 if (fs_info && (btrfs_test_opt(fs_info, PANIC_ON_FATAL_ERROR)))
295 panic(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (errno=%d %s)\n",
296 s_id, function, line, &vaf, errno, errstr);
298 btrfs_crit(fs_info, "panic in %s:%d: %pV (errno=%d %s)",
299 function, line, &vaf, errno, errstr);
301 /* Caller calls BUG() */
304 static void btrfs_put_super(struct super_block *sb)
306 close_ctree(btrfs_sb(sb));
315 Opt_compress_force_type,
320 Opt_flushoncommit, Opt_noflushoncommit,
321 Opt_inode_cache, Opt_noinode_cache,
323 Opt_barrier, Opt_nobarrier,
324 Opt_datacow, Opt_nodatacow,
325 Opt_datasum, Opt_nodatasum,
326 Opt_defrag, Opt_nodefrag,
327 Opt_discard, Opt_nodiscard,
332 Opt_rescan_uuid_tree,
334 Opt_space_cache, Opt_no_space_cache,
335 Opt_space_cache_version,
337 Opt_ssd_spread, Opt_nossd_spread,
342 Opt_treelog, Opt_notreelog,
344 Opt_user_subvol_rm_allowed,
346 /* Deprecated options */
351 /* Debugging options */
353 Opt_check_integrity_including_extent_data,
354 Opt_check_integrity_print_mask,
355 Opt_enospc_debug, Opt_noenospc_debug,
356 #ifdef CONFIG_BTRFS_DEBUG
357 Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all,
359 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
365 static const match_table_t tokens = {
367 {Opt_noacl, "noacl"},
368 {Opt_clear_cache, "clear_cache"},
369 {Opt_commit_interval, "commit=%u"},
370 {Opt_compress, "compress"},
371 {Opt_compress_type, "compress=%s"},
372 {Opt_compress_force, "compress-force"},
373 {Opt_compress_force_type, "compress-force=%s"},
374 {Opt_degraded, "degraded"},
375 {Opt_device, "device=%s"},
376 {Opt_fatal_errors, "fatal_errors=%s"},
377 {Opt_flushoncommit, "flushoncommit"},
378 {Opt_noflushoncommit, "noflushoncommit"},
379 {Opt_inode_cache, "inode_cache"},
380 {Opt_noinode_cache, "noinode_cache"},
381 {Opt_max_inline, "max_inline=%s"},
382 {Opt_barrier, "barrier"},
383 {Opt_nobarrier, "nobarrier"},
384 {Opt_datacow, "datacow"},
385 {Opt_nodatacow, "nodatacow"},
386 {Opt_datasum, "datasum"},
387 {Opt_nodatasum, "nodatasum"},
388 {Opt_defrag, "autodefrag"},
389 {Opt_nodefrag, "noautodefrag"},
390 {Opt_discard, "discard"},
391 {Opt_discard_mode, "discard=%s"},
392 {Opt_nodiscard, "nodiscard"},
393 {Opt_nologreplay, "nologreplay"},
394 {Opt_norecovery, "norecovery"},
395 {Opt_ratio, "metadata_ratio=%u"},
396 {Opt_rescan_uuid_tree, "rescan_uuid_tree"},
397 {Opt_skip_balance, "skip_balance"},
398 {Opt_space_cache, "space_cache"},
399 {Opt_no_space_cache, "nospace_cache"},
400 {Opt_space_cache_version, "space_cache=%s"},
402 {Opt_nossd, "nossd"},
403 {Opt_ssd_spread, "ssd_spread"},
404 {Opt_nossd_spread, "nossd_spread"},
405 {Opt_subvol, "subvol=%s"},
406 {Opt_subvol_empty, "subvol="},
407 {Opt_subvolid, "subvolid=%s"},
408 {Opt_thread_pool, "thread_pool=%u"},
409 {Opt_treelog, "treelog"},
410 {Opt_notreelog, "notreelog"},
411 {Opt_usebackuproot, "usebackuproot"},
412 {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
414 /* Deprecated options */
415 {Opt_alloc_start, "alloc_start=%s"},
416 {Opt_recovery, "recovery"},
417 {Opt_subvolrootid, "subvolrootid=%d"},
419 /* Debugging options */
420 {Opt_check_integrity, "check_int"},
421 {Opt_check_integrity_including_extent_data, "check_int_data"},
422 {Opt_check_integrity_print_mask, "check_int_print_mask=%u"},
423 {Opt_enospc_debug, "enospc_debug"},
424 {Opt_noenospc_debug, "noenospc_debug"},
425 #ifdef CONFIG_BTRFS_DEBUG
426 {Opt_fragment_data, "fragment=data"},
427 {Opt_fragment_metadata, "fragment=metadata"},
428 {Opt_fragment_all, "fragment=all"},
430 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
431 {Opt_ref_verify, "ref_verify"},
437 * Regular mount options parser. Everything that is needed only when
438 * reading in a new superblock is parsed here.
439 * XXX JDM: This needs to be cleaned up for remount.
441 int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
442 unsigned long new_flags)
444 substring_t args[MAX_OPT_ARGS];
450 bool compress_force = false;
451 enum btrfs_compression_type saved_compress_type;
452 bool saved_compress_force;
455 cache_gen = btrfs_super_cache_generation(info->super_copy);
456 if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE))
457 btrfs_set_opt(info->mount_opt, FREE_SPACE_TREE);
459 btrfs_set_opt(info->mount_opt, SPACE_CACHE);
462 * Even the options are empty, we still need to do extra check
468 while ((p = strsep(&options, ",")) != NULL) {
473 token = match_token(p, tokens, args);
476 btrfs_info(info, "allowing degraded mounts");
477 btrfs_set_opt(info->mount_opt, DEGRADED);
480 case Opt_subvol_empty:
482 case Opt_subvolrootid:
485 * These are parsed by btrfs_parse_subvol_options or
486 * btrfs_parse_device_options and can be ignored here.
490 btrfs_set_and_info(info, NODATASUM,
491 "setting nodatasum");
494 if (btrfs_test_opt(info, NODATASUM)) {
495 if (btrfs_test_opt(info, NODATACOW))
497 "setting datasum, datacow enabled");
499 btrfs_info(info, "setting datasum");
501 btrfs_clear_opt(info->mount_opt, NODATACOW);
502 btrfs_clear_opt(info->mount_opt, NODATASUM);
505 if (!btrfs_test_opt(info, NODATACOW)) {
506 if (!btrfs_test_opt(info, COMPRESS) ||
507 !btrfs_test_opt(info, FORCE_COMPRESS)) {
509 "setting nodatacow, compression disabled");
511 btrfs_info(info, "setting nodatacow");
514 btrfs_clear_opt(info->mount_opt, COMPRESS);
515 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS);
516 btrfs_set_opt(info->mount_opt, NODATACOW);
517 btrfs_set_opt(info->mount_opt, NODATASUM);
520 btrfs_clear_and_info(info, NODATACOW,
523 case Opt_compress_force:
524 case Opt_compress_force_type:
525 compress_force = true;
528 case Opt_compress_type:
529 saved_compress_type = btrfs_test_opt(info,
531 info->compress_type : BTRFS_COMPRESS_NONE;
532 saved_compress_force =
533 btrfs_test_opt(info, FORCE_COMPRESS);
534 if (token == Opt_compress ||
535 token == Opt_compress_force ||
536 strncmp(args[0].from, "zlib", 4) == 0) {
537 compress_type = "zlib";
539 info->compress_type = BTRFS_COMPRESS_ZLIB;
540 info->compress_level = BTRFS_ZLIB_DEFAULT_LEVEL;
542 * args[0] contains uninitialized data since
543 * for these tokens we don't expect any
546 if (token != Opt_compress &&
547 token != Opt_compress_force)
548 info->compress_level =
549 btrfs_compress_str2level(
552 btrfs_set_opt(info->mount_opt, COMPRESS);
553 btrfs_clear_opt(info->mount_opt, NODATACOW);
554 btrfs_clear_opt(info->mount_opt, NODATASUM);
556 } else if (strncmp(args[0].from, "lzo", 3) == 0) {
557 compress_type = "lzo";
558 info->compress_type = BTRFS_COMPRESS_LZO;
559 btrfs_set_opt(info->mount_opt, COMPRESS);
560 btrfs_clear_opt(info->mount_opt, NODATACOW);
561 btrfs_clear_opt(info->mount_opt, NODATASUM);
562 btrfs_set_fs_incompat(info, COMPRESS_LZO);
564 } else if (strncmp(args[0].from, "zstd", 4) == 0) {
565 compress_type = "zstd";
566 info->compress_type = BTRFS_COMPRESS_ZSTD;
567 info->compress_level =
568 btrfs_compress_str2level(
571 btrfs_set_opt(info->mount_opt, COMPRESS);
572 btrfs_clear_opt(info->mount_opt, NODATACOW);
573 btrfs_clear_opt(info->mount_opt, NODATASUM);
574 btrfs_set_fs_incompat(info, COMPRESS_ZSTD);
576 } else if (strncmp(args[0].from, "no", 2) == 0) {
577 compress_type = "no";
578 btrfs_clear_opt(info->mount_opt, COMPRESS);
579 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS);
580 compress_force = false;
587 if (compress_force) {
588 btrfs_set_opt(info->mount_opt, FORCE_COMPRESS);
591 * If we remount from compress-force=xxx to
592 * compress=xxx, we need clear FORCE_COMPRESS
593 * flag, otherwise, there is no way for users
594 * to disable forcible compression separately.
596 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS);
598 if ((btrfs_test_opt(info, COMPRESS) &&
599 (info->compress_type != saved_compress_type ||
600 compress_force != saved_compress_force)) ||
601 (!btrfs_test_opt(info, COMPRESS) &&
603 btrfs_info(info, "%s %s compression, level %d",
604 (compress_force) ? "force" : "use",
605 compress_type, info->compress_level);
607 compress_force = false;
610 btrfs_set_and_info(info, SSD,
611 "enabling ssd optimizations");
612 btrfs_clear_opt(info->mount_opt, NOSSD);
615 btrfs_set_and_info(info, SSD,
616 "enabling ssd optimizations");
617 btrfs_set_and_info(info, SSD_SPREAD,
618 "using spread ssd allocation scheme");
619 btrfs_clear_opt(info->mount_opt, NOSSD);
622 btrfs_set_opt(info->mount_opt, NOSSD);
623 btrfs_clear_and_info(info, SSD,
624 "not using ssd optimizations");
626 case Opt_nossd_spread:
627 btrfs_clear_and_info(info, SSD_SPREAD,
628 "not using spread ssd allocation scheme");
631 btrfs_clear_and_info(info, NOBARRIER,
632 "turning on barriers");
635 btrfs_set_and_info(info, NOBARRIER,
636 "turning off barriers");
638 case Opt_thread_pool:
639 ret = match_int(&args[0], &intarg);
642 } else if (intarg == 0) {
646 info->thread_pool_size = intarg;
649 num = match_strdup(&args[0]);
651 info->max_inline = memparse(num, NULL);
654 if (info->max_inline) {
655 info->max_inline = min_t(u64,
659 btrfs_info(info, "max_inline at %llu",
666 case Opt_alloc_start:
668 "option alloc_start is obsolete, ignored");
671 #ifdef CONFIG_BTRFS_FS_POSIX_ACL
672 info->sb->s_flags |= SB_POSIXACL;
675 btrfs_err(info, "support for ACL not compiled in!");
680 info->sb->s_flags &= ~SB_POSIXACL;
683 btrfs_set_and_info(info, NOTREELOG,
684 "disabling tree log");
687 btrfs_clear_and_info(info, NOTREELOG,
688 "enabling tree log");
691 case Opt_nologreplay:
692 btrfs_set_and_info(info, NOLOGREPLAY,
693 "disabling log replay at mount time");
695 case Opt_flushoncommit:
696 btrfs_set_and_info(info, FLUSHONCOMMIT,
697 "turning on flush-on-commit");
699 case Opt_noflushoncommit:
700 btrfs_clear_and_info(info, FLUSHONCOMMIT,
701 "turning off flush-on-commit");
704 ret = match_int(&args[0], &intarg);
707 info->metadata_ratio = intarg;
708 btrfs_info(info, "metadata ratio %u",
709 info->metadata_ratio);
712 case Opt_discard_mode:
713 if (token == Opt_discard ||
714 strcmp(args[0].from, "sync") == 0) {
715 btrfs_clear_opt(info->mount_opt, DISCARD_ASYNC);
716 btrfs_set_and_info(info, DISCARD_SYNC,
717 "turning on sync discard");
718 } else if (strcmp(args[0].from, "async") == 0) {
719 btrfs_clear_opt(info->mount_opt, DISCARD_SYNC);
720 btrfs_set_and_info(info, DISCARD_ASYNC,
721 "turning on async discard");
728 btrfs_clear_and_info(info, DISCARD_SYNC,
729 "turning off discard");
730 btrfs_clear_and_info(info, DISCARD_ASYNC,
731 "turning off async discard");
733 case Opt_space_cache:
734 case Opt_space_cache_version:
735 if (token == Opt_space_cache ||
736 strcmp(args[0].from, "v1") == 0) {
737 btrfs_clear_opt(info->mount_opt,
739 btrfs_set_and_info(info, SPACE_CACHE,
740 "enabling disk space caching");
741 } else if (strcmp(args[0].from, "v2") == 0) {
742 btrfs_clear_opt(info->mount_opt,
744 btrfs_set_and_info(info, FREE_SPACE_TREE,
745 "enabling free space tree");
751 case Opt_rescan_uuid_tree:
752 btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE);
754 case Opt_no_space_cache:
755 if (btrfs_test_opt(info, SPACE_CACHE)) {
756 btrfs_clear_and_info(info, SPACE_CACHE,
757 "disabling disk space caching");
759 if (btrfs_test_opt(info, FREE_SPACE_TREE)) {
760 btrfs_clear_and_info(info, FREE_SPACE_TREE,
761 "disabling free space tree");
764 case Opt_inode_cache:
765 btrfs_set_pending_and_info(info, INODE_MAP_CACHE,
766 "enabling inode map caching");
768 case Opt_noinode_cache:
769 btrfs_clear_pending_and_info(info, INODE_MAP_CACHE,
770 "disabling inode map caching");
772 case Opt_clear_cache:
773 btrfs_set_and_info(info, CLEAR_CACHE,
774 "force clearing of disk cache");
776 case Opt_user_subvol_rm_allowed:
777 btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED);
779 case Opt_enospc_debug:
780 btrfs_set_opt(info->mount_opt, ENOSPC_DEBUG);
782 case Opt_noenospc_debug:
783 btrfs_clear_opt(info->mount_opt, ENOSPC_DEBUG);
786 btrfs_set_and_info(info, AUTO_DEFRAG,
787 "enabling auto defrag");
790 btrfs_clear_and_info(info, AUTO_DEFRAG,
791 "disabling auto defrag");
795 "'recovery' is deprecated, use 'usebackuproot' instead");
797 case Opt_usebackuproot:
799 "trying to use backup root at mount time");
800 btrfs_set_opt(info->mount_opt, USEBACKUPROOT);
802 case Opt_skip_balance:
803 btrfs_set_opt(info->mount_opt, SKIP_BALANCE);
805 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
806 case Opt_check_integrity_including_extent_data:
808 "enabling check integrity including extent data");
809 btrfs_set_opt(info->mount_opt,
810 CHECK_INTEGRITY_INCLUDING_EXTENT_DATA);
811 btrfs_set_opt(info->mount_opt, CHECK_INTEGRITY);
813 case Opt_check_integrity:
814 btrfs_info(info, "enabling check integrity");
815 btrfs_set_opt(info->mount_opt, CHECK_INTEGRITY);
817 case Opt_check_integrity_print_mask:
818 ret = match_int(&args[0], &intarg);
821 info->check_integrity_print_mask = intarg;
822 btrfs_info(info, "check_integrity_print_mask 0x%x",
823 info->check_integrity_print_mask);
826 case Opt_check_integrity_including_extent_data:
827 case Opt_check_integrity:
828 case Opt_check_integrity_print_mask:
830 "support for check_integrity* not compiled in!");
834 case Opt_fatal_errors:
835 if (strcmp(args[0].from, "panic") == 0)
836 btrfs_set_opt(info->mount_opt,
837 PANIC_ON_FATAL_ERROR);
838 else if (strcmp(args[0].from, "bug") == 0)
839 btrfs_clear_opt(info->mount_opt,
840 PANIC_ON_FATAL_ERROR);
846 case Opt_commit_interval:
848 ret = match_int(&args[0], &intarg);
853 "using default commit interval %us",
854 BTRFS_DEFAULT_COMMIT_INTERVAL);
855 intarg = BTRFS_DEFAULT_COMMIT_INTERVAL;
856 } else if (intarg > 300) {
857 btrfs_warn(info, "excessive commit interval %d",
860 info->commit_interval = intarg;
862 #ifdef CONFIG_BTRFS_DEBUG
863 case Opt_fragment_all:
864 btrfs_info(info, "fragmenting all space");
865 btrfs_set_opt(info->mount_opt, FRAGMENT_DATA);
866 btrfs_set_opt(info->mount_opt, FRAGMENT_METADATA);
868 case Opt_fragment_metadata:
869 btrfs_info(info, "fragmenting metadata");
870 btrfs_set_opt(info->mount_opt,
873 case Opt_fragment_data:
874 btrfs_info(info, "fragmenting data");
875 btrfs_set_opt(info->mount_opt, FRAGMENT_DATA);
878 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
880 btrfs_info(info, "doing ref verification");
881 btrfs_set_opt(info->mount_opt, REF_VERIFY);
885 btrfs_err(info, "unrecognized mount option '%s'", p);
894 * Extra check for current option against current flag
896 if (btrfs_test_opt(info, NOLOGREPLAY) && !(new_flags & SB_RDONLY)) {
898 "nologreplay must be used with ro mount option");
902 if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE) &&
903 !btrfs_test_opt(info, FREE_SPACE_TREE) &&
904 !btrfs_test_opt(info, CLEAR_CACHE)) {
905 btrfs_err(info, "cannot disable free space tree");
909 if (!ret && btrfs_test_opt(info, SPACE_CACHE))
910 btrfs_info(info, "disk space caching is enabled");
911 if (!ret && btrfs_test_opt(info, FREE_SPACE_TREE))
912 btrfs_info(info, "using free space tree");
917 * Parse mount options that are required early in the mount process.
919 * All other options will be parsed on much later in the mount process and
920 * only when we need to allocate a new super block.
922 static int btrfs_parse_device_options(const char *options, fmode_t flags,
925 substring_t args[MAX_OPT_ARGS];
926 char *device_name, *opts, *orig, *p;
927 struct btrfs_device *device = NULL;
930 lockdep_assert_held(&uuid_mutex);
936 * strsep changes the string, duplicate it because btrfs_parse_options
939 opts = kstrdup(options, GFP_KERNEL);
944 while ((p = strsep(&opts, ",")) != NULL) {
950 token = match_token(p, tokens, args);
951 if (token == Opt_device) {
952 device_name = match_strdup(&args[0]);
957 device = btrfs_scan_one_device(device_name, flags,
960 if (IS_ERR(device)) {
961 error = PTR_ERR(device);
973 * Parse mount options that are related to subvolume id
975 * The value is later passed to mount_subvol()
977 static int btrfs_parse_subvol_options(const char *options, char **subvol_name,
978 u64 *subvol_objectid)
980 substring_t args[MAX_OPT_ARGS];
981 char *opts, *orig, *p;
989 * strsep changes the string, duplicate it because
990 * btrfs_parse_device_options gets called later
992 opts = kstrdup(options, GFP_KERNEL);
997 while ((p = strsep(&opts, ",")) != NULL) {
1002 token = match_token(p, tokens, args);
1005 kfree(*subvol_name);
1006 *subvol_name = match_strdup(&args[0]);
1007 if (!*subvol_name) {
1013 error = match_u64(&args[0], &subvolid);
1017 /* we want the original fs_tree */
1019 subvolid = BTRFS_FS_TREE_OBJECTID;
1021 *subvol_objectid = subvolid;
1023 case Opt_subvolrootid:
1024 pr_warn("BTRFS: 'subvolrootid' mount option is deprecated and has no effect\n");
1036 char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info,
1037 u64 subvol_objectid)
1039 struct btrfs_root *root = fs_info->tree_root;
1040 struct btrfs_root *fs_root = NULL;
1041 struct btrfs_root_ref *root_ref;
1042 struct btrfs_inode_ref *inode_ref;
1043 struct btrfs_key key;
1044 struct btrfs_path *path = NULL;
1045 char *name = NULL, *ptr;
1050 path = btrfs_alloc_path();
1055 path->leave_spinning = 1;
1057 name = kmalloc(PATH_MAX, GFP_KERNEL);
1062 ptr = name + PATH_MAX - 1;
1066 * Walk up the subvolume trees in the tree of tree roots by root
1067 * backrefs until we hit the top-level subvolume.
1069 while (subvol_objectid != BTRFS_FS_TREE_OBJECTID) {
1070 key.objectid = subvol_objectid;
1071 key.type = BTRFS_ROOT_BACKREF_KEY;
1072 key.offset = (u64)-1;
1074 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
1077 } else if (ret > 0) {
1078 ret = btrfs_previous_item(root, path, subvol_objectid,
1079 BTRFS_ROOT_BACKREF_KEY);
1082 } else if (ret > 0) {
1088 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
1089 subvol_objectid = key.offset;
1091 root_ref = btrfs_item_ptr(path->nodes[0], path->slots[0],
1092 struct btrfs_root_ref);
1093 len = btrfs_root_ref_name_len(path->nodes[0], root_ref);
1096 ret = -ENAMETOOLONG;
1099 read_extent_buffer(path->nodes[0], ptr + 1,
1100 (unsigned long)(root_ref + 1), len);
1102 dirid = btrfs_root_ref_dirid(path->nodes[0], root_ref);
1103 btrfs_release_path(path);
1105 fs_root = btrfs_get_fs_root(fs_info, subvol_objectid, true);
1106 if (IS_ERR(fs_root)) {
1107 ret = PTR_ERR(fs_root);
1113 * Walk up the filesystem tree by inode refs until we hit the
1116 while (dirid != BTRFS_FIRST_FREE_OBJECTID) {
1117 key.objectid = dirid;
1118 key.type = BTRFS_INODE_REF_KEY;
1119 key.offset = (u64)-1;
1121 ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0);
1124 } else if (ret > 0) {
1125 ret = btrfs_previous_item(fs_root, path, dirid,
1126 BTRFS_INODE_REF_KEY);
1129 } else if (ret > 0) {
1135 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
1138 inode_ref = btrfs_item_ptr(path->nodes[0],
1140 struct btrfs_inode_ref);
1141 len = btrfs_inode_ref_name_len(path->nodes[0],
1145 ret = -ENAMETOOLONG;
1148 read_extent_buffer(path->nodes[0], ptr + 1,
1149 (unsigned long)(inode_ref + 1), len);
1151 btrfs_release_path(path);
1153 btrfs_put_root(fs_root);
1157 btrfs_free_path(path);
1158 if (ptr == name + PATH_MAX - 1) {
1162 memmove(name, ptr, name + PATH_MAX - ptr);
1167 btrfs_put_root(fs_root);
1168 btrfs_free_path(path);
1170 return ERR_PTR(ret);
1173 static int get_default_subvol_objectid(struct btrfs_fs_info *fs_info, u64 *objectid)
1175 struct btrfs_root *root = fs_info->tree_root;
1176 struct btrfs_dir_item *di;
1177 struct btrfs_path *path;
1178 struct btrfs_key location;
1181 path = btrfs_alloc_path();
1184 path->leave_spinning = 1;
1187 * Find the "default" dir item which points to the root item that we
1188 * will mount by default if we haven't been given a specific subvolume
1191 dir_id = btrfs_super_root_dir(fs_info->super_copy);
1192 di = btrfs_lookup_dir_item(NULL, root, path, dir_id, "default", 7, 0);
1194 btrfs_free_path(path);
1199 * Ok the default dir item isn't there. This is weird since
1200 * it's always been there, but don't freak out, just try and
1201 * mount the top-level subvolume.
1203 btrfs_free_path(path);
1204 *objectid = BTRFS_FS_TREE_OBJECTID;
1208 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location);
1209 btrfs_free_path(path);
1210 *objectid = location.objectid;
1214 static int btrfs_fill_super(struct super_block *sb,
1215 struct btrfs_fs_devices *fs_devices,
1218 struct inode *inode;
1219 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
1222 sb->s_maxbytes = MAX_LFS_FILESIZE;
1223 sb->s_magic = BTRFS_SUPER_MAGIC;
1224 sb->s_op = &btrfs_super_ops;
1225 sb->s_d_op = &btrfs_dentry_operations;
1226 sb->s_export_op = &btrfs_export_ops;
1227 sb->s_xattr = btrfs_xattr_handlers;
1228 sb->s_time_gran = 1;
1229 #ifdef CONFIG_BTRFS_FS_POSIX_ACL
1230 sb->s_flags |= SB_POSIXACL;
1232 sb->s_flags |= SB_I_VERSION;
1233 sb->s_iflags |= SB_I_CGROUPWB;
1235 err = super_setup_bdi(sb);
1237 btrfs_err(fs_info, "super_setup_bdi failed");
1241 err = open_ctree(sb, fs_devices, (char *)data);
1243 btrfs_err(fs_info, "open_ctree failed");
1247 inode = btrfs_iget(sb, BTRFS_FIRST_FREE_OBJECTID, fs_info->fs_root);
1248 if (IS_ERR(inode)) {
1249 err = PTR_ERR(inode);
1253 sb->s_root = d_make_root(inode);
1259 cleancache_init_fs(sb);
1260 sb->s_flags |= SB_ACTIVE;
1264 close_ctree(fs_info);
1268 int btrfs_sync_fs(struct super_block *sb, int wait)
1270 struct btrfs_trans_handle *trans;
1271 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
1272 struct btrfs_root *root = fs_info->tree_root;
1274 trace_btrfs_sync_fs(fs_info, wait);
1277 filemap_flush(fs_info->btree_inode->i_mapping);
1281 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
1283 trans = btrfs_attach_transaction_barrier(root);
1284 if (IS_ERR(trans)) {
1285 /* no transaction, don't bother */
1286 if (PTR_ERR(trans) == -ENOENT) {
1288 * Exit unless we have some pending changes
1289 * that need to go through commit
1291 if (fs_info->pending_changes == 0)
1294 * A non-blocking test if the fs is frozen. We must not
1295 * start a new transaction here otherwise a deadlock
1296 * happens. The pending operations are delayed to the
1297 * next commit after thawing.
1299 if (sb_start_write_trylock(sb))
1303 trans = btrfs_start_transaction(root, 0);
1306 return PTR_ERR(trans);
1308 return btrfs_commit_transaction(trans);
1311 static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
1313 struct btrfs_fs_info *info = btrfs_sb(dentry->d_sb);
1314 const char *compress_type;
1316 if (btrfs_test_opt(info, DEGRADED))
1317 seq_puts(seq, ",degraded");
1318 if (btrfs_test_opt(info, NODATASUM))
1319 seq_puts(seq, ",nodatasum");
1320 if (btrfs_test_opt(info, NODATACOW))
1321 seq_puts(seq, ",nodatacow");
1322 if (btrfs_test_opt(info, NOBARRIER))
1323 seq_puts(seq, ",nobarrier");
1324 if (info->max_inline != BTRFS_DEFAULT_MAX_INLINE)
1325 seq_printf(seq, ",max_inline=%llu", info->max_inline);
1326 if (info->thread_pool_size != min_t(unsigned long,
1327 num_online_cpus() + 2, 8))
1328 seq_printf(seq, ",thread_pool=%u", info->thread_pool_size);
1329 if (btrfs_test_opt(info, COMPRESS)) {
1330 compress_type = btrfs_compress_type2str(info->compress_type);
1331 if (btrfs_test_opt(info, FORCE_COMPRESS))
1332 seq_printf(seq, ",compress-force=%s", compress_type);
1334 seq_printf(seq, ",compress=%s", compress_type);
1335 if (info->compress_level)
1336 seq_printf(seq, ":%d", info->compress_level);
1338 if (btrfs_test_opt(info, NOSSD))
1339 seq_puts(seq, ",nossd");
1340 if (btrfs_test_opt(info, SSD_SPREAD))
1341 seq_puts(seq, ",ssd_spread");
1342 else if (btrfs_test_opt(info, SSD))
1343 seq_puts(seq, ",ssd");
1344 if (btrfs_test_opt(info, NOTREELOG))
1345 seq_puts(seq, ",notreelog");
1346 if (btrfs_test_opt(info, NOLOGREPLAY))
1347 seq_puts(seq, ",nologreplay");
1348 if (btrfs_test_opt(info, FLUSHONCOMMIT))
1349 seq_puts(seq, ",flushoncommit");
1350 if (btrfs_test_opt(info, DISCARD_SYNC))
1351 seq_puts(seq, ",discard");
1352 if (btrfs_test_opt(info, DISCARD_ASYNC))
1353 seq_puts(seq, ",discard=async");
1354 if (!(info->sb->s_flags & SB_POSIXACL))
1355 seq_puts(seq, ",noacl");
1356 if (btrfs_test_opt(info, SPACE_CACHE))
1357 seq_puts(seq, ",space_cache");
1358 else if (btrfs_test_opt(info, FREE_SPACE_TREE))
1359 seq_puts(seq, ",space_cache=v2");
1361 seq_puts(seq, ",nospace_cache");
1362 if (btrfs_test_opt(info, RESCAN_UUID_TREE))
1363 seq_puts(seq, ",rescan_uuid_tree");
1364 if (btrfs_test_opt(info, CLEAR_CACHE))
1365 seq_puts(seq, ",clear_cache");
1366 if (btrfs_test_opt(info, USER_SUBVOL_RM_ALLOWED))
1367 seq_puts(seq, ",user_subvol_rm_allowed");
1368 if (btrfs_test_opt(info, ENOSPC_DEBUG))
1369 seq_puts(seq, ",enospc_debug");
1370 if (btrfs_test_opt(info, AUTO_DEFRAG))
1371 seq_puts(seq, ",autodefrag");
1372 if (btrfs_test_opt(info, INODE_MAP_CACHE))
1373 seq_puts(seq, ",inode_cache");
1374 if (btrfs_test_opt(info, SKIP_BALANCE))
1375 seq_puts(seq, ",skip_balance");
1376 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
1377 if (btrfs_test_opt(info, CHECK_INTEGRITY_INCLUDING_EXTENT_DATA))
1378 seq_puts(seq, ",check_int_data");
1379 else if (btrfs_test_opt(info, CHECK_INTEGRITY))
1380 seq_puts(seq, ",check_int");
1381 if (info->check_integrity_print_mask)
1382 seq_printf(seq, ",check_int_print_mask=%d",
1383 info->check_integrity_print_mask);
1385 if (info->metadata_ratio)
1386 seq_printf(seq, ",metadata_ratio=%u", info->metadata_ratio);
1387 if (btrfs_test_opt(info, PANIC_ON_FATAL_ERROR))
1388 seq_puts(seq, ",fatal_errors=panic");
1389 if (info->commit_interval != BTRFS_DEFAULT_COMMIT_INTERVAL)
1390 seq_printf(seq, ",commit=%u", info->commit_interval);
1391 #ifdef CONFIG_BTRFS_DEBUG
1392 if (btrfs_test_opt(info, FRAGMENT_DATA))
1393 seq_puts(seq, ",fragment=data");
1394 if (btrfs_test_opt(info, FRAGMENT_METADATA))
1395 seq_puts(seq, ",fragment=metadata");
1397 if (btrfs_test_opt(info, REF_VERIFY))
1398 seq_puts(seq, ",ref_verify");
1399 seq_printf(seq, ",subvolid=%llu",
1400 BTRFS_I(d_inode(dentry))->root->root_key.objectid);
1401 seq_puts(seq, ",subvol=");
1402 seq_dentry(seq, dentry, " \t\n\\");
1406 static int btrfs_test_super(struct super_block *s, void *data)
1408 struct btrfs_fs_info *p = data;
1409 struct btrfs_fs_info *fs_info = btrfs_sb(s);
1411 return fs_info->fs_devices == p->fs_devices;
1414 static int btrfs_set_super(struct super_block *s, void *data)
1416 int err = set_anon_super(s, data);
1418 s->s_fs_info = data;
1423 * subvolumes are identified by ino 256
1425 static inline int is_subvolume_inode(struct inode *inode)
1427 if (inode && inode->i_ino == BTRFS_FIRST_FREE_OBJECTID)
1432 static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,
1433 struct vfsmount *mnt)
1435 struct dentry *root;
1439 if (!subvol_objectid) {
1440 ret = get_default_subvol_objectid(btrfs_sb(mnt->mnt_sb),
1443 root = ERR_PTR(ret);
1447 subvol_name = btrfs_get_subvol_name_from_objectid(
1448 btrfs_sb(mnt->mnt_sb), subvol_objectid);
1449 if (IS_ERR(subvol_name)) {
1450 root = ERR_CAST(subvol_name);
1457 root = mount_subtree(mnt, subvol_name);
1458 /* mount_subtree() drops our reference on the vfsmount. */
1461 if (!IS_ERR(root)) {
1462 struct super_block *s = root->d_sb;
1463 struct btrfs_fs_info *fs_info = btrfs_sb(s);
1464 struct inode *root_inode = d_inode(root);
1465 u64 root_objectid = BTRFS_I(root_inode)->root->root_key.objectid;
1468 if (!is_subvolume_inode(root_inode)) {
1469 btrfs_err(fs_info, "'%s' is not a valid subvolume",
1473 if (subvol_objectid && root_objectid != subvol_objectid) {
1475 * This will also catch a race condition where a
1476 * subvolume which was passed by ID is renamed and
1477 * another subvolume is renamed over the old location.
1480 "subvol '%s' does not match subvolid %llu",
1481 subvol_name, subvol_objectid);
1486 root = ERR_PTR(ret);
1487 deactivate_locked_super(s);
1498 * Find a superblock for the given device / mount point.
1500 * Note: This is based on mount_bdev from fs/super.c with a few additions
1501 * for multiple device setup. Make sure to keep it in sync.
1503 static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
1504 int flags, const char *device_name, void *data)
1506 struct block_device *bdev = NULL;
1507 struct super_block *s;
1508 struct btrfs_device *device = NULL;
1509 struct btrfs_fs_devices *fs_devices = NULL;
1510 struct btrfs_fs_info *fs_info = NULL;
1511 void *new_sec_opts = NULL;
1512 fmode_t mode = FMODE_READ;
1515 if (!(flags & SB_RDONLY))
1516 mode |= FMODE_WRITE;
1519 error = security_sb_eat_lsm_opts(data, &new_sec_opts);
1521 return ERR_PTR(error);
1525 * Setup a dummy root and fs_info for test/set super. This is because
1526 * we don't actually fill this stuff out until open_ctree, but we need
1527 * then open_ctree will properly initialize the file system specific
1528 * settings later. btrfs_init_fs_info initializes the static elements
1529 * of the fs_info (locks and such) to make cleanup easier if we find a
1530 * superblock with our given fs_devices later on at sget() time.
1532 fs_info = kvzalloc(sizeof(struct btrfs_fs_info), GFP_KERNEL);
1535 goto error_sec_opts;
1537 btrfs_init_fs_info(fs_info);
1539 fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL);
1540 fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL);
1541 if (!fs_info->super_copy || !fs_info->super_for_commit) {
1546 mutex_lock(&uuid_mutex);
1547 error = btrfs_parse_device_options(data, mode, fs_type);
1549 mutex_unlock(&uuid_mutex);
1553 device = btrfs_scan_one_device(device_name, mode, fs_type);
1554 if (IS_ERR(device)) {
1555 mutex_unlock(&uuid_mutex);
1556 error = PTR_ERR(device);
1560 fs_devices = device->fs_devices;
1561 fs_info->fs_devices = fs_devices;
1563 error = btrfs_open_devices(fs_devices, mode, fs_type);
1564 mutex_unlock(&uuid_mutex);
1568 if (!(flags & SB_RDONLY) && fs_devices->rw_devices == 0) {
1570 goto error_close_devices;
1573 bdev = fs_devices->latest_bdev;
1574 s = sget(fs_type, btrfs_test_super, btrfs_set_super, flags | SB_NOSEC,
1578 goto error_close_devices;
1582 btrfs_close_devices(fs_devices);
1583 btrfs_free_fs_info(fs_info);
1584 if ((flags ^ s->s_flags) & SB_RDONLY)
1587 snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev);
1588 btrfs_sb(s)->bdev_holder = fs_type;
1589 if (!strstr(crc32c_impl(), "generic"))
1590 set_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags);
1591 error = btrfs_fill_super(s, fs_devices, data);
1594 error = security_sb_set_mnt_opts(s, new_sec_opts, 0, NULL);
1595 security_free_mnt_opts(&new_sec_opts);
1597 deactivate_locked_super(s);
1598 return ERR_PTR(error);
1601 return dget(s->s_root);
1603 error_close_devices:
1604 btrfs_close_devices(fs_devices);
1606 btrfs_free_fs_info(fs_info);
1608 security_free_mnt_opts(&new_sec_opts);
1609 return ERR_PTR(error);
1613 * Mount function which is called by VFS layer.
1615 * In order to allow mounting a subvolume directly, btrfs uses mount_subtree()
1616 * which needs vfsmount* of device's root (/). This means device's root has to
1617 * be mounted internally in any case.
1620 * 1. Parse subvol id related options for later use in mount_subvol().
1622 * 2. Mount device's root (/) by calling vfs_kern_mount().
1624 * NOTE: vfs_kern_mount() is used by VFS to call btrfs_mount() in the
1625 * first place. In order to avoid calling btrfs_mount() again, we use
1626 * different file_system_type which is not registered to VFS by
1627 * register_filesystem() (btrfs_root_fs_type). As a result,
1628 * btrfs_mount_root() is called. The return value will be used by
1629 * mount_subtree() in mount_subvol().
1631 * 3. Call mount_subvol() to get the dentry of subvolume. Since there is
1632 * "btrfs subvolume set-default", mount_subvol() is called always.
1634 static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
1635 const char *device_name, void *data)
1637 struct vfsmount *mnt_root;
1638 struct dentry *root;
1639 char *subvol_name = NULL;
1640 u64 subvol_objectid = 0;
1643 error = btrfs_parse_subvol_options(data, &subvol_name,
1647 return ERR_PTR(error);
1650 /* mount device's root (/) */
1651 mnt_root = vfs_kern_mount(&btrfs_root_fs_type, flags, device_name, data);
1652 if (PTR_ERR_OR_ZERO(mnt_root) == -EBUSY) {
1653 if (flags & SB_RDONLY) {
1654 mnt_root = vfs_kern_mount(&btrfs_root_fs_type,
1655 flags & ~SB_RDONLY, device_name, data);
1657 mnt_root = vfs_kern_mount(&btrfs_root_fs_type,
1658 flags | SB_RDONLY, device_name, data);
1659 if (IS_ERR(mnt_root)) {
1660 root = ERR_CAST(mnt_root);
1665 down_write(&mnt_root->mnt_sb->s_umount);
1666 error = btrfs_remount(mnt_root->mnt_sb, &flags, NULL);
1667 up_write(&mnt_root->mnt_sb->s_umount);
1669 root = ERR_PTR(error);
1676 if (IS_ERR(mnt_root)) {
1677 root = ERR_CAST(mnt_root);
1682 /* mount_subvol() will free subvol_name and mnt_root */
1683 root = mount_subvol(subvol_name, subvol_objectid, mnt_root);
1689 static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info,
1690 u32 new_pool_size, u32 old_pool_size)
1692 if (new_pool_size == old_pool_size)
1695 fs_info->thread_pool_size = new_pool_size;
1697 btrfs_info(fs_info, "resize thread pool %d -> %d",
1698 old_pool_size, new_pool_size);
1700 btrfs_workqueue_set_max(fs_info->workers, new_pool_size);
1701 btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size);
1702 btrfs_workqueue_set_max(fs_info->caching_workers, new_pool_size);
1703 btrfs_workqueue_set_max(fs_info->endio_workers, new_pool_size);
1704 btrfs_workqueue_set_max(fs_info->endio_meta_workers, new_pool_size);
1705 btrfs_workqueue_set_max(fs_info->endio_meta_write_workers,
1707 btrfs_workqueue_set_max(fs_info->endio_write_workers, new_pool_size);
1708 btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size);
1709 btrfs_workqueue_set_max(fs_info->delayed_workers, new_pool_size);
1710 btrfs_workqueue_set_max(fs_info->readahead_workers, new_pool_size);
1711 btrfs_workqueue_set_max(fs_info->scrub_wr_completion_workers,
1715 static inline void btrfs_remount_prepare(struct btrfs_fs_info *fs_info)
1717 set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state);
1720 static inline void btrfs_remount_begin(struct btrfs_fs_info *fs_info,
1721 unsigned long old_opts, int flags)
1723 if (btrfs_raw_test_opt(old_opts, AUTO_DEFRAG) &&
1724 (!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) ||
1725 (flags & SB_RDONLY))) {
1726 /* wait for any defraggers to finish */
1727 wait_event(fs_info->transaction_wait,
1728 (atomic_read(&fs_info->defrag_running) == 0));
1729 if (flags & SB_RDONLY)
1730 sync_filesystem(fs_info->sb);
1734 static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info,
1735 unsigned long old_opts)
1738 * We need to cleanup all defragable inodes if the autodefragment is
1739 * close or the filesystem is read only.
1741 if (btrfs_raw_test_opt(old_opts, AUTO_DEFRAG) &&
1742 (!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) || sb_rdonly(fs_info->sb))) {
1743 btrfs_cleanup_defrag_inodes(fs_info);
1746 /* If we toggled discard async */
1747 if (!btrfs_raw_test_opt(old_opts, DISCARD_ASYNC) &&
1748 btrfs_test_opt(fs_info, DISCARD_ASYNC))
1749 btrfs_discard_resume(fs_info);
1750 else if (btrfs_raw_test_opt(old_opts, DISCARD_ASYNC) &&
1751 !btrfs_test_opt(fs_info, DISCARD_ASYNC))
1752 btrfs_discard_cleanup(fs_info);
1754 clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state);
1757 static int btrfs_remount(struct super_block *sb, int *flags, char *data)
1759 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
1760 struct btrfs_root *root = fs_info->tree_root;
1761 unsigned old_flags = sb->s_flags;
1762 unsigned long old_opts = fs_info->mount_opt;
1763 unsigned long old_compress_type = fs_info->compress_type;
1764 u64 old_max_inline = fs_info->max_inline;
1765 u32 old_thread_pool_size = fs_info->thread_pool_size;
1766 u32 old_metadata_ratio = fs_info->metadata_ratio;
1769 sync_filesystem(sb);
1770 btrfs_remount_prepare(fs_info);
1773 void *new_sec_opts = NULL;
1775 ret = security_sb_eat_lsm_opts(data, &new_sec_opts);
1777 ret = security_sb_remount(sb, new_sec_opts);
1778 security_free_mnt_opts(&new_sec_opts);
1783 ret = btrfs_parse_options(fs_info, data, *flags);
1787 btrfs_remount_begin(fs_info, old_opts, *flags);
1788 btrfs_resize_thread_pool(fs_info,
1789 fs_info->thread_pool_size, old_thread_pool_size);
1791 if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
1794 if (*flags & SB_RDONLY) {
1796 * this also happens on 'umount -rf' or on shutdown, when
1797 * the filesystem is busy.
1799 cancel_work_sync(&fs_info->async_reclaim_work);
1801 btrfs_discard_cleanup(fs_info);
1803 /* wait for the uuid_scan task to finish */
1804 down(&fs_info->uuid_tree_rescan_sem);
1805 /* avoid complains from lockdep et al. */
1806 up(&fs_info->uuid_tree_rescan_sem);
1808 sb->s_flags |= SB_RDONLY;
1811 * Setting SB_RDONLY will put the cleaner thread to
1812 * sleep at the next loop if it's already active.
1813 * If it's already asleep, we'll leave unused block
1814 * groups on disk until we're mounted read-write again
1815 * unless we clean them up here.
1817 btrfs_delete_unused_bgs(fs_info);
1819 btrfs_dev_replace_suspend_for_unmount(fs_info);
1820 btrfs_scrub_cancel(fs_info);
1821 btrfs_pause_balance(fs_info);
1823 ret = btrfs_commit_super(fs_info);
1827 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
1829 "Remounting read-write after error is not allowed");
1833 if (fs_info->fs_devices->rw_devices == 0) {
1838 if (!btrfs_check_rw_degradable(fs_info, NULL)) {
1840 "too many missing devices, writable remount is not allowed");
1845 if (btrfs_super_log_root(fs_info->super_copy) != 0) {
1847 "mount required to replay tree-log, cannot remount read-write");
1852 ret = btrfs_cleanup_fs_roots(fs_info);
1856 /* recover relocation */
1857 mutex_lock(&fs_info->cleaner_mutex);
1858 ret = btrfs_recover_relocation(root);
1859 mutex_unlock(&fs_info->cleaner_mutex);
1863 ret = btrfs_resume_balance_async(fs_info);
1867 ret = btrfs_resume_dev_replace_async(fs_info);
1869 btrfs_warn(fs_info, "failed to resume dev_replace");
1873 btrfs_qgroup_rescan_resume(fs_info);
1875 if (!fs_info->uuid_root) {
1876 btrfs_info(fs_info, "creating UUID tree");
1877 ret = btrfs_create_uuid_tree(fs_info);
1880 "failed to create the UUID tree %d",
1885 sb->s_flags &= ~SB_RDONLY;
1887 set_bit(BTRFS_FS_OPEN, &fs_info->flags);
1890 wake_up_process(fs_info->transaction_kthread);
1891 btrfs_remount_cleanup(fs_info, old_opts);
1895 /* We've hit an error - don't reset SB_RDONLY */
1897 old_flags |= SB_RDONLY;
1898 sb->s_flags = old_flags;
1899 fs_info->mount_opt = old_opts;
1900 fs_info->compress_type = old_compress_type;
1901 fs_info->max_inline = old_max_inline;
1902 btrfs_resize_thread_pool(fs_info,
1903 old_thread_pool_size, fs_info->thread_pool_size);
1904 fs_info->metadata_ratio = old_metadata_ratio;
1905 btrfs_remount_cleanup(fs_info, old_opts);
1909 /* Used to sort the devices by max_avail(descending sort) */
1910 static inline int btrfs_cmp_device_free_bytes(const void *dev_info1,
1911 const void *dev_info2)
1913 if (((struct btrfs_device_info *)dev_info1)->max_avail >
1914 ((struct btrfs_device_info *)dev_info2)->max_avail)
1916 else if (((struct btrfs_device_info *)dev_info1)->max_avail <
1917 ((struct btrfs_device_info *)dev_info2)->max_avail)
1924 * sort the devices by max_avail, in which max free extent size of each device
1925 * is stored.(Descending Sort)
1927 static inline void btrfs_descending_sort_devices(
1928 struct btrfs_device_info *devices,
1931 sort(devices, nr_devices, sizeof(struct btrfs_device_info),
1932 btrfs_cmp_device_free_bytes, NULL);
1936 * The helper to calc the free space on the devices that can be used to store
1939 static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
1942 struct btrfs_device_info *devices_info;
1943 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
1944 struct btrfs_device *device;
1947 u64 min_stripe_size;
1948 int num_stripes = 1;
1949 int i = 0, nr_devices;
1950 const struct btrfs_raid_attr *rattr;
1953 * We aren't under the device list lock, so this is racy-ish, but good
1954 * enough for our purposes.
1956 nr_devices = fs_info->fs_devices->open_devices;
1959 nr_devices = fs_info->fs_devices->open_devices;
1967 devices_info = kmalloc_array(nr_devices, sizeof(*devices_info),
1972 /* calc min stripe number for data space allocation */
1973 type = btrfs_data_alloc_profile(fs_info);
1974 rattr = &btrfs_raid_array[btrfs_bg_flags_to_raid_index(type)];
1976 if (type & BTRFS_BLOCK_GROUP_RAID0)
1977 num_stripes = nr_devices;
1978 else if (type & BTRFS_BLOCK_GROUP_RAID1)
1980 else if (type & BTRFS_BLOCK_GROUP_RAID1C3)
1982 else if (type & BTRFS_BLOCK_GROUP_RAID1C4)
1984 else if (type & BTRFS_BLOCK_GROUP_RAID10)
1987 /* Adjust for more than 1 stripe per device */
1988 min_stripe_size = rattr->dev_stripes * BTRFS_STRIPE_LEN;
1991 list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
1992 if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
1993 &device->dev_state) ||
1995 test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
1998 if (i >= nr_devices)
2001 avail_space = device->total_bytes - device->bytes_used;
2003 /* align with stripe_len */
2004 avail_space = rounddown(avail_space, BTRFS_STRIPE_LEN);
2007 * In order to avoid overwriting the superblock on the drive,
2008 * btrfs starts at an offset of at least 1MB when doing chunk
2011 * This ensures we have at least min_stripe_size free space
2012 * after excluding 1MB.
2014 if (avail_space <= SZ_1M + min_stripe_size)
2017 avail_space -= SZ_1M;
2019 devices_info[i].dev = device;
2020 devices_info[i].max_avail = avail_space;
2028 btrfs_descending_sort_devices(devices_info, nr_devices);
2032 while (nr_devices >= rattr->devs_min) {
2033 num_stripes = min(num_stripes, nr_devices);
2035 if (devices_info[i].max_avail >= min_stripe_size) {
2039 avail_space += devices_info[i].max_avail * num_stripes;
2040 alloc_size = devices_info[i].max_avail;
2041 for (j = i + 1 - num_stripes; j <= i; j++)
2042 devices_info[j].max_avail -= alloc_size;
2048 kfree(devices_info);
2049 *free_bytes = avail_space;
2054 * Calculate numbers for 'df', pessimistic in case of mixed raid profiles.
2056 * If there's a redundant raid level at DATA block groups, use the respective
2057 * multiplier to scale the sizes.
2059 * Unused device space usage is based on simulating the chunk allocator
2060 * algorithm that respects the device sizes and order of allocations. This is
2061 * a close approximation of the actual use but there are other factors that may
2062 * change the result (like a new metadata chunk).
2064 * If metadata is exhausted, f_bavail will be 0.
2066 static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
2068 struct btrfs_fs_info *fs_info = btrfs_sb(dentry->d_sb);
2069 struct btrfs_super_block *disk_super = fs_info->super_copy;
2070 struct btrfs_space_info *found;
2072 u64 total_free_data = 0;
2073 u64 total_free_meta = 0;
2074 int bits = dentry->d_sb->s_blocksize_bits;
2075 __be32 *fsid = (__be32 *)fs_info->fs_devices->fsid;
2076 unsigned factor = 1;
2077 struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
2083 list_for_each_entry_rcu(found, &fs_info->space_info, list) {
2084 if (found->flags & BTRFS_BLOCK_GROUP_DATA) {
2087 total_free_data += found->disk_total - found->disk_used;
2089 btrfs_account_ro_block_groups_free_space(found);
2091 for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
2092 if (!list_empty(&found->block_groups[i]))
2093 factor = btrfs_bg_type_to_factor(
2094 btrfs_raid_array[i].bg_flag);
2099 * Metadata in mixed block goup profiles are accounted in data
2101 if (!mixed && found->flags & BTRFS_BLOCK_GROUP_METADATA) {
2102 if (found->flags & BTRFS_BLOCK_GROUP_DATA)
2105 total_free_meta += found->disk_total -
2109 total_used += found->disk_used;
2114 buf->f_blocks = div_u64(btrfs_super_total_bytes(disk_super), factor);
2115 buf->f_blocks >>= bits;
2116 buf->f_bfree = buf->f_blocks - (div_u64(total_used, factor) >> bits);
2118 /* Account global block reserve as used, it's in logical size already */
2119 spin_lock(&block_rsv->lock);
2120 /* Mixed block groups accounting is not byte-accurate, avoid overflow */
2121 if (buf->f_bfree >= block_rsv->size >> bits)
2122 buf->f_bfree -= block_rsv->size >> bits;
2125 spin_unlock(&block_rsv->lock);
2127 buf->f_bavail = div_u64(total_free_data, factor);
2128 ret = btrfs_calc_avail_data_space(fs_info, &total_free_data);
2131 buf->f_bavail += div_u64(total_free_data, factor);
2132 buf->f_bavail = buf->f_bavail >> bits;
2135 * We calculate the remaining metadata space minus global reserve. If
2136 * this is (supposedly) smaller than zero, there's no space. But this
2137 * does not hold in practice, the exhausted state happens where's still
2138 * some positive delta. So we apply some guesswork and compare the
2139 * delta to a 4M threshold. (Practically observed delta was ~2M.)
2141 * We probably cannot calculate the exact threshold value because this
2142 * depends on the internal reservations requested by various
2143 * operations, so some operations that consume a few metadata will
2144 * succeed even if the Avail is zero. But this is better than the other
2150 * We only want to claim there's no available space if we can no longer
2151 * allocate chunks for our metadata profile and our global reserve will
2152 * not fit in the free metadata space. If we aren't ->full then we
2153 * still can allocate chunks and thus are fine using the currently
2154 * calculated f_bavail.
2156 if (!mixed && block_rsv->space_info->full &&
2157 total_free_meta - thresh < block_rsv->size)
2160 buf->f_type = BTRFS_SUPER_MAGIC;
2161 buf->f_bsize = dentry->d_sb->s_blocksize;
2162 buf->f_namelen = BTRFS_NAME_LEN;
2164 /* We treat it as constant endianness (it doesn't matter _which_)
2165 because we want the fsid to come out the same whether mounted
2166 on a big-endian or little-endian host */
2167 buf->f_fsid.val[0] = be32_to_cpu(fsid[0]) ^ be32_to_cpu(fsid[2]);
2168 buf->f_fsid.val[1] = be32_to_cpu(fsid[1]) ^ be32_to_cpu(fsid[3]);
2169 /* Mask in the root object ID too, to disambiguate subvols */
2170 buf->f_fsid.val[0] ^=
2171 BTRFS_I(d_inode(dentry))->root->root_key.objectid >> 32;
2172 buf->f_fsid.val[1] ^=
2173 BTRFS_I(d_inode(dentry))->root->root_key.objectid;
2178 static void btrfs_kill_super(struct super_block *sb)
2180 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
2181 kill_anon_super(sb);
2182 btrfs_free_fs_info(fs_info);
2185 static struct file_system_type btrfs_fs_type = {
2186 .owner = THIS_MODULE,
2188 .mount = btrfs_mount,
2189 .kill_sb = btrfs_kill_super,
2190 .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA,
2193 static struct file_system_type btrfs_root_fs_type = {
2194 .owner = THIS_MODULE,
2196 .mount = btrfs_mount_root,
2197 .kill_sb = btrfs_kill_super,
2198 .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA,
2201 MODULE_ALIAS_FS("btrfs");
2203 static int btrfs_control_open(struct inode *inode, struct file *file)
2206 * The control file's private_data is used to hold the
2207 * transaction when it is started and is used to keep
2208 * track of whether a transaction is already in progress.
2210 file->private_data = NULL;
2215 * Used by /dev/btrfs-control for devices ioctls.
2217 static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
2220 struct btrfs_ioctl_vol_args *vol;
2221 struct btrfs_device *device = NULL;
2224 if (!capable(CAP_SYS_ADMIN))
2227 vol = memdup_user((void __user *)arg, sizeof(*vol));
2229 return PTR_ERR(vol);
2230 vol->name[BTRFS_PATH_NAME_MAX] = '\0';
2233 case BTRFS_IOC_SCAN_DEV:
2234 mutex_lock(&uuid_mutex);
2235 device = btrfs_scan_one_device(vol->name, FMODE_READ,
2236 &btrfs_root_fs_type);
2237 ret = PTR_ERR_OR_ZERO(device);
2238 mutex_unlock(&uuid_mutex);
2240 case BTRFS_IOC_FORGET_DEV:
2241 ret = btrfs_forget_devices(vol->name);
2243 case BTRFS_IOC_DEVICES_READY:
2244 mutex_lock(&uuid_mutex);
2245 device = btrfs_scan_one_device(vol->name, FMODE_READ,
2246 &btrfs_root_fs_type);
2247 if (IS_ERR(device)) {
2248 mutex_unlock(&uuid_mutex);
2249 ret = PTR_ERR(device);
2252 ret = !(device->fs_devices->num_devices ==
2253 device->fs_devices->total_devices);
2254 mutex_unlock(&uuid_mutex);
2256 case BTRFS_IOC_GET_SUPPORTED_FEATURES:
2257 ret = btrfs_ioctl_get_supported_features((void __user*)arg);
2265 static int btrfs_freeze(struct super_block *sb)
2267 struct btrfs_trans_handle *trans;
2268 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
2269 struct btrfs_root *root = fs_info->tree_root;
2271 set_bit(BTRFS_FS_FROZEN, &fs_info->flags);
2273 * We don't need a barrier here, we'll wait for any transaction that
2274 * could be in progress on other threads (and do delayed iputs that
2275 * we want to avoid on a frozen filesystem), or do the commit
2278 trans = btrfs_attach_transaction_barrier(root);
2279 if (IS_ERR(trans)) {
2280 /* no transaction, don't bother */
2281 if (PTR_ERR(trans) == -ENOENT)
2283 return PTR_ERR(trans);
2285 return btrfs_commit_transaction(trans);
2288 static int btrfs_unfreeze(struct super_block *sb)
2290 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
2292 clear_bit(BTRFS_FS_FROZEN, &fs_info->flags);
2296 static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
2298 struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb);
2299 struct btrfs_fs_devices *cur_devices;
2300 struct btrfs_device *dev, *first_dev = NULL;
2301 struct list_head *head;
2304 * Lightweight locking of the devices. We should not need
2305 * device_list_mutex here as we only read the device data and the list
2306 * is protected by RCU. Even if a device is deleted during the list
2307 * traversals, we'll get valid data, the freeing callback will wait at
2308 * least until the rcu_read_unlock.
2311 cur_devices = fs_info->fs_devices;
2312 while (cur_devices) {
2313 head = &cur_devices->devices;
2314 list_for_each_entry_rcu(dev, head, dev_list) {
2315 if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state))
2319 if (!first_dev || dev->devid < first_dev->devid)
2322 cur_devices = cur_devices->seed;
2326 seq_escape(m, rcu_str_deref(first_dev->name), " \t\n\\");
2333 static const struct super_operations btrfs_super_ops = {
2334 .drop_inode = btrfs_drop_inode,
2335 .evict_inode = btrfs_evict_inode,
2336 .put_super = btrfs_put_super,
2337 .sync_fs = btrfs_sync_fs,
2338 .show_options = btrfs_show_options,
2339 .show_devname = btrfs_show_devname,
2340 .alloc_inode = btrfs_alloc_inode,
2341 .destroy_inode = btrfs_destroy_inode,
2342 .free_inode = btrfs_free_inode,
2343 .statfs = btrfs_statfs,
2344 .remount_fs = btrfs_remount,
2345 .freeze_fs = btrfs_freeze,
2346 .unfreeze_fs = btrfs_unfreeze,
2349 static const struct file_operations btrfs_ctl_fops = {
2350 .open = btrfs_control_open,
2351 .unlocked_ioctl = btrfs_control_ioctl,
2352 .compat_ioctl = compat_ptr_ioctl,
2353 .owner = THIS_MODULE,
2354 .llseek = noop_llseek,
2357 static struct miscdevice btrfs_misc = {
2358 .minor = BTRFS_MINOR,
2359 .name = "btrfs-control",
2360 .fops = &btrfs_ctl_fops
2363 MODULE_ALIAS_MISCDEV(BTRFS_MINOR);
2364 MODULE_ALIAS("devname:btrfs-control");
2366 static int __init btrfs_interface_init(void)
2368 return misc_register(&btrfs_misc);
2371 static __cold void btrfs_interface_exit(void)
2373 misc_deregister(&btrfs_misc);
2376 static void __init btrfs_print_mod_info(void)
2378 static const char options[] = ""
2379 #ifdef CONFIG_BTRFS_DEBUG
2382 #ifdef CONFIG_BTRFS_ASSERT
2385 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
2386 ", integrity-checker=on"
2388 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
2392 pr_info("Btrfs loaded, crc32c=%s%s\n", crc32c_impl(), options);
2395 static int __init init_btrfs_fs(void)
2401 err = btrfs_init_sysfs();
2405 btrfs_init_compress();
2407 err = btrfs_init_cachep();
2411 err = extent_io_init();
2415 err = extent_state_cache_init();
2417 goto free_extent_io;
2419 err = extent_map_init();
2421 goto free_extent_state_cache;
2423 err = ordered_data_init();
2425 goto free_extent_map;
2427 err = btrfs_delayed_inode_init();
2429 goto free_ordered_data;
2431 err = btrfs_auto_defrag_init();
2433 goto free_delayed_inode;
2435 err = btrfs_delayed_ref_init();
2437 goto free_auto_defrag;
2439 err = btrfs_prelim_ref_init();
2441 goto free_delayed_ref;
2443 err = btrfs_end_io_wq_init();
2445 goto free_prelim_ref;
2447 err = btrfs_interface_init();
2449 goto free_end_io_wq;
2451 btrfs_init_lockdep();
2453 btrfs_print_mod_info();
2455 err = btrfs_run_sanity_tests();
2457 goto unregister_ioctl;
2459 err = register_filesystem(&btrfs_fs_type);
2461 goto unregister_ioctl;
2466 btrfs_interface_exit();
2468 btrfs_end_io_wq_exit();
2470 btrfs_prelim_ref_exit();
2472 btrfs_delayed_ref_exit();
2474 btrfs_auto_defrag_exit();
2476 btrfs_delayed_inode_exit();
2478 ordered_data_exit();
2481 free_extent_state_cache:
2482 extent_state_cache_exit();
2486 btrfs_destroy_cachep();
2488 btrfs_exit_compress();
2494 static void __exit exit_btrfs_fs(void)
2496 btrfs_destroy_cachep();
2497 btrfs_delayed_ref_exit();
2498 btrfs_auto_defrag_exit();
2499 btrfs_delayed_inode_exit();
2500 btrfs_prelim_ref_exit();
2501 ordered_data_exit();
2503 extent_state_cache_exit();
2505 btrfs_interface_exit();
2506 btrfs_end_io_wq_exit();
2507 unregister_filesystem(&btrfs_fs_type);
2509 btrfs_cleanup_fs_uuids();
2510 btrfs_exit_compress();
2513 late_initcall(init_btrfs_fs);
2514 module_exit(exit_btrfs_fs)
2516 MODULE_LICENSE("GPL");
2517 MODULE_SOFTDEP("pre: crc32c");
2518 MODULE_SOFTDEP("pre: xxhash64");
2519 MODULE_SOFTDEP("pre: sha256");
2520 MODULE_SOFTDEP("pre: blake2b-256");