diff options
author | David Sterba <dsterba@suse.cz> | 2011-04-13 09:41:04 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2011-11-06 03:04:01 -0500 |
commit | 6c41761fc6efe1503103a1afe03a6635c0b5d4ec (patch) | |
tree | 08ad34d43aac48e8f8143a0b1fa07141df8f202a /fs | |
parent | c8174313a8102e874aaa321e2fc4c7c460a87151 (diff) |
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: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/compression.c | 3 | ||||
-rw-r--r-- | fs/btrfs/ctree.h | 16 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 33 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 16 | ||||
-rw-r--r-- | fs/btrfs/file-item.c | 17 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 2 | ||||
-rw-r--r-- | fs/btrfs/ioctl.c | 8 | ||||
-rw-r--r-- | fs/btrfs/scrub.c | 2 | ||||
-rw-r--r-- | fs/btrfs/super.c | 19 | ||||
-rw-r--r-- | fs/btrfs/transaction.c | 10 | ||||
-rw-r--r-- | fs/btrfs/tree-log.c | 4 | ||||
-rw-r--r-- | fs/btrfs/volumes.c | 24 |
12 files changed, 78 insertions, 76 deletions
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 8ec5d86f1734..14f1c5a0b2d2 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c | |||
@@ -85,7 +85,8 @@ struct compressed_bio { | |||
85 | static inline int compressed_bio_size(struct btrfs_root *root, | 85 | static inline int compressed_bio_size(struct btrfs_root *root, |
86 | unsigned long disk_size) | 86 | unsigned long disk_size) |
87 | { | 87 | { |
88 | u16 csum_size = btrfs_super_csum_size(&root->fs_info->super_copy); | 88 | u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); |
89 | |||
89 | return sizeof(struct compressed_bio) + | 90 | return sizeof(struct compressed_bio) + |
90 | ((disk_size + root->sectorsize - 1) / root->sectorsize) * | 91 | ((disk_size + root->sectorsize - 1) / root->sectorsize) * |
91 | csum_size; | 92 | csum_size; |
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index f63c9b3f6e08..5181c53c1124 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -936,8 +936,8 @@ struct btrfs_fs_info { | |||
936 | wait_queue_head_t transaction_blocked_wait; | 936 | wait_queue_head_t transaction_blocked_wait; |
937 | wait_queue_head_t async_submit_wait; | 937 | wait_queue_head_t async_submit_wait; |
938 | 938 | ||
939 | struct btrfs_super_block super_copy; | 939 | struct btrfs_super_block *super_copy; |
940 | struct btrfs_super_block super_for_commit; | 940 | struct btrfs_super_block *super_for_commit; |
941 | struct block_device *__bdev; | 941 | struct block_device *__bdev; |
942 | struct super_block *sb; | 942 | struct super_block *sb; |
943 | struct inode *btree_inode; | 943 | struct inode *btree_inode; |
@@ -2387,6 +2387,18 @@ static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info) | |||
2387 | smp_mb(); | 2387 | smp_mb(); |
2388 | return fs_info->closing; | 2388 | return fs_info->closing; |
2389 | } | 2389 | } |
2390 | static inline void free_fs_info(struct btrfs_fs_info *fs_info) | ||
2391 | { | ||
2392 | kfree(fs_info->delayed_root); | ||
2393 | kfree(fs_info->extent_root); | ||
2394 | kfree(fs_info->tree_root); | ||
2395 | kfree(fs_info->chunk_root); | ||
2396 | kfree(fs_info->dev_root); | ||
2397 | kfree(fs_info->csum_root); | ||
2398 | kfree(fs_info->super_copy); | ||
2399 | kfree(fs_info->super_for_commit); | ||
2400 | kfree(fs_info); | ||
2401 | } | ||
2390 | 2402 | ||
2391 | /* root-item.c */ | 2403 | /* root-item.c */ |
2392 | int btrfs_find_root_ref(struct btrfs_root *tree_root, | 2404 | int btrfs_find_root_ref(struct btrfs_root *tree_root, |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 6f58911ece0d..761717c98278 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -256,8 +256,7 @@ void btrfs_csum_final(u32 crc, char *result) | |||
256 | static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, | 256 | static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, |
257 | int verify) | 257 | int verify) |
258 | { | 258 | { |
259 | u16 csum_size = | 259 | u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); |
260 | btrfs_super_csum_size(&root->fs_info->super_copy); | ||
261 | char *result = NULL; | 260 | char *result = NULL; |
262 | unsigned long len; | 261 | unsigned long len; |
263 | unsigned long cur_len; | 262 | unsigned long cur_len; |
@@ -1766,14 +1765,14 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1766 | goto fail_alloc; | 1765 | goto fail_alloc; |
1767 | } | 1766 | } |
1768 | 1767 | ||
1769 | memcpy(&fs_info->super_copy, bh->b_data, sizeof(fs_info->super_copy)); | 1768 | memcpy(fs_info->super_copy, bh->b_data, sizeof(*fs_info->super_copy)); |
1770 | memcpy(&fs_info->super_for_commit, &fs_info->super_copy, | 1769 | memcpy(fs_info->super_for_commit, fs_info->super_copy, |
1771 | sizeof(fs_info->super_for_commit)); | 1770 | sizeof(*fs_info->super_for_commit)); |
1772 | brelse(bh); | 1771 | brelse(bh); |
1773 | 1772 | ||
1774 | memcpy(fs_info->fsid, fs_info->super_copy.fsid, BTRFS_FSID_SIZE); | 1773 | memcpy(fs_info->fsid, fs_info->super_copy->fsid, BTRFS_FSID_SIZE); |
1775 | 1774 | ||
1776 | disk_super = &fs_info->super_copy; | 1775 | disk_super = fs_info->super_copy; |
1777 | if (!btrfs_super_root(disk_super)) | 1776 | if (!btrfs_super_root(disk_super)) |
1778 | goto fail_alloc; | 1777 | goto fail_alloc; |
1779 | 1778 | ||
@@ -2152,7 +2151,6 @@ fail_sb_buffer: | |||
2152 | btrfs_stop_workers(&fs_info->delayed_workers); | 2151 | btrfs_stop_workers(&fs_info->delayed_workers); |
2153 | btrfs_stop_workers(&fs_info->caching_workers); | 2152 | btrfs_stop_workers(&fs_info->caching_workers); |
2154 | fail_alloc: | 2153 | fail_alloc: |
2155 | kfree(fs_info->delayed_root); | ||
2156 | fail_iput: | 2154 | fail_iput: |
2157 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); | 2155 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); |
2158 | iput(fs_info->btree_inode); | 2156 | iput(fs_info->btree_inode); |
@@ -2164,12 +2162,7 @@ fail_bdi: | |||
2164 | fail_srcu: | 2162 | fail_srcu: |
2165 | cleanup_srcu_struct(&fs_info->subvol_srcu); | 2163 | cleanup_srcu_struct(&fs_info->subvol_srcu); |
2166 | fail: | 2164 | fail: |
2167 | kfree(extent_root); | 2165 | free_fs_info(fs_info); |
2168 | kfree(tree_root); | ||
2169 | kfree(fs_info); | ||
2170 | kfree(chunk_root); | ||
2171 | kfree(dev_root); | ||
2172 | kfree(csum_root); | ||
2173 | return ERR_PTR(err); | 2166 | return ERR_PTR(err); |
2174 | } | 2167 | } |
2175 | 2168 | ||
@@ -2338,10 +2331,10 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors) | |||
2338 | int total_errors = 0; | 2331 | int total_errors = 0; |
2339 | u64 flags; | 2332 | u64 flags; |
2340 | 2333 | ||
2341 | max_errors = btrfs_super_num_devices(&root->fs_info->super_copy) - 1; | 2334 | max_errors = btrfs_super_num_devices(root->fs_info->super_copy) - 1; |
2342 | do_barriers = !btrfs_test_opt(root, NOBARRIER); | 2335 | do_barriers = !btrfs_test_opt(root, NOBARRIER); |
2343 | 2336 | ||
2344 | sb = &root->fs_info->super_for_commit; | 2337 | sb = root->fs_info->super_for_commit; |
2345 | dev_item = &sb->dev_item; | 2338 | dev_item = &sb->dev_item; |
2346 | 2339 | ||
2347 | mutex_lock(&root->fs_info->fs_devices->device_list_mutex); | 2340 | mutex_lock(&root->fs_info->fs_devices->device_list_mutex); |
@@ -2603,7 +2596,6 @@ int close_ctree(struct btrfs_root *root) | |||
2603 | del_fs_roots(fs_info); | 2596 | del_fs_roots(fs_info); |
2604 | 2597 | ||
2605 | iput(fs_info->btree_inode); | 2598 | iput(fs_info->btree_inode); |
2606 | kfree(fs_info->delayed_root); | ||
2607 | 2599 | ||
2608 | btrfs_stop_workers(&fs_info->generic_worker); | 2600 | btrfs_stop_workers(&fs_info->generic_worker); |
2609 | btrfs_stop_workers(&fs_info->fixup_workers); | 2601 | btrfs_stop_workers(&fs_info->fixup_workers); |
@@ -2624,12 +2616,7 @@ int close_ctree(struct btrfs_root *root) | |||
2624 | bdi_destroy(&fs_info->bdi); | 2616 | bdi_destroy(&fs_info->bdi); |
2625 | cleanup_srcu_struct(&fs_info->subvol_srcu); | 2617 | cleanup_srcu_struct(&fs_info->subvol_srcu); |
2626 | 2618 | ||
2627 | kfree(fs_info->extent_root); | 2619 | free_fs_info(fs_info); |
2628 | kfree(fs_info->tree_root); | ||
2629 | kfree(fs_info->chunk_root); | ||
2630 | kfree(fs_info->dev_root); | ||
2631 | kfree(fs_info->csum_root); | ||
2632 | kfree(fs_info); | ||
2633 | 2620 | ||
2634 | return 0; | 2621 | return 0; |
2635 | } | 2622 | } |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index cb7626646bba..782eb3ea8edf 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -3209,7 +3209,7 @@ static int should_alloc_chunk(struct btrfs_root *root, | |||
3209 | * about 1% of the FS size. | 3209 | * about 1% of the FS size. |
3210 | */ | 3210 | */ |
3211 | if (force == CHUNK_ALLOC_LIMITED) { | 3211 | if (force == CHUNK_ALLOC_LIMITED) { |
3212 | thresh = btrfs_super_total_bytes(&root->fs_info->super_copy); | 3212 | thresh = btrfs_super_total_bytes(root->fs_info->super_copy); |
3213 | thresh = max_t(u64, 64 * 1024 * 1024, | 3213 | thresh = max_t(u64, 64 * 1024 * 1024, |
3214 | div_factor_fine(thresh, 1)); | 3214 | div_factor_fine(thresh, 1)); |
3215 | 3215 | ||
@@ -3231,7 +3231,7 @@ static int should_alloc_chunk(struct btrfs_root *root, | |||
3231 | if (num_allocated + alloc_bytes < div_factor(num_bytes, 8)) | 3231 | if (num_allocated + alloc_bytes < div_factor(num_bytes, 8)) |
3232 | return 0; | 3232 | return 0; |
3233 | 3233 | ||
3234 | thresh = btrfs_super_total_bytes(&root->fs_info->super_copy); | 3234 | thresh = btrfs_super_total_bytes(root->fs_info->super_copy); |
3235 | 3235 | ||
3236 | /* 256MB or 5% of the FS */ | 3236 | /* 256MB or 5% of the FS */ |
3237 | thresh = max_t(u64, 256 * 1024 * 1024, div_factor_fine(thresh, 5)); | 3237 | 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 | u64 num_bytes; | 3843 | u64 num_bytes; |
3844 | u64 meta_used; | 3844 | u64 meta_used; |
3845 | u64 data_used; | 3845 | u64 data_used; |
3846 | int csum_size = btrfs_super_csum_size(&fs_info->super_copy); | 3846 | int csum_size = btrfs_super_csum_size(fs_info->super_copy); |
3847 | 3847 | ||
3848 | sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_DATA); | 3848 | sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_DATA); |
3849 | spin_lock(&sinfo->lock); | 3849 | spin_lock(&sinfo->lock); |
@@ -4222,12 +4222,12 @@ static int update_block_group(struct btrfs_trans_handle *trans, | |||
4222 | 4222 | ||
4223 | /* block accounting for super block */ | 4223 | /* block accounting for super block */ |
4224 | spin_lock(&info->delalloc_lock); | 4224 | spin_lock(&info->delalloc_lock); |
4225 | old_val = btrfs_super_bytes_used(&info->super_copy); | 4225 | old_val = btrfs_super_bytes_used(info->super_copy); |
4226 | if (alloc) | 4226 | if (alloc) |
4227 | old_val += num_bytes; | 4227 | old_val += num_bytes; |
4228 | else | 4228 | else |
4229 | old_val -= num_bytes; | 4229 | old_val -= num_bytes; |
4230 | btrfs_set_super_bytes_used(&info->super_copy, old_val); | 4230 | btrfs_set_super_bytes_used(info->super_copy, old_val); |
4231 | spin_unlock(&info->delalloc_lock); | 4231 | spin_unlock(&info->delalloc_lock); |
4232 | 4232 | ||
4233 | while (total) { | 4233 | while (total) { |
@@ -7127,9 +7127,9 @@ int btrfs_read_block_groups(struct btrfs_root *root) | |||
7127 | return -ENOMEM; | 7127 | return -ENOMEM; |
7128 | path->reada = 1; | 7128 | path->reada = 1; |
7129 | 7129 | ||
7130 | cache_gen = btrfs_super_cache_generation(&root->fs_info->super_copy); | 7130 | cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy); |
7131 | if (btrfs_test_opt(root, SPACE_CACHE) && | 7131 | if (btrfs_test_opt(root, SPACE_CACHE) && |
7132 | btrfs_super_generation(&root->fs_info->super_copy) != cache_gen) | 7132 | btrfs_super_generation(root->fs_info->super_copy) != cache_gen) |
7133 | need_clear = 1; | 7133 | need_clear = 1; |
7134 | if (btrfs_test_opt(root, CLEAR_CACHE)) | 7134 | if (btrfs_test_opt(root, CLEAR_CACHE)) |
7135 | need_clear = 1; | 7135 | need_clear = 1; |
@@ -7458,7 +7458,7 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info) | |||
7458 | int mixed = 0; | 7458 | int mixed = 0; |
7459 | int ret; | 7459 | int ret; |
7460 | 7460 | ||
7461 | disk_super = &fs_info->super_copy; | 7461 | disk_super = fs_info->super_copy; |
7462 | if (!btrfs_super_root(disk_super)) | 7462 | if (!btrfs_super_root(disk_super)) |
7463 | return 1; | 7463 | return 1; |
7464 | 7464 | ||
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index a1cb7821becd..c7fb3a4247d3 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -91,8 +91,7 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, | |||
91 | struct btrfs_csum_item *item; | 91 | struct btrfs_csum_item *item; |
92 | struct extent_buffer *leaf; | 92 | struct extent_buffer *leaf; |
93 | u64 csum_offset = 0; | 93 | u64 csum_offset = 0; |
94 | u16 csum_size = | 94 | u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); |
95 | btrfs_super_csum_size(&root->fs_info->super_copy); | ||
96 | int csums_in_item; | 95 | int csums_in_item; |
97 | 96 | ||
98 | file_key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; | 97 | file_key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; |
@@ -162,8 +161,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, | |||
162 | u64 item_last_offset = 0; | 161 | u64 item_last_offset = 0; |
163 | u64 disk_bytenr; | 162 | u64 disk_bytenr; |
164 | u32 diff; | 163 | u32 diff; |
165 | u16 csum_size = | 164 | u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); |
166 | btrfs_super_csum_size(&root->fs_info->super_copy); | ||
167 | int ret; | 165 | int ret; |
168 | struct btrfs_path *path; | 166 | struct btrfs_path *path; |
169 | struct btrfs_csum_item *item = NULL; | 167 | struct btrfs_csum_item *item = NULL; |
@@ -290,7 +288,7 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, | |||
290 | int ret; | 288 | int ret; |
291 | size_t size; | 289 | size_t size; |
292 | u64 csum_end; | 290 | u64 csum_end; |
293 | u16 csum_size = btrfs_super_csum_size(&root->fs_info->super_copy); | 291 | u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); |
294 | 292 | ||
295 | path = btrfs_alloc_path(); | 293 | path = btrfs_alloc_path(); |
296 | if (!path) | 294 | if (!path) |
@@ -492,8 +490,7 @@ static noinline int truncate_one_csum(struct btrfs_trans_handle *trans, | |||
492 | u64 bytenr, u64 len) | 490 | u64 bytenr, u64 len) |
493 | { | 491 | { |
494 | struct extent_buffer *leaf; | 492 | struct extent_buffer *leaf; |
495 | u16 csum_size = | 493 | u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); |
496 | btrfs_super_csum_size(&root->fs_info->super_copy); | ||
497 | u64 csum_end; | 494 | u64 csum_end; |
498 | u64 end_byte = bytenr + len; | 495 | u64 end_byte = bytenr + len; |
499 | u32 blocksize_bits = root->fs_info->sb->s_blocksize_bits; | 496 | u32 blocksize_bits = root->fs_info->sb->s_blocksize_bits; |
@@ -549,8 +546,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, | |||
549 | u64 csum_end; | 546 | u64 csum_end; |
550 | struct extent_buffer *leaf; | 547 | struct extent_buffer *leaf; |
551 | int ret; | 548 | int ret; |
552 | u16 csum_size = | 549 | u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); |
553 | btrfs_super_csum_size(&root->fs_info->super_copy); | ||
554 | int blocksize_bits = root->fs_info->sb->s_blocksize_bits; | 550 | int blocksize_bits = root->fs_info->sb->s_blocksize_bits; |
555 | 551 | ||
556 | root = root->fs_info->csum_root; | 552 | root = root->fs_info->csum_root; |
@@ -676,8 +672,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, | |||
676 | struct btrfs_sector_sum *sector_sum; | 672 | struct btrfs_sector_sum *sector_sum; |
677 | u32 nritems; | 673 | u32 nritems; |
678 | u32 ins_size; | 674 | u32 ins_size; |
679 | u16 csum_size = | 675 | u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); |
680 | btrfs_super_csum_size(&root->fs_info->super_copy); | ||
681 | 676 | ||
682 | path = btrfs_alloc_path(); | 677 | path = btrfs_alloc_path(); |
683 | if (!path) | 678 | if (!path) |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a8586e10953c..b6b612e14ed7 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -824,7 +824,7 @@ static noinline int cow_file_range(struct inode *inode, | |||
824 | } | 824 | } |
825 | 825 | ||
826 | BUG_ON(disk_num_bytes > | 826 | BUG_ON(disk_num_bytes > |
827 | btrfs_super_total_bytes(&root->fs_info->super_copy)); | 827 | btrfs_super_total_bytes(root->fs_info->super_copy)); |
828 | 828 | ||
829 | alloc_hint = get_extent_allocation_hint(inode, start, num_bytes); | 829 | alloc_hint = get_extent_allocation_hint(inode, start, num_bytes); |
830 | btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0); | 830 | btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0); |
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 33aae13cc74b..8f6e14279409 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -282,7 +282,7 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg) | |||
282 | struct fstrim_range range; | 282 | struct fstrim_range range; |
283 | u64 minlen = ULLONG_MAX; | 283 | u64 minlen = ULLONG_MAX; |
284 | u64 num_devices = 0; | 284 | u64 num_devices = 0; |
285 | u64 total_bytes = btrfs_super_total_bytes(&root->fs_info->super_copy); | 285 | u64 total_bytes = btrfs_super_total_bytes(root->fs_info->super_copy); |
286 | int ret; | 286 | int ret; |
287 | 287 | ||
288 | if (!capable(CAP_SYS_ADMIN)) | 288 | if (!capable(CAP_SYS_ADMIN)) |
@@ -1164,7 +1164,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, | |||
1164 | mutex_unlock(&inode->i_mutex); | 1164 | mutex_unlock(&inode->i_mutex); |
1165 | } | 1165 | } |
1166 | 1166 | ||
1167 | disk_super = &root->fs_info->super_copy; | 1167 | disk_super = root->fs_info->super_copy; |
1168 | features = btrfs_super_incompat_flags(disk_super); | 1168 | features = btrfs_super_incompat_flags(disk_super); |
1169 | if (range->compress_type == BTRFS_COMPRESS_LZO) { | 1169 | if (range->compress_type == BTRFS_COMPRESS_LZO) { |
1170 | features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO; | 1170 | features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO; |
@@ -2613,7 +2613,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp) | |||
2613 | return PTR_ERR(trans); | 2613 | return PTR_ERR(trans); |
2614 | } | 2614 | } |
2615 | 2615 | ||
2616 | dir_id = btrfs_super_root_dir(&root->fs_info->super_copy); | 2616 | dir_id = btrfs_super_root_dir(root->fs_info->super_copy); |
2617 | di = btrfs_lookup_dir_item(trans, root->fs_info->tree_root, path, | 2617 | di = btrfs_lookup_dir_item(trans, root->fs_info->tree_root, path, |
2618 | dir_id, "default", 7, 1); | 2618 | dir_id, "default", 7, 1); |
2619 | if (IS_ERR_OR_NULL(di)) { | 2619 | if (IS_ERR_OR_NULL(di)) { |
@@ -2629,7 +2629,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp) | |||
2629 | btrfs_mark_buffer_dirty(path->nodes[0]); | 2629 | btrfs_mark_buffer_dirty(path->nodes[0]); |
2630 | btrfs_free_path(path); | 2630 | btrfs_free_path(path); |
2631 | 2631 | ||
2632 | disk_super = &root->fs_info->super_copy; | 2632 | disk_super = root->fs_info->super_copy; |
2633 | features = btrfs_super_incompat_flags(disk_super); | 2633 | features = btrfs_super_incompat_flags(disk_super); |
2634 | if (!(features & BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL)) { | 2634 | if (!(features & BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL)) { |
2635 | features |= BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL; | 2635 | features |= BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL; |
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index a8d03d5efb5d..69a600f07763 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c | |||
@@ -182,7 +182,7 @@ struct scrub_dev *scrub_setup_dev(struct btrfs_device *dev) | |||
182 | sdev->curr = -1; | 182 | sdev->curr = -1; |
183 | atomic_set(&sdev->in_flight, 0); | 183 | atomic_set(&sdev->in_flight, 0); |
184 | atomic_set(&sdev->cancel_req, 0); | 184 | atomic_set(&sdev->cancel_req, 0); |
185 | sdev->csum_size = btrfs_super_csum_size(&fs_info->super_copy); | 185 | sdev->csum_size = btrfs_super_csum_size(fs_info->super_copy); |
186 | INIT_LIST_HEAD(&sdev->csum_list); | 186 | INIT_LIST_HEAD(&sdev->csum_list); |
187 | 187 | ||
188 | spin_lock_init(&sdev->list_lock); | 188 | spin_lock_init(&sdev->list_lock); |
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 5429b1fa0bfc..f7e9de724ef2 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -216,7 +216,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
216 | char *compress_type; | 216 | char *compress_type; |
217 | bool compress_force = false; | 217 | bool compress_force = false; |
218 | 218 | ||
219 | cache_gen = btrfs_super_cache_generation(&root->fs_info->super_copy); | 219 | cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy); |
220 | if (cache_gen) | 220 | if (cache_gen) |
221 | btrfs_set_opt(info->mount_opt, SPACE_CACHE); | 221 | btrfs_set_opt(info->mount_opt, SPACE_CACHE); |
222 | 222 | ||
@@ -524,7 +524,7 @@ static struct dentry *get_default_root(struct super_block *sb, | |||
524 | * will mount by default if we haven't been given a specific subvolume | 524 | * will mount by default if we haven't been given a specific subvolume |
525 | * to mount. | 525 | * to mount. |
526 | */ | 526 | */ |
527 | dir_id = btrfs_super_root_dir(&root->fs_info->super_copy); | 527 | dir_id = btrfs_super_root_dir(root->fs_info->super_copy); |
528 | di = btrfs_lookup_dir_item(NULL, root, path, dir_id, "default", 7, 0); | 528 | di = btrfs_lookup_dir_item(NULL, root, path, dir_id, "default", 7, 0); |
529 | if (IS_ERR(di)) { | 529 | if (IS_ERR(di)) { |
530 | btrfs_free_path(path); | 530 | btrfs_free_path(path); |
@@ -937,6 +937,13 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, | |||
937 | fs_info->fs_devices = fs_devices; | 937 | fs_info->fs_devices = fs_devices; |
938 | tree_root->fs_info = fs_info; | 938 | tree_root->fs_info = fs_info; |
939 | 939 | ||
940 | fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS); | ||
941 | fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS); | ||
942 | if (!fs_info->super_copy || !fs_info->super_for_commit) { | ||
943 | error = -ENOMEM; | ||
944 | goto error_close_devices; | ||
945 | } | ||
946 | |||
940 | bdev = fs_devices->latest_bdev; | 947 | bdev = fs_devices->latest_bdev; |
941 | s = sget(fs_type, btrfs_test_super, btrfs_set_super, tree_root); | 948 | s = sget(fs_type, btrfs_test_super, btrfs_set_super, tree_root); |
942 | if (IS_ERR(s)) { | 949 | if (IS_ERR(s)) { |
@@ -951,7 +958,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, | |||
951 | } | 958 | } |
952 | 959 | ||
953 | btrfs_close_devices(fs_devices); | 960 | btrfs_close_devices(fs_devices); |
954 | kfree(fs_info); | 961 | free_fs_info(fs_info); |
955 | kfree(tree_root); | 962 | kfree(tree_root); |
956 | } else { | 963 | } else { |
957 | char b[BDEVNAME_SIZE]; | 964 | char b[BDEVNAME_SIZE]; |
@@ -979,7 +986,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, | |||
979 | 986 | ||
980 | error_close_devices: | 987 | error_close_devices: |
981 | btrfs_close_devices(fs_devices); | 988 | btrfs_close_devices(fs_devices); |
982 | kfree(fs_info); | 989 | free_fs_info(fs_info); |
983 | kfree(tree_root); | 990 | kfree(tree_root); |
984 | return ERR_PTR(error); | 991 | return ERR_PTR(error); |
985 | } | 992 | } |
@@ -1005,7 +1012,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) | |||
1005 | if (root->fs_info->fs_devices->rw_devices == 0) | 1012 | if (root->fs_info->fs_devices->rw_devices == 0) |
1006 | return -EACCES; | 1013 | return -EACCES; |
1007 | 1014 | ||
1008 | if (btrfs_super_log_root(&root->fs_info->super_copy) != 0) | 1015 | if (btrfs_super_log_root(root->fs_info->super_copy) != 0) |
1009 | return -EINVAL; | 1016 | return -EINVAL; |
1010 | 1017 | ||
1011 | ret = btrfs_cleanup_fs_roots(root->fs_info); | 1018 | 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 | static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) | 1178 | static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
1172 | { | 1179 | { |
1173 | struct btrfs_root *root = btrfs_sb(dentry->d_sb); | 1180 | struct btrfs_root *root = btrfs_sb(dentry->d_sb); |
1174 | struct btrfs_super_block *disk_super = &root->fs_info->super_copy; | 1181 | struct btrfs_super_block *disk_super = root->fs_info->super_copy; |
1175 | struct list_head *head = &root->fs_info->space_info; | 1182 | struct list_head *head = &root->fs_info->space_info; |
1176 | struct btrfs_space_info *found; | 1183 | struct btrfs_space_info *found; |
1177 | u64 total_used = 0; | 1184 | u64 total_used = 0; |
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 29bef63e23ba..373c7ec1a026 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -991,7 +991,7 @@ static void update_super_roots(struct btrfs_root *root) | |||
991 | struct btrfs_root_item *root_item; | 991 | struct btrfs_root_item *root_item; |
992 | struct btrfs_super_block *super; | 992 | struct btrfs_super_block *super; |
993 | 993 | ||
994 | super = &root->fs_info->super_copy; | 994 | super = root->fs_info->super_copy; |
995 | 995 | ||
996 | root_item = &root->fs_info->chunk_root->root_item; | 996 | root_item = &root->fs_info->chunk_root->root_item; |
997 | super->chunk_root = root_item->bytenr; | 997 | super->chunk_root = root_item->bytenr; |
@@ -1301,12 +1301,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, | |||
1301 | update_super_roots(root); | 1301 | update_super_roots(root); |
1302 | 1302 | ||
1303 | if (!root->fs_info->log_root_recovering) { | 1303 | if (!root->fs_info->log_root_recovering) { |
1304 | btrfs_set_super_log_root(&root->fs_info->super_copy, 0); | 1304 | btrfs_set_super_log_root(root->fs_info->super_copy, 0); |
1305 | btrfs_set_super_log_root_level(&root->fs_info->super_copy, 0); | 1305 | btrfs_set_super_log_root_level(root->fs_info->super_copy, 0); |
1306 | } | 1306 | } |
1307 | 1307 | ||
1308 | memcpy(&root->fs_info->super_for_commit, &root->fs_info->super_copy, | 1308 | memcpy(root->fs_info->super_for_commit, root->fs_info->super_copy, |
1309 | sizeof(root->fs_info->super_copy)); | 1309 | sizeof(*root->fs_info->super_copy)); |
1310 | 1310 | ||
1311 | trans->transaction->blocked = 0; | 1311 | trans->transaction->blocked = 0; |
1312 | spin_lock(&root->fs_info->trans_lock); | 1312 | spin_lock(&root->fs_info->trans_lock); |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 8ca1b6b83bd1..f4d81c06d48f 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -2118,9 +2118,9 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2118 | BUG_ON(ret); | 2118 | BUG_ON(ret); |
2119 | btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark); | 2119 | btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark); |
2120 | 2120 | ||
2121 | btrfs_set_super_log_root(&root->fs_info->super_for_commit, | 2121 | btrfs_set_super_log_root(root->fs_info->super_for_commit, |
2122 | log_root_tree->node->start); | 2122 | log_root_tree->node->start); |
2123 | btrfs_set_super_log_root_level(&root->fs_info->super_for_commit, | 2123 | btrfs_set_super_log_root_level(root->fs_info->super_for_commit, |
2124 | btrfs_header_level(log_root_tree->node)); | 2124 | btrfs_header_level(log_root_tree->node)); |
2125 | 2125 | ||
2126 | log_root_tree->log_batch = 0; | 2126 | log_root_tree->log_batch = 0; |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index c6938b45e0fd..c3b45564048e 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -1395,8 +1395,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) | |||
1395 | call_rcu(&device->rcu, free_device); | 1395 | call_rcu(&device->rcu, free_device); |
1396 | mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); | 1396 | mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); |
1397 | 1397 | ||
1398 | num_devices = btrfs_super_num_devices(&root->fs_info->super_copy) - 1; | 1398 | num_devices = btrfs_super_num_devices(root->fs_info->super_copy) - 1; |
1399 | btrfs_set_super_num_devices(&root->fs_info->super_copy, num_devices); | 1399 | btrfs_set_super_num_devices(root->fs_info->super_copy, num_devices); |
1400 | 1400 | ||
1401 | if (cur_devices->open_devices == 0) { | 1401 | if (cur_devices->open_devices == 0) { |
1402 | struct btrfs_fs_devices *fs_devices; | 1402 | struct btrfs_fs_devices *fs_devices; |
@@ -1458,7 +1458,7 @@ static int btrfs_prepare_sprout(struct btrfs_trans_handle *trans, | |||
1458 | struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; | 1458 | struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; |
1459 | struct btrfs_fs_devices *old_devices; | 1459 | struct btrfs_fs_devices *old_devices; |
1460 | struct btrfs_fs_devices *seed_devices; | 1460 | struct btrfs_fs_devices *seed_devices; |
1461 | struct btrfs_super_block *disk_super = &root->fs_info->super_copy; | 1461 | struct btrfs_super_block *disk_super = root->fs_info->super_copy; |
1462 | struct btrfs_device *device; | 1462 | struct btrfs_device *device; |
1463 | u64 super_flags; | 1463 | u64 super_flags; |
1464 | 1464 | ||
@@ -1706,12 +1706,12 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) | |||
1706 | if (!blk_queue_nonrot(bdev_get_queue(bdev))) | 1706 | if (!blk_queue_nonrot(bdev_get_queue(bdev))) |
1707 | root->fs_info->fs_devices->rotating = 1; | 1707 | root->fs_info->fs_devices->rotating = 1; |
1708 | 1708 | ||
1709 | total_bytes = btrfs_super_total_bytes(&root->fs_info->super_copy); | 1709 | total_bytes = btrfs_super_total_bytes(root->fs_info->super_copy); |
1710 | btrfs_set_super_total_bytes(&root->fs_info->super_copy, | 1710 | btrfs_set_super_total_bytes(root->fs_info->super_copy, |
1711 | total_bytes + device->total_bytes); | 1711 | total_bytes + device->total_bytes); |
1712 | 1712 | ||
1713 | total_bytes = btrfs_super_num_devices(&root->fs_info->super_copy); | 1713 | total_bytes = btrfs_super_num_devices(root->fs_info->super_copy); |
1714 | btrfs_set_super_num_devices(&root->fs_info->super_copy, | 1714 | btrfs_set_super_num_devices(root->fs_info->super_copy, |
1715 | total_bytes + 1); | 1715 | total_bytes + 1); |
1716 | mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); | 1716 | mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); |
1717 | 1717 | ||
@@ -1802,7 +1802,7 @@ static int __btrfs_grow_device(struct btrfs_trans_handle *trans, | |||
1802 | struct btrfs_device *device, u64 new_size) | 1802 | struct btrfs_device *device, u64 new_size) |
1803 | { | 1803 | { |
1804 | struct btrfs_super_block *super_copy = | 1804 | struct btrfs_super_block *super_copy = |
1805 | &device->dev_root->fs_info->super_copy; | 1805 | device->dev_root->fs_info->super_copy; |
1806 | u64 old_total = btrfs_super_total_bytes(super_copy); | 1806 | u64 old_total = btrfs_super_total_bytes(super_copy); |
1807 | u64 diff = new_size - device->total_bytes; | 1807 | u64 diff = new_size - device->total_bytes; |
1808 | 1808 | ||
@@ -1861,7 +1861,7 @@ static int btrfs_free_chunk(struct btrfs_trans_handle *trans, | |||
1861 | static int btrfs_del_sys_chunk(struct btrfs_root *root, u64 chunk_objectid, u64 | 1861 | static int btrfs_del_sys_chunk(struct btrfs_root *root, u64 chunk_objectid, u64 |
1862 | chunk_offset) | 1862 | chunk_offset) |
1863 | { | 1863 | { |
1864 | struct btrfs_super_block *super_copy = &root->fs_info->super_copy; | 1864 | struct btrfs_super_block *super_copy = root->fs_info->super_copy; |
1865 | struct btrfs_disk_key *disk_key; | 1865 | struct btrfs_disk_key *disk_key; |
1866 | struct btrfs_chunk *chunk; | 1866 | struct btrfs_chunk *chunk; |
1867 | u8 *ptr; | 1867 | u8 *ptr; |
@@ -2187,7 +2187,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) | |||
2187 | bool retried = false; | 2187 | bool retried = false; |
2188 | struct extent_buffer *l; | 2188 | struct extent_buffer *l; |
2189 | struct btrfs_key key; | 2189 | struct btrfs_key key; |
2190 | struct btrfs_super_block *super_copy = &root->fs_info->super_copy; | 2190 | struct btrfs_super_block *super_copy = root->fs_info->super_copy; |
2191 | u64 old_total = btrfs_super_total_bytes(super_copy); | 2191 | u64 old_total = btrfs_super_total_bytes(super_copy); |
2192 | u64 old_size = device->total_bytes; | 2192 | u64 old_size = device->total_bytes; |
2193 | u64 diff = device->total_bytes - new_size; | 2193 | u64 diff = device->total_bytes - new_size; |
@@ -2311,7 +2311,7 @@ static int btrfs_add_system_chunk(struct btrfs_trans_handle *trans, | |||
2311 | struct btrfs_key *key, | 2311 | struct btrfs_key *key, |
2312 | struct btrfs_chunk *chunk, int item_size) | 2312 | struct btrfs_chunk *chunk, int item_size) |
2313 | { | 2313 | { |
2314 | struct btrfs_super_block *super_copy = &root->fs_info->super_copy; | 2314 | struct btrfs_super_block *super_copy = root->fs_info->super_copy; |
2315 | struct btrfs_disk_key disk_key; | 2315 | struct btrfs_disk_key disk_key; |
2316 | u32 array_size; | 2316 | u32 array_size; |
2317 | u8 *ptr; | 2317 | u8 *ptr; |
@@ -3653,7 +3653,7 @@ static int read_one_dev(struct btrfs_root *root, | |||
3653 | 3653 | ||
3654 | int btrfs_read_sys_array(struct btrfs_root *root) | 3654 | int btrfs_read_sys_array(struct btrfs_root *root) |
3655 | { | 3655 | { |
3656 | struct btrfs_super_block *super_copy = &root->fs_info->super_copy; | 3656 | struct btrfs_super_block *super_copy = root->fs_info->super_copy; |
3657 | struct extent_buffer *sb; | 3657 | struct extent_buffer *sb; |
3658 | struct btrfs_disk_key *disk_key; | 3658 | struct btrfs_disk_key *disk_key; |
3659 | struct btrfs_chunk *chunk; | 3659 | struct btrfs_chunk *chunk; |