diff options
author | Jeff Mahoney <jeffm@suse.com> | 2016-06-15 09:22:56 -0400 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-12-06 16:06:58 +0100 |
commit | da17066c40472c2d6a1aab7bb0090c3d285531c9 (patch) | |
tree | f51910799ffea3bfe5af34d009a2967b9e99e6ad | |
parent | f15376df0dc2b632eb689793a73d4adba8404987 (diff) | |
download | op-kernel-dev-da17066c40472c2d6a1aab7bb0090c3d285531c9.zip op-kernel-dev-da17066c40472c2d6a1aab7bb0090c3d285531c9.tar.gz |
btrfs: pull node/sector/stripe sizes out of root and into fs_info
We track the node sizes per-root, but they never vary from the values
in the superblock. This patch messes with the 80-column style a bit,
but subsequent patches to factor out root->fs_info into a convenience
variable fix it up again.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
39 files changed, 432 insertions, 414 deletions
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 85dc7ab..45ef41f 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -1829,7 +1829,7 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical, } btrfs_item_key_to_cpu(path->nodes[0], found_key, path->slots[0]); if (found_key->type == BTRFS_METADATA_ITEM_KEY) - size = fs_info->extent_root->nodesize; + size = fs_info->nodesize; else if (found_key->type == BTRFS_EXTENT_ITEM_KEY) size = found_key->offset; diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c index 91f6bd9..a6243cc 100644 --- a/fs/btrfs/check-integrity.c +++ b/fs/btrfs/check-integrity.c @@ -2911,14 +2911,14 @@ int btrfsic_mount(struct btrfs_root *root, struct list_head *dev_head = &fs_devices->devices; struct btrfs_device *device; - if (root->nodesize & ((u64)PAGE_SIZE - 1)) { + if (root->fs_info->nodesize & ((u64)PAGE_SIZE - 1)) { pr_info("btrfsic: cannot handle nodesize %d not being a multiple of PAGE_SIZE %ld!\n", - root->nodesize, PAGE_SIZE); + root->fs_info->nodesize, PAGE_SIZE); return -1; } - if (root->sectorsize & ((u64)PAGE_SIZE - 1)) { + if (root->fs_info->sectorsize & ((u64)PAGE_SIZE - 1)) { pr_info("btrfsic: cannot handle sectorsize %d not being a multiple of PAGE_SIZE %ld!\n", - root->sectorsize, PAGE_SIZE); + root->fs_info->sectorsize, PAGE_SIZE); return -1; } state = kzalloc(sizeof(*state), GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT); @@ -2940,8 +2940,8 @@ int btrfsic_mount(struct btrfs_root *root, state->print_mask = print_mask; state->include_extent_data = including_extent_data; state->csum_size = 0; - state->metablock_size = root->nodesize; - state->datablock_size = root->sectorsize; + state->metablock_size = root->fs_info->nodesize; + state->datablock_size = root->fs_info->sectorsize; INIT_LIST_HEAD(&state->all_blocks_list); btrfsic_block_hashtable_init(&state->block_hashtable); btrfsic_block_link_hashtable_init(&state->block_link_hashtable); diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index ae4c000..e4a8c3a 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -91,7 +91,7 @@ static inline int compressed_bio_size(struct btrfs_root *root, u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); return sizeof(struct compressed_bio) + - (DIV_ROUND_UP(disk_size, root->sectorsize)) * csum_size; + (DIV_ROUND_UP(disk_size, root->fs_info->sectorsize)) * csum_size; } static struct bio *compressed_bio_alloc(struct block_device *bdev, @@ -696,7 +696,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, BUG_ON(ret); /* -ENOMEM */ } sums += DIV_ROUND_UP(comp_bio->bi_iter.bi_size, - root->sectorsize); + root->fs_info->sectorsize); ret = btrfs_map_bio(root, comp_bio, mirror_num, 0); if (ret) { diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 25286a5..431b150 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1357,8 +1357,7 @@ tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct btrfs_path *path, if (tm->op == MOD_LOG_KEY_REMOVE_WHILE_FREEING) { BUG_ON(tm->slot != 0); - eb_rewin = alloc_dummy_extent_buffer(fs_info, eb->start, - eb->len); + eb_rewin = alloc_dummy_extent_buffer(fs_info, eb->start); if (!eb_rewin) { btrfs_tree_read_unlock_blocking(eb); free_extent_buffer(eb); @@ -1386,7 +1385,7 @@ tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct btrfs_path *path, btrfs_tree_read_lock(eb_rewin); __tree_mod_log_rewind(fs_info, eb_rewin, time_seq, tm); WARN_ON(btrfs_header_nritems(eb_rewin) > - BTRFS_NODEPTRS_PER_BLOCK(fs_info->tree_root)); + BTRFS_NODEPTRS_PER_BLOCK(fs_info)); return eb_rewin; } @@ -1439,8 +1438,7 @@ get_old_root(struct btrfs_root *root, u64 time_seq) } else if (old_root) { btrfs_tree_read_unlock(eb_root); free_extent_buffer(eb_root); - eb = alloc_dummy_extent_buffer(root->fs_info, logical, - root->nodesize); + eb = alloc_dummy_extent_buffer(root->fs_info, logical); } else { btrfs_set_lock_blocking_rw(eb_root, BTRFS_READ_LOCK); eb = btrfs_clone_extent_buffer(eb_root); @@ -1463,7 +1461,7 @@ get_old_root(struct btrfs_root *root, u64 time_seq) __tree_mod_log_rewind(root->fs_info, eb, time_seq, tm); else WARN_ON(btrfs_header_level(eb) != 0); - WARN_ON(btrfs_header_nritems(eb) > BTRFS_NODEPTRS_PER_BLOCK(root)); + WARN_ON(btrfs_header_nritems(eb) > BTRFS_NODEPTRS_PER_BLOCK(root->fs_info)); return eb; } @@ -1634,7 +1632,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, WARN_ON(trans->transid != root->fs_info->generation); parent_nritems = btrfs_header_nritems(parent); - blocksize = root->nodesize; + blocksize = root->fs_info->nodesize; end_slot = parent_nritems - 1; if (parent_nritems <= 1) @@ -1940,7 +1938,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, return 0; } if (btrfs_header_nritems(mid) > - BTRFS_NODEPTRS_PER_BLOCK(root) / 4) + BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) / 4) return 0; left = read_node_slot(root, parent, pslot - 1); @@ -2127,7 +2125,7 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans, btrfs_set_lock_blocking(left); left_nr = btrfs_header_nritems(left); - if (left_nr >= BTRFS_NODEPTRS_PER_BLOCK(root) - 1) { + if (left_nr >= BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - 1) { wret = 1; } else { ret = btrfs_cow_block(trans, root, left, parent, @@ -2181,7 +2179,7 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans, btrfs_set_lock_blocking(right); right_nr = btrfs_header_nritems(right); - if (right_nr >= BTRFS_NODEPTRS_PER_BLOCK(root) - 1) { + if (right_nr >= BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - 1) { wret = 1; } else { ret = btrfs_cow_block(trans, root, right, @@ -2252,7 +2250,7 @@ static void reada_for_search(struct btrfs_root *root, node = path->nodes[level]; search = btrfs_node_blockptr(node, slot); - blocksize = root->nodesize; + blocksize = root->fs_info->nodesize; eb = find_extent_buffer(root->fs_info, search); if (eb) { free_extent_buffer(eb); @@ -2521,7 +2519,7 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans, { int ret; if ((p->search_for_split || ins_len > 0) && btrfs_header_nritems(b) >= - BTRFS_NODEPTRS_PER_BLOCK(root) - 3) { + BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - 3) { int sret; if (*write_lock_level < level + 1) { @@ -2542,7 +2540,7 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans, } b = p->nodes[level]; } else if (ins_len < 0 && btrfs_header_nritems(b) < - BTRFS_NODEPTRS_PER_BLOCK(root) / 2) { + BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) / 2) { int sret; if (*write_lock_level < level + 1) { @@ -3195,7 +3193,7 @@ static int push_node_left(struct btrfs_trans_handle *trans, src_nritems = btrfs_header_nritems(src); dst_nritems = btrfs_header_nritems(dst); - push_items = BTRFS_NODEPTRS_PER_BLOCK(root) - dst_nritems; + push_items = BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - dst_nritems; WARN_ON(btrfs_header_generation(src) != trans->transid); WARN_ON(btrfs_header_generation(dst) != trans->transid); @@ -3274,7 +3272,7 @@ static int balance_node_right(struct btrfs_trans_handle *trans, src_nritems = btrfs_header_nritems(src); dst_nritems = btrfs_header_nritems(dst); - push_items = BTRFS_NODEPTRS_PER_BLOCK(root) - dst_nritems; + push_items = BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - dst_nritems; if (push_items <= 0) return 1; @@ -3346,7 +3344,7 @@ static noinline int insert_new_root(struct btrfs_trans_handle *trans, if (IS_ERR(c)) return PTR_ERR(c); - root_add_used(root, root->nodesize); + root_add_used(root, root->fs_info->nodesize); memzero_extent_buffer(c, 0, sizeof(struct btrfs_header)); btrfs_set_header_nritems(c, 1); @@ -3404,7 +3402,7 @@ static void insert_ptr(struct btrfs_trans_handle *trans, lower = path->nodes[level]; nritems = btrfs_header_nritems(lower); BUG_ON(slot > nritems); - BUG_ON(nritems == BTRFS_NODEPTRS_PER_BLOCK(root)); + BUG_ON(nritems == BTRFS_NODEPTRS_PER_BLOCK(root->fs_info)); if (slot != nritems) { if (level) tree_mod_log_eb_move(root->fs_info, lower, slot + 1, @@ -3467,7 +3465,7 @@ static noinline int split_node(struct btrfs_trans_handle *trans, ret = push_nodes_for_insert(trans, root, path, level); c = path->nodes[level]; if (!ret && btrfs_header_nritems(c) < - BTRFS_NODEPTRS_PER_BLOCK(root) - 3) + BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - 3) return 0; if (ret < 0) return ret; @@ -3482,7 +3480,7 @@ static noinline int split_node(struct btrfs_trans_handle *trans, if (IS_ERR(split)) return PTR_ERR(split); - root_add_used(root, root->nodesize); + root_add_used(root, root->fs_info->nodesize); memzero_extent_buffer(split, 0, sizeof(struct btrfs_header)); btrfs_set_header_level(split, btrfs_header_level(c)); @@ -3564,11 +3562,12 @@ noinline int btrfs_leaf_free_space(struct btrfs_root *root, { int nritems = btrfs_header_nritems(leaf); int ret; - ret = BTRFS_LEAF_DATA_SIZE(root) - leaf_space_used(leaf, 0, nritems); + ret = BTRFS_LEAF_DATA_SIZE(root->fs_info) - leaf_space_used(leaf, 0, nritems); if (ret < 0) { btrfs_crit(root->fs_info, "leaf free space ret %d, leaf data size %lu, used %d nritems %d", - ret, (unsigned long) BTRFS_LEAF_DATA_SIZE(root), + ret, + (unsigned long) BTRFS_LEAF_DATA_SIZE(root->fs_info), leaf_space_used(leaf, 0, nritems), nritems); } return ret; @@ -3655,11 +3654,11 @@ static noinline int __push_leaf_right(struct btrfs_trans_handle *trans, memmove_extent_buffer(right, btrfs_leaf_data(right) + data_end - push_space, btrfs_leaf_data(right) + data_end, - BTRFS_LEAF_DATA_SIZE(root) - data_end); + BTRFS_LEAF_DATA_SIZE(root->fs_info) - data_end); /* copy from the left data area */ copy_extent_buffer(right, left, btrfs_leaf_data(right) + - BTRFS_LEAF_DATA_SIZE(root) - push_space, + BTRFS_LEAF_DATA_SIZE(root->fs_info) - push_space, btrfs_leaf_data(left) + leaf_data_end(root, left), push_space); @@ -3675,7 +3674,7 @@ static noinline int __push_leaf_right(struct btrfs_trans_handle *trans, /* update the item pointers */ right_nritems += push_items; btrfs_set_header_nritems(right, right_nritems); - push_space = BTRFS_LEAF_DATA_SIZE(root); + push_space = BTRFS_LEAF_DATA_SIZE(root->fs_info); for (i = 0; i < right_nritems; i++) { item = btrfs_item_nr(i); push_space -= btrfs_token_item_size(right, item, &token); @@ -3871,7 +3870,7 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans, btrfs_item_nr_offset(0), push_items * sizeof(struct btrfs_item)); - push_space = BTRFS_LEAF_DATA_SIZE(root) - + push_space = BTRFS_LEAF_DATA_SIZE(root->fs_info) - btrfs_item_offset_nr(right, push_items - 1); copy_extent_buffer(left, right, btrfs_leaf_data(left) + @@ -3890,7 +3889,7 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans, ioff = btrfs_token_item_offset(left, item, &token); btrfs_set_token_item_offset(left, item, - ioff - (BTRFS_LEAF_DATA_SIZE(root) - old_left_item_size), + ioff - (BTRFS_LEAF_DATA_SIZE(root->fs_info) - old_left_item_size), &token); } btrfs_set_header_nritems(left, old_left_nritems + push_items); @@ -3904,7 +3903,7 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans, push_space = btrfs_item_offset_nr(right, push_items - 1) - leaf_data_end(root, right); memmove_extent_buffer(right, btrfs_leaf_data(right) + - BTRFS_LEAF_DATA_SIZE(root) - push_space, + BTRFS_LEAF_DATA_SIZE(root->fs_info) - push_space, btrfs_leaf_data(right) + leaf_data_end(root, right), push_space); @@ -3915,7 +3914,7 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans, } right_nritems -= push_items; btrfs_set_header_nritems(right, right_nritems); - push_space = BTRFS_LEAF_DATA_SIZE(root); + push_space = BTRFS_LEAF_DATA_SIZE(root->fs_info); for (i = 0; i < right_nritems; i++) { item = btrfs_item_nr(i); @@ -4054,11 +4053,11 @@ static noinline void copy_for_split(struct btrfs_trans_handle *trans, nritems * sizeof(struct btrfs_item)); copy_extent_buffer(right, l, - btrfs_leaf_data(right) + BTRFS_LEAF_DATA_SIZE(root) - + btrfs_leaf_data(right) + BTRFS_LEAF_DATA_SIZE(root->fs_info) - data_copy_size, btrfs_leaf_data(l) + leaf_data_end(root, l), data_copy_size); - rt_data_off = BTRFS_LEAF_DATA_SIZE(root) - + rt_data_off = BTRFS_LEAF_DATA_SIZE(root->fs_info) - btrfs_item_end_nr(l, mid); for (i = 0; i < nritems; i++) { @@ -4182,7 +4181,7 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans, l = path->nodes[0]; slot = path->slots[0]; if (extend && data_size + btrfs_item_size_nr(l, slot) + - sizeof(struct btrfs_item) > BTRFS_LEAF_DATA_SIZE(root)) + sizeof(struct btrfs_item) > BTRFS_LEAF_DATA_SIZE(root->fs_info)) return -EOVERFLOW; /* first try to make some room by pushing left and right */ @@ -4224,14 +4223,14 @@ again: if (mid <= slot) { if (nritems == 1 || leaf_space_used(l, mid, nritems - mid) + data_size > - BTRFS_LEAF_DATA_SIZE(root)) { + BTRFS_LEAF_DATA_SIZE(root->fs_info)) { if (slot >= nritems) { split = 0; } else { mid = slot; if (mid != nritems && leaf_space_used(l, mid, nritems - mid) + - data_size > BTRFS_LEAF_DATA_SIZE(root)) { + data_size > BTRFS_LEAF_DATA_SIZE(root->fs_info)) { if (data_size && !tried_avoid_double) goto push_for_double; split = 2; @@ -4240,7 +4239,7 @@ again: } } else { if (leaf_space_used(l, 0, mid) + data_size > - BTRFS_LEAF_DATA_SIZE(root)) { + BTRFS_LEAF_DATA_SIZE(root->fs_info)) { if (!extend && data_size && slot == 0) { split = 0; } else if ((extend || !data_size) && slot == 0) { @@ -4249,7 +4248,7 @@ again: mid = slot; if (mid != nritems && leaf_space_used(l, mid, nritems - mid) + - data_size > BTRFS_LEAF_DATA_SIZE(root)) { + data_size > BTRFS_LEAF_DATA_SIZE(root->fs_info)) { if (data_size && !tried_avoid_double) goto push_for_double; split = 2; @@ -4268,7 +4267,7 @@ again: if (IS_ERR(right)) return PTR_ERR(right); - root_add_used(root, root->nodesize); + root_add_used(root, root->fs_info->nodesize); memzero_extent_buffer(right, 0, sizeof(struct btrfs_header)); btrfs_set_header_bytenr(right, right->start); @@ -5001,7 +5000,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, } /* delete the leaf if it is mostly empty */ - if (used < BTRFS_LEAF_DATA_SIZE(root) / 3) { + if (used < BTRFS_LEAF_DATA_SIZE(root->fs_info) / 3) { /* push_leaf_left fixes the path. * make sure the path still points to our leaf * for possible call to del_ptr below @@ -5369,9 +5368,10 @@ int btrfs_compare_trees(struct btrfs_root *left_root, goto out; } - tmp_buf = kmalloc(left_root->nodesize, GFP_KERNEL | __GFP_NOWARN); + tmp_buf = kmalloc(left_root->fs_info->nodesize, + GFP_KERNEL | __GFP_NOWARN); if (!tmp_buf) { - tmp_buf = vmalloc(left_root->nodesize); + tmp_buf = vmalloc(left_root->fs_info->nodesize); if (!tmp_buf) { ret = -ENOMEM; goto out; diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 15ff880..6a5c007 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -337,7 +337,7 @@ struct btrfs_path { unsigned int need_commit_sem:1; unsigned int skip_release_on_error:1; }; -#define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r) >> 4) - \ +#define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \ sizeof(struct btrfs_item)) struct btrfs_dev_replace { u64 replace_state; /* see #define above */ @@ -1084,8 +1084,18 @@ struct btrfs_fs_info { /* Used to record internally whether fs has been frozen */ int fs_frozen; + + /* Cached block sizes */ + u32 nodesize; + u32 sectorsize; + u32 stripesize; }; +static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) +{ + return sb->s_fs_info; +} + struct btrfs_subvolume_writers { struct percpu_counter counter; wait_queue_head_t wait; @@ -1159,14 +1169,6 @@ struct btrfs_root { u64 objectid; u64 last_trans; - /* data allocations are done in sectorsize units */ - u32 sectorsize; - - /* node allocations are done in nodesize units */ - u32 nodesize; - - u32 stripesize; - u32 type; u64 highest_objectid; @@ -1250,38 +1252,42 @@ struct btrfs_root { /* For qgroup metadata space reserve */ atomic_t qgroup_meta_rsv; }; +static inline u32 btrfs_inode_sectorsize(const struct inode *inode) +{ + return btrfs_sb(inode->i_sb)->sectorsize; +} static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 blocksize) { return blocksize - sizeof(struct btrfs_header); } -static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_root *root) +static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info) { - return __BTRFS_LEAF_DATA_SIZE(root->nodesize); + return __BTRFS_LEAF_DATA_SIZE(info->nodesize); } -static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_root *root) +static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info *info) { - return BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item); + return BTRFS_LEAF_DATA_SIZE(info) - sizeof(struct btrfs_item); } -static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_root *root) +static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info *info) { - return BTRFS_LEAF_DATA_SIZE(root) / sizeof(struct btrfs_key_ptr); + return BTRFS_LEAF_DATA_SIZE(info) / sizeof(struct btrfs_key_ptr); } #define BTRFS_FILE_EXTENT_INLINE_DATA_START \ (offsetof(struct btrfs_file_extent_item, disk_bytenr)) -static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_root *root) +static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info) { - return BTRFS_MAX_ITEM_SIZE(root) - + return BTRFS_MAX_ITEM_SIZE(info) - BTRFS_FILE_EXTENT_INLINE_DATA_START; } -static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_root *root) +static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) { - return BTRFS_MAX_ITEM_SIZE(root) - sizeof(struct btrfs_dir_item); + return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item); } /* @@ -2309,7 +2315,7 @@ static inline unsigned int leaf_data_end(struct btrfs_root *root, u32 nr = btrfs_header_nritems(leaf); if (nr == 0) - return BTRFS_LEAF_DATA_SIZE(root); + return BTRFS_LEAF_DATA_SIZE(root->fs_info); return btrfs_item_offset_nr(leaf, nr - 1); } @@ -2505,11 +2511,6 @@ BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_left, BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right, struct btrfs_dev_replace_item, cursor_right, 64); -static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) -{ - return sb->s_fs_info; -} - /* helper function to cast into the data area of the leaf. */ #define btrfs_item_ptr(leaf, slot, type) \ ((type *)(btrfs_leaf_data(leaf) + \ @@ -2537,7 +2538,7 @@ u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes); static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root, unsigned num_items) { - return root->nodesize * BTRFS_MAX_LEVEL * 2 * num_items; + return root->fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items; } /* @@ -2547,7 +2548,7 @@ static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root, static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_root *root, unsigned num_items) { - return root->nodesize * BTRFS_MAX_LEVEL * num_items; + return root->fs_info->nodesize * BTRFS_MAX_LEVEL * num_items; } int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index 0dc1a03..79233ab 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c @@ -79,7 +79,7 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, struct extent_buffer *leaf; u32 data_size; - BUG_ON(name_len + data_len > BTRFS_MAX_XATTR_SIZE(root)); + BUG_ON(name_len + data_len > BTRFS_MAX_XATTR_SIZE(root->fs_info)); key.objectid = objectid; key.type = BTRFS_XATTR_ITEM_KEY; @@ -261,7 +261,7 @@ int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir, leaf = path->nodes[0]; slot = path->slots[0]; if (data_size + btrfs_item_size_nr(leaf, slot) + - sizeof(struct btrfs_item) > BTRFS_LEAF_DATA_SIZE(root)) { + sizeof(struct btrfs_item) > BTRFS_LEAF_DATA_SIZE(root->fs_info)) { ret = -EOVERFLOW; } else { /* plenty of insertion room */ @@ -471,7 +471,7 @@ int verify_dir_item(struct btrfs_root *root, /* BTRFS_MAX_XATTR_SIZE is the same for all dir items */ if ((btrfs_dir_data_len(leaf, dir_item) + - btrfs_dir_name_len(leaf, dir_item)) > BTRFS_MAX_XATTR_SIZE(root)) { + btrfs_dir_name_len(leaf, dir_item)) > BTRFS_MAX_XATTR_SIZE(root->fs_info)) { btrfs_crit(root->fs_info, "invalid dir item name + data len: %u + %u", (unsigned)btrfs_dir_name_len(leaf, dir_item), diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8384831..3d4fb99 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -585,7 +585,7 @@ static noinline int check_leaf(struct btrfs_root *root, /* Check the 0 item */ if (btrfs_item_offset_nr(leaf, 0) + btrfs_item_size_nr(leaf, 0) != - BTRFS_LEAF_DATA_SIZE(root)) { + BTRFS_LEAF_DATA_SIZE(root->fs_info)) { CORRUPT("invalid item offset size pair", leaf, root, 0); return -EIO; } @@ -624,7 +624,7 @@ static noinline int check_leaf(struct btrfs_root *root, * all point outside of the leaf. */ if (btrfs_item_end_nr(leaf, slot) > - BTRFS_LEAF_DATA_SIZE(root)) { + BTRFS_LEAF_DATA_SIZE(root->fs_info)) { CORRUPT("slot end outside of leaf", leaf, root, slot); return -EIO; } @@ -641,7 +641,7 @@ static int check_node(struct btrfs_root *root, struct extent_buffer *node) u64 bytenr; int ret = 0; - if (nr == 0 || nr > BTRFS_NODEPTRS_PER_BLOCK(root)) { + if (nr == 0 || nr > BTRFS_NODEPTRS_PER_BLOCK(root->fs_info)) { btrfs_crit(root->fs_info, "corrupt node: block %llu root %llu nritems %lu", node->start, root->objectid, nr); @@ -1195,8 +1195,7 @@ struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, u64 bytenr) { if (btrfs_is_testing(root->fs_info)) - return alloc_test_extent_buffer(root->fs_info, bytenr, - root->nodesize); + return alloc_test_extent_buffer(root->fs_info, bytenr); return alloc_extent_buffer(root->fs_info, bytenr); } @@ -1277,16 +1276,12 @@ btrfs_free_subvolume_writers(struct btrfs_subvolume_writers *writers) kfree(writers); } -static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize, - struct btrfs_root *root, struct btrfs_fs_info *fs_info, +static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info, u64 objectid) { bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); root->node = NULL; root->commit_root = NULL; - root->sectorsize = sectorsize; - root->nodesize = nodesize; - root->stripesize = stripesize; root->state = 0; root->orphan_cleanup_state = 0; @@ -1364,8 +1359,7 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info, #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS /* Should only be used by the testing infrastructure */ -struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info, - u32 sectorsize, u32 nodesize) +struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info) { struct btrfs_root *root; @@ -1375,9 +1369,9 @@ struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info, root = btrfs_alloc_root(fs_info, GFP_KERNEL); if (!root) return ERR_PTR(-ENOMEM); + /* We don't use the stripesize in selftest, set it as sectorsize */ - __setup_root(nodesize, sectorsize, sectorsize, root, fs_info, - BTRFS_ROOT_TREE_OBJECTID); + __setup_root(root, fs_info, BTRFS_ROOT_TREE_OBJECTID); root->alloc_bytenr = 0; return root; @@ -1399,8 +1393,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, if (!root) return ERR_PTR(-ENOMEM); - __setup_root(tree_root->nodesize, tree_root->sectorsize, - tree_root->stripesize, root, fs_info, objectid); + __setup_root(root, fs_info, objectid); root->root_key.objectid = objectid; root->root_key.type = BTRFS_ROOT_ITEM_KEY; root->root_key.offset = 0; @@ -1465,16 +1458,13 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info) { struct btrfs_root *root; - struct btrfs_root *tree_root = fs_info->tree_root; struct extent_buffer *leaf; root = btrfs_alloc_root(fs_info, GFP_NOFS); if (!root) return ERR_PTR(-ENOMEM); - __setup_root(tree_root->nodesize, tree_root->sectorsize, - tree_root->stripesize, root, fs_info, - BTRFS_TREE_LOG_OBJECTID); + __setup_root(root, fs_info, BTRFS_TREE_LOG_OBJECTID); root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID; root->root_key.type = BTRFS_ROOT_ITEM_KEY; @@ -1539,7 +1529,8 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans, btrfs_set_stack_inode_generation(inode_item, 1); btrfs_set_stack_inode_size(inode_item, 3); btrfs_set_stack_inode_nlink(inode_item, 1); - btrfs_set_stack_inode_nbytes(inode_item, root->nodesize); + btrfs_set_stack_inode_nbytes(inode_item, + root->fs_info->nodesize); btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755); btrfs_set_root_node(&log_root->root_item, log_root->node); @@ -1571,8 +1562,7 @@ static struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root, goto alloc_fail; } - __setup_root(tree_root->nodesize, tree_root->sectorsize, - tree_root->stripesize, root, fs_info, key->objectid); + __setup_root(root, fs_info, key->objectid); ret = btrfs_find_root(tree_root, key, path, &root->root_item, &root->root_key); @@ -2456,9 +2446,7 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info, if (!log_tree_root) return -ENOMEM; - __setup_root(tree_root->nodesize, tree_root->sectorsize, - tree_root->stripesize, log_tree_root, fs_info, - BTRFS_TREE_LOG_OBJECTID); + __setup_root(log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID); log_tree_root->node = read_tree_block(tree_root, bytenr, fs_info->generation + 1); @@ -2749,14 +2737,18 @@ int open_ctree(struct super_block *sb, INIT_LIST_HEAD(&fs_info->pinned_chunks); + /* Usable values until the real ones are cached from the superblock */ + fs_info->nodesize = 4096; + fs_info->sectorsize = 4096; + fs_info->stripesize = 4096; + ret = btrfs_alloc_stripe_hash_table(fs_info); if (ret) { err = ret; goto fail_alloc; } - __setup_root(4096, 4096, 4096, tree_root, - fs_info, BTRFS_ROOT_TREE_OBJECTID); + __setup_root(tree_root, fs_info, BTRFS_ROOT_TREE_OBJECTID); invalidate_bdev(fs_devices->latest_bdev); @@ -2861,6 +2853,11 @@ int open_ctree(struct super_block *sb, fs_info->dirty_metadata_batch = nodesize * (1 + ilog2(nr_cpu_ids)); fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids)); + /* Cache block sizes */ + fs_info->nodesize = nodesize; + fs_info->sectorsize = sectorsize; + fs_info->stripesize = stripesize; + /* * mixed block groups end up with duplicate but slightly offset * extent buffers for the same range. It leads to corruptions @@ -2901,10 +2898,6 @@ int open_ctree(struct super_block *sb, fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages, SZ_4M / PAGE_SIZE); - tree_root->nodesize = nodesize; - tree_root->sectorsize = sectorsize; - tree_root->stripesize = stripesize; - sb->s_blocksize = sectorsize; sb->s_blocksize_bits = blksize_bits(sectorsize); @@ -2918,8 +2911,7 @@ int open_ctree(struct super_block *sb, generation = btrfs_super_chunk_root_generation(disk_super); - __setup_root(nodesize, sectorsize, stripesize, chunk_root, - fs_info, BTRFS_CHUNK_TREE_OBJECTID); + __setup_root(chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID); chunk_root->node = read_tree_block(chunk_root, btrfs_super_chunk_root(disk_super), @@ -4447,7 +4439,7 @@ static int btrfs_destroy_marked_extents(struct btrfs_root *root, clear_extent_bits(dirty_pages, start, end, mark); while (start <= end) { eb = find_extent_buffer(root->fs_info, start); - start += root->nodesize; + start += root->fs_info->nodesize; if (!eb) continue; wait_on_extent_buffer_writeback(eb); diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 4f15335..b7f9711 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -90,8 +90,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, void btrfs_free_fs_root(struct btrfs_root *root); #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info, - u32 sectorsize, u32 nodesize); +struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info); #endif /* diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 9e83423..127a54b 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -335,7 +335,7 @@ static void fragment_free_space(struct btrfs_root *root, u64 start = block_group->key.objectid; u64 len = block_group->key.offset; u64 chunk = block_group->flags & BTRFS_BLOCK_GROUP_METADATA ? - root->nodesize : root->sectorsize; + root->fs_info->nodesize : root->fs_info->sectorsize; u64 step = chunk << 1; while (len > chunk) { @@ -510,7 +510,7 @@ next: key.objectid); if (key.type == BTRFS_METADATA_ITEM_KEY) last = key.objectid + - fs_info->tree_root->nodesize; + fs_info->nodesize; else last = key.objectid + key.offset; @@ -826,7 +826,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, * different */ if (metadata && !btrfs_fs_incompat(root->fs_info, SKINNY_METADATA)) { - offset = root->nodesize; + offset = root->fs_info->nodesize; metadata = 0; } @@ -859,7 +859,7 @@ search_again: path->slots[0]); if (key.objectid == bytenr && key.type == BTRFS_EXTENT_ITEM_KEY && - key.offset == root->nodesize) + key.offset == root->fs_info->nodesize) ret = 0; } } @@ -2759,7 +2759,7 @@ static inline u64 heads_to_leaves(struct btrfs_root *root, u64 heads) * We don't ever fill up leaves all the way so multiply by 2 just to be * closer to what we're really going to want to use. */ - return div_u64(num_bytes, BTRFS_LEAF_DATA_SIZE(root)); + return div_u64(num_bytes, BTRFS_LEAF_DATA_SIZE(root->fs_info)); } /* @@ -2772,10 +2772,10 @@ u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes) u64 num_csums_per_leaf; u64 num_csums; - csum_size = BTRFS_MAX_ITEM_SIZE(root); + csum_size = BTRFS_MAX_ITEM_SIZE(root->fs_info); num_csums_per_leaf = div64_u64(csum_size, (u64)btrfs_super_csum_size(root->fs_info->super_copy)); - num_csums = div64_u64(csum_bytes, root->sectorsize); + num_csums = div64_u64(csum_bytes, root->fs_info->sectorsize); num_csums += num_csums_per_leaf - 1; num_csums = div64_u64(num_csums, num_csums_per_leaf); return num_csums; @@ -2794,9 +2794,9 @@ int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans, num_bytes = btrfs_calc_trans_metadata_size(root, 1); num_heads = heads_to_leaves(root, num_heads); if (num_heads > 1) - num_bytes += (num_heads - 1) * root->nodesize; + num_bytes += (num_heads - 1) * root->fs_info->nodesize; num_bytes <<= 1; - num_bytes += btrfs_csum_bytes_to_leaves(root, csum_bytes) * root->nodesize; + num_bytes += btrfs_csum_bytes_to_leaves(root, csum_bytes) * root->fs_info->nodesize; num_dirty_bgs_bytes = btrfs_calc_trans_metadata_size(root, num_dirty_bgs); global_rsv = &root->fs_info->global_block_rsv; @@ -3270,7 +3270,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, goto fail; } else { bytenr = btrfs_node_blockptr(buf, i); - num_bytes = root->nodesize; + num_bytes = root->fs_info->nodesize; ret = process_func(trans, root, bytenr, num_bytes, parent, ref_root, level - 1, 0); if (ret) @@ -4140,7 +4140,7 @@ int btrfs_alloc_data_chunk_ondemand(struct inode *inode, u64 bytes) int have_pinned_space; /* make sure bytes are sectorsize aligned */ - bytes = ALIGN(bytes, root->sectorsize); + bytes = ALIGN(bytes, root->fs_info->sectorsize); if (btrfs_is_free_space_inode(inode)) { need_commit = 0; @@ -4273,9 +4273,9 @@ int btrfs_check_data_free_space(struct inode *inode, u64 start, u64 len) int ret; /* align the range */ - len = round_up(start + len, root->sectorsize) - - round_down(start, root->sectorsize); - start = round_down(start, root->sectorsize); + len = round_up(start + len, root->fs_info->sectorsize) - + round_down(start, root->fs_info->sectorsize); + start = round_down(start, root->fs_info->sectorsize); ret = btrfs_alloc_data_chunk_ondemand(inode, len); if (ret < 0) @@ -4303,9 +4303,9 @@ void btrfs_free_reserved_data_space_noquota(struct inode *inode, u64 start, struct btrfs_space_info *data_sinfo; /* Make sure the range is aligned to sectorsize */ - len = round_up(start + len, root->sectorsize) - - round_down(start, root->sectorsize); - start = round_down(start, root->sectorsize); + len = round_up(start + len, root->fs_info->sectorsize) - + round_down(start, root->fs_info->sectorsize); + start = round_down(start, root->fs_info->sectorsize); data_sinfo = root->fs_info->data_sinfo; spin_lock(&data_sinfo->lock); @@ -4330,9 +4330,9 @@ void btrfs_free_reserved_data_space(struct inode *inode, u64 start, u64 len) struct btrfs_root *root = BTRFS_I(inode)->root; /* Make sure the range is aligned to sectorsize */ - len = round_up(start + len, root->sectorsize) - - round_down(start, root->sectorsize); - start = round_down(start, root->sectorsize); + len = round_up(start + len, root->fs_info->sectorsize) - + round_down(start, root->fs_info->sectorsize); + start = round_down(start, root->fs_info->sectorsize); btrfs_free_reserved_data_space_noquota(inode, start, len); btrfs_qgroup_free_data(inode, start, len); @@ -5811,7 +5811,7 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, if (test_bit(BTRFS_FS_QUOTA_ENABLED, &root->fs_info->flags)) { /* One for parent inode, two for dir entries */ - num_bytes = 3 * root->nodesize; + num_bytes = 3 * root->fs_info->nodesize; ret = btrfs_qgroup_reserve_meta(root, num_bytes); if (ret) return ret; @@ -5967,7 +5967,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) if (delalloc_lock) mutex_lock(&BTRFS_I(inode)->delalloc_mutex); - num_bytes = ALIGN(num_bytes, root->sectorsize); + num_bytes = ALIGN(num_bytes, root->fs_info->sectorsize); spin_lock(&BTRFS_I(inode)->lock); nr_extents = (unsigned)div64_u64(num_bytes + @@ -5989,14 +5989,15 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) if (test_bit(BTRFS_FS_QUOTA_ENABLED, &root->fs_info->flags)) { ret = btrfs_qgroup_reserve_meta(root, - nr_extents * root->nodesize); + nr_extents * root->fs_info->nodesize); if (ret) goto out_fail; } ret = btrfs_block_rsv_add(root, block_rsv, to_reserve, flush); if (unlikely(ret)) { - btrfs_qgroup_free_meta(root, nr_extents * root->nodesize); + btrfs_qgroup_free_meta(root, + nr_extents * root->fs_info->nodesize); goto out_fail; } @@ -6100,7 +6101,7 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes) u64 to_free = 0; unsigned dropped; - num_bytes = ALIGN(num_bytes, root->sectorsize); + num_bytes = ALIGN(num_bytes, root->fs_info->sectorsize); spin_lock(&BTRFS_I(inode)->lock); dropped = drop_outstanding_extent(inode, num_bytes); @@ -7455,7 +7456,7 @@ static noinline int find_free_extent(struct btrfs_root *orig_root, bool orig_have_caching_bg = false; bool full_search = false; - WARN_ON(num_bytes < root->sectorsize); + WARN_ON(num_bytes < root->fs_info->sectorsize); ins->type = BTRFS_EXTENT_ITEM_KEY; ins->objectid = 0; ins->offset = 0; @@ -7765,7 +7766,7 @@ unclustered_alloc: goto loop; } checks: - search_start = ALIGN(offset, root->stripesize); + search_start = ALIGN(offset, root->fs_info->stripesize); /* move on to the next group */ if (search_start + num_bytes > @@ -7964,7 +7965,7 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, flags = btrfs_get_alloc_profile(root, is_data); again: - WARN_ON(num_bytes < root->sectorsize); + WARN_ON(num_bytes < root->fs_info->sectorsize); ret = find_free_extent(root, ram_bytes, num_bytes, empty_size, hint_byte, ins, flags, delalloc); if (!ret && !is_data) { @@ -7972,7 +7973,8 @@ again: } else if (ret == -ENOSPC) { if (!final_tried && ins->offset) { num_bytes = min(num_bytes >> 1, ins->offset); - num_bytes = round_down(num_bytes, root->sectorsize); + num_bytes = round_down(num_bytes, + root->fs_info->sectorsize); num_bytes = max(num_bytes, min_alloc_size); ram_bytes = num_bytes; if (num_bytes == min_alloc_size) @@ -8134,7 +8136,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, path = btrfs_alloc_path(); if (!path) { btrfs_free_and_pin_reserved_extent(root, ins->objectid, - root->nodesize); + root->fs_info->nodesize); return -ENOMEM; } @@ -8144,7 +8146,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, if (ret) { btrfs_free_path(path); btrfs_free_and_pin_reserved_extent(root, ins->objectid, - root->nodesize); + root->fs_info->nodesize); return ret; } @@ -8158,7 +8160,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, if (skinny_metadata) { iref = (struct btrfs_extent_inline_ref *)(extent_item + 1); - num_bytes = root->nodesize; + num_bytes = root->fs_info->nodesize; } else { block_info = (struct btrfs_tree_block_info *)(extent_item + 1); btrfs_set_tree_block_key(leaf, block_info, key); @@ -8185,7 +8187,8 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, if (ret) return ret; - ret = update_block_group(trans, root, ins->objectid, root->nodesize, + ret = update_block_group(trans, root, ins->objectid, + root->fs_info->nodesize, 1); if (ret) { /* -ENOENT, logic error */ btrfs_err(fs_info, "update block group failed for %llu %llu", @@ -8193,7 +8196,8 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, BUG(); } - trace_btrfs_reserved_extent_alloc(root, ins->objectid, root->nodesize); + trace_btrfs_reserved_extent_alloc(root, ins->objectid, + root->fs_info->nodesize); return ret; } @@ -8375,7 +8379,7 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, struct btrfs_delayed_extent_op *extent_op; u64 flags = 0; int ret; - u32 blocksize = root->nodesize; + u32 blocksize = root->fs_info->nodesize; bool skinny_metadata = btrfs_fs_incompat(root->fs_info, SKINNY_METADATA); @@ -8487,7 +8491,7 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, } else { wc->reada_count = wc->reada_count * 3 / 2; wc->reada_count = min_t(int, wc->reada_count, - BTRFS_NODEPTRS_PER_BLOCK(root)); + BTRFS_NODEPTRS_PER_BLOCK(root->fs_info)); } eb = path->nodes[wc->level]; @@ -8663,7 +8667,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, } bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); - blocksize = root->nodesize; + blocksize = root->fs_info->nodesize; next = find_extent_buffer(root->fs_info, bytenr); if (!next) { @@ -9088,7 +9092,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, wc->update_ref = update_ref; wc->keep_locks = 0; wc->for_reloc = for_reloc; - wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root); + wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root->fs_info); while (1) { @@ -9252,7 +9256,7 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans, wc->update_ref = 0; wc->keep_locks = 1; wc->for_reloc = 1; - wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root); + wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root->fs_info); while (1) { wret = walk_down_tree(trans, root, path, wc); @@ -9908,7 +9912,7 @@ btrfs_create_block_group_cache(struct btrfs_root *root, u64 start, u64 size) cache->key.offset = size; cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; - cache->sectorsize = root->sectorsize; + cache->sectorsize = root->fs_info->sectorsize; cache->fs_info = root->fs_info; cache->full_stripe_len = btrfs_full_stripe_len(root, &root->fs_info->mapping_tree, diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index d24af9d..3747af6 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -4343,7 +4343,7 @@ static struct extent_map *get_extent_skip_holes(struct inode *inode, u64 last, get_extent_t *get_extent) { - u64 sectorsize = BTRFS_I(inode)->root->sectorsize; + u64 sectorsize = btrfs_inode_sectorsize(inode); struct extent_map *em; u64 len; @@ -4404,8 +4404,8 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, return -ENOMEM; path->leave_spinning = 1; - start = round_down(start, BTRFS_I(inode)->root->sectorsize); - len = round_up(max, BTRFS_I(inode)->root->sectorsize) - start; + start = round_down(start, btrfs_inode_sectorsize(inode)); + len = round_up(max, btrfs_inode_sectorsize(inode)) - start; /* * lookup the last file extent. We're not using i_size here @@ -4760,21 +4760,9 @@ err: } struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info, - u64 start, u32 nodesize) + u64 start) { - unsigned long len; - - if (!fs_info) { - /* - * Called only from tests that don't always have a fs_info - * available - */ - len = nodesize; - } else { - len = fs_info->tree_root->nodesize; - } - - return __alloc_dummy_extent_buffer(fs_info, start, len); + return __alloc_dummy_extent_buffer(fs_info, start, fs_info->nodesize); } static void check_buffer_tree_ref(struct extent_buffer *eb) @@ -4865,7 +4853,7 @@ struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info, #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info, - u64 start, u32 nodesize) + u64 start) { struct extent_buffer *eb, *exists = NULL; int ret; @@ -4873,7 +4861,7 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info, eb = find_extent_buffer(fs_info, start); if (eb) return eb; - eb = alloc_dummy_extent_buffer(fs_info, start, nodesize); + eb = alloc_dummy_extent_buffer(fs_info, start); if (!eb) return NULL; eb->fs_info = fs_info; @@ -4913,7 +4901,7 @@ free_eb: struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, u64 start) { - unsigned long len = fs_info->tree_root->nodesize; + unsigned long len = fs_info->nodesize; unsigned long num_pages = num_extent_pages(start, len); unsigned long i; unsigned long index = start >> PAGE_SHIFT; @@ -4924,7 +4912,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, int uptodate = 1; int ret; - if (!IS_ALIGNED(start, fs_info->tree_root->sectorsize)) { + if (!IS_ALIGNED(start, fs_info->sectorsize)) { btrfs_err(fs_info, "bad tree block start %llu", start); return ERR_PTR(-EINVAL); } diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index ae64c19..f786156 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -371,7 +371,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info, u64 start, unsigned long len); struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info, - u64 start, u32 nodesize); + u64 start); struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src); struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info, u64 start); @@ -496,5 +496,5 @@ noinline u64 find_lock_delalloc_range(struct inode *inode, u64 *end, u64 max_bytes); #endif struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info, - u64 start, u32 nodesize); + u64 start); #endif diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 41c1145..5349e8e 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -34,9 +34,9 @@ #define MAX_CSUM_ITEMS(r, size) (min_t(u32, __MAX_CSUM_ITEMS(r, size), \ PAGE_SIZE)) -#define MAX_ORDERED_SUM_BYTES(r) ((PAGE_SIZE - \ +#define MAX_ORDERED_SUM_BYTES(fs_info) ((PAGE_SIZE - \ sizeof(struct btrfs_ordered_sum)) / \ - sizeof(u32) * (r)->sectorsize) + sizeof(u32) * (fs_info)->sectorsize) int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root, @@ -249,7 +249,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, if (BTRFS_I(inode)->root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID) { set_extent_bits(io_tree, offset, - offset + root->sectorsize - 1, + offset + root->fs_info->sectorsize - 1, EXTENT_NODATASUM); } else { btrfs_info_rl(BTRFS_I(inode)->root->fs_info, @@ -268,7 +268,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, path->slots[0]); item_last_offset = item_start_offset + (item_size / csum_size) * - root->sectorsize; + root->fs_info->sectorsize; item = btrfs_item_ptr(path->nodes[0], path->slots[0], struct btrfs_csum_item); } @@ -277,7 +277,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, * a single leaf so it will also fit inside a u32 */ diff = disk_bytenr - item_start_offset; - diff = diff / root->sectorsize; + diff = diff / root->fs_info->sectorsize; diff = diff * csum_size; count = min_t(int, nblocks, (item_last_offset - disk_bytenr) >> inode->i_sb->s_blocksize_bits); @@ -289,9 +289,9 @@ found: nblocks -= count; next: while (count--) { - disk_bytenr += root->sectorsize; - offset += root->sectorsize; - page_bytes_left -= root->sectorsize; + disk_bytenr += root->fs_info->sectorsize; + offset += root->fs_info->sectorsize; + page_bytes_left -= root->fs_info->sectorsize; if (!page_bytes_left) break; /* move to next bio */ } @@ -329,8 +329,8 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, u64 csum_end; u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); - ASSERT(IS_ALIGNED(start, root->sectorsize) && - IS_ALIGNED(end + 1, root->sectorsize)); + ASSERT(IS_ALIGNED(start, root->fs_info->sectorsize) && + IS_ALIGNED(end + 1, root->fs_info->sectorsize)); path = btrfs_alloc_path(); if (!path) @@ -383,7 +383,7 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, start = key.offset; size = btrfs_item_size_nr(leaf, path->slots[0]); - csum_end = key.offset + (size / csum_size) * root->sectorsize; + csum_end = key.offset + (size / csum_size) * root->fs_info->sectorsize; if (csum_end <= start) { path->slots[0]++; continue; @@ -394,8 +394,9 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, struct btrfs_csum_item); while (start < csum_end) { size = min_t(size_t, csum_end - start, - MAX_ORDERED_SUM_BYTES(root)); - sums = kzalloc(btrfs_ordered_sum_size(root, size), + MAX_ORDERED_SUM_BYTES(root->fs_info)); + sums = kzalloc(btrfs_ordered_sum_size(root->fs_info, + size), GFP_NOFS); if (!sums) { ret = -ENOMEM; @@ -415,7 +416,7 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, ((unsigned long)item) + offset, csum_size * size); - start += root->sectorsize * size; + start += root->fs_info->sectorsize * size; list_add_tail(&sums->list, &tmplist); } path->slots[0]++; @@ -448,7 +449,8 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, u64 offset; WARN_ON(bio->bi_vcnt <= 0); - sums = kzalloc(btrfs_ordered_sum_size(root, bio->bi_iter.bi_size), + sums = kzalloc(btrfs_ordered_sum_size(root->fs_info, + bio->bi_iter.bi_size), GFP_NOFS); if (!sums) return -ENOMEM; @@ -476,7 +478,7 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, data = kmap_atomic(bvec->bv_page); nr_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info, - bvec->bv_len + root->sectorsize + bvec->bv_len + root->fs_info->sectorsize - 1); for (i = 0; i < nr_sectors; i++) { @@ -492,7 +494,7 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, bytes_left = bio->bi_iter.bi_size - total_bytes; - sums = kzalloc(btrfs_ordered_sum_size(root, bytes_left), + sums = kzalloc(btrfs_ordered_sum_size(root->fs_info, bytes_left), GFP_NOFS); BUG_ON(!sums); /* -ENOMEM */ sums->len = bytes_left; @@ -509,15 +511,15 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, sums->sums[index] = ~(u32)0; sums->sums[index] = btrfs_csum_data(data + bvec->bv_offset - + (i * root->sectorsize), + + (i * root->fs_info->sectorsize), sums->sums[index], - root->sectorsize); + root->fs_info->sectorsize); btrfs_csum_final(sums->sums[index], (char *)(sums->sums + index)); index++; - offset += root->sectorsize; - this_sum_bytes += root->sectorsize; - total_bytes += root->sectorsize; + offset += root->fs_info->sectorsize; + this_sum_bytes += root->fs_info->sectorsize; + total_bytes += root->fs_info->sectorsize; } kunmap_atomic(data); @@ -757,7 +759,7 @@ again: leaf = path->nodes[0]; item_size = btrfs_item_size_nr(leaf, path->slots[0]); if ((item_size / csum_size) >= - MAX_CSUM_ITEMS(root, csum_size)) { + MAX_CSUM_ITEMS(root->fs_info, csum_size)) { /* already at max size, make a new one */ goto insert; } @@ -807,7 +809,7 @@ again: if (found_key.type != BTRFS_EXTENT_CSUM_KEY || found_key.objectid != BTRFS_EXTENT_CSUM_OBJECTID || - csum_offset >= MAX_CSUM_ITEMS(root, csum_size)) { + csum_offset >= MAX_CSUM_ITEMS(root->fs_info, csum_size)) { goto insert; } @@ -830,7 +832,7 @@ again: extend_nr = max_t(int, 1, (int)tmp); diff = (csum_offset + extend_nr) * csum_size; - diff = min(diff, MAX_CSUM_ITEMS(root, csum_size) * csum_size); + diff = min(diff, MAX_CSUM_ITEMS(root->fs_info, csum_size) * csum_size); diff = diff - btrfs_item_size_nr(leaf, path->slots[0]); diff = min(free_space, diff); @@ -854,7 +856,7 @@ insert: root->fs_info->sb->s_blocksize_bits); tmp = max((u64)1, tmp); - tmp = min(tmp, (u64)MAX_CSUM_ITEMS(root, csum_size)); + tmp = min(tmp, (u64)MAX_CSUM_ITEMS(root->fs_info, csum_size)); ins_size = csum_size * tmp; } else { ins_size = csum_size; @@ -884,7 +886,7 @@ found: ins_size); ins_size /= csum_size; - total_bytes += ins_size * root->sectorsize; + total_bytes += ins_size * root->fs_info->sectorsize; index += ins_size; btrfs_mark_buffer_dirty(path->nodes[0]); @@ -927,7 +929,8 @@ void btrfs_extent_item_to_extent_map(struct inode *inode, } else if (type == BTRFS_FILE_EXTENT_INLINE) { size_t size; size = btrfs_file_extent_inline_len(leaf, slot, fi); - extent_end = ALIGN(extent_start + size, root->sectorsize); + extent_end = ALIGN(extent_start + size, + root->fs_info->sectorsize); } em->ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi); diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 3c1f4be..1e0af55 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -497,8 +497,9 @@ int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode, u64 end_pos = pos + write_bytes; loff_t isize = i_size_read(inode); - start_pos = pos & ~((u64)root->sectorsize - 1); - num_bytes = round_up(write_bytes + pos - start_pos, root->sectorsize); + start_pos = pos & ~((u64) root->fs_info->sectorsize - 1); + num_bytes = round_up(write_bytes + pos - start_pos, + root->fs_info->sectorsize); end_of_last_block = start_pos + num_bytes - 1; err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block, @@ -935,7 +936,7 @@ delete_extent_item: inode_sub_bytes(inode, extent_end - key.offset); extent_end = ALIGN(extent_end, - root->sectorsize); + root->fs_info->sectorsize); } else if (update_refs && disk_bytenr > 0) { ret = btrfs_free_extent(trans, root, disk_bytenr, num_bytes, 0, @@ -1423,9 +1424,10 @@ lock_and_cleanup_extent_if_need(struct inode *inode, struct page **pages, int i; int ret = 0; - start_pos = round_down(pos, root->sectorsize); + start_pos = round_down(pos, root->fs_info->sectorsize); last_pos = start_pos - + round_up(pos + write_bytes - start_pos, root->sectorsize) - 1; + + round_up(pos + write_bytes - start_pos, + root->fs_info->sectorsize) - 1; if (start_pos < inode->i_size) { struct btrfs_ordered_extent *ordered; @@ -1482,8 +1484,9 @@ static noinline int check_can_nocow(struct inode *inode, loff_t pos, if (!ret) return -ENOSPC; - lockstart = round_down(pos, root->sectorsize); - lockend = round_up(pos + *write_bytes, root->sectorsize) - 1; + lockstart = round_down(pos, root->fs_info->sectorsize); + lockend = round_up(pos + *write_bytes, + root->fs_info->sectorsize) - 1; while (1) { lock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend); @@ -1518,6 +1521,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file, { struct inode *inode = file_inode(file); struct btrfs_root *root = BTRFS_I(inode)->root; + struct btrfs_fs_info *fs_info = root->fs_info; struct page **pages = NULL; struct extent_state *cached_state = NULL; u64 release_bytes = 0; @@ -1563,9 +1567,9 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file, break; } - sector_offset = pos & (root->sectorsize - 1); + sector_offset = pos & (fs_info->sectorsize - 1); reserve_bytes = round_up(write_bytes + sector_offset, - root->sectorsize); + fs_info->sectorsize); ret = btrfs_check_data_free_space(inode, pos, write_bytes); if (ret < 0) { @@ -1585,7 +1589,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file, PAGE_SIZE); reserve_bytes = round_up(write_bytes + sector_offset, - root->sectorsize); + fs_info->sectorsize); } else { break; } @@ -1632,7 +1636,7 @@ again: num_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info, reserve_bytes); dirty_sectors = round_up(copied + sector_offset, - root->sectorsize); + root->fs_info->sectorsize); dirty_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info, dirty_sectors); @@ -1678,7 +1682,8 @@ again: } else { u64 __pos; - __pos = round_down(pos, root->sectorsize) + + __pos = round_down(pos, + root->fs_info->sectorsize) + (dirty_pages << PAGE_SHIFT); btrfs_delalloc_release_space(inode, __pos, release_bytes); @@ -1686,7 +1691,7 @@ again: } release_bytes = round_up(copied + sector_offset, - root->sectorsize); + root->fs_info->sectorsize); if (copied > 0) ret = btrfs_dirty_pages(root, inode, pages, @@ -1706,8 +1711,10 @@ again: btrfs_end_write_no_snapshoting(root); if (only_release_metadata && copied > 0) { - lockstart = round_down(pos, root->sectorsize); - lockend = round_up(pos + copied, root->sectorsize) - 1; + lockstart = round_down(pos, + root->fs_info->sectorsize); + lockend = round_up(pos + copied, + root->fs_info->sectorsize) - 1; set_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, lockend, EXTENT_NORESERVE, NULL, @@ -1720,7 +1727,7 @@ again: cond_resched(); balance_dirty_pages_ratelimited(inode->i_mapping); - if (dirty_pages < (root->nodesize >> PAGE_SHIFT) + 1) + if (dirty_pages < (root->fs_info->nodesize >> PAGE_SHIFT) + 1) btrfs_btree_balance_dirty(root); pos += copied; @@ -1735,7 +1742,7 @@ again: btrfs_delalloc_release_metadata(inode, release_bytes); } else { btrfs_delalloc_release_space(inode, - round_down(pos, root->sectorsize), + round_down(pos, root->fs_info->sectorsize), release_bytes); } } @@ -1853,17 +1860,18 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb, pos = iocb->ki_pos; count = iov_iter_count(from); - start_pos = round_down(pos, root->sectorsize); + start_pos = round_down(pos, root->fs_info->sectorsize); oldsize = i_size_read(inode); if (start_pos > oldsize) { /* Expand hole size to cover write data, preventing empty gap */ - end_pos = round_up(pos + count, root->sectorsize); + end_pos = round_up(pos + count, + root->fs_info->sectorsize); err = btrfs_cont_expand(inode, oldsize, end_pos); if (err) { inode_unlock(inode); goto out; } - if (start_pos > round_up(oldsize, root->sectorsize)) + if (start_pos > round_up(oldsize, root->fs_info->sectorsize)) clean_page = 1; } @@ -2377,7 +2385,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) return ret; inode_lock(inode); - ino_size = round_up(inode->i_size, root->sectorsize); + ino_size = round_up(inode->i_size, root->fs_info->sectorsize); ret = find_first_non_hole(inode, &offset, &len); if (ret < 0) goto out_only_mutex; @@ -2387,9 +2395,9 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) goto out_only_mutex; } - lockstart = round_up(offset, BTRFS_I(inode)->root->sectorsize); + lockstart = round_up(offset, btrfs_inode_sectorsize(inode)); lockend = round_down(offset + len, - BTRFS_I(inode)->root->sectorsize) - 1; + btrfs_inode_sectorsize(inode)) - 1; same_block = (BTRFS_BYTES_TO_BLKS(root->fs_info, offset)) == (BTRFS_BYTES_TO_BLKS(root->fs_info, offset + len - 1)); /* @@ -2400,7 +2408,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) * Only do this if we are in the same block and we aren't doing the * entire block. */ - if (same_block && len < root->sectorsize) { + if (same_block && len < root->fs_info->sectorsize) { if (offset < ino_size) { truncated_block = true; ret = btrfs_truncate_block(inode, offset, len, 0); @@ -2718,7 +2726,7 @@ static long btrfs_fallocate(struct file *file, int mode, u64 locked_end; u64 actual_end = 0; struct extent_map *em; - int blocksize = BTRFS_I(inode)->root->sectorsize; + int blocksize = btrfs_inode_sectorsize(inode); int ret; alloc_start = round_down(offset, blocksize); @@ -2932,10 +2940,11 @@ static int find_desired_extent(struct inode *inode, loff_t *offset, int whence) */ start = max_t(loff_t, 0, *offset); - lockstart = round_down(start, root->sectorsize); - lockend = round_up(i_size_read(inode), root->sectorsize); + lockstart = round_down(start, root->fs_info->sectorsize); + lockend = round_up(i_size_read(inode), + root->fs_info->sectorsize); if (lockend <= lockstart) - lockend = lockstart + root->sectorsize; + lockend = lockstart + root->fs_info->sectorsize; lockend--; len = lockend - lockstart + 1; diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index d2320ee..2d71654 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -1985,7 +1985,7 @@ static bool use_bitmap(struct btrfs_free_space_ctl *ctl, * of cache left then go ahead an dadd them, no sense in adding * the overhead of a bitmap if we don't have to. */ - if (info->bytes <= block_group->sectorsize * 4) { + if (info->bytes <= block_group->fs_info->sectorsize * 4) { if (ctl->free_extents * 2 <= ctl->extents_thresh) return false; } else { @@ -2469,7 +2469,7 @@ void btrfs_init_free_space_ctl(struct btrfs_block_group_cache *block_group) struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; spin_lock_init(&ctl->tree_lock); - ctl->unit = block_group->sectorsize; + ctl->unit = block_group->fs_info->sectorsize; ctl->start = block_group->key.objectid; ctl->private = block_group; ctl->op = &free_space_op; @@ -3030,10 +3030,10 @@ int btrfs_find_space_cluster(struct btrfs_root *root, cont1_bytes = min_bytes = bytes + empty_size; } else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) { cont1_bytes = bytes; - min_bytes = block_group->sectorsize; + min_bytes = block_group->fs_info->sectorsize; } else { cont1_bytes = max(bytes, (bytes + empty_size) >> 2); - min_bytes = block_group->sectorsize; + min_bytes = block_group->fs_info->sectorsize; } spin_lock(&ctl->tree_lock); diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c index 57401b4..9dfb535 100644 --- a/fs/btrfs/free-space-tree.c +++ b/fs/btrfs/free-space-tree.c @@ -39,7 +39,7 @@ void set_free_space_tree_thresholds(struct btrfs_block_group_cache *cache) * We convert to bitmaps when the disk space required for using extents * exceeds that required for using bitmaps. */ - bitmap_range = cache->sectorsize * BTRFS_FREE_SPACE_BITMAP_BITS; + bitmap_range = cache->fs_info->sectorsize * BTRFS_FREE_SPACE_BITMAP_BITS; num_bitmaps = div_u64(cache->key.offset + bitmap_range - 1, bitmap_range); bitmap_size = sizeof(struct btrfs_item) + BTRFS_FREE_SPACE_BITMAP_SIZE; @@ -189,7 +189,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans, int ret; bitmap_size = free_space_bitmap_size(block_group->key.offset, - block_group->sectorsize); + block_group->fs_info->sectorsize); bitmap = alloc_bitmap(bitmap_size); if (!bitmap) { ret = -ENOMEM; @@ -227,9 +227,9 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans, ASSERT(found_key.objectid + found_key.offset <= end); first = div_u64(found_key.objectid - start, - block_group->sectorsize); + block_group->fs_info->sectorsize); last = div_u64(found_key.objectid + found_key.offset - start, - block_group->sectorsize); + block_group->fs_info->sectorsize); le_bitmap_set(bitmap, first, last - first); extent_count++; @@ -270,7 +270,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans, } bitmap_cursor = bitmap; - bitmap_range = block_group->sectorsize * BTRFS_FREE_SPACE_BITMAP_BITS; + bitmap_range = block_group->fs_info->sectorsize * BTRFS_FREE_SPACE_BITMAP_BITS; i = start; while (i < end) { unsigned long ptr; @@ -279,7 +279,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans, extent_size = min(end - i, bitmap_range); data_size = free_space_bitmap_size(extent_size, - block_group->sectorsize); + block_group->fs_info->sectorsize); key.objectid = i; key.type = BTRFS_FREE_SPACE_BITMAP_KEY; @@ -330,7 +330,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans, int ret; bitmap_size = free_space_bitmap_size(block_group->key.offset, - block_group->sectorsize); + block_group->fs_info->sectorsize); bitmap = alloc_bitmap(bitmap_size); if (!bitmap) { ret = -ENOMEM; @@ -370,11 +370,11 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans, ASSERT(found_key.objectid + found_key.offset <= end); bitmap_pos = div_u64(found_key.objectid - start, - block_group->sectorsize * + block_group->fs_info->sectorsize * BITS_PER_BYTE); bitmap_cursor = bitmap + bitmap_pos; data_size = free_space_bitmap_size(found_key.offset, - block_group->sectorsize); + block_group->fs_info->sectorsize); ptr = btrfs_item_ptr_offset(leaf, path->slots[0] - 1); read_extent_buffer(leaf, bitmap_cursor, ptr, @@ -425,7 +425,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans, extent_count++; } prev_bit = bit; - offset += block_group->sectorsize; + offset += block_group->fs_info->sectorsize; bitnr++; } if (prev_bit == 1) { @@ -517,7 +517,8 @@ int free_space_test_bit(struct btrfs_block_group_cache *block_group, ASSERT(offset >= found_start && offset < found_end); ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); - i = div_u64(offset - found_start, block_group->sectorsize); + i = div_u64(offset - found_start, + block_group->fs_info->sectorsize); return !!extent_buffer_test_bit(leaf, ptr, i); } @@ -544,8 +545,10 @@ static void free_space_set_bits(struct btrfs_block_group_cache *block_group, end = found_end; ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); - first = div_u64(*start - found_start, block_group->sectorsize); - last = div_u64(end - found_start, block_group->sectorsize); + first = div_u64(*start - found_start, + block_group->fs_info->sectorsize); + last = div_u64(end - found_start, + block_group->fs_info->sectorsize); if (bit) extent_buffer_bitmap_set(leaf, ptr, first, last - first); else @@ -606,7 +609,7 @@ static int modify_free_space_bitmap(struct btrfs_trans_handle *trans, * that block is within the block group. */ if (start > block_group->key.objectid) { - u64 prev_block = start - block_group->sectorsize; + u64 prev_block = start - block_group->fs_info->sectorsize; key.objectid = prev_block; key.type = (u8)-1; @@ -1121,7 +1124,7 @@ static int populate_free_space_tree(struct btrfs_trans_handle *trans, } start = key.objectid; if (key.type == BTRFS_METADATA_ITEM_KEY) - start += fs_info->tree_root->nodesize; + start += fs_info->nodesize; else start += key.offset; } else if (key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) { @@ -1473,7 +1476,7 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl, extent_count++; } prev_bit = bit; - offset += block_group->sectorsize; + offset += block_group->fs_info->sectorsize; } } if (prev_bit == 1) { diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 22ab45d..9d2dbdb 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -253,7 +253,7 @@ static noinline int cow_file_range_inline(struct btrfs_root *root, u64 isize = i_size_read(inode); u64 actual_end = min(end + 1, isize); u64 inline_len = actual_end - start; - u64 aligned_end = ALIGN(end, root->sectorsize); + u64 aligned_end = ALIGN(end, root->fs_info->sectorsize); u64 data_len = inline_len; int ret; struct btrfs_path *path; @@ -264,10 +264,10 @@ static noinline int cow_file_range_inline(struct btrfs_root *root, data_len = compressed_size; if (start > 0 || - actual_end > root->sectorsize || - data_len > BTRFS_MAX_INLINE_DATA_SIZE(root) || + actual_end > root->fs_info->sectorsize || + data_len > BTRFS_MAX_INLINE_DATA_SIZE(root->fs_info) || (!compressed_size && - (actual_end & (root->sectorsize - 1)) == 0) || + (actual_end & (root->fs_info->sectorsize - 1)) == 0) || end + 1 < isize || data_len > root->fs_info->max_inline) { return 1; @@ -412,7 +412,7 @@ static noinline void compress_file_range(struct inode *inode, { struct btrfs_root *root = BTRFS_I(inode)->root; u64 num_bytes; - u64 blocksize = root->sectorsize; + u64 blocksize = root->fs_info->sectorsize; u64 actual_end; u64 isize = i_size_read(inode); int ret = 0; @@ -945,7 +945,7 @@ static noinline int cow_file_range(struct inode *inode, unsigned long ram_size; u64 disk_num_bytes; u64 cur_alloc_size; - u64 blocksize = root->sectorsize; + u64 blocksize = root->fs_info->sectorsize; struct btrfs_key ins; struct extent_map *em; struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; @@ -999,7 +999,8 @@ static noinline int cow_file_range(struct inode *inode, cur_alloc_size = disk_num_bytes; ret = btrfs_reserve_extent(root, cur_alloc_size, cur_alloc_size, - root->sectorsize, 0, alloc_hint, + root->fs_info->sectorsize, 0, + alloc_hint, &ins, 1, 1); if (ret < 0) goto out_unlock; @@ -1406,7 +1407,8 @@ next_slot: extent_end = found_key.offset + btrfs_file_extent_inline_len(leaf, path->slots[0], fi); - extent_end = ALIGN(extent_end, root->sectorsize); + extent_end = ALIGN(extent_end, + root->fs_info->sectorsize); } else { BUG_ON(1); } @@ -4290,7 +4292,7 @@ static int truncate_space_check(struct btrfs_trans_handle *trans, * intend to use this reservation at all. */ bytes_deleted = btrfs_csum_bytes_to_leaves(root, bytes_deleted); - bytes_deleted *= root->nodesize; + bytes_deleted *= root->fs_info->nodesize; ret = btrfs_block_rsv_add(root, &root->fs_info->trans_block_rsv, bytes_deleted, BTRFS_RESERVE_NO_FLUSH); if (!ret) { @@ -4408,7 +4410,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) || root == root->fs_info->tree_root) btrfs_drop_extent_cache(inode, ALIGN(new_size, - root->sectorsize), (u64)-1, 0); + root->fs_info->sectorsize), + (u64)-1, 0); /* * This function is also used to drop the items in the log tree before @@ -4507,7 +4510,7 @@ search_again: btrfs_file_extent_num_bytes(leaf, fi); extent_num_bytes = ALIGN(new_size - found_key.offset, - root->sectorsize); + root->fs_info->sectorsize); btrfs_set_file_extent_num_bytes(leaf, fi, extent_num_bytes); num_dec = (orig_num_bytes - @@ -4702,7 +4705,7 @@ int btrfs_truncate_block(struct inode *inode, loff_t from, loff_t len, struct btrfs_ordered_extent *ordered; struct extent_state *cached_state = NULL; char *kaddr; - u32 blocksize = root->sectorsize; + u32 blocksize = root->fs_info->sectorsize; pgoff_t index = from >> PAGE_SHIFT; unsigned offset = from & (blocksize - 1); struct page *page; @@ -4859,8 +4862,8 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) struct extent_map *em = NULL; struct extent_state *cached_state = NULL; struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; - u64 hole_start = ALIGN(oldsize, root->sectorsize); - u64 block_end = ALIGN(size, root->sectorsize); + u64 hole_start = ALIGN(oldsize, root->fs_info->sectorsize); + u64 block_end = ALIGN(size, root->fs_info->sectorsize); u64 last_byte; u64 cur_offset; u64 hole_size; @@ -4903,7 +4906,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) break; } last_byte = min(extent_map_end(em), block_end); - last_byte = ALIGN(last_byte , root->sectorsize); + last_byte = ALIGN(last_byte, root->fs_info->sectorsize); if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) { struct extent_map *hole_em; hole_size = last_byte - cur_offset; @@ -6854,7 +6857,8 @@ again: } else if (found_type == BTRFS_FILE_EXTENT_INLINE) { size_t size; size = btrfs_file_extent_inline_len(leaf, path->slots[0], item); - extent_end = ALIGN(extent_start + size, root->sectorsize); + extent_end = ALIGN(extent_start + size, + root->fs_info->sectorsize); } next: if (start >= extent_end) { @@ -6903,7 +6907,7 @@ next: copy_size = min_t(u64, PAGE_SIZE - pg_offset, size - extent_offset); em->start = extent_start + extent_offset; - em->len = ALIGN(copy_size, root->sectorsize); + em->len = ALIGN(copy_size, root->fs_info->sectorsize); em->orig_block_len = em->len; em->orig_start = em->start; ptr = btrfs_file_extent_inline_start(item) + extent_offset; @@ -7209,8 +7213,8 @@ static struct extent_map *btrfs_new_extent_direct(struct inode *inode, int ret; alloc_hint = get_extent_allocation_hint(inode, start, len); - ret = btrfs_reserve_extent(root, len, len, root->sectorsize, 0, - alloc_hint, &ins, 1, 1); + ret = btrfs_reserve_extent(root, len, len, root->fs_info->sectorsize, + 0, alloc_hint, &ins, 1, 1); if (ret) return ERR_PTR(ret); @@ -7319,7 +7323,8 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, if (!nocow && found_type == BTRFS_FILE_EXTENT_PREALLOC) { u64 range_end; - range_end = round_up(offset + num_bytes, root->sectorsize) - 1; + range_end = round_up(offset + num_bytes, + root->fs_info->sectorsize) - 1; ret = test_range_bit(io_tree, offset, range_end, EXTENT_DELALLOC, 0, NULL); if (ret) { @@ -7604,7 +7609,7 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock, if (create) unlock_bits |= EXTENT_DIRTY; else - len = min_t(u64, len, root->sectorsize); + len = min_t(u64, len, root->fs_info->sectorsize); lockstart = start; lockend = start + len - 1; @@ -7726,7 +7731,7 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock, * give it a chance to use preallocated space. */ len = min_t(u64, bh_result->b_size, em->len - (start - em->start)); - len = ALIGN(len, root->sectorsize); + len = ALIGN(len, root->fs_info->sectorsize); free_extent_map(em); em = btrfs_new_extent_direct(inode, start, len); if (IS_ERR(em)) { @@ -7875,7 +7880,7 @@ static int dio_read_error(struct inode *inode, struct bio *failed_bio, if ((failed_bio->bi_vcnt > 1) || (failed_bio->bi_io_vec->bv_len - > BTRFS_I(inode)->root->sectorsize)) + > btrfs_inode_sectorsize(inode))) read_mode = READ_SYNC | REQ_FAILFAST_DEV; else read_mode = READ_SYNC; @@ -7922,7 +7927,7 @@ static void btrfs_retry_endio_nocsum(struct bio *bio) ASSERT(bio->bi_vcnt == 1); inode = bio->bi_io_vec->bv_page->mapping->host; - ASSERT(bio->bi_io_vec->bv_len == BTRFS_I(inode)->root->sectorsize); + ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(inode)); done->uptodate = 1; bio_for_each_segment_all(bvec, bio, i) @@ -7946,7 +7951,7 @@ static int __btrfs_correct_data_nocsum(struct inode *inode, int ret; fs_info = BTRFS_I(inode)->root->fs_info; - sectorsize = BTRFS_I(inode)->root->sectorsize; + sectorsize = fs_info->sectorsize; start = io_bio->logical; done.inode = inode; @@ -8005,7 +8010,7 @@ static void btrfs_retry_endio(struct bio *bio) ASSERT(bio->bi_vcnt == 1); inode = bio->bi_io_vec->bv_page->mapping->host; - ASSERT(bio->bi_io_vec->bv_len == BTRFS_I(inode)->root->sectorsize); + ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(inode)); bio_for_each_segment_all(bvec, bio, i) { ret = __readpage_endio_check(done->inode, io_bio, i, @@ -8040,7 +8045,7 @@ static int __btrfs_subio_endio_read(struct inode *inode, int ret; fs_info = BTRFS_I(inode)->root->fs_info; - sectorsize = BTRFS_I(inode)->root->sectorsize; + sectorsize = fs_info->sectorsize; err = 0; start = io_bio->logical; @@ -8339,7 +8344,7 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip, u64 file_offset = dip->logical_offset; u64 submit_len = 0; u64 map_length; - u32 blocksize = root->sectorsize; + u32 blocksize = root->fs_info->sectorsize; int async_submit = 0; int nr_sectors; int ret; @@ -8563,7 +8568,7 @@ static ssize_t check_direct_IO(struct btrfs_root *root, struct kiocb *iocb, { int seg; int i; - unsigned blocksize_mask = root->sectorsize - 1; + unsigned int blocksize_mask = root->fs_info->sectorsize - 1; ssize_t retval = -EINVAL; if (offset & blocksize_mask) @@ -8644,7 +8649,8 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) * do the accounting properly if we go over the number we * originally calculated. Abuse current->journal_info for this. */ - dio_data.reserve = round_up(count, root->sectorsize); + dio_data.reserve = round_up(count, + root->fs_info->sectorsize); dio_data.unsubmitted_oe_range_start = (u64)offset; dio_data.unsubmitted_oe_range_end = (u64)offset; current->journal_info = &dio_data; @@ -8990,7 +8996,8 @@ again: } if (page->index == ((size - 1) >> PAGE_SHIFT)) { - reserved_space = round_up(size - page_start, root->sectorsize); + reserved_space = round_up(size - page_start, + root->fs_info->sectorsize); if (reserved_space < PAGE_SIZE) { end = page_start + reserved_space - 1; spin_lock(&BTRFS_I(inode)->lock); @@ -9065,7 +9072,7 @@ static int btrfs_truncate(struct inode *inode) int ret = 0; int err = 0; struct btrfs_trans_handle *trans; - u64 mask = root->sectorsize - 1; + u64 mask = root->fs_info->sectorsize - 1; u64 min_size = btrfs_calc_trunc_metadata_size(root, 1); ret = btrfs_wait_ordered_range(inode, inode->i_size & (~mask), @@ -10157,7 +10164,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, struct extent_buffer *leaf; name_len = strlen(symname); - if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root)) + if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root->fs_info)) return -ENAMETOOLONG; /* diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 5b21a9b..062f67a 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -516,7 +516,8 @@ static noinline int create_subvol(struct inode *dir, btrfs_set_stack_inode_generation(inode_item, 1); btrfs_set_stack_inode_size(inode_item, 3); btrfs_set_stack_inode_nlink(inode_item, 1); - btrfs_set_stack_inode_nbytes(inode_item, root->nodesize); + btrfs_set_stack_inode_nbytes(inode_item, + root->fs_info->nodesize); btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755); btrfs_set_root_flags(root_item, 0); @@ -1595,8 +1596,8 @@ static noinline int btrfs_ioctl_resize(struct file *file, goto out_free; } - new_size = div_u64(new_size, root->sectorsize); - new_size *= root->sectorsize; + new_size = div_u64(new_size, root->fs_info->sectorsize); + new_size *= root->fs_info->sectorsize; btrfs_info_in_rcu(root->fs_info, "new size for %s is %llu", rcu_str_deref(device->name), new_size); @@ -3404,7 +3405,7 @@ static int clone_copy_inline_extent(struct inode *src, { struct btrfs_root *root = BTRFS_I(dst)->root; const u64 aligned_end = ALIGN(new_key->offset + datal, - root->sectorsize); + root->fs_info->sectorsize); int ret; struct btrfs_key key; @@ -3538,9 +3539,10 @@ static int btrfs_clone(struct inode *src, struct inode *inode, u64 last_dest_end = destoff; ret = -ENOMEM; - buf = kmalloc(root->nodesize, GFP_KERNEL | __GFP_NOWARN); + buf = kmalloc(root->fs_info->nodesize, + GFP_KERNEL | __GFP_NOWARN); if (!buf) { - buf = vmalloc(root->nodesize); + buf = vmalloc(root->fs_info->nodesize); if (!buf) return ret; } @@ -3798,7 +3800,7 @@ process_slot: btrfs_release_path(path); last_dest_end = ALIGN(new_key.offset + datal, - root->sectorsize); + root->fs_info->sectorsize); ret = clone_finish_inode_update(trans, inode, last_dest_end, destoff, olen, diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index b2d1e95..763bdfca 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -978,7 +978,7 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset, ordered->file_offset + ordered->truncated_len); } else { - offset = ALIGN(offset, BTRFS_I(inode)->root->sectorsize); + offset = ALIGN(offset, btrfs_inode_sectorsize(inode)); } disk_i_size = BTRFS_I(inode)->disk_i_size; @@ -1087,7 +1087,7 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree; unsigned long num_sectors; unsigned long i; - u32 sectorsize = BTRFS_I(inode)->root->sectorsize; + u32 sectorsize = btrfs_inode_sectorsize(inode); int index = 0; ordered = btrfs_lookup_ordered_extent(inode, offset); diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index 4515077..5f2b0ca 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -145,10 +145,10 @@ struct btrfs_ordered_extent { * calculates the total size you need to allocate for an ordered sum * structure spanning 'bytes' in the file */ -static inline int btrfs_ordered_sum_size(struct btrfs_root *root, +static inline int btrfs_ordered_sum_size(struct btrfs_fs_info *fs_info, unsigned long bytes) { - int num_sectors = (int)DIV_ROUND_UP(bytes, root->sectorsize); + int num_sectors = (int)DIV_ROUND_UP(bytes, fs_info->sectorsize); return sizeof(struct btrfs_ordered_sum) + num_sectors * sizeof(u32); } diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c index 438575e..57c403b 100644 --- a/fs/btrfs/print-tree.c +++ b/fs/btrfs/print-tree.c @@ -331,7 +331,7 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *c) btrfs_info(root->fs_info, "node %llu level %d total ptrs %d free spc %u", btrfs_header_bytenr(c), level, nr, - (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr); + (u32)BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - nr); for (i = 0; i < nr; i++) { btrfs_node_key_to_cpu(c, &key, i); pr_info("\tkey %d (%llu %u %llu) block %llu\n", diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 605a322..1fd9bef 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1700,7 +1700,7 @@ walk_down: ret = btrfs_qgroup_trace_extent(trans, root->fs_info, child_bytenr, - root->nodesize, GFP_NOFS); + root->fs_info->nodesize, GFP_NOFS); if (ret) goto out; } @@ -2170,7 +2170,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, } rcu_read_lock(); - level_size = srcroot->nodesize; + level_size = srcroot->fs_info->nodesize; rcu_read_unlock(); } @@ -2522,7 +2522,7 @@ qgroup_rescan_leaf(struct btrfs_fs_info *fs_info, struct btrfs_path *path, found.type != BTRFS_METADATA_ITEM_KEY) continue; if (found.type == BTRFS_METADATA_ITEM_KEY) - num_bytes = fs_info->extent_root->nodesize; + num_bytes = fs_info->nodesize; else num_bytes = found.offset; @@ -2903,7 +2903,7 @@ int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes) !is_fstree(root->objectid) || num_bytes == 0) return 0; - BUG_ON(num_bytes != round_down(num_bytes, root->nodesize)); + BUG_ON(num_bytes != round_down(num_bytes, root->fs_info->nodesize)); ret = qgroup_reserve(root, num_bytes); if (ret < 0) return ret; @@ -2931,7 +2931,7 @@ void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes) !is_fstree(root->objectid)) return; - BUG_ON(num_bytes != round_down(num_bytes, root->nodesize)); + BUG_ON(num_bytes != round_down(num_bytes, root->fs_info->nodesize)); WARN_ON(atomic_read(&root->qgroup_meta_rsv) < num_bytes); atomic_sub(num_bytes, &root->qgroup_meta_rsv); qgroup_free(root, num_bytes); diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index eece126..6e9e21d 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c @@ -2235,7 +2235,7 @@ raid56_parity_alloc_scrub_rbio(struct btrfs_root *root, struct bio *bio, } /* Now we just support the sectorsize equals to page size */ - ASSERT(root->sectorsize == PAGE_SIZE); + ASSERT(root->fs_info->sectorsize == PAGE_SIZE); ASSERT(rbio->stripe_npages == stripe_nsectors); bitmap_copy(rbio->dbitmap, dbitmap, stripe_nsectors); diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c index 540e729..c51292a 100644 --- a/fs/btrfs/reada.c +++ b/fs/btrfs/reada.c @@ -335,7 +335,7 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root, if (!re) return NULL; - blocksize = root->nodesize; + blocksize = root->fs_info->nodesize; re->logical = logical; re->top = *top; INIT_LIST_HEAD(&re->extctl); @@ -679,7 +679,7 @@ static int reada_start_machine_dev(struct btrfs_fs_info *fs_info, spin_unlock(&fs_info->reada_lock); return 0; } - dev->reada_next = re->logical + fs_info->tree_root->nodesize; + dev->reada_next = re->logical + fs_info->nodesize; re->refcnt++; spin_unlock(&fs_info->reada_lock); @@ -843,7 +843,7 @@ static void dump_devs(struct btrfs_fs_info *fs_info, int all) if (ret == 0) break; pr_debug(" re: logical %llu size %u empty %d scheduled %d", - re->logical, fs_info->tree_root->nodesize, + re->logical, fs_info->nodesize, list_empty(&re->extctl), re->scheduled); for (i = 0; i < re->nzones; ++i) { @@ -876,7 +876,7 @@ static void dump_devs(struct btrfs_fs_info *fs_info, int all) continue; } pr_debug("re: logical %llu size %u list empty %d scheduled %d", - re->logical, fs_info->tree_root->nodesize, + re->logical, fs_info->nodesize, list_empty(&re->extctl), re->scheduled); for (i = 0; i < re->nzones; ++i) { pr_cont(" zone %llu-%llu devs", diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 466c345..a515591 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1698,8 +1698,8 @@ int replace_file_extents(struct btrfs_trans_handle *trans, end = key.offset + btrfs_file_extent_num_bytes(leaf, fi); WARN_ON(!IS_ALIGNED(key.offset, - root->sectorsize)); - WARN_ON(!IS_ALIGNED(end, root->sectorsize)); + root->fs_info->sectorsize)); + WARN_ON(!IS_ALIGNED(end, root->fs_info->sectorsize)); end--; ret = try_lock_extent(&BTRFS_I(inode)->io_tree, key.offset, end); @@ -1834,7 +1834,7 @@ again: btrfs_node_key_to_cpu(parent, next_key, slot + 1); old_bytenr = btrfs_node_blockptr(parent, slot); - blocksize = dest->nodesize; + blocksize = dest->fs_info->nodesize; old_ptr_gen = btrfs_node_ptr_generation(parent, slot); if (level <= max_level) { @@ -2095,7 +2095,7 @@ static int invalidate_extent_cache(struct btrfs_root *root, start = 0; else { start = min_key->offset; - WARN_ON(!IS_ALIGNED(start, root->sectorsize)); + WARN_ON(!IS_ALIGNED(start, root->fs_info->sectorsize)); } } else { start = 0; @@ -2110,7 +2110,7 @@ static int invalidate_extent_cache(struct btrfs_root *root, if (max_key->offset == 0) continue; end = max_key->offset; - WARN_ON(!IS_ALIGNED(end, root->sectorsize)); + WARN_ON(!IS_ALIGNED(end, root->fs_info->sectorsize)); end--; } } else { @@ -2198,7 +2198,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc, btrfs_unlock_up_safe(path, 0); } - min_reserved = root->nodesize * (BTRFS_MAX_LEVEL - 1) * 2; + min_reserved = root->fs_info->nodesize * (BTRFS_MAX_LEVEL - 1) * 2; memset(&next_key, 0, sizeof(next_key)); while (1) { @@ -2311,7 +2311,7 @@ int prepare_to_merge(struct reloc_control *rc, int err) int ret; mutex_lock(&root->fs_info->reloc_mutex); - rc->merging_rsv_size += root->nodesize * (BTRFS_MAX_LEVEL - 1) * 2; + rc->merging_rsv_size += root->fs_info->nodesize * (BTRFS_MAX_LEVEL - 1) * 2; rc->merging_rsv_size += rc->nodes_relocated * 2; mutex_unlock(&root->fs_info->reloc_mutex); @@ -2616,7 +2616,7 @@ u64 calcu_metadata_size(struct reloc_control *rc, if (next->processed && (reserve || next != node)) break; - num_bytes += rc->extent_root->nodesize; + num_bytes += rc->extent_root->fs_info->nodesize; if (list_empty(&next->upper)) break; @@ -2636,6 +2636,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, struct backref_node *node) { struct btrfs_root *root = rc->extent_root; + struct btrfs_fs_info *fs_info = root->fs_info; u64 num_bytes; int ret; u64 tmp; @@ -2653,7 +2654,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, ret = btrfs_block_rsv_refill(root, rc->block_rsv, num_bytes, BTRFS_RESERVE_FLUSH_LIMIT); if (ret) { - tmp = rc->extent_root->nodesize * RELOCATION_RESERVED_NODES; + tmp = fs_info->nodesize * RELOCATION_RESERVED_NODES; while (tmp <= rc->reserved_bytes) tmp <<= 1; /* @@ -2663,8 +2664,8 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, * space for relocation and we will return eailer in * enospc case. */ - rc->block_rsv->size = tmp + rc->extent_root->nodesize * - RELOCATION_RESERVED_NODES; + rc->block_rsv->size = tmp + fs_info->nodesize * + RELOCATION_RESERVED_NODES; return -EAGAIN; } @@ -2764,7 +2765,7 @@ static int do_relocation(struct btrfs_trans_handle *trans, goto next; } - blocksize = root->nodesize; + blocksize = root->fs_info->nodesize; generation = btrfs_node_ptr_generation(upper->eb, slot); eb = read_tree_block(root, bytenr, generation); if (IS_ERR(eb)) { @@ -2877,7 +2878,7 @@ static void __mark_block_processed(struct reloc_control *rc, u32 blocksize; if (node->level == 0 || in_block_group(node->bytenr, rc->block_group)) { - blocksize = rc->extent_root->nodesize; + blocksize = rc->extent_root->fs_info->nodesize; mark_block_processed(rc, node->bytenr, blocksize); } node->processed = 1; @@ -2917,7 +2918,7 @@ static void update_processed_blocks(struct reloc_control *rc, static int tree_block_processed(u64 bytenr, struct reloc_control *rc) { - u32 blocksize = rc->extent_root->nodesize; + u32 blocksize = rc->extent_root->fs_info->nodesize; if (test_range_bit(&rc->processed_blocks, bytenr, bytenr + blocksize - 1, EXTENT_DIRTY, 1, NULL)) @@ -3399,7 +3400,7 @@ static int add_tree_block(struct reloc_control *rc, return -ENOMEM; block->bytenr = extent_key->objectid; - block->key.objectid = rc->extent_root->nodesize; + block->key.objectid = rc->extent_root->fs_info->nodesize; block->key.offset = generation; block->level = level; block->key_ready = 0; @@ -3729,7 +3730,7 @@ int add_data_references(struct reloc_control *rc, struct btrfs_extent_inline_ref *iref; unsigned long ptr; unsigned long end; - u32 blocksize = rc->extent_root->nodesize; + u32 blocksize = rc->extent_root->fs_info->nodesize; int ret = 0; int err = 0; @@ -3871,7 +3872,7 @@ next: } if (key.type == BTRFS_METADATA_ITEM_KEY && - key.objectid + rc->extent_root->nodesize <= + key.objectid + rc->extent_root->fs_info->nodesize <= rc->search_start) { path->slots[0]++; goto next; @@ -3889,7 +3890,7 @@ next: rc->search_start = key.objectid + key.offset; else rc->search_start = key.objectid + - rc->extent_root->nodesize; + rc->extent_root->fs_info->nodesize; memcpy(extent_key, &key, sizeof(key)); return 0; } @@ -3947,7 +3948,7 @@ int prepare_to_relocate(struct reloc_control *rc) rc->nodes_relocated = 0; rc->merging_rsv_size = 0; rc->reserved_bytes = 0; - rc->block_rsv->size = rc->extent_root->nodesize * + rc->block_rsv->size = rc->extent_root->fs_info->nodesize * RELOCATION_RESERVED_NODES; ret = btrfs_block_rsv_refill(rc->extent_root, rc->block_rsv, rc->block_rsv->size, diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index ed70246..6834ff8 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -489,8 +489,8 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace) sctx->bios[i]->next_free = -1; } sctx->first_free = 0; - sctx->nodesize = dev->fs_info->dev_root->nodesize; - sctx->sectorsize = dev->fs_info->dev_root->sectorsize; + sctx->nodesize = dev->fs_info->nodesize; + sctx->sectorsize = dev->fs_info->sectorsize; atomic_set(&sctx->bios_in_flight, 0); atomic_set(&sctx->workers_pending, 0); atomic_set(&sctx->cancel_req, 0); @@ -2390,7 +2390,7 @@ static inline void __scrub_mark_bitmap(struct scrub_parity *sparity, { u32 offset; int nsectors; - int sectorsize = sparity->sctx->fs_info->dev_root->sectorsize; + int sectorsize = sparity->sctx->fs_info->sectorsize; if (len >= sparity->stripe_len) { bitmap_set(bitmap, 0, sparity->nsectors); @@ -2866,7 +2866,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx, int extent_mirror_num; int stop_loop = 0; - nsectors = div_u64(map->stripe_len, root->sectorsize); + nsectors = div_u64(map->stripe_len, root->fs_info->sectorsize); bitmap_len = scrub_calc_parity_bitmap_len(nsectors); sparity = kzalloc(sizeof(struct scrub_parity) + 2 * bitmap_len, GFP_NOFS); @@ -2937,7 +2937,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx, goto next; if (key.type == BTRFS_METADATA_ITEM_KEY) - bytes = root->nodesize; + bytes = root->fs_info->nodesize; else bytes = key.offset; @@ -3290,7 +3290,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, goto next; if (key.type == BTRFS_METADATA_ITEM_KEY) - bytes = root->nodesize; + bytes = root->fs_info->nodesize; else bytes = key.offset; @@ -3848,7 +3848,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, if (btrfs_fs_closing(fs_info)) return -EINVAL; - if (fs_info->chunk_root->nodesize > BTRFS_STRIPE_LEN) { + if (fs_info->nodesize > BTRFS_STRIPE_LEN) { /* * in this case scrub is unable to calculate the checksum * the way scrub is implemented. Do not handle this @@ -3856,31 +3856,31 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, */ btrfs_err(fs_info, "scrub: size assumption nodesize <= BTRFS_STRIPE_LEN (%d <= %d) fails", - fs_info->chunk_root->nodesize, BTRFS_STRIPE_LEN); + fs_info->nodesize, + BTRFS_STRIPE_LEN); return -EINVAL; } - if (fs_info->chunk_root->sectorsize != PAGE_SIZE) { + if (fs_info->sectorsize != PAGE_SIZE) { /* not supported for data w/o checksums */ btrfs_err_rl(fs_info, "scrub: size assumption sectorsize != PAGE_SIZE (%d != %lu) fails", - fs_info->chunk_root->sectorsize, PAGE_SIZE); + fs_info->sectorsize, PAGE_SIZE); return -EINVAL; } - if (fs_info->chunk_root->nodesize > + if (fs_info->nodesize > PAGE_SIZE * SCRUB_MAX_PAGES_PER_BLOCK || - fs_info->chunk_root->sectorsize > - PAGE_SIZE * SCRUB_MAX_PAGES_PER_BLOCK) { + fs_info->sectorsize > PAGE_SIZE * SCRUB_MAX_PAGES_PER_BLOCK) { /* * would exhaust the array bounds of pagev member in * struct scrub_block */ btrfs_err(fs_info, "scrub: size assumption nodesize and sectorsize <= SCRUB_MAX_PAGES_PER_BLOCK (%d <= %d && %d <= %d) fails", - fs_info->chunk_root->nodesize, + fs_info->nodesize, SCRUB_MAX_PAGES_PER_BLOCK, - fs_info->chunk_root->sectorsize, + fs_info->sectorsize, SCRUB_MAX_PAGES_PER_BLOCK); return -EINVAL; } diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 71261b4..78845cc 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -1054,7 +1054,8 @@ static int iterate_dir_item(struct btrfs_root *root, struct btrfs_path *path, ret = -ENAMETOOLONG; goto out; } - if (name_len + data_len > BTRFS_MAX_XATTR_SIZE(root)) { + if (name_len + data_len > + BTRFS_MAX_XATTR_SIZE(root->fs_info)) { ret = -E2BIG; goto out; } @@ -5264,7 +5265,7 @@ static int get_last_extent(struct send_ctx *sctx, u64 offset) u64 size = btrfs_file_extent_inline_len(path->nodes[0], path->slots[0], fi); extent_end = ALIGN(key.offset + size, - sctx->send_root->sectorsize); + sctx->send_root->fs_info->sectorsize); } else { extent_end = key.offset + btrfs_file_extent_num_bytes(path->nodes[0], fi); @@ -5299,7 +5300,7 @@ static int maybe_send_hole(struct send_ctx *sctx, struct btrfs_path *path, u64 size = btrfs_file_extent_inline_len(path->nodes[0], path->slots[0], fi); extent_end = ALIGN(key->offset + size, - sctx->send_root->sectorsize); + sctx->send_root->fs_info->sectorsize); } else { extent_end = key->offset + btrfs_file_extent_num_bytes(path->nodes[0], fi); diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 457e05e..c91a51f 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -594,7 +594,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, if (info->max_inline) { info->max_inline = min_t(u64, info->max_inline, - root->sectorsize); + root->fs_info->sectorsize); } btrfs_info(root->fs_info, "max_inline at %llu", info->max_inline); diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c index bf62ad9..cfabeeb 100644 --- a/fs/btrfs/tests/btrfs-tests.c +++ b/fs/btrfs/tests/btrfs-tests.c @@ -79,7 +79,7 @@ static void btrfs_destroy_test_fs(void) unregister_filesystem(&test_type); } -struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void) +struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize) { struct btrfs_fs_info *fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_KERNEL); @@ -100,6 +100,9 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void) return NULL; } + fs_info->nodesize = nodesize; + fs_info->sectorsize = sectorsize; + if (init_srcu_struct(&fs_info->subvol_srcu)) { kfree(fs_info->fs_devices); kfree(fs_info->super_copy); @@ -189,7 +192,8 @@ void btrfs_free_dummy_root(struct btrfs_root *root) } struct btrfs_block_group_cache * -btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize) +btrfs_alloc_dummy_block_group(struct btrfs_fs_info *fs_info, + unsigned long length) { struct btrfs_block_group_cache *cache; @@ -206,8 +210,9 @@ btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize) cache->key.objectid = 0; cache->key.offset = length; cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; - cache->sectorsize = sectorsize; - cache->full_stripe_len = sectorsize; + cache->sectorsize = fs_info->sectorsize; + cache->full_stripe_len = fs_info->sectorsize; + cache->fs_info = fs_info; INIT_LIST_HEAD(&cache->list); INIT_LIST_HEAD(&cache->cluster_list); diff --git a/fs/btrfs/tests/btrfs-tests.h b/fs/btrfs/tests/btrfs-tests.h index b17ffbe..266f1e3 100644 --- a/fs/btrfs/tests/btrfs-tests.h +++ b/fs/btrfs/tests/btrfs-tests.h @@ -34,11 +34,11 @@ int btrfs_test_inodes(u32 sectorsize, u32 nodesize); int btrfs_test_qgroups(u32 sectorsize, u32 nodesize); int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize); struct inode *btrfs_new_test_inode(void); -struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void); +struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize); void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info); void btrfs_free_dummy_root(struct btrfs_root *root); struct btrfs_block_group_cache * -btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize); +btrfs_alloc_dummy_block_group(struct btrfs_fs_info *fs_info, unsigned long length); void btrfs_free_dummy_block_group(struct btrfs_block_group_cache *cache); void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans); #else diff --git a/fs/btrfs/tests/extent-buffer-tests.c b/fs/btrfs/tests/extent-buffer-tests.c index 1995691..b9142c6 100644 --- a/fs/btrfs/tests/extent-buffer-tests.c +++ b/fs/btrfs/tests/extent-buffer-tests.c @@ -41,13 +41,13 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize) test_msg("Running btrfs_split_item tests\n"); - fs_info = btrfs_alloc_dummy_fs_info(); + fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize); if (!fs_info) { test_msg("Could not allocate fs_info\n"); return -ENOMEM; } - root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); + root = btrfs_alloc_dummy_root(fs_info); if (IS_ERR(root)) { test_msg("Could not allocate root\n"); ret = PTR_ERR(root); @@ -61,8 +61,7 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize) goto out; } - path->nodes[0] = eb = alloc_dummy_extent_buffer(NULL, nodesize, - nodesize); + path->nodes[0] = eb = alloc_dummy_extent_buffer(fs_info, nodesize); if (!eb) { test_msg("Could not allocate dummy buffer\n"); ret = -ENOMEM; diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c index 2c7a0a9..1337532 100644 --- a/fs/btrfs/tests/extent-io-tests.c +++ b/fs/btrfs/tests/extent-io-tests.c @@ -383,6 +383,7 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb, static int test_eb_bitmaps(u32 sectorsize, u32 nodesize) { + struct btrfs_fs_info *fs_info; unsigned long len; unsigned long *bitmap; struct extent_buffer *eb; @@ -397,13 +398,15 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize) len = (sectorsize < BTRFS_MAX_METADATA_BLOCKSIZE) ? sectorsize * 4 : sectorsize; + fs_info = btrfs_alloc_dummy_fs_info(len, len); + bitmap = kmalloc(len, GFP_KERNEL); if (!bitmap) { test_msg("Couldn't allocate test bitmap\n"); return -ENOMEM; } - eb = __alloc_dummy_extent_buffer(NULL, 0, len); + eb = __alloc_dummy_extent_buffer(fs_info, 0, len); if (!eb) { test_msg("Couldn't allocate test extent buffer\n"); kfree(bitmap); diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c index 3221c8d..eca6412 100644 --- a/fs/btrfs/tests/free-space-tests.c +++ b/fs/btrfs/tests/free-space-tests.c @@ -843,33 +843,31 @@ int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize) int ret = -ENOMEM; test_msg("Running btrfs free space cache tests\n"); + fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize); + if (!fs_info) + return -ENOMEM; + /* * For ppc64 (with 64k page size), bytes per bitmap might be * larger than 1G. To make bitmap test available in ppc64, * alloc dummy block group whose size cross bitmaps. */ - cache = btrfs_alloc_dummy_block_group(BITS_PER_BITMAP * sectorsize - + PAGE_SIZE, sectorsize); + cache = btrfs_alloc_dummy_block_group(fs_info, + BITS_PER_BITMAP * sectorsize + PAGE_SIZE); if (!cache) { test_msg("Couldn't run the tests\n"); + btrfs_free_dummy_fs_info(fs_info); return 0; } - fs_info = btrfs_alloc_dummy_fs_info(); - if (!fs_info) { - ret = -ENOMEM; - goto out; - } - - root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); + root = btrfs_alloc_dummy_root(fs_info); if (IS_ERR(root)) { ret = PTR_ERR(root); goto out; } root->fs_info->extent_root = root; - cache->fs_info = root->fs_info; ret = test_extents(cache); if (ret) diff --git a/fs/btrfs/tests/free-space-tree-tests.c b/fs/btrfs/tests/free-space-tree-tests.c index 6e14404..b29954c 100644 --- a/fs/btrfs/tests/free-space-tree-tests.c +++ b/fs/btrfs/tests/free-space-tree-tests.c @@ -455,14 +455,14 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize, struct btrfs_path *path = NULL; int ret; - fs_info = btrfs_alloc_dummy_fs_info(); + fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize); if (!fs_info) { test_msg("Couldn't allocate dummy fs info\n"); ret = -ENOMEM; goto out; } - root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); + root = btrfs_alloc_dummy_root(fs_info); if (IS_ERR(root)) { test_msg("Couldn't allocate dummy root\n"); ret = PTR_ERR(root); @@ -474,8 +474,7 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize, root->fs_info->free_space_root = root; root->fs_info->tree_root = root; - root->node = alloc_test_extent_buffer(root->fs_info, - nodesize, nodesize); + root->node = alloc_test_extent_buffer(root->fs_info, nodesize); if (!root->node) { test_msg("Couldn't allocate dummy buffer\n"); ret = -ENOMEM; @@ -485,7 +484,7 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize, btrfs_set_header_nritems(root->node, 0); root->alloc_bytenr += 2 * nodesize; - cache = btrfs_alloc_dummy_block_group(8 * alignment, sectorsize); + cache = btrfs_alloc_dummy_block_group(fs_info, 8 * alignment); if (!cache) { test_msg("Couldn't allocate dummy block group cache\n"); ret = -ENOMEM; diff --git a/fs/btrfs/tests/inode-tests.c b/fs/btrfs/tests/inode-tests.c index 0bf4680..4d0f038 100644 --- a/fs/btrfs/tests/inode-tests.c +++ b/fs/btrfs/tests/inode-tests.c @@ -249,19 +249,19 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize) BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID; BTRFS_I(inode)->location.offset = 0; - fs_info = btrfs_alloc_dummy_fs_info(); + fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize); if (!fs_info) { test_msg("Couldn't allocate dummy fs info\n"); goto out; } - root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); + root = btrfs_alloc_dummy_root(fs_info); if (IS_ERR(root)) { test_msg("Couldn't allocate root\n"); goto out; } - root->node = alloc_dummy_extent_buffer(NULL, nodesize, nodesize); + root->node = alloc_dummy_extent_buffer(fs_info, nodesize); if (!root->node) { test_msg("Couldn't allocate dummy buffer\n"); goto out; @@ -854,19 +854,19 @@ static int test_hole_first(u32 sectorsize, u32 nodesize) BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID; BTRFS_I(inode)->location.offset = 0; - fs_info = btrfs_alloc_dummy_fs_info(); + fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize); if (!fs_info) { test_msg("Couldn't allocate dummy fs info\n"); goto out; } - root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); + root = btrfs_alloc_dummy_root(fs_info); if (IS_ERR(root)) { test_msg("Couldn't allocate root\n"); goto out; } - root->node = alloc_dummy_extent_buffer(NULL, nodesize, nodesize); + root->node = alloc_dummy_extent_buffer(fs_info, nodesize); if (!root->node) { test_msg("Couldn't allocate dummy buffer\n"); goto out; @@ -950,13 +950,13 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) return ret; } - fs_info = btrfs_alloc_dummy_fs_info(); + fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize); if (!fs_info) { test_msg("Couldn't allocate dummy fs info\n"); goto out; } - root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); + root = btrfs_alloc_dummy_root(fs_info); if (IS_ERR(root)) { test_msg("Couldn't allocate root\n"); goto out; diff --git a/fs/btrfs/tests/qgroup-tests.c b/fs/btrfs/tests/qgroup-tests.c index ca7cb5e..0f4ce97 100644 --- a/fs/btrfs/tests/qgroup-tests.c +++ b/fs/btrfs/tests/qgroup-tests.c @@ -458,13 +458,13 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) struct btrfs_root *tmp_root; int ret = 0; - fs_info = btrfs_alloc_dummy_fs_info(); + fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize); if (!fs_info) { test_msg("Couldn't allocate dummy fs info\n"); return -ENOMEM; } - root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); + root = btrfs_alloc_dummy_root(fs_info); if (IS_ERR(root)) { test_msg("Couldn't allocate root\n"); ret = PTR_ERR(root); @@ -486,8 +486,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) * Can't use bytenr 0, some things freak out * *cough*backref walking code*cough* */ - root->node = alloc_test_extent_buffer(root->fs_info, nodesize, - nodesize); + root->node = alloc_test_extent_buffer(root->fs_info, nodesize); if (!root->node) { test_msg("Couldn't allocate dummy buffer\n"); ret = -ENOMEM; @@ -497,7 +496,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) btrfs_set_header_nritems(root->node, 0); root->alloc_bytenr += 2 * nodesize; - tmp_root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); + tmp_root = btrfs_alloc_dummy_root(fs_info); if (IS_ERR(tmp_root)) { test_msg("Couldn't allocate a fs root\n"); ret = PTR_ERR(tmp_root); @@ -512,7 +511,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) goto out; } - tmp_root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); + tmp_root = btrfs_alloc_dummy_root(fs_info); if (IS_ERR(tmp_root)) { test_msg("Couldn't allocate a fs root\n"); ret = PTR_ERR(tmp_root); diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index ab1fa59..b8aaf1c 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -497,7 +497,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items, * the appropriate flushing if need be. */ if (num_items > 0 && root != root->fs_info->chunk_root) { - qgroup_reserved = num_items * root->nodesize; + qgroup_reserved = num_items * root->fs_info->nodesize; ret = btrfs_qgroup_reserve_meta(root, qgroup_reserved); if (ret) return ERR_PTR(ret); @@ -507,7 +507,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items, * Do the reservation for the relocation root creation */ if (need_reserve_reloc_root(root)) { - num_bytes += root->nodesize; + num_bytes += root->fs_info->nodesize; reloc_reserved = true; } diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 72bd398..ad3ae2e 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -608,7 +608,8 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, } else if (found_type == BTRFS_FILE_EXTENT_INLINE) { size = btrfs_file_extent_inline_len(eb, slot, item); nbytes = btrfs_file_extent_ram_bytes(eb, item); - extent_end = ALIGN(start + size, root->sectorsize); + extent_end = ALIGN(start + size, + root->fs_info->sectorsize); } else { ret = 0; goto out; @@ -2432,7 +2433,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, bytenr = btrfs_node_blockptr(cur, path->slots[*level]); ptr_gen = btrfs_node_ptr_generation(cur, path->slots[*level]); - blocksize = root->nodesize; + blocksize = root->fs_info->nodesize; parent = path->nodes[*level]; root_owner = btrfs_header_owner(parent); @@ -3789,7 +3790,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans, src_path->slots[0], extent); *last_extent = ALIGN(key.offset + len, - log->sectorsize); + log->fs_info->sectorsize); } else { len = btrfs_file_extent_num_bytes(src, extent); *last_extent = key.offset + len; @@ -3852,7 +3853,8 @@ fill_holes: if (btrfs_file_extent_type(src, extent) == BTRFS_FILE_EXTENT_INLINE) { len = btrfs_file_extent_inline_len(src, i, extent); - extent_end = ALIGN(key.offset + len, log->sectorsize); + extent_end = ALIGN(key.offset + len, + log->fs_info->sectorsize); } else { len = btrfs_file_extent_num_bytes(src, extent); extent_end = key.offset + len; @@ -4427,7 +4429,7 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans, if (hole_size == 0) return 0; - hole_size = ALIGN(hole_size, root->sectorsize); + hole_size = ALIGN(hole_size, root->fs_info->sectorsize); ret = btrfs_insert_file_extent(trans, log, ino, hole_start, 0, 0, hole_size, 0, hole_size, 0, 0, 0); return ret; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 4a21d82..4d3e5c4 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2381,9 +2381,9 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path) device->can_discard = 1; device->writeable = 1; device->generation = trans->transid; - device->io_width = root->sectorsize; - device->io_align = root->sectorsize; - device->sector_size = root->sectorsize; + device->io_width = root->fs_info->sectorsize; + device->io_align = root->fs_info->sectorsize; + device->sector_size = root->fs_info->sectorsize; device->total_bytes = i_size_read(bdev->bd_inode); device->disk_total_bytes = device->total_bytes; device->commit_total_bytes = device->total_bytes; @@ -2587,9 +2587,9 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path, mutex_lock(&root->fs_info->fs_devices->device_list_mutex); device->writeable = 1; device->generation = 0; - device->io_width = root->sectorsize; - device->io_align = root->sectorsize; - device->sector_size = root->sectorsize; + device->io_width = root->fs_info->sectorsize; + device->io_align = root->fs_info->sectorsize; + device->sector_size = root->fs_info->sectorsize; device->total_bytes = btrfs_device_get_total_bytes(srcdev); device->disk_total_bytes = btrfs_device_get_disk_total_bytes(srcdev); device->bytes_used = btrfs_device_get_bytes_used(srcdev); @@ -2620,10 +2620,12 @@ error: void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info, struct btrfs_device *tgtdev) { + u32 sectorsize = fs_info->sectorsize; + WARN_ON(fs_info->fs_devices->rw_devices == 0); - tgtdev->io_width = fs_info->dev_root->sectorsize; - tgtdev->io_align = fs_info->dev_root->sectorsize; - tgtdev->sector_size = fs_info->dev_root->sectorsize; + tgtdev->io_width = sectorsize; + tgtdev->io_align = sectorsize; + tgtdev->sector_size = sectorsize; tgtdev->fs_info = fs_info; tgtdev->in_fs_metadata = 1; } @@ -4582,7 +4584,7 @@ static void check_raid56_incompat_flag(struct btrfs_fs_info *info, u64 type) btrfs_set_fs_incompat(info, RAID56); } -#define BTRFS_MAX_DEVS(r) ((BTRFS_MAX_ITEM_SIZE(r) \ +#define BTRFS_MAX_DEVS(r) ((BTRFS_MAX_ITEM_SIZE(r->fs_info) \ - sizeof(struct btrfs_chunk)) \ / sizeof(struct btrfs_stripe) + 1) @@ -4761,12 +4763,12 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, if (type & BTRFS_BLOCK_GROUP_RAID5) { raid_stripe_len = find_raid56_stripe_len(ndevs - 1, - extent_root->stripesize); + info->stripesize); data_stripes = num_stripes - 1; } if (type & BTRFS_BLOCK_GROUP_RAID6) { raid_stripe_len = find_raid56_stripe_len(ndevs - 2, - extent_root->stripesize); + info->stripesize); data_stripes = num_stripes - 2; } @@ -4811,7 +4813,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, j * stripe_size; } } - map->sector_size = extent_root->sectorsize; + map->sector_size = info->sectorsize; map->stripe_len = raid_stripe_len; map->io_align = raid_stripe_len; map->io_width = raid_stripe_len; @@ -4983,7 +4985,8 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, btrfs_set_stack_chunk_num_stripes(chunk, map->num_stripes); btrfs_set_stack_chunk_io_align(chunk, map->stripe_len); btrfs_set_stack_chunk_io_width(chunk, map->stripe_len); - btrfs_set_stack_chunk_sector_size(chunk, extent_root->sectorsize); + btrfs_set_stack_chunk_sector_size(chunk, + extent_root->fs_info->sectorsize); btrfs_set_stack_chunk_sub_stripes(chunk, map->sub_stripes); key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; @@ -5189,7 +5192,7 @@ unsigned long btrfs_full_stripe_len(struct btrfs_root *root, struct extent_map *em; struct map_lookup *map; struct extent_map_tree *em_tree = &map_tree->map_tree; - unsigned long len = root->sectorsize; + unsigned long len = root->fs_info->sectorsize; read_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, logical, len); @@ -6360,17 +6363,17 @@ static int btrfs_check_chunk_valid(struct btrfs_root *root, num_stripes); return -EIO; } - if (!IS_ALIGNED(logical, root->sectorsize)) { + if (!IS_ALIGNED(logical, root->fs_info->sectorsize)) { btrfs_err(root->fs_info, "invalid chunk logical %llu", logical); return -EIO; } - if (btrfs_chunk_sector_size(leaf, chunk) != root->sectorsize) { + if (btrfs_chunk_sector_size(leaf, chunk) != root->fs_info->sectorsize) { btrfs_err(root->fs_info, "invalid chunk sectorsize %u", btrfs_chunk_sector_size(leaf, chunk)); return -EIO; } - if (!length || !IS_ALIGNED(length, root->sectorsize)) { + if (!length || !IS_ALIGNED(length, root->fs_info->sectorsize)) { btrfs_err(root->fs_info, "invalid chunk length %llu", length); return -EIO; @@ -6682,7 +6685,7 @@ int btrfs_read_sys_array(struct btrfs_fs_info *fs_info) u64 type; struct btrfs_key key; - ASSERT(BTRFS_SUPER_INFO_SIZE <= root->nodesize); + ASSERT(BTRFS_SUPER_INFO_SIZE <= root->fs_info->nodesize); /* * This will create extent buffer of nodesize, superblock size is * fixed to BTRFS_SUPER_INFO_SIZE. If nodesize > sb size, this will diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c index fccbf55..b295574 100644 --- a/fs/btrfs/xattr.c +++ b/fs/btrfs/xattr.c @@ -98,7 +98,7 @@ static int do_setxattr(struct btrfs_trans_handle *trans, size_t name_len = strlen(name); int ret = 0; - if (name_len + size > BTRFS_MAX_XATTR_SIZE(root)) + if (name_len + size > BTRFS_MAX_XATTR_SIZE(root->fs_info)) return -ENOSPC; path = btrfs_alloc_path(); |