Commit 6c41761f authored by David Sterba's avatar David Sterba Committed by Chris Mason

btrfs: separate superblock items out of fs_info

fs_info has now ~9kb, more than fits into one page. This will cause
mount failure when memory is too fragmented. Top space consumers are
super block structures super_copy and super_for_commit, ~2.8kb each.
Allocate them dynamically. fs_info will be ~3.5kb. (measured on x86_64)

Add a wrapper for freeing fs_info and all of it's dynamically allocated
members.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.cz>
parent c8174313
...@@ -85,7 +85,8 @@ struct compressed_bio { ...@@ -85,7 +85,8 @@ struct compressed_bio {
static inline int compressed_bio_size(struct btrfs_root *root, static inline int compressed_bio_size(struct btrfs_root *root,
unsigned long disk_size) unsigned long disk_size)
{ {
u16 csum_size = btrfs_super_csum_size(&root->fs_info->super_copy); u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
return sizeof(struct compressed_bio) + return sizeof(struct compressed_bio) +
((disk_size + root->sectorsize - 1) / root->sectorsize) * ((disk_size + root->sectorsize - 1) / root->sectorsize) *
csum_size; csum_size;
......
...@@ -936,8 +936,8 @@ struct btrfs_fs_info { ...@@ -936,8 +936,8 @@ struct btrfs_fs_info {
wait_queue_head_t transaction_blocked_wait; wait_queue_head_t transaction_blocked_wait;
wait_queue_head_t async_submit_wait; wait_queue_head_t async_submit_wait;
struct btrfs_super_block super_copy; struct btrfs_super_block *super_copy;
struct btrfs_super_block super_for_commit; struct btrfs_super_block *super_for_commit;
struct block_device *__bdev; struct block_device *__bdev;
struct super_block *sb; struct super_block *sb;
struct inode *btree_inode; struct inode *btree_inode;
...@@ -2387,6 +2387,18 @@ static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info) ...@@ -2387,6 +2387,18 @@ static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)
smp_mb(); smp_mb();
return fs_info->closing; return fs_info->closing;
} }
static inline void free_fs_info(struct btrfs_fs_info *fs_info)
{
kfree(fs_info->delayed_root);
kfree(fs_info->extent_root);
kfree(fs_info->tree_root);
kfree(fs_info->chunk_root);
kfree(fs_info->dev_root);
kfree(fs_info->csum_root);
kfree(fs_info->super_copy);
kfree(fs_info->super_for_commit);
kfree(fs_info);
}
/* root-item.c */ /* root-item.c */
int btrfs_find_root_ref(struct btrfs_root *tree_root, int btrfs_find_root_ref(struct btrfs_root *tree_root,
......
...@@ -256,8 +256,7 @@ void btrfs_csum_final(u32 crc, char *result) ...@@ -256,8 +256,7 @@ void btrfs_csum_final(u32 crc, char *result)
static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
int verify) int verify)
{ {
u16 csum_size = u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
btrfs_super_csum_size(&root->fs_info->super_copy);
char *result = NULL; char *result = NULL;
unsigned long len; unsigned long len;
unsigned long cur_len; unsigned long cur_len;
...@@ -1766,14 +1765,14 @@ struct btrfs_root *open_ctree(struct super_block *sb, ...@@ -1766,14 +1765,14 @@ struct btrfs_root *open_ctree(struct super_block *sb,
goto fail_alloc; goto fail_alloc;
} }
memcpy(&fs_info->super_copy, bh->b_data, sizeof(fs_info->super_copy)); memcpy(fs_info->super_copy, bh->b_data, sizeof(*fs_info->super_copy));
memcpy(&fs_info->super_for_commit, &fs_info->super_copy, memcpy(fs_info->super_for_commit, fs_info->super_copy,
sizeof(fs_info->super_for_commit)); sizeof(*fs_info->super_for_commit));
brelse(bh); brelse(bh);
memcpy(fs_info->fsid, fs_info->super_copy.fsid, BTRFS_FSID_SIZE); memcpy(fs_info->fsid, fs_info->super_copy->fsid, BTRFS_FSID_SIZE);
disk_super = &fs_info->super_copy; disk_super = fs_info->super_copy;
if (!btrfs_super_root(disk_super)) if (!btrfs_super_root(disk_super))
goto fail_alloc; goto fail_alloc;
...@@ -2152,7 +2151,6 @@ struct btrfs_root *open_ctree(struct super_block *sb, ...@@ -2152,7 +2151,6 @@ struct btrfs_root *open_ctree(struct super_block *sb,
btrfs_stop_workers(&fs_info->delayed_workers); btrfs_stop_workers(&fs_info->delayed_workers);
btrfs_stop_workers(&fs_info->caching_workers); btrfs_stop_workers(&fs_info->caching_workers);
fail_alloc: fail_alloc:
kfree(fs_info->delayed_root);
fail_iput: fail_iput:
invalidate_inode_pages2(fs_info->btree_inode->i_mapping); invalidate_inode_pages2(fs_info->btree_inode->i_mapping);
iput(fs_info->btree_inode); iput(fs_info->btree_inode);
...@@ -2164,12 +2162,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, ...@@ -2164,12 +2162,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
fail_srcu: fail_srcu:
cleanup_srcu_struct(&fs_info->subvol_srcu); cleanup_srcu_struct(&fs_info->subvol_srcu);
fail: fail:
kfree(extent_root); free_fs_info(fs_info);
kfree(tree_root);
kfree(fs_info);
kfree(chunk_root);
kfree(dev_root);
kfree(csum_root);
return ERR_PTR(err); return ERR_PTR(err);
} }
...@@ -2338,10 +2331,10 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors) ...@@ -2338,10 +2331,10 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors)
int total_errors = 0; int total_errors = 0;
u64 flags; u64 flags;
max_errors = btrfs_super_num_devices(&root->fs_info->super_copy) - 1; max_errors = btrfs_super_num_devices(root->fs_info->super_copy) - 1;
do_barriers = !btrfs_test_opt(root, NOBARRIER); do_barriers = !btrfs_test_opt(root, NOBARRIER);
sb = &root->fs_info->super_for_commit; sb = root->fs_info->super_for_commit;
dev_item = &sb->dev_item; dev_item = &sb->dev_item;
mutex_lock(&root->fs_info->fs_devices->device_list_mutex); mutex_lock(&root->fs_info->fs_devices->device_list_mutex);
...@@ -2603,7 +2596,6 @@ int close_ctree(struct btrfs_root *root) ...@@ -2603,7 +2596,6 @@ int close_ctree(struct btrfs_root *root)
del_fs_roots(fs_info); del_fs_roots(fs_info);
iput(fs_info->btree_inode); iput(fs_info->btree_inode);
kfree(fs_info->delayed_root);
btrfs_stop_workers(&fs_info->generic_worker); btrfs_stop_workers(&fs_info->generic_worker);
btrfs_stop_workers(&fs_info->fixup_workers); btrfs_stop_workers(&fs_info->fixup_workers);
...@@ -2624,12 +2616,7 @@ int close_ctree(struct btrfs_root *root) ...@@ -2624,12 +2616,7 @@ int close_ctree(struct btrfs_root *root)
bdi_destroy(&fs_info->bdi); bdi_destroy(&fs_info->bdi);
cleanup_srcu_struct(&fs_info->subvol_srcu); cleanup_srcu_struct(&fs_info->subvol_srcu);
kfree(fs_info->extent_root); free_fs_info(fs_info);
kfree(fs_info->tree_root);
kfree(fs_info->chunk_root);
kfree(fs_info->dev_root);
kfree(fs_info->csum_root);
kfree(fs_info);
return 0; return 0;
} }
......
...@@ -3209,7 +3209,7 @@ static int should_alloc_chunk(struct btrfs_root *root, ...@@ -3209,7 +3209,7 @@ static int should_alloc_chunk(struct btrfs_root *root,
* about 1% of the FS size. * about 1% of the FS size.
*/ */
if (force == CHUNK_ALLOC_LIMITED) { if (force == CHUNK_ALLOC_LIMITED) {
thresh = btrfs_super_total_bytes(&root->fs_info->super_copy); thresh = btrfs_super_total_bytes(root->fs_info->super_copy);
thresh = max_t(u64, 64 * 1024 * 1024, thresh = max_t(u64, 64 * 1024 * 1024,
div_factor_fine(thresh, 1)); div_factor_fine(thresh, 1));
...@@ -3231,7 +3231,7 @@ static int should_alloc_chunk(struct btrfs_root *root, ...@@ -3231,7 +3231,7 @@ static int should_alloc_chunk(struct btrfs_root *root,
if (num_allocated + alloc_bytes < div_factor(num_bytes, 8)) if (num_allocated + alloc_bytes < div_factor(num_bytes, 8))
return 0; return 0;
thresh = btrfs_super_total_bytes(&root->fs_info->super_copy); thresh = btrfs_super_total_bytes(root->fs_info->super_copy);
/* 256MB or 5% of the FS */ /* 256MB or 5% of the FS */
thresh = max_t(u64, 256 * 1024 * 1024, div_factor_fine(thresh, 5)); thresh = max_t(u64, 256 * 1024 * 1024, div_factor_fine(thresh, 5));
...@@ -3843,7 +3843,7 @@ static u64 calc_global_metadata_size(struct btrfs_fs_info *fs_info) ...@@ -3843,7 +3843,7 @@ static u64 calc_global_metadata_size(struct btrfs_fs_info *fs_info)
u64 num_bytes; u64 num_bytes;
u64 meta_used; u64 meta_used;
u64 data_used; u64 data_used;
int csum_size = btrfs_super_csum_size(&fs_info->super_copy); int csum_size = btrfs_super_csum_size(fs_info->super_copy);
sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_DATA); sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_DATA);
spin_lock(&sinfo->lock); spin_lock(&sinfo->lock);
...@@ -4222,12 +4222,12 @@ static int update_block_group(struct btrfs_trans_handle *trans, ...@@ -4222,12 +4222,12 @@ static int update_block_group(struct btrfs_trans_handle *trans,
/* block accounting for super block */ /* block accounting for super block */
spin_lock(&info->delalloc_lock); spin_lock(&info->delalloc_lock);
old_val = btrfs_super_bytes_used(&info->super_copy); old_val = btrfs_super_bytes_used(info->super_copy);
if (alloc) if (alloc)
old_val += num_bytes; old_val += num_bytes;
else else
old_val -= num_bytes; old_val -= num_bytes;
btrfs_set_super_bytes_used(&info->super_copy, old_val); btrfs_set_super_bytes_used(info->super_copy, old_val);
spin_unlock(&info->delalloc_lock); spin_unlock(&info->delalloc_lock);
while (total) { while (total) {
...@@ -7127,9 +7127,9 @@ int btrfs_read_block_groups(struct btrfs_root *root) ...@@ -7127,9 +7127,9 @@ int btrfs_read_block_groups(struct btrfs_root *root)
return -ENOMEM; return -ENOMEM;
path->reada = 1; path->reada = 1;
cache_gen = btrfs_super_cache_generation(&root->fs_info->super_copy); cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
if (btrfs_test_opt(root, SPACE_CACHE) && if (btrfs_test_opt(root, SPACE_CACHE) &&
btrfs_super_generation(&root->fs_info->super_copy) != cache_gen) btrfs_super_generation(root->fs_info->super_copy) != cache_gen)
need_clear = 1; need_clear = 1;
if (btrfs_test_opt(root, CLEAR_CACHE)) if (btrfs_test_opt(root, CLEAR_CACHE))
need_clear = 1; need_clear = 1;
...@@ -7458,7 +7458,7 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info) ...@@ -7458,7 +7458,7 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info)
int mixed = 0; int mixed = 0;
int ret; int ret;
disk_super = &fs_info->super_copy; disk_super = fs_info->super_copy;
if (!btrfs_super_root(disk_super)) if (!btrfs_super_root(disk_super))
return 1; return 1;
......
...@@ -91,8 +91,7 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, ...@@ -91,8 +91,7 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
struct btrfs_csum_item *item; struct btrfs_csum_item *item;
struct extent_buffer *leaf; struct extent_buffer *leaf;
u64 csum_offset = 0; u64 csum_offset = 0;
u16 csum_size = u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
btrfs_super_csum_size(&root->fs_info->super_copy);
int csums_in_item; int csums_in_item;
file_key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; file_key.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
...@@ -162,8 +161,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, ...@@ -162,8 +161,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
u64 item_last_offset = 0; u64 item_last_offset = 0;
u64 disk_bytenr; u64 disk_bytenr;
u32 diff; u32 diff;
u16 csum_size = u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
btrfs_super_csum_size(&root->fs_info->super_copy);
int ret; int ret;
struct btrfs_path *path; struct btrfs_path *path;
struct btrfs_csum_item *item = NULL; struct btrfs_csum_item *item = NULL;
...@@ -290,7 +288,7 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, ...@@ -290,7 +288,7 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
int ret; int ret;
size_t size; size_t size;
u64 csum_end; u64 csum_end;
u16 csum_size = btrfs_super_csum_size(&root->fs_info->super_copy); u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
...@@ -492,8 +490,7 @@ static noinline int truncate_one_csum(struct btrfs_trans_handle *trans, ...@@ -492,8 +490,7 @@ static noinline int truncate_one_csum(struct btrfs_trans_handle *trans,
u64 bytenr, u64 len) u64 bytenr, u64 len)
{ {
struct extent_buffer *leaf; struct extent_buffer *leaf;
u16 csum_size = u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
btrfs_super_csum_size(&root->fs_info->super_copy);
u64 csum_end; u64 csum_end;
u64 end_byte = bytenr + len; u64 end_byte = bytenr + len;
u32 blocksize_bits = root->fs_info->sb->s_blocksize_bits; u32 blocksize_bits = root->fs_info->sb->s_blocksize_bits;
...@@ -549,8 +546,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, ...@@ -549,8 +546,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
u64 csum_end; u64 csum_end;
struct extent_buffer *leaf; struct extent_buffer *leaf;
int ret; int ret;
u16 csum_size = u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
btrfs_super_csum_size(&root->fs_info->super_copy);
int blocksize_bits = root->fs_info->sb->s_blocksize_bits; int blocksize_bits = root->fs_info->sb->s_blocksize_bits;
root = root->fs_info->csum_root; root = root->fs_info->csum_root;
...@@ -676,8 +672,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, ...@@ -676,8 +672,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
struct btrfs_sector_sum *sector_sum; struct btrfs_sector_sum *sector_sum;
u32 nritems; u32 nritems;
u32 ins_size; u32 ins_size;
u16 csum_size = u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
btrfs_super_csum_size(&root->fs_info->super_copy);
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
......
...@@ -824,7 +824,7 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -824,7 +824,7 @@ static noinline int cow_file_range(struct inode *inode,
} }
BUG_ON(disk_num_bytes > BUG_ON(disk_num_bytes >
btrfs_super_total_bytes(&root->fs_info->super_copy)); btrfs_super_total_bytes(root->fs_info->super_copy));
alloc_hint = get_extent_allocation_hint(inode, start, num_bytes); alloc_hint = get_extent_allocation_hint(inode, start, num_bytes);
btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0); btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0);
......
...@@ -282,7 +282,7 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg) ...@@ -282,7 +282,7 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
struct fstrim_range range; struct fstrim_range range;
u64 minlen = ULLONG_MAX; u64 minlen = ULLONG_MAX;
u64 num_devices = 0; u64 num_devices = 0;
u64 total_bytes = btrfs_super_total_bytes(&root->fs_info->super_copy); u64 total_bytes = btrfs_super_total_bytes(root->fs_info->super_copy);
int ret; int ret;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
...@@ -1164,7 +1164,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, ...@@ -1164,7 +1164,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
} }
disk_super = &root->fs_info->super_copy; disk_super = root->fs_info->super_copy;
features = btrfs_super_incompat_flags(disk_super); features = btrfs_super_incompat_flags(disk_super);
if (range->compress_type == BTRFS_COMPRESS_LZO) { if (range->compress_type == BTRFS_COMPRESS_LZO) {
features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO; features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
...@@ -2613,7 +2613,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp) ...@@ -2613,7 +2613,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
return PTR_ERR(trans); return PTR_ERR(trans);
} }
dir_id = btrfs_super_root_dir(&root->fs_info->super_copy); dir_id = btrfs_super_root_dir(root->fs_info->super_copy);
di = btrfs_lookup_dir_item(trans, root->fs_info->tree_root, path, di = btrfs_lookup_dir_item(trans, root->fs_info->tree_root, path,
dir_id, "default", 7, 1); dir_id, "default", 7, 1);
if (IS_ERR_OR_NULL(di)) { if (IS_ERR_OR_NULL(di)) {
...@@ -2629,7 +2629,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp) ...@@ -2629,7 +2629,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
btrfs_mark_buffer_dirty(path->nodes[0]); btrfs_mark_buffer_dirty(path->nodes[0]);
btrfs_free_path(path); btrfs_free_path(path);
disk_super = &root->fs_info->super_copy; disk_super = root->fs_info->super_copy;
features = btrfs_super_incompat_flags(disk_super); features = btrfs_super_incompat_flags(disk_super);
if (!(features & BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL)) { if (!(features & BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL)) {
features |= BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL; features |= BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL;
......
...@@ -182,7 +182,7 @@ struct scrub_dev *scrub_setup_dev(struct btrfs_device *dev) ...@@ -182,7 +182,7 @@ struct scrub_dev *scrub_setup_dev(struct btrfs_device *dev)
sdev->curr = -1; sdev->curr = -1;
atomic_set(&sdev->in_flight, 0); atomic_set(&sdev->in_flight, 0);
atomic_set(&sdev->cancel_req, 0); atomic_set(&sdev->cancel_req, 0);
sdev->csum_size = btrfs_super_csum_size(&fs_info->super_copy); sdev->csum_size = btrfs_super_csum_size(fs_info->super_copy);
INIT_LIST_HEAD(&sdev->csum_list); INIT_LIST_HEAD(&sdev->csum_list);
spin_lock_init(&sdev->list_lock); spin_lock_init(&sdev->list_lock);
......
...@@ -216,7 +216,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) ...@@ -216,7 +216,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
char *compress_type; char *compress_type;
bool compress_force = false; bool compress_force = false;
cache_gen = btrfs_super_cache_generation(&root->fs_info->super_copy); cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
if (cache_gen) if (cache_gen)
btrfs_set_opt(info->mount_opt, SPACE_CACHE); btrfs_set_opt(info->mount_opt, SPACE_CACHE);
...@@ -524,7 +524,7 @@ static struct dentry *get_default_root(struct super_block *sb, ...@@ -524,7 +524,7 @@ static struct dentry *get_default_root(struct super_block *sb,
* will mount by default if we haven't been given a specific subvolume * will mount by default if we haven't been given a specific subvolume
* to mount. * to mount.
*/ */
dir_id = btrfs_super_root_dir(&root->fs_info->super_copy); dir_id = btrfs_super_root_dir(root->fs_info->super_copy);
di = btrfs_lookup_dir_item(NULL, root, path, dir_id, "default", 7, 0); di = btrfs_lookup_dir_item(NULL, root, path, dir_id, "default", 7, 0);
if (IS_ERR(di)) { if (IS_ERR(di)) {
btrfs_free_path(path); btrfs_free_path(path);
...@@ -937,6 +937,13 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, ...@@ -937,6 +937,13 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
fs_info->fs_devices = fs_devices; fs_info->fs_devices = fs_devices;
tree_root->fs_info = fs_info; tree_root->fs_info = fs_info;
fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
if (!fs_info->super_copy || !fs_info->super_for_commit) {
error = -ENOMEM;
goto error_close_devices;
}
bdev = fs_devices->latest_bdev; bdev = fs_devices->latest_bdev;
s = sget(fs_type, btrfs_test_super, btrfs_set_super, tree_root); s = sget(fs_type, btrfs_test_super, btrfs_set_super, tree_root);
if (IS_ERR(s)) { if (IS_ERR(s)) {
...@@ -951,7 +958,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, ...@@ -951,7 +958,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
} }
btrfs_close_devices(fs_devices); btrfs_close_devices(fs_devices);
kfree(fs_info); free_fs_info(fs_info);
kfree(tree_root); kfree(tree_root);
} else { } else {
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
...@@ -979,7 +986,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, ...@@ -979,7 +986,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
error_close_devices: error_close_devices:
btrfs_close_devices(fs_devices); btrfs_close_devices(fs_devices);
kfree(fs_info); free_fs_info(fs_info);
kfree(tree_root); kfree(tree_root);
return ERR_PTR(error); return ERR_PTR(error);
} }
...@@ -1005,7 +1012,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) ...@@ -1005,7 +1012,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
if (root->fs_info->fs_devices->rw_devices == 0) if (root->fs_info->fs_devices->rw_devices == 0)
return -EACCES; return -EACCES;
if (btrfs_super_log_root(&root->fs_info->super_copy) != 0) if (btrfs_super_log_root(root->fs_info->super_copy) != 0)
return -EINVAL; return -EINVAL;
ret = btrfs_cleanup_fs_roots(root->fs_info); ret = btrfs_cleanup_fs_roots(root->fs_info);
...@@ -1171,7 +1178,7 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes) ...@@ -1171,7 +1178,7 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
{ {
struct btrfs_root *root = btrfs_sb(dentry->d_sb); struct btrfs_root *root = btrfs_sb(dentry->d_sb);
struct btrfs_super_block *disk_super = &root->fs_info->super_copy; struct btrfs_super_block *disk_super = root->fs_info->super_copy;
struct list_head *head = &root->fs_info->space_info; struct list_head *head = &root->fs_info->space_info;
struct btrfs_space_info *found; struct btrfs_space_info *found;
u64 total_used = 0; u64 total_used = 0;
......
...@@ -991,7 +991,7 @@ static void update_super_roots(struct btrfs_root *root) ...@@ -991,7 +991,7 @@ static void update_super_roots(struct btrfs_root *root)
struct btrfs_root_item *root_item; struct btrfs_root_item *root_item;
struct btrfs_super_block *super; struct btrfs_super_block *super;
super = &root->fs_info->super_copy; super = root->fs_info->super_copy;
root_item = &root->fs_info->chunk_root->root_item; root_item = &root->fs_info->chunk_root->root_item;
super->chunk_root = root_item->bytenr; super->chunk_root = root_item->bytenr;
...@@ -1301,12 +1301,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, ...@@ -1301,12 +1301,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
update_super_roots(root); update_super_roots(root);
if (!root->fs_info->log_root_recovering) { if (!root->fs_info->log_root_recovering) {
btrfs_set_super_log_root(&root->fs_info->super_copy, 0); btrfs_set_super_log_root(root->fs_info->super_copy, 0);
btrfs_set_super_log_root_level(&root->fs_info->super_copy, 0); btrfs_set_super_log_root_level(root->fs_info->super_copy, 0);
} }
memcpy(&root->fs_info->super_for_commit, &root->fs_info->super_copy, memcpy(root->fs_info->super_for_commit, root->fs_info->super_copy,
sizeof(root->fs_info->super_copy)); sizeof(*root->fs_info->super_copy));
trans->transaction->blocked = 0; trans->transaction->blocked = 0;
spin_lock(&root->fs_info->trans_lock); spin_lock(&root->fs_info->trans_lock);
......
...@@ -2118,9 +2118,9 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, ...@@ -2118,9 +2118,9 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
BUG_ON(ret); BUG_ON(ret);
btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark); btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
btrfs_set_super_log_root(&root->fs_info->super_for_commit, btrfs_set_super_log_root(root->fs_info->super_for_commit,
log_root_tree->node->start); log_root_tree->node->start);
btrfs_set_super_log_root_level(&root->fs_info->super_for_commit, btrfs_set_super_log_root_level(root->fs_info->super_for_commit,
btrfs_header_level(log_root_tree->node)); btrfs_header_level(log_root_tree->node));
log_root_tree->log_batch = 0; log_root_tree->log_batch = 0;
......
...@@ -1395,8 +1395,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ...@@ -1395,8 +1395,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
call_rcu(&device->rcu, free_device); call_rcu(&device->rcu, free_device);
mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
num_devices = btrfs_super_num_devices(&root->fs_info->super_copy) - 1; num_devices = btrfs_super_num_devices(root->fs_info->super_copy) - 1;
btrfs_set_super_num_devices(&root->fs_info->super_copy, num_devices); btrfs_set_super_num_devices(root->fs_info->super_copy, num_devices);
if (cur_devices->open_devices == 0) { if (cur_devices->open_devices == 0) {
struct btrfs_fs_devices *fs_devices; struct btrfs_fs_devices *fs_devices;
...@@ -1458,7 +1458,7 @@ static int btrfs_prepare_sprout(struct btrfs_trans_handle *trans, ...@@ -1458,7 +1458,7 @@ static int btrfs_prepare_sprout(struct btrfs_trans_handle *trans,
struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
struct btrfs_fs_devices *old_devices; struct btrfs_fs_devices *old_devices;
struct btrfs_fs_devices *seed_devices; struct btrfs_fs_devices *seed_devices;
struct btrfs_super_block *disk_super = &root->fs_info->super_copy; struct btrfs_super_block *disk_super = root->fs_info->super_copy;
struct btrfs_device *device; struct btrfs_device *device;
u64 super_flags; u64 super_flags;
...@@ -1706,12 +1706,12 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) ...@@ -1706,12 +1706,12 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
if (!blk_queue_nonrot(bdev_get_queue(bdev))) if (!blk_queue_nonrot(bdev_get_queue(bdev)))
root->fs_info->fs_devices->rotating = 1; root->fs_info->fs_devices->rotating = 1;
total_bytes = btrfs_super_total_bytes(&root->fs_info->super_copy); total_bytes = btrfs_super_total_bytes(root->fs_info->super_copy);
btrfs_set_super_total_bytes(&root->fs_info->super_copy, btrfs_set_super_total_bytes(root->fs_info->super_copy,
total_bytes + device->total_bytes); total_bytes + device->total_bytes);
total_bytes = btrfs_super_num_devices(&root->fs_info->super_copy); total_bytes = btrfs_super_num_devices(root->fs_info->super_copy);
btrfs_set_super_num_devices(&root->fs_info->super_copy, btrfs_set_super_num_devices(root->fs_info->super_copy,
total_bytes + 1); total_bytes + 1);
mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
...@@ -1802,7 +1802,7 @@ static int __btrfs_grow_device(struct btrfs_trans_handle *trans, ...@@ -1802,7 +1802,7 @@ static int __btrfs_grow_device(struct btrfs_trans_handle *trans,
struct btrfs_device *device, u64 new_size) struct btrfs_device *device, u64 new_size)
{ {
struct btrfs_super_block *super_copy = struct btrfs_super_block *super_copy =
&device->dev_root->fs_info->super_copy; device->dev_root->fs_info->super_copy;
u64 old_total = btrfs_super_total_bytes(super_copy); u64 old_total = btrfs_super_total_bytes(super_copy);
u64 diff = new_size - device->total_bytes; u64 diff = new_size - device->total_bytes;
...@@ -1861,7 +1861,7 @@ static int btrfs_free_chunk(struct btrfs_trans_handle *trans, ...@@ -1861,7 +1861,7 @@ static int btrfs_free_chunk(struct btrfs_trans_handle *trans,
static int btrfs_del_sys_chunk(struct btrfs_root *root, u64 chunk_objectid, u64 static int btrfs_del_sys_chunk(struct btrfs_root *root, u64 chunk_objectid, u64
chunk_offset) chunk_offset)
{ {
struct btrfs_super_block *super_copy = &root->fs_info->super_copy; struct btrfs_super_block *super_copy = root->fs_info->super_copy;
struct btrfs_disk_key *disk_key; struct btrfs_disk_key *disk_key;
struct btrfs_chunk *chunk; struct btrfs_chunk *chunk;
u8 *ptr; u8 *ptr;
...@@ -2187,7 +2187,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -2187,7 +2187,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
bool retried = false; bool retried = false;
struct extent_buffer *l; struct extent_buffer *l;
struct btrfs_key key; struct btrfs_key key;
struct btrfs_super_block *super_copy = &root->fs_info->super_copy; struct btrfs_super_block *super_copy = root->fs_info->super_copy;
u64 old_total = btrfs_super_total_bytes(super_copy); u64 old_total = btrfs_super_total_bytes(super_copy);
u64 old_size = device->total_bytes; u64 old_size = device->total_bytes;
u64 diff = device->total_bytes - new_size; u64 diff = device->total_bytes - new_size;
...@@ -2311,7 +2311,7 @@ static int btrfs_add_system_chunk(struct btrfs_trans_handle *trans, ...@@ -2311,7 +2311,7 @@ static int btrfs_add_system_chunk(struct btrfs_trans_handle *trans,
struct btrfs_key *key, struct btrfs_key *key,
struct btrfs_chunk *chunk, int item_size) struct btrfs_chunk *chunk, int item_size)
{ {
struct btrfs_super_block *super_copy = &root->fs_info->super_copy; struct btrfs_super_block *super_copy = root->fs_info->super_copy;
struct btrfs_disk_key disk_key; struct btrfs_disk_key disk_key;
u32 array_size; u32 array_size;
u8 *ptr; u8 *ptr;
...@@ -3653,7 +3653,7 @@ static int read_one_dev(struct btrfs_root *root, ...@@ -3653,7 +3653,7 @@ static int read_one_dev(struct btrfs_root *root,
int btrfs_read_sys_array(struct btrfs_root *root) int btrfs_read_sys_array(struct btrfs_root *root)
{ {
struct btrfs_super_block *super_copy = &root->fs_info->super_copy; struct btrfs_super_block *super_copy = root->fs_info->super_copy;
struct extent_buffer *sb; struct extent_buffer *sb;
struct btrfs_disk_key *disk_key; struct btrfs_disk_key *disk_key;
struct btrfs_chunk *chunk; struct btrfs_chunk *chunk;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment