• 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"
47 #include "tests/btrfs-tests.h"
48 #include "block-group.h"
74 * EUCLEAN: Any sort of corruption that we encounter. The tree-checker for
90 case -ENOENT: /* -2 */ in btrfs_decode_error()
93 case -EIO: /* -5 */ in btrfs_decode_error()
96 case -ENOMEM: /* -12*/ in btrfs_decode_error()
99 case -EEXIST: /* -17 */ in btrfs_decode_error()
102 case -ENOSPC: /* -28 */ in btrfs_decode_error()
105 case -EROFS: /* -30 */ in btrfs_decode_error()
108 case -EOPNOTSUPP: /* -95 */ in btrfs_decode_error()
111 case -EUCLEAN: /* -117 */ in btrfs_decode_error()
114 case -EDQUOT: /* -122 */ in btrfs_decode_error()
130 struct super_block *sb = fs_info->sb; in __btrfs_handle_fs_error()
139 if (errno == -EROFS && sb_rdonly(sb)) in __btrfs_handle_fs_error()
153 sb->s_id, function, line, errno, errstr, &vaf); in __btrfs_handle_fs_error()
157 sb->s_id, function, line, errno, errstr); in __btrfs_handle_fs_error()
165 set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state); in __btrfs_handle_fs_error()
168 if (!(sb->s_flags & SB_BORN)) in __btrfs_handle_fs_error()
177 sb->s_flags |= SB_RDONLY; in __btrfs_handle_fs_error()
229 size_t size = printk_skip_level(fmt) - fmt; in btrfs_printk()
234 type = logtypes[kern_level - '0']; in btrfs_printk()
235 ratelimit = &printk_limits[kern_level - '0']; in btrfs_printk()
245 fs_info ? fs_info->sb->s_id : "<unknown>", &vaf); in btrfs_printk()
252 * We only mark the transaction aborted and then set the file system read-only.
259 * in the call path but will return -EIO.
269 struct btrfs_fs_info *fs_info = trans->fs_info; in __btrfs_abort_transaction()
271 WRITE_ONCE(trans->aborted, errno); in __btrfs_abort_transaction()
274 if (!trans->dirty && list_empty(&trans->new_bgs)) { in __btrfs_abort_transaction()
283 WRITE_ONCE(trans->transaction->aborted, errno); in __btrfs_abort_transaction()
285 wake_up(&fs_info->transaction_wait); in __btrfs_abort_transaction()
286 wake_up(&fs_info->transaction_blocked_wait); in __btrfs_abort_transaction()
303 s_id = fs_info->sb->s_id; in __btrfs_panic()
388 {Opt_compress_force, "compress-force"},
389 {Opt_compress_force_type, "compress-force=%s"},
471 return -ENOMEM; in parse_rescue_options()
484 btrfs_set_opt(info->mount_opt, USEBACKUPROOT); in parse_rescue_options()
492 ret = -EINVAL; in parse_rescue_options()
524 cache_gen = btrfs_super_cache_generation(info->super_copy); in btrfs_parse_options()
526 btrfs_set_opt(info->mount_opt, FREE_SPACE_TREE); in btrfs_parse_options()
528 btrfs_set_opt(info->mount_opt, SPACE_CACHE); in btrfs_parse_options()
546 btrfs_set_opt(info->mount_opt, DEGRADED); in btrfs_parse_options()
569 btrfs_clear_opt(info->mount_opt, NODATACOW); in btrfs_parse_options()
570 btrfs_clear_opt(info->mount_opt, NODATASUM); in btrfs_parse_options()
582 btrfs_clear_opt(info->mount_opt, COMPRESS); in btrfs_parse_options()
583 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); in btrfs_parse_options()
584 btrfs_set_opt(info->mount_opt, NODATACOW); in btrfs_parse_options()
585 btrfs_set_opt(info->mount_opt, NODATASUM); in btrfs_parse_options()
599 info->compress_type : BTRFS_COMPRESS_NONE; in btrfs_parse_options()
602 saved_compress_level = info->compress_level; in btrfs_parse_options()
608 info->compress_type = BTRFS_COMPRESS_ZLIB; in btrfs_parse_options()
609 info->compress_level = BTRFS_ZLIB_DEFAULT_LEVEL; in btrfs_parse_options()
617 info->compress_level = in btrfs_parse_options()
621 btrfs_set_opt(info->mount_opt, COMPRESS); in btrfs_parse_options()
622 btrfs_clear_opt(info->mount_opt, NODATACOW); in btrfs_parse_options()
623 btrfs_clear_opt(info->mount_opt, NODATASUM); in btrfs_parse_options()
627 info->compress_type = BTRFS_COMPRESS_LZO; in btrfs_parse_options()
628 info->compress_level = 0; in btrfs_parse_options()
629 btrfs_set_opt(info->mount_opt, COMPRESS); in btrfs_parse_options()
630 btrfs_clear_opt(info->mount_opt, NODATACOW); in btrfs_parse_options()
631 btrfs_clear_opt(info->mount_opt, NODATASUM); in btrfs_parse_options()
636 info->compress_type = BTRFS_COMPRESS_ZSTD; in btrfs_parse_options()
637 info->compress_level = in btrfs_parse_options()
641 btrfs_set_opt(info->mount_opt, COMPRESS); in btrfs_parse_options()
642 btrfs_clear_opt(info->mount_opt, NODATACOW); in btrfs_parse_options()
643 btrfs_clear_opt(info->mount_opt, NODATASUM); in btrfs_parse_options()
648 info->compress_level = 0; in btrfs_parse_options()
649 info->compress_type = 0; in btrfs_parse_options()
650 btrfs_clear_opt(info->mount_opt, COMPRESS); in btrfs_parse_options()
651 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); in btrfs_parse_options()
657 ret = -EINVAL; in btrfs_parse_options()
662 btrfs_set_opt(info->mount_opt, FORCE_COMPRESS); in btrfs_parse_options()
665 * If we remount from compress-force=xxx to in btrfs_parse_options()
670 btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); in btrfs_parse_options()
674 } else if ((info->compress_type != saved_compress_type) || in btrfs_parse_options()
676 (info->compress_level != saved_compress_level)) { in btrfs_parse_options()
679 compress_type, info->compress_level); in btrfs_parse_options()
686 btrfs_clear_opt(info->mount_opt, NOSSD); in btrfs_parse_options()
693 btrfs_clear_opt(info->mount_opt, NOSSD); in btrfs_parse_options()
696 btrfs_set_opt(info->mount_opt, NOSSD); in btrfs_parse_options()
720 ret = -EINVAL; in btrfs_parse_options()
723 info->thread_pool_size = intarg; in btrfs_parse_options()
728 info->max_inline = memparse(num, NULL); in btrfs_parse_options()
731 if (info->max_inline) { in btrfs_parse_options()
732 info->max_inline = min_t(u64, in btrfs_parse_options()
733 info->max_inline, in btrfs_parse_options()
734 info->sectorsize); in btrfs_parse_options()
737 info->max_inline); in btrfs_parse_options()
739 ret = -ENOMEM; in btrfs_parse_options()
745 info->sb->s_flags |= SB_POSIXACL; in btrfs_parse_options()
749 ret = -EINVAL; in btrfs_parse_options()
753 info->sb->s_flags &= ~SB_POSIXACL; in btrfs_parse_options()
772 "turning on flush-on-commit"); in btrfs_parse_options()
776 "turning off flush-on-commit"); in btrfs_parse_options()
785 info->metadata_ratio = intarg; in btrfs_parse_options()
787 info->metadata_ratio); in btrfs_parse_options()
793 btrfs_clear_opt(info->mount_opt, DISCARD_ASYNC); in btrfs_parse_options()
797 btrfs_clear_opt(info->mount_opt, DISCARD_SYNC); in btrfs_parse_options()
803 ret = -EINVAL; in btrfs_parse_options()
817 btrfs_clear_opt(info->mount_opt, in btrfs_parse_options()
822 btrfs_clear_opt(info->mount_opt, in btrfs_parse_options()
829 ret = -EINVAL; in btrfs_parse_options()
834 btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE); in btrfs_parse_options()
861 btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED); in btrfs_parse_options()
864 btrfs_set_opt(info->mount_opt, ENOSPC_DEBUG); in btrfs_parse_options()
867 btrfs_clear_opt(info->mount_opt, ENOSPC_DEBUG); in btrfs_parse_options()
885 btrfs_set_opt(info->mount_opt, USEBACKUPROOT); in btrfs_parse_options()
888 btrfs_set_opt(info->mount_opt, SKIP_BALANCE); in btrfs_parse_options()
894 btrfs_set_opt(info->mount_opt, in btrfs_parse_options()
896 btrfs_set_opt(info->mount_opt, CHECK_INTEGRITY); in btrfs_parse_options()
900 btrfs_set_opt(info->mount_opt, CHECK_INTEGRITY); in btrfs_parse_options()
910 info->check_integrity_print_mask = intarg; in btrfs_parse_options()
912 info->check_integrity_print_mask); in btrfs_parse_options()
920 ret = -EINVAL; in btrfs_parse_options()
925 btrfs_set_opt(info->mount_opt, in btrfs_parse_options()
928 btrfs_clear_opt(info->mount_opt, in btrfs_parse_options()
933 ret = -EINVAL; in btrfs_parse_options()
943 ret = -EINVAL; in btrfs_parse_options()
955 info->commit_interval = intarg; in btrfs_parse_options()
968 btrfs_set_opt(info->mount_opt, FRAGMENT_DATA); in btrfs_parse_options()
969 btrfs_set_opt(info->mount_opt, FRAGMENT_METADATA); in btrfs_parse_options()
973 btrfs_set_opt(info->mount_opt, in btrfs_parse_options()
978 btrfs_set_opt(info->mount_opt, FRAGMENT_DATA); in btrfs_parse_options()
984 btrfs_set_opt(info->mount_opt, REF_VERIFY); in btrfs_parse_options()
989 ret = -EINVAL; in btrfs_parse_options()
1002 ret = -EINVAL; in btrfs_parse_options()
1009 ret = -EINVAL; in btrfs_parse_options()
1044 return -ENOMEM; in btrfs_parse_device_options()
1057 error = -ENOMEM; in btrfs_parse_device_options()
1097 return -ENOMEM; in btrfs_parse_subvol_options()
1111 error = -ENOMEM; in btrfs_parse_subvol_options()
1139 struct btrfs_root *root = fs_info->tree_root; in btrfs_get_subvol_name_from_objectid()
1152 ret = -ENOMEM; in btrfs_get_subvol_name_from_objectid()
1155 path->leave_spinning = 1; in btrfs_get_subvol_name_from_objectid()
1159 ret = -ENOMEM; in btrfs_get_subvol_name_from_objectid()
1162 ptr = name + PATH_MAX - 1; in btrfs_get_subvol_name_from_objectid()
1167 * backrefs until we hit the top-level subvolume. in btrfs_get_subvol_name_from_objectid()
1172 key.offset = (u64)-1; in btrfs_get_subvol_name_from_objectid()
1183 ret = -ENOENT; in btrfs_get_subvol_name_from_objectid()
1188 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); in btrfs_get_subvol_name_from_objectid()
1191 root_ref = btrfs_item_ptr(path->nodes[0], path->slots[0], in btrfs_get_subvol_name_from_objectid()
1193 len = btrfs_root_ref_name_len(path->nodes[0], root_ref); in btrfs_get_subvol_name_from_objectid()
1194 ptr -= len + 1; in btrfs_get_subvol_name_from_objectid()
1196 ret = -ENAMETOOLONG; in btrfs_get_subvol_name_from_objectid()
1199 read_extent_buffer(path->nodes[0], ptr + 1, in btrfs_get_subvol_name_from_objectid()
1202 dirid = btrfs_root_ref_dirid(path->nodes[0], root_ref); in btrfs_get_subvol_name_from_objectid()
1219 key.offset = (u64)-1; in btrfs_get_subvol_name_from_objectid()
1230 ret = -ENOENT; in btrfs_get_subvol_name_from_objectid()
1235 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); in btrfs_get_subvol_name_from_objectid()
1238 inode_ref = btrfs_item_ptr(path->nodes[0], in btrfs_get_subvol_name_from_objectid()
1239 path->slots[0], in btrfs_get_subvol_name_from_objectid()
1241 len = btrfs_inode_ref_name_len(path->nodes[0], in btrfs_get_subvol_name_from_objectid()
1243 ptr -= len + 1; in btrfs_get_subvol_name_from_objectid()
1245 ret = -ENAMETOOLONG; in btrfs_get_subvol_name_from_objectid()
1248 read_extent_buffer(path->nodes[0], ptr + 1, in btrfs_get_subvol_name_from_objectid()
1258 if (ptr == name + PATH_MAX - 1) { in btrfs_get_subvol_name_from_objectid()
1262 memmove(name, ptr, name + PATH_MAX - ptr); in btrfs_get_subvol_name_from_objectid()
1275 struct btrfs_root *root = fs_info->tree_root; in get_default_subvol_objectid()
1283 return -ENOMEM; in get_default_subvol_objectid()
1284 path->leave_spinning = 1; in get_default_subvol_objectid()
1291 dir_id = btrfs_super_root_dir(fs_info->super_copy); in get_default_subvol_objectid()
1301 * mount the top-level subvolume. in get_default_subvol_objectid()
1308 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location); in get_default_subvol_objectid()
1322 sb->s_maxbytes = MAX_LFS_FILESIZE; in btrfs_fill_super()
1323 sb->s_magic = BTRFS_SUPER_MAGIC; in btrfs_fill_super()
1324 sb->s_op = &btrfs_super_ops; in btrfs_fill_super()
1325 sb->s_d_op = &btrfs_dentry_operations; in btrfs_fill_super()
1326 sb->s_export_op = &btrfs_export_ops; in btrfs_fill_super()
1327 sb->s_xattr = btrfs_xattr_handlers; in btrfs_fill_super()
1328 sb->s_time_gran = 1; in btrfs_fill_super()
1330 sb->s_flags |= SB_POSIXACL; in btrfs_fill_super()
1332 sb->s_flags |= SB_I_VERSION; in btrfs_fill_super()
1333 sb->s_iflags |= SB_I_CGROUPWB; in btrfs_fill_super()
1347 inode = btrfs_iget(sb, BTRFS_FIRST_FREE_OBJECTID, fs_info->fs_root); in btrfs_fill_super()
1353 sb->s_root = d_make_root(inode); in btrfs_fill_super()
1354 if (!sb->s_root) { in btrfs_fill_super()
1355 err = -ENOMEM; in btrfs_fill_super()
1360 sb->s_flags |= SB_ACTIVE; in btrfs_fill_super()
1372 struct btrfs_root *root = fs_info->tree_root; in btrfs_sync_fs()
1377 filemap_flush(fs_info->btree_inode->i_mapping); in btrfs_sync_fs()
1381 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_sync_fs()
1386 if (PTR_ERR(trans) == -ENOENT) { in btrfs_sync_fs()
1391 if (fs_info->pending_changes == 0) in btrfs_sync_fs()
1394 * A non-blocking test if the fs is frozen. We must not in btrfs_sync_fs()
1413 struct btrfs_fs_info *info = btrfs_sb(dentry->d_sb); in btrfs_show_options()
1425 if (info->max_inline != BTRFS_DEFAULT_MAX_INLINE) in btrfs_show_options()
1426 seq_printf(seq, ",max_inline=%llu", info->max_inline); in btrfs_show_options()
1427 if (info->thread_pool_size != min_t(unsigned long, in btrfs_show_options()
1429 seq_printf(seq, ",thread_pool=%u", info->thread_pool_size); in btrfs_show_options()
1431 compress_type = btrfs_compress_type2str(info->compress_type); in btrfs_show_options()
1433 seq_printf(seq, ",compress-force=%s", compress_type); in btrfs_show_options()
1436 if (info->compress_level) in btrfs_show_options()
1437 seq_printf(seq, ":%d", info->compress_level); in btrfs_show_options()
1455 if (!(info->sb->s_flags & SB_POSIXACL)) in btrfs_show_options()
1482 if (info->check_integrity_print_mask) in btrfs_show_options()
1484 info->check_integrity_print_mask); in btrfs_show_options()
1486 if (info->metadata_ratio) in btrfs_show_options()
1487 seq_printf(seq, ",metadata_ratio=%u", info->metadata_ratio); in btrfs_show_options()
1490 if (info->commit_interval != BTRFS_DEFAULT_COMMIT_INTERVAL) in btrfs_show_options()
1491 seq_printf(seq, ",commit=%u", info->commit_interval); in btrfs_show_options()
1501 BTRFS_I(d_inode(dentry))->root->root_key.objectid); in btrfs_show_options()
1503 BTRFS_I(d_inode(dentry))->root->root_key.objectid); in btrfs_show_options()
1517 return fs_info->fs_devices == p->fs_devices; in btrfs_test_super()
1524 s->s_fs_info = data; in btrfs_set_super()
1533 if (inode && inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) in is_subvolume_inode()
1546 ret = get_default_subvol_objectid(btrfs_sb(mnt->mnt_sb), in mount_subvol()
1554 btrfs_sb(mnt->mnt_sb), subvol_objectid); in mount_subvol()
1568 struct super_block *s = root->d_sb; in mount_subvol()
1571 u64 root_objectid = BTRFS_I(root_inode)->root->root_key.objectid; in mount_subvol()
1577 ret = -EINVAL; in mount_subvol()
1588 ret = -EINVAL; in mount_subvol()
1640 error = -ENOMEM; in btrfs_mount_root()
1645 fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL); in btrfs_mount_root()
1646 fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL); in btrfs_mount_root()
1647 if (!fs_info->super_copy || !fs_info->super_for_commit) { in btrfs_mount_root()
1648 error = -ENOMEM; in btrfs_mount_root()
1666 fs_devices = device->fs_devices; in btrfs_mount_root()
1667 fs_info->fs_devices = fs_devices; in btrfs_mount_root()
1674 if (!(flags & SB_RDONLY) && fs_devices->rw_devices == 0) { in btrfs_mount_root()
1675 error = -EACCES; in btrfs_mount_root()
1679 bdev = fs_devices->latest_bdev; in btrfs_mount_root()
1687 if (s->s_root) { in btrfs_mount_root()
1690 if ((flags ^ s->s_flags) & SB_RDONLY) in btrfs_mount_root()
1691 error = -EBUSY; in btrfs_mount_root()
1693 snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev); in btrfs_mount_root()
1694 btrfs_sb(s)->bdev_holder = fs_type; in btrfs_mount_root()
1705 return dget(s->s_root); in btrfs_mount_root()
1736 * "btrfs subvolume set-default", mount_subvol() is called always.
1756 if (PTR_ERR_OR_ZERO(mnt_root) == -EBUSY) { in btrfs_mount()
1769 down_write(&mnt_root->mnt_sb->s_umount); in btrfs_mount()
1770 error = btrfs_remount(mnt_root->mnt_sb, &flags, NULL); in btrfs_mount()
1771 up_write(&mnt_root->mnt_sb->s_umount); in btrfs_mount()
1799 fs_info->thread_pool_size = new_pool_size; in btrfs_resize_thread_pool()
1801 btrfs_info(fs_info, "resize thread pool %d -> %d", in btrfs_resize_thread_pool()
1804 btrfs_workqueue_set_max(fs_info->workers, new_pool_size); in btrfs_resize_thread_pool()
1805 btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size); in btrfs_resize_thread_pool()
1806 btrfs_workqueue_set_max(fs_info->caching_workers, new_pool_size); in btrfs_resize_thread_pool()
1807 btrfs_workqueue_set_max(fs_info->endio_workers, new_pool_size); in btrfs_resize_thread_pool()
1808 btrfs_workqueue_set_max(fs_info->endio_meta_workers, new_pool_size); in btrfs_resize_thread_pool()
1809 btrfs_workqueue_set_max(fs_info->endio_meta_write_workers, in btrfs_resize_thread_pool()
1811 btrfs_workqueue_set_max(fs_info->endio_write_workers, new_pool_size); in btrfs_resize_thread_pool()
1812 btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size); in btrfs_resize_thread_pool()
1813 btrfs_workqueue_set_max(fs_info->delayed_workers, new_pool_size); in btrfs_resize_thread_pool()
1814 btrfs_workqueue_set_max(fs_info->readahead_workers, new_pool_size); in btrfs_resize_thread_pool()
1815 btrfs_workqueue_set_max(fs_info->scrub_wr_completion_workers, in btrfs_resize_thread_pool()
1823 (!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) || in btrfs_remount_begin()
1826 wait_event(fs_info->transaction_wait, in btrfs_remount_begin()
1827 (atomic_read(&fs_info->defrag_running) == 0)); in btrfs_remount_begin()
1829 sync_filesystem(fs_info->sb); in btrfs_remount_begin()
1841 (!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) || sb_rdonly(fs_info->sb))) { in btrfs_remount_cleanup()
1857 struct btrfs_root *root = fs_info->tree_root; in btrfs_remount()
1858 unsigned old_flags = sb->s_flags; in btrfs_remount()
1859 unsigned long old_opts = fs_info->mount_opt; in btrfs_remount()
1860 unsigned long old_compress_type = fs_info->compress_type; in btrfs_remount()
1861 u64 old_max_inline = fs_info->max_inline; in btrfs_remount()
1862 u32 old_thread_pool_size = fs_info->thread_pool_size; in btrfs_remount()
1863 u32 old_metadata_ratio = fs_info->metadata_ratio; in btrfs_remount()
1867 set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); in btrfs_remount()
1886 fs_info->thread_pool_size, old_thread_pool_size); in btrfs_remount()
1893 * this also happens on 'umount -rf' or on shutdown, when in btrfs_remount()
1896 cancel_work_sync(&fs_info->async_reclaim_work); in btrfs_remount()
1897 cancel_work_sync(&fs_info->async_data_reclaim_work); in btrfs_remount()
1902 down(&fs_info->uuid_tree_rescan_sem); in btrfs_remount()
1904 up(&fs_info->uuid_tree_rescan_sem); in btrfs_remount()
1906 sb->s_flags |= SB_RDONLY; in btrfs_remount()
1912 * groups on disk until we're mounted read-write again in btrfs_remount()
1933 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { in btrfs_remount()
1935 "Remounting read-write after error is not allowed"); in btrfs_remount()
1936 ret = -EINVAL; in btrfs_remount()
1939 if (fs_info->fs_devices->rw_devices == 0) { in btrfs_remount()
1940 ret = -EACCES; in btrfs_remount()
1947 ret = -EACCES; in btrfs_remount()
1951 if (btrfs_super_log_root(fs_info->super_copy) != 0) { in btrfs_remount()
1953 "mount required to replay tree-log, cannot remount read-write"); in btrfs_remount()
1954 ret = -EINVAL; in btrfs_remount()
1963 mutex_lock(&fs_info->cleaner_mutex); in btrfs_remount()
1965 mutex_unlock(&fs_info->cleaner_mutex); in btrfs_remount()
1981 if (!fs_info->uuid_root) { in btrfs_remount()
1991 sb->s_flags &= ~SB_RDONLY; in btrfs_remount()
1993 set_bit(BTRFS_FS_OPEN, &fs_info->flags); in btrfs_remount()
2002 wake_up_process(fs_info->transaction_kthread); in btrfs_remount()
2004 clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); in btrfs_remount()
2009 /* We've hit an error - don't reset SB_RDONLY */ in btrfs_remount()
2012 sb->s_flags = old_flags; in btrfs_remount()
2013 fs_info->mount_opt = old_opts; in btrfs_remount()
2014 fs_info->compress_type = old_compress_type; in btrfs_remount()
2015 fs_info->max_inline = old_max_inline; in btrfs_remount()
2017 old_thread_pool_size, fs_info->thread_pool_size); in btrfs_remount()
2018 fs_info->metadata_ratio = old_metadata_ratio; in btrfs_remount()
2020 clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); in btrfs_remount()
2029 if (((struct btrfs_device_info *)dev_info1)->max_avail > in btrfs_cmp_device_free_bytes()
2030 ((struct btrfs_device_info *)dev_info2)->max_avail) in btrfs_cmp_device_free_bytes()
2031 return -1; in btrfs_cmp_device_free_bytes()
2032 else if (((struct btrfs_device_info *)dev_info1)->max_avail < in btrfs_cmp_device_free_bytes()
2033 ((struct btrfs_device_info *)dev_info2)->max_avail) in btrfs_cmp_device_free_bytes()
2059 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; in btrfs_calc_avail_data_space()
2069 * We aren't under the device list lock, so this is racy-ish, but good in btrfs_calc_avail_data_space()
2072 nr_devices = fs_info->fs_devices->open_devices; in btrfs_calc_avail_data_space()
2075 nr_devices = fs_info->fs_devices->open_devices; in btrfs_calc_avail_data_space()
2086 return -ENOMEM; in btrfs_calc_avail_data_space()
2104 min_stripe_size = rattr->dev_stripes * BTRFS_STRIPE_LEN; in btrfs_calc_avail_data_space()
2107 list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) { in btrfs_calc_avail_data_space()
2109 &device->dev_state) || in btrfs_calc_avail_data_space()
2110 !device->bdev || in btrfs_calc_avail_data_space()
2111 test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) in btrfs_calc_avail_data_space()
2117 avail_space = device->total_bytes - device->bytes_used; in btrfs_calc_avail_data_space()
2133 avail_space -= SZ_1M; in btrfs_calc_avail_data_space()
2146 i = nr_devices - 1; in btrfs_calc_avail_data_space()
2148 while (nr_devices >= rattr->devs_min) { in btrfs_calc_avail_data_space()
2157 for (j = i + 1 - num_stripes; j <= i; j++) in btrfs_calc_avail_data_space()
2158 devices_info[j].max_avail -= alloc_size; in btrfs_calc_avail_data_space()
2160 i--; in btrfs_calc_avail_data_space()
2161 nr_devices--; in btrfs_calc_avail_data_space()
2184 struct btrfs_fs_info *fs_info = btrfs_sb(dentry->d_sb); in btrfs_statfs()
2185 struct btrfs_super_block *disk_super = fs_info->super_copy; in btrfs_statfs()
2190 int bits = dentry->d_sb->s_blocksize_bits; in btrfs_statfs()
2191 __be32 *fsid = (__be32 *)fs_info->fs_devices->fsid; in btrfs_statfs()
2193 struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv; in btrfs_statfs()
2198 list_for_each_entry(found, &fs_info->space_info, list) { in btrfs_statfs()
2199 if (found->flags & BTRFS_BLOCK_GROUP_DATA) { in btrfs_statfs()
2202 total_free_data += found->disk_total - found->disk_used; in btrfs_statfs()
2203 total_free_data -= in btrfs_statfs()
2207 if (!list_empty(&found->block_groups[i])) in btrfs_statfs()
2216 if (!mixed && found->flags & BTRFS_BLOCK_GROUP_METADATA) { in btrfs_statfs()
2217 if (found->flags & BTRFS_BLOCK_GROUP_DATA) in btrfs_statfs()
2220 total_free_meta += found->disk_total - in btrfs_statfs()
2221 found->disk_used; in btrfs_statfs()
2224 total_used += found->disk_used; in btrfs_statfs()
2227 buf->f_blocks = div_u64(btrfs_super_total_bytes(disk_super), factor); in btrfs_statfs()
2228 buf->f_blocks >>= bits; in btrfs_statfs()
2229 buf->f_bfree = buf->f_blocks - (div_u64(total_used, factor) >> bits); in btrfs_statfs()
2232 spin_lock(&block_rsv->lock); in btrfs_statfs()
2233 /* Mixed block groups accounting is not byte-accurate, avoid overflow */ in btrfs_statfs()
2234 if (buf->f_bfree >= block_rsv->size >> bits) in btrfs_statfs()
2235 buf->f_bfree -= block_rsv->size >> bits; in btrfs_statfs()
2237 buf->f_bfree = 0; in btrfs_statfs()
2238 spin_unlock(&block_rsv->lock); in btrfs_statfs()
2240 buf->f_bavail = div_u64(total_free_data, factor); in btrfs_statfs()
2244 buf->f_bavail += div_u64(total_free_data, factor); in btrfs_statfs()
2245 buf->f_bavail = buf->f_bavail >> bits; in btrfs_statfs()
2265 * not fit in the free metadata space. If we aren't ->full then we in btrfs_statfs()
2269 if (!mixed && block_rsv->space_info->full && in btrfs_statfs()
2270 (total_free_meta < thresh || total_free_meta - thresh < block_rsv->size)) in btrfs_statfs()
2271 buf->f_bavail = 0; in btrfs_statfs()
2273 buf->f_type = BTRFS_SUPER_MAGIC; in btrfs_statfs()
2274 buf->f_bsize = dentry->d_sb->s_blocksize; in btrfs_statfs()
2275 buf->f_namelen = BTRFS_NAME_LEN; in btrfs_statfs()
2279 on a big-endian or little-endian host */ in btrfs_statfs()
2280 buf->f_fsid.val[0] = be32_to_cpu(fsid[0]) ^ be32_to_cpu(fsid[2]); in btrfs_statfs()
2281 buf->f_fsid.val[1] = be32_to_cpu(fsid[1]) ^ be32_to_cpu(fsid[3]); in btrfs_statfs()
2282 /* Mask in the root object ID too, to disambiguate subvols */ in btrfs_statfs()
2283 buf->f_fsid.val[0] ^= in btrfs_statfs()
2284 BTRFS_I(d_inode(dentry))->root->root_key.objectid >> 32; in btrfs_statfs()
2285 buf->f_fsid.val[1] ^= in btrfs_statfs()
2286 BTRFS_I(d_inode(dentry))->root->root_key.objectid; in btrfs_statfs()
2323 file->private_data = NULL; in btrfs_control_open()
2328 * Used by /dev/btrfs-control for devices ioctls.
2335 int ret = -ENOTTY; in btrfs_control_ioctl()
2338 return -EPERM; in btrfs_control_ioctl()
2343 vol->name[BTRFS_PATH_NAME_MAX] = '\0'; in btrfs_control_ioctl()
2348 device = btrfs_scan_one_device(vol->name, FMODE_READ, in btrfs_control_ioctl()
2354 ret = btrfs_forget_devices(vol->name); in btrfs_control_ioctl()
2358 device = btrfs_scan_one_device(vol->name, FMODE_READ, in btrfs_control_ioctl()
2365 ret = !(device->fs_devices->num_devices == in btrfs_control_ioctl()
2366 device->fs_devices->total_devices); in btrfs_control_ioctl()
2382 struct btrfs_root *root = fs_info->tree_root; in btrfs_freeze()
2384 set_bit(BTRFS_FS_FROZEN, &fs_info->flags); in btrfs_freeze()
2394 if (PTR_ERR(trans) == -ENOENT) in btrfs_freeze()
2405 clear_bit(BTRFS_FS_FROZEN, &fs_info->flags); in btrfs_unfreeze()
2411 struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb); in btrfs_show_devname()
2417 * is protected by RCU. Even if a device is deleted during the list in btrfs_show_devname()
2422 list_for_each_entry_rcu(dev, &fs_info->fs_devices->devices, dev_list) { in btrfs_show_devname()
2423 if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state)) in btrfs_show_devname()
2425 if (!dev->name) in btrfs_show_devname()
2427 if (!first_dev || dev->devid < first_dev->devid) in btrfs_show_devname()
2432 seq_escape(m, rcu_str_deref(first_dev->name), " \t\n\\"); in btrfs_show_devname()
2465 .name = "btrfs-control",
2470 MODULE_ALIAS("devname:btrfs-control");
2492 ", integrity-checker=on" in btrfs_print_mod_info()
2495 ", ref-verify=on" in btrfs_print_mod_info()
2626 MODULE_SOFTDEP("pre: blake2b-256");