• Home
  • Raw
  • Download

Lines Matching +full:rcu +full:- +full:big +full:- +full:endian +full:- +full:mask

1 // SPDX-License-Identifier: GPL-2.0
15 #include <linux/backing-dev.h>
30 #include "delayed-inode.h"
32 #include "disk-io.h"
35 #include "print-tree.h"
41 #include "rcu-string.h"
42 #include "dev-replace.h"
43 #include "free-space-cache.h"
45 #include "space-info.h"
48 #include "tests/btrfs-tests.h"
49 #include "block-group.h"
56 #include "dir-item.h"
61 #include "extent-tree.h"
84 btrfs_info(fs_info, "last unmount of filesystem %pU", fs_info->fs_devices->fsid); in btrfs_put_super()
155 {Opt_compress_force, "compress-force"},
156 {Opt_compress_force_type, "compress-force=%s"},
236 if (fs_info->mount_opt & opt) { in check_ro_option()
254 return -ENOMEM; in parse_rescue_options()
267 btrfs_set_opt(info->mount_opt, USEBACKUPROOT); in parse_rescue_options()
292 ret = -EINVAL; in parse_rescue_options()
322 const bool remounting = test_bit(BTRFS_FS_STATE_REMOUNTING, &info->fs_state); in btrfs_parse_options()
325 btrfs_set_opt(info->mount_opt, FREE_SPACE_TREE); in btrfs_parse_options()
330 btrfs_set_super_cache_generation(info->super_copy, 0); in btrfs_parse_options()
332 btrfs_set_opt(info->mount_opt, SPACE_CACHE); in btrfs_parse_options()
352 btrfs_set_opt(info->mount_opt, DEGRADED); in btrfs_parse_options()
375 btrfs_clear_opt(info->mount_opt, NODATACOW); in btrfs_parse_options()
376 btrfs_clear_opt(info->mount_opt, NODATASUM); in btrfs_parse_options()
388 btrfs_clear_opt(info->mount_opt, COMPRESS); in btrfs_parse_options()
389 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); in btrfs_parse_options()
390 btrfs_set_opt(info->mount_opt, NODATACOW); in btrfs_parse_options()
391 btrfs_set_opt(info->mount_opt, NODATASUM); in btrfs_parse_options()
405 info->compress_type : BTRFS_COMPRESS_NONE; in btrfs_parse_options()
408 saved_compress_level = info->compress_level; in btrfs_parse_options()
414 info->compress_type = BTRFS_COMPRESS_ZLIB; in btrfs_parse_options()
415 info->compress_level = BTRFS_ZLIB_DEFAULT_LEVEL; in btrfs_parse_options()
423 info->compress_level = in btrfs_parse_options()
427 btrfs_set_opt(info->mount_opt, COMPRESS); in btrfs_parse_options()
428 btrfs_clear_opt(info->mount_opt, NODATACOW); in btrfs_parse_options()
429 btrfs_clear_opt(info->mount_opt, NODATASUM); in btrfs_parse_options()
433 info->compress_type = BTRFS_COMPRESS_LZO; in btrfs_parse_options()
434 info->compress_level = 0; in btrfs_parse_options()
435 btrfs_set_opt(info->mount_opt, COMPRESS); in btrfs_parse_options()
436 btrfs_clear_opt(info->mount_opt, NODATACOW); in btrfs_parse_options()
437 btrfs_clear_opt(info->mount_opt, NODATASUM); in btrfs_parse_options()
442 info->compress_type = BTRFS_COMPRESS_ZSTD; in btrfs_parse_options()
443 info->compress_level = in btrfs_parse_options()
447 btrfs_set_opt(info->mount_opt, COMPRESS); in btrfs_parse_options()
448 btrfs_clear_opt(info->mount_opt, NODATACOW); in btrfs_parse_options()
449 btrfs_clear_opt(info->mount_opt, NODATASUM); in btrfs_parse_options()
454 info->compress_level = 0; in btrfs_parse_options()
455 info->compress_type = 0; in btrfs_parse_options()
456 btrfs_clear_opt(info->mount_opt, COMPRESS); in btrfs_parse_options()
457 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); in btrfs_parse_options()
463 ret = -EINVAL; in btrfs_parse_options()
468 btrfs_set_opt(info->mount_opt, FORCE_COMPRESS); in btrfs_parse_options()
471 * If we remount from compress-force=xxx to in btrfs_parse_options()
476 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); in btrfs_parse_options()
480 } else if ((info->compress_type != saved_compress_type) || in btrfs_parse_options()
482 (info->compress_level != saved_compress_level)) { in btrfs_parse_options()
485 compress_type, info->compress_level); in btrfs_parse_options()
492 btrfs_clear_opt(info->mount_opt, NOSSD); in btrfs_parse_options()
499 btrfs_clear_opt(info->mount_opt, NOSSD); in btrfs_parse_options()
502 btrfs_set_opt(info->mount_opt, NOSSD); in btrfs_parse_options()
526 ret = -EINVAL; in btrfs_parse_options()
529 info->thread_pool_size = intarg; in btrfs_parse_options()
534 info->max_inline = memparse(num, NULL); in btrfs_parse_options()
537 if (info->max_inline) { in btrfs_parse_options()
538 info->max_inline = min_t(u64, in btrfs_parse_options()
539 info->max_inline, in btrfs_parse_options()
540 info->sectorsize); in btrfs_parse_options()
543 info->max_inline); in btrfs_parse_options()
545 ret = -ENOMEM; in btrfs_parse_options()
551 info->sb->s_flags |= SB_POSIXACL; in btrfs_parse_options()
555 ret = -EINVAL; in btrfs_parse_options()
559 info->sb->s_flags &= ~SB_POSIXACL; in btrfs_parse_options()
578 "turning on flush-on-commit"); in btrfs_parse_options()
582 "turning off flush-on-commit"); in btrfs_parse_options()
591 info->metadata_ratio = intarg; in btrfs_parse_options()
593 info->metadata_ratio); in btrfs_parse_options()
599 btrfs_clear_opt(info->mount_opt, DISCARD_ASYNC); in btrfs_parse_options()
603 btrfs_clear_opt(info->mount_opt, DISCARD_SYNC); in btrfs_parse_options()
609 ret = -EINVAL; in btrfs_parse_options()
612 btrfs_clear_opt(info->mount_opt, NODISCARD); in btrfs_parse_options()
619 btrfs_set_opt(info->mount_opt, NODISCARD); in btrfs_parse_options()
633 btrfs_clear_opt(info->mount_opt, in btrfs_parse_options()
638 btrfs_clear_opt(info->mount_opt, in btrfs_parse_options()
645 ret = -EINVAL; in btrfs_parse_options()
650 btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE); in btrfs_parse_options()
684 btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED); in btrfs_parse_options()
687 btrfs_set_opt(info->mount_opt, ENOSPC_DEBUG); in btrfs_parse_options()
690 btrfs_clear_opt(info->mount_opt, ENOSPC_DEBUG); in btrfs_parse_options()
708 btrfs_set_opt(info->mount_opt, USEBACKUPROOT); in btrfs_parse_options()
711 btrfs_set_opt(info->mount_opt, SKIP_BALANCE); in btrfs_parse_options()
719 btrfs_set_opt(info->mount_opt, CHECK_INTEGRITY_DATA); in btrfs_parse_options()
720 btrfs_set_opt(info->mount_opt, CHECK_INTEGRITY); in btrfs_parse_options()
726 btrfs_set_opt(info->mount_opt, CHECK_INTEGRITY); in btrfs_parse_options()
736 info->check_integrity_print_mask = intarg; in btrfs_parse_options()
740 info->check_integrity_print_mask); in btrfs_parse_options()
748 ret = -EINVAL; in btrfs_parse_options()
753 btrfs_set_opt(info->mount_opt, in btrfs_parse_options()
756 btrfs_clear_opt(info->mount_opt, in btrfs_parse_options()
761 ret = -EINVAL; in btrfs_parse_options()
771 ret = -EINVAL; in btrfs_parse_options()
783 info->commit_interval = intarg; in btrfs_parse_options()
796 btrfs_set_opt(info->mount_opt, FRAGMENT_DATA); in btrfs_parse_options()
797 btrfs_set_opt(info->mount_opt, FRAGMENT_METADATA); in btrfs_parse_options()
801 btrfs_set_opt(info->mount_opt, in btrfs_parse_options()
806 btrfs_set_opt(info->mount_opt, FRAGMENT_DATA); in btrfs_parse_options()
812 btrfs_set_opt(info->mount_opt, REF_VERIFY); in btrfs_parse_options()
817 ret = -EINVAL; in btrfs_parse_options()
824 /* We're read-only, don't have to check. */ in btrfs_parse_options()
831 ret = -EINVAL; in btrfs_parse_options()
837 ret = -EINVAL; in btrfs_parse_options()
841 btrfs_err(info, "cannot disable free space tree with block-group-tree feature"); in btrfs_parse_options()
842 ret = -EINVAL; in btrfs_parse_options()
879 return -ENOMEM; in btrfs_parse_device_options()
892 error = -ENOMEM; in btrfs_parse_device_options()
931 return -ENOMEM; in btrfs_parse_subvol_options()
945 error = -ENOMEM; in btrfs_parse_subvol_options()
973 struct btrfs_root *root = fs_info->tree_root; in btrfs_get_subvol_name_from_objectid()
986 ret = -ENOMEM; in btrfs_get_subvol_name_from_objectid()
992 ret = -ENOMEM; in btrfs_get_subvol_name_from_objectid()
995 ptr = name + PATH_MAX - 1; in btrfs_get_subvol_name_from_objectid()
1000 * backrefs until we hit the top-level subvolume. in btrfs_get_subvol_name_from_objectid()
1005 key.offset = (u64)-1; in btrfs_get_subvol_name_from_objectid()
1011 ret = -ENOENT; in btrfs_get_subvol_name_from_objectid()
1017 root_ref = btrfs_item_ptr(path->nodes[0], path->slots[0], in btrfs_get_subvol_name_from_objectid()
1019 len = btrfs_root_ref_name_len(path->nodes[0], root_ref); in btrfs_get_subvol_name_from_objectid()
1020 ptr -= len + 1; in btrfs_get_subvol_name_from_objectid()
1022 ret = -ENAMETOOLONG; in btrfs_get_subvol_name_from_objectid()
1025 read_extent_buffer(path->nodes[0], ptr + 1, in btrfs_get_subvol_name_from_objectid()
1028 dirid = btrfs_root_ref_dirid(path->nodes[0], root_ref); in btrfs_get_subvol_name_from_objectid()
1045 key.offset = (u64)-1; in btrfs_get_subvol_name_from_objectid()
1051 ret = -ENOENT; in btrfs_get_subvol_name_from_objectid()
1057 inode_ref = btrfs_item_ptr(path->nodes[0], in btrfs_get_subvol_name_from_objectid()
1058 path->slots[0], in btrfs_get_subvol_name_from_objectid()
1060 len = btrfs_inode_ref_name_len(path->nodes[0], in btrfs_get_subvol_name_from_objectid()
1062 ptr -= len + 1; in btrfs_get_subvol_name_from_objectid()
1064 ret = -ENAMETOOLONG; in btrfs_get_subvol_name_from_objectid()
1067 read_extent_buffer(path->nodes[0], ptr + 1, in btrfs_get_subvol_name_from_objectid()
1077 if (ptr == name + PATH_MAX - 1) { in btrfs_get_subvol_name_from_objectid()
1081 memmove(name, ptr, name + PATH_MAX - ptr); in btrfs_get_subvol_name_from_objectid()
1094 struct btrfs_root *root = fs_info->tree_root; in get_default_subvol_objectid()
1103 return -ENOMEM; in get_default_subvol_objectid()
1110 dir_id = btrfs_super_root_dir(fs_info->super_copy); in get_default_subvol_objectid()
1120 * mount the top-level subvolume. in get_default_subvol_objectid()
1127 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location); in get_default_subvol_objectid()
1141 sb->s_maxbytes = MAX_LFS_FILESIZE; in btrfs_fill_super()
1142 sb->s_magic = BTRFS_SUPER_MAGIC; in btrfs_fill_super()
1143 sb->s_op = &btrfs_super_ops; in btrfs_fill_super()
1144 sb->s_d_op = &btrfs_dentry_operations; in btrfs_fill_super()
1145 sb->s_export_op = &btrfs_export_ops; in btrfs_fill_super()
1147 sb->s_vop = &btrfs_verityops; in btrfs_fill_super()
1149 sb->s_xattr = btrfs_xattr_handlers; in btrfs_fill_super()
1150 sb->s_time_gran = 1; in btrfs_fill_super()
1152 sb->s_flags |= SB_POSIXACL; in btrfs_fill_super()
1154 sb->s_flags |= SB_I_VERSION; in btrfs_fill_super()
1155 sb->s_iflags |= SB_I_CGROUPWB; in btrfs_fill_super()
1169 inode = btrfs_iget(sb, BTRFS_FIRST_FREE_OBJECTID, fs_info->fs_root); in btrfs_fill_super()
1176 sb->s_root = d_make_root(inode); in btrfs_fill_super()
1177 if (!sb->s_root) { in btrfs_fill_super()
1178 err = -ENOMEM; in btrfs_fill_super()
1182 sb->s_flags |= SB_ACTIVE; in btrfs_fill_super()
1194 struct btrfs_root *root = fs_info->tree_root; in btrfs_sync_fs()
1199 filemap_flush(fs_info->btree_inode->i_mapping); in btrfs_sync_fs()
1203 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_sync_fs()
1208 if (PTR_ERR(trans) == -ENOENT) { in btrfs_sync_fs()
1214 &fs_info->flags)) in btrfs_sync_fs()
1217 * A non-blocking test if the fs is frozen. We must not in btrfs_sync_fs()
1242 struct btrfs_fs_info *info = btrfs_sb(dentry->d_sb); in btrfs_show_options()
1255 if (info->max_inline != BTRFS_DEFAULT_MAX_INLINE) in btrfs_show_options()
1256 seq_printf(seq, ",max_inline=%llu", info->max_inline); in btrfs_show_options()
1257 if (info->thread_pool_size != min_t(unsigned long, in btrfs_show_options()
1259 seq_printf(seq, ",thread_pool=%u", info->thread_pool_size); in btrfs_show_options()
1261 compress_type = btrfs_compress_type2str(info->compress_type); in btrfs_show_options()
1263 seq_printf(seq, ",compress-force=%s", compress_type); in btrfs_show_options()
1266 if (info->compress_level) in btrfs_show_options()
1267 seq_printf(seq, ":%d", info->compress_level); in btrfs_show_options()
1291 if (!(info->sb->s_flags & SB_POSIXACL)) in btrfs_show_options()
1316 if (info->check_integrity_print_mask) in btrfs_show_options()
1318 info->check_integrity_print_mask); in btrfs_show_options()
1320 if (info->metadata_ratio) in btrfs_show_options()
1321 seq_printf(seq, ",metadata_ratio=%u", info->metadata_ratio); in btrfs_show_options()
1324 if (info->commit_interval != BTRFS_DEFAULT_COMMIT_INTERVAL) in btrfs_show_options()
1325 seq_printf(seq, ",commit=%u", info->commit_interval); in btrfs_show_options()
1335 BTRFS_I(d_inode(dentry))->root->root_key.objectid); in btrfs_show_options()
1337 BTRFS_I(d_inode(dentry))->root->root_key.objectid); in btrfs_show_options()
1351 return fs_info->fs_devices == p->fs_devices; in btrfs_test_super()
1358 s->s_fs_info = data; in btrfs_set_super()
1367 if (inode && inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) in is_subvolume_inode()
1380 ret = get_default_subvol_objectid(btrfs_sb(mnt->mnt_sb), in mount_subvol()
1388 btrfs_sb(mnt->mnt_sb), subvol_objectid); in mount_subvol()
1402 struct super_block *s = root->d_sb; in mount_subvol()
1405 u64 root_objectid = BTRFS_I(root_inode)->root->root_key.objectid; in mount_subvol()
1411 ret = -EINVAL; in mount_subvol()
1422 ret = -EINVAL; in mount_subvol()
1471 error = -ENOMEM; in btrfs_mount_root()
1476 fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL); in btrfs_mount_root()
1477 fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL); in btrfs_mount_root()
1478 if (!fs_info->super_copy || !fs_info->super_for_commit) { in btrfs_mount_root()
1479 error = -ENOMEM; in btrfs_mount_root()
1497 fs_devices = device->fs_devices; in btrfs_mount_root()
1498 fs_info->fs_devices = fs_devices; in btrfs_mount_root()
1505 if (!(flags & SB_RDONLY) && fs_devices->rw_devices == 0) { in btrfs_mount_root()
1506 error = -EACCES; in btrfs_mount_root()
1510 bdev = fs_devices->latest_dev->bdev; in btrfs_mount_root()
1518 if (s->s_root) { in btrfs_mount_root()
1521 if ((flags ^ s->s_flags) & SB_RDONLY) in btrfs_mount_root()
1522 error = -EBUSY; in btrfs_mount_root()
1524 snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev); in btrfs_mount_root()
1525 shrinker_debugfs_rename(&s->s_shrink, "sb-%s:%s", fs_type->name, in btrfs_mount_root()
1526 s->s_id); in btrfs_mount_root()
1527 btrfs_sb(s)->bdev_holder = fs_type; in btrfs_mount_root()
1538 return dget(s->s_root); in btrfs_mount_root()
1569 * "btrfs subvolume set-default", mount_subvol() is called always.
1589 if (PTR_ERR_OR_ZERO(mnt_root) == -EBUSY) { in btrfs_mount()
1602 down_write(&mnt_root->mnt_sb->s_umount); in btrfs_mount()
1603 error = btrfs_remount(mnt_root->mnt_sb, &flags, NULL); in btrfs_mount()
1604 up_write(&mnt_root->mnt_sb->s_umount); in btrfs_mount()
1632 fs_info->thread_pool_size = new_pool_size; in btrfs_resize_thread_pool()
1634 btrfs_info(fs_info, "resize thread pool %d -> %d", in btrfs_resize_thread_pool()
1637 btrfs_workqueue_set_max(fs_info->workers, new_pool_size); in btrfs_resize_thread_pool()
1638 btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size); in btrfs_resize_thread_pool()
1639 btrfs_workqueue_set_max(fs_info->caching_workers, new_pool_size); in btrfs_resize_thread_pool()
1640 workqueue_set_max_active(fs_info->endio_workers, new_pool_size); in btrfs_resize_thread_pool()
1641 workqueue_set_max_active(fs_info->endio_meta_workers, new_pool_size); in btrfs_resize_thread_pool()
1642 btrfs_workqueue_set_max(fs_info->endio_write_workers, new_pool_size); in btrfs_resize_thread_pool()
1643 btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size); in btrfs_resize_thread_pool()
1644 btrfs_workqueue_set_max(fs_info->delayed_workers, new_pool_size); in btrfs_resize_thread_pool()
1651 (!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) || in btrfs_remount_begin()
1654 wait_event(fs_info->transaction_wait, in btrfs_remount_begin()
1655 (atomic_read(&fs_info->defrag_running) == 0)); in btrfs_remount_begin()
1657 sync_filesystem(fs_info->sb); in btrfs_remount_begin()
1671 (!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) || sb_rdonly(fs_info->sb))) { in btrfs_remount_cleanup()
1691 unsigned old_flags = sb->s_flags; in btrfs_remount()
1692 unsigned long old_opts = fs_info->mount_opt; in btrfs_remount()
1693 unsigned long old_compress_type = fs_info->compress_type; in btrfs_remount()
1694 u64 old_max_inline = fs_info->max_inline; in btrfs_remount()
1695 u32 old_thread_pool_size = fs_info->thread_pool_size; in btrfs_remount()
1696 u32 old_metadata_ratio = fs_info->metadata_ratio; in btrfs_remount()
1700 set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); in btrfs_remount()
1723 fs_info->thread_pool_size, old_thread_pool_size); in btrfs_remount()
1732 btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE); in btrfs_remount()
1733 btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE); in btrfs_remount()
1736 btrfs_clear_opt(fs_info->mount_opt, FREE_SPACE_TREE); in btrfs_remount()
1737 btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE); in btrfs_remount()
1746 * this also happens on 'umount -rf' or on shutdown, when in btrfs_remount()
1749 cancel_work_sync(&fs_info->async_reclaim_work); in btrfs_remount()
1750 cancel_work_sync(&fs_info->async_data_reclaim_work); in btrfs_remount()
1755 down(&fs_info->uuid_tree_rescan_sem); in btrfs_remount()
1757 up(&fs_info->uuid_tree_rescan_sem); in btrfs_remount()
1765 * groups on disk until we're mounted read-write again in btrfs_remount()
1775 * a transaction - either because it was dropping a dead root, in btrfs_remount()
1781 wait_on_bit(&fs_info->flags, BTRFS_FS_CLEANER_RUNNING, in btrfs_remount()
1789 * finishing close_ctree() with a non-empty list of delayed in btrfs_remount()
1812 "Remounting read-write after error is not allowed"); in btrfs_remount()
1813 ret = -EINVAL; in btrfs_remount()
1816 if (fs_info->fs_devices->rw_devices == 0) { in btrfs_remount()
1817 ret = -EACCES; in btrfs_remount()
1824 ret = -EACCES; in btrfs_remount()
1828 if (btrfs_super_log_root(fs_info->super_copy) != 0) { in btrfs_remount()
1830 "mount required to replay tree-log, cannot remount read-write"); in btrfs_remount()
1831 ret = -EINVAL; in btrfs_remount()
1846 set_bit(BTRFS_FS_OPEN, &fs_info->flags); in btrfs_remount()
1849 * If we've gone from readonly -> read/write, we need to get in btrfs_remount()
1861 wake_up_process(fs_info->transaction_kthread); in btrfs_remount()
1864 clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); in btrfs_remount()
1869 /* We've hit an error - don't reset SB_RDONLY */ in btrfs_remount()
1873 clear_bit(BTRFS_FS_STATE_RO, &fs_info->fs_state); in btrfs_remount()
1874 sb->s_flags = old_flags; in btrfs_remount()
1875 fs_info->mount_opt = old_opts; in btrfs_remount()
1876 fs_info->compress_type = old_compress_type; in btrfs_remount()
1877 fs_info->max_inline = old_max_inline; in btrfs_remount()
1879 old_thread_pool_size, fs_info->thread_pool_size); in btrfs_remount()
1880 fs_info->metadata_ratio = old_metadata_ratio; in btrfs_remount()
1882 clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); in btrfs_remount()
1893 if (dev_info1->max_avail > dev_info2->max_avail) in btrfs_cmp_device_free_bytes()
1894 return -1; in btrfs_cmp_device_free_bytes()
1895 else if (dev_info1->max_avail < dev_info2->max_avail) in btrfs_cmp_device_free_bytes()
1920 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; in btrfs_calc_avail_data_space()
1930 * We aren't under the device list lock, so this is racy-ish, but good in btrfs_calc_avail_data_space()
1933 nr_devices = fs_info->fs_devices->open_devices; in btrfs_calc_avail_data_space()
1936 nr_devices = fs_info->fs_devices->open_devices; in btrfs_calc_avail_data_space()
1947 return -ENOMEM; in btrfs_calc_avail_data_space()
1956 num_stripes = rattr->ncopies; in btrfs_calc_avail_data_space()
1961 min_stripe_size = rattr->dev_stripes * BTRFS_STRIPE_LEN; in btrfs_calc_avail_data_space()
1964 list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) { in btrfs_calc_avail_data_space()
1966 &device->dev_state) || in btrfs_calc_avail_data_space()
1967 !device->bdev || in btrfs_calc_avail_data_space()
1968 test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) in btrfs_calc_avail_data_space()
1974 avail_space = device->total_bytes - device->bytes_used; in btrfs_calc_avail_data_space()
1986 avail_space -= BTRFS_DEVICE_RANGE_RESERVED; in btrfs_calc_avail_data_space()
1999 i = nr_devices - 1; in btrfs_calc_avail_data_space()
2001 while (nr_devices >= rattr->devs_min) { in btrfs_calc_avail_data_space()
2010 for (j = i + 1 - num_stripes; j <= i; j++) in btrfs_calc_avail_data_space()
2011 devices_info[j].max_avail -= alloc_size; in btrfs_calc_avail_data_space()
2013 i--; in btrfs_calc_avail_data_space()
2014 nr_devices--; in btrfs_calc_avail_data_space()
2037 struct btrfs_fs_info *fs_info = btrfs_sb(dentry->d_sb); in btrfs_statfs()
2038 struct btrfs_super_block *disk_super = fs_info->super_copy; in btrfs_statfs()
2043 u32 bits = fs_info->sectorsize_bits; in btrfs_statfs()
2044 __be32 *fsid = (__be32 *)fs_info->fs_devices->fsid; in btrfs_statfs()
2046 struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv; in btrfs_statfs()
2051 list_for_each_entry(found, &fs_info->space_info, list) { in btrfs_statfs()
2052 if (found->flags & BTRFS_BLOCK_GROUP_DATA) { in btrfs_statfs()
2055 total_free_data += found->disk_total - found->disk_used; in btrfs_statfs()
2056 total_free_data -= in btrfs_statfs()
2060 if (!list_empty(&found->block_groups[i])) in btrfs_statfs()
2069 if (!mixed && found->flags & BTRFS_BLOCK_GROUP_METADATA) { in btrfs_statfs()
2070 if (found->flags & BTRFS_BLOCK_GROUP_DATA) in btrfs_statfs()
2073 total_free_meta += found->disk_total - in btrfs_statfs()
2074 found->disk_used; in btrfs_statfs()
2077 total_used += found->disk_used; in btrfs_statfs()
2080 buf->f_blocks = div_u64(btrfs_super_total_bytes(disk_super), factor); in btrfs_statfs()
2081 buf->f_blocks >>= bits; in btrfs_statfs()
2082 buf->f_bfree = buf->f_blocks - (div_u64(total_used, factor) >> bits); in btrfs_statfs()
2085 spin_lock(&block_rsv->lock); in btrfs_statfs()
2086 /* Mixed block groups accounting is not byte-accurate, avoid overflow */ in btrfs_statfs()
2087 if (buf->f_bfree >= block_rsv->size >> bits) in btrfs_statfs()
2088 buf->f_bfree -= block_rsv->size >> bits; in btrfs_statfs()
2090 buf->f_bfree = 0; in btrfs_statfs()
2091 spin_unlock(&block_rsv->lock); in btrfs_statfs()
2093 buf->f_bavail = div_u64(total_free_data, factor); in btrfs_statfs()
2097 buf->f_bavail += div_u64(total_free_data, factor); in btrfs_statfs()
2098 buf->f_bavail = buf->f_bavail >> bits; in btrfs_statfs()
2118 * not fit in the free metadata space. If we aren't ->full then we in btrfs_statfs()
2122 if (!mixed && block_rsv->space_info->full && in btrfs_statfs()
2123 (total_free_meta < thresh || total_free_meta - thresh < block_rsv->size)) in btrfs_statfs()
2124 buf->f_bavail = 0; in btrfs_statfs()
2126 buf->f_type = BTRFS_SUPER_MAGIC; in btrfs_statfs()
2127 buf->f_bsize = dentry->d_sb->s_blocksize; in btrfs_statfs()
2128 buf->f_namelen = BTRFS_NAME_LEN; in btrfs_statfs()
2132 on a big-endian or little-endian host */ in btrfs_statfs()
2133 buf->f_fsid.val[0] = be32_to_cpu(fsid[0]) ^ be32_to_cpu(fsid[2]); in btrfs_statfs()
2134 buf->f_fsid.val[1] = be32_to_cpu(fsid[1]) ^ be32_to_cpu(fsid[3]); in btrfs_statfs()
2135 /* Mask in the root object ID too, to disambiguate subvols */ in btrfs_statfs()
2136 buf->f_fsid.val[0] ^= in btrfs_statfs()
2137 BTRFS_I(d_inode(dentry))->root->root_key.objectid >> 32; in btrfs_statfs()
2138 buf->f_fsid.val[1] ^= in btrfs_statfs()
2139 BTRFS_I(d_inode(dentry))->root->root_key.objectid; in btrfs_statfs()
2176 file->private_data = NULL; in btrfs_control_open()
2181 * Used by /dev/btrfs-control for devices ioctls.
2189 int ret = -ENOTTY; in btrfs_control_ioctl()
2192 return -EPERM; in btrfs_control_ioctl()
2197 vol->name[BTRFS_PATH_NAME_MAX] = '\0'; in btrfs_control_ioctl()
2202 device = btrfs_scan_one_device(vol->name, BLK_OPEN_READ); in btrfs_control_ioctl()
2207 if (vol->name[0] != 0) { in btrfs_control_ioctl()
2208 ret = lookup_bdev(vol->name, &devt); in btrfs_control_ioctl()
2216 device = btrfs_scan_one_device(vol->name, BLK_OPEN_READ); in btrfs_control_ioctl()
2222 ret = !(device->fs_devices->num_devices == in btrfs_control_ioctl()
2223 device->fs_devices->total_devices); in btrfs_control_ioctl()
2239 struct btrfs_root *root = fs_info->tree_root; in btrfs_freeze()
2241 set_bit(BTRFS_FS_FROZEN, &fs_info->flags); in btrfs_freeze()
2251 if (PTR_ERR(trans) == -ENOENT) in btrfs_freeze()
2260 struct btrfs_fs_info *fs_info = dev->fs_info; in check_dev_super()
2266 ASSERT(test_bit(BTRFS_FS_FROZEN, &fs_info->flags)); in check_dev_super()
2269 if (!dev->bdev) in check_dev_super()
2273 sb = btrfs_read_dev_one_super(dev->bdev, 0, true); in check_dev_super()
2279 if (csum_type != btrfs_super_csum_type(fs_info->super_copy)) { in check_dev_super()
2281 csum_type, btrfs_super_csum_type(fs_info->super_copy)); in check_dev_super()
2282 ret = -EUCLEAN; in check_dev_super()
2287 btrfs_err(fs_info, "csum for on-disk super block no longer matches"); in check_dev_super()
2288 ret = -EUCLEAN; in check_dev_super()
2292 /* Btrfs_validate_super() includes fsid check against super->fsid. */ in check_dev_super()
2297 if (btrfs_super_generation(sb) != fs_info->last_trans_committed) { in check_dev_super()
2300 fs_info->last_trans_committed); in check_dev_super()
2301 ret = -EUCLEAN; in check_dev_super()
2323 list_for_each_entry(device, &fs_info->fs_devices->devices, dev_list) { in btrfs_unfreeze()
2328 device->devid); in btrfs_unfreeze()
2332 clear_bit(BTRFS_FS_FROZEN, &fs_info->flags); in btrfs_unfreeze()
2336 * above checks failed. Since the fs is either fine or read-only, we're in btrfs_unfreeze()
2344 struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb); in btrfs_show_devname()
2349 * the end of RCU grace period. in btrfs_show_devname()
2352 seq_escape(m, btrfs_dev_name(fs_info->fs_devices->latest_dev), " \t\n\\"); in btrfs_show_devname()
2384 .name = "btrfs-control",
2389 MODULE_ALIAS("devname:btrfs-control");
2411 ", integrity-checker=on" in btrfs_print_mod_info()
2414 ", ref-verify=on" in btrfs_print_mod_info()
2518 for (i = ARRAY_SIZE(mod_init_seq) - 1; i >= 0; i--) { in btrfs_exit_btrfs_fs()
2557 MODULE_SOFTDEP("pre: blake2b-256");