aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2014-06-04 13:22:26 -0400
committerChris Mason <clm@fb.com>2014-09-17 16:37:14 -0400
commit707e8a071528385a87b63a72a37c2322e463c7b8 (patch)
tree02fa581efa4d2a05b4e786a553cf9e88bd6274b3
parent962a298f35110edd8f326814ae41a3dd306ecb64 (diff)
btrfs: use nodesize everywhere, kill leafsize
The nodesize and leafsize were never of different values. Unify the usage and make nodesize the one. Cleanup the redundant checks and helpers. Shaves a few bytes from .text: text data bss dec hex filename 852418 24560 23112 900090 dbbfa btrfs.ko.before 851074 24584 23112 898770 db6d2 btrfs.ko.after Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r--fs/btrfs/backref.c8
-rw-r--r--fs/btrfs/check-integrity.c13
-rw-r--r--fs/btrfs/ctree.c18
-rw-r--r--fs/btrfs/ctree.h21
-rw-r--r--fs/btrfs/disk-io.c74
-rw-r--r--fs/btrfs/extent-tree.c36
-rw-r--r--fs/btrfs/file.c2
-rw-r--r--fs/btrfs/ioctl.c6
-rw-r--r--fs/btrfs/print-tree.c2
-rw-r--r--fs/btrfs/qgroup.c6
-rw-r--r--fs/btrfs/reada.c2
-rw-r--r--fs/btrfs/relocation.c21
-rw-r--r--fs/btrfs/scrub.c17
-rw-r--r--fs/btrfs/transaction.c2
-rw-r--r--fs/btrfs/tree-log.c2
15 files changed, 89 insertions, 141 deletions
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index cfe8566e6e33..4de97926939e 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -482,7 +482,7 @@ static int __add_missing_keys(struct btrfs_fs_info *fs_info,
482 continue; 482 continue;
483 BUG_ON(!ref->wanted_disk_byte); 483 BUG_ON(!ref->wanted_disk_byte);
484 eb = read_tree_block(fs_info->tree_root, ref->wanted_disk_byte, 484 eb = read_tree_block(fs_info->tree_root, ref->wanted_disk_byte,
485 fs_info->tree_root->leafsize, 0); 485 fs_info->tree_root->nodesize, 0);
486 if (!eb || !extent_buffer_uptodate(eb)) { 486 if (!eb || !extent_buffer_uptodate(eb)) {
487 free_extent_buffer(eb); 487 free_extent_buffer(eb);
488 return -EIO; 488 return -EIO;
@@ -991,8 +991,8 @@ again:
991 ref->level == 0) { 991 ref->level == 0) {
992 u32 bsz; 992 u32 bsz;
993 struct extent_buffer *eb; 993 struct extent_buffer *eb;
994 bsz = btrfs_level_size(fs_info->extent_root, 994
995 ref->level); 995 bsz = fs_info->extent_root->nodesize;
996 eb = read_tree_block(fs_info->extent_root, 996 eb = read_tree_block(fs_info->extent_root,
997 ref->parent, bsz, 0); 997 ref->parent, bsz, 0);
998 if (!eb || !extent_buffer_uptodate(eb)) { 998 if (!eb || !extent_buffer_uptodate(eb)) {
@@ -1366,7 +1366,7 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
1366 } 1366 }
1367 btrfs_item_key_to_cpu(path->nodes[0], found_key, path->slots[0]); 1367 btrfs_item_key_to_cpu(path->nodes[0], found_key, path->slots[0]);
1368 if (found_key->type == BTRFS_METADATA_ITEM_KEY) 1368 if (found_key->type == BTRFS_METADATA_ITEM_KEY)
1369 size = fs_info->extent_root->leafsize; 1369 size = fs_info->extent_root->nodesize;
1370 else if (found_key->type == BTRFS_EXTENT_ITEM_KEY) 1370 else if (found_key->type == BTRFS_EXTENT_ITEM_KEY)
1371 size = found_key->offset; 1371 size = found_key->offset;
1372 1372
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index ce92ae30250f..d0690da3b150 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -820,7 +820,6 @@ static int btrfsic_process_superblock_dev_mirror(
820 btrfs_super_magic(super_tmp) != BTRFS_MAGIC || 820 btrfs_super_magic(super_tmp) != BTRFS_MAGIC ||
821 memcmp(device->uuid, super_tmp->dev_item.uuid, BTRFS_UUID_SIZE) || 821 memcmp(device->uuid, super_tmp->dev_item.uuid, BTRFS_UUID_SIZE) ||
822 btrfs_super_nodesize(super_tmp) != state->metablock_size || 822 btrfs_super_nodesize(super_tmp) != state->metablock_size ||
823 btrfs_super_leafsize(super_tmp) != state->metablock_size ||
824 btrfs_super_sectorsize(super_tmp) != state->datablock_size) { 823 btrfs_super_sectorsize(super_tmp) != state->datablock_size) {
825 brelse(bh); 824 brelse(bh);
826 return 0; 825 return 0;
@@ -3120,24 +3119,12 @@ int btrfsic_mount(struct btrfs_root *root,
3120 struct list_head *dev_head = &fs_devices->devices; 3119 struct list_head *dev_head = &fs_devices->devices;
3121 struct btrfs_device *device; 3120 struct btrfs_device *device;
3122 3121
3123 if (root->nodesize != root->leafsize) {
3124 printk(KERN_INFO
3125 "btrfsic: cannot handle nodesize %d != leafsize %d!\n",
3126 root->nodesize, root->leafsize);
3127 return -1;
3128 }
3129 if (root->nodesize & ((u64)PAGE_CACHE_SIZE - 1)) { 3122 if (root->nodesize & ((u64)PAGE_CACHE_SIZE - 1)) {
3130 printk(KERN_INFO 3123 printk(KERN_INFO
3131 "btrfsic: cannot handle nodesize %d not being a multiple of PAGE_CACHE_SIZE %ld!\n", 3124 "btrfsic: cannot handle nodesize %d not being a multiple of PAGE_CACHE_SIZE %ld!\n",
3132 root->nodesize, PAGE_CACHE_SIZE); 3125 root->nodesize, PAGE_CACHE_SIZE);
3133 return -1; 3126 return -1;
3134 } 3127 }
3135 if (root->leafsize & ((u64)PAGE_CACHE_SIZE - 1)) {
3136 printk(KERN_INFO
3137 "btrfsic: cannot handle leafsize %d not being a multiple of PAGE_CACHE_SIZE %ld!\n",
3138 root->leafsize, PAGE_CACHE_SIZE);
3139 return -1;
3140 }
3141 if (root->sectorsize & ((u64)PAGE_CACHE_SIZE - 1)) { 3128 if (root->sectorsize & ((u64)PAGE_CACHE_SIZE - 1)) {
3142 printk(KERN_INFO 3129 printk(KERN_INFO
3143 "btrfsic: cannot handle sectorsize %d not being a multiple of PAGE_CACHE_SIZE %ld!\n", 3130 "btrfsic: cannot handle sectorsize %d not being a multiple of PAGE_CACHE_SIZE %ld!\n",
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 44ee5d2e52a4..263145b27155 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1444,7 +1444,7 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
1444 if (old_root && tm && tm->op != MOD_LOG_KEY_REMOVE_WHILE_FREEING) { 1444 if (old_root && tm && tm->op != MOD_LOG_KEY_REMOVE_WHILE_FREEING) {
1445 btrfs_tree_read_unlock(eb_root); 1445 btrfs_tree_read_unlock(eb_root);
1446 free_extent_buffer(eb_root); 1446 free_extent_buffer(eb_root);
1447 blocksize = btrfs_level_size(root, old_root->level); 1447 blocksize = root->nodesize;
1448 old = read_tree_block(root, logical, blocksize, 0); 1448 old = read_tree_block(root, logical, blocksize, 0);
1449 if (WARN_ON(!old || !extent_buffer_uptodate(old))) { 1449 if (WARN_ON(!old || !extent_buffer_uptodate(old))) {
1450 free_extent_buffer(old); 1450 free_extent_buffer(old);
@@ -1651,7 +1651,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
1651 WARN_ON(trans->transid != root->fs_info->generation); 1651 WARN_ON(trans->transid != root->fs_info->generation);
1652 1652
1653 parent_nritems = btrfs_header_nritems(parent); 1653 parent_nritems = btrfs_header_nritems(parent);
1654 blocksize = btrfs_level_size(root, parent_level - 1); 1654 blocksize = root->nodesize;
1655 end_slot = parent_nritems; 1655 end_slot = parent_nritems;
1656 1656
1657 if (parent_nritems == 1) 1657 if (parent_nritems == 1)
@@ -1872,7 +1872,7 @@ static noinline struct extent_buffer *read_node_slot(struct btrfs_root *root,
1872 BUG_ON(level == 0); 1872 BUG_ON(level == 0);
1873 1873
1874 eb = read_tree_block(root, btrfs_node_blockptr(parent, slot), 1874 eb = read_tree_block(root, btrfs_node_blockptr(parent, slot),
1875 btrfs_level_size(root, level - 1), 1875 root->nodesize,
1876 btrfs_node_ptr_generation(parent, slot)); 1876 btrfs_node_ptr_generation(parent, slot));
1877 if (eb && !extent_buffer_uptodate(eb)) { 1877 if (eb && !extent_buffer_uptodate(eb)) {
1878 free_extent_buffer(eb); 1878 free_extent_buffer(eb);
@@ -2267,7 +2267,7 @@ static void reada_for_search(struct btrfs_root *root,
2267 node = path->nodes[level]; 2267 node = path->nodes[level];
2268 2268
2269 search = btrfs_node_blockptr(node, slot); 2269 search = btrfs_node_blockptr(node, slot);
2270 blocksize = btrfs_level_size(root, level - 1); 2270 blocksize = root->nodesize;
2271 eb = btrfs_find_tree_block(root, search, blocksize); 2271 eb = btrfs_find_tree_block(root, search, blocksize);
2272 if (eb) { 2272 if (eb) {
2273 free_extent_buffer(eb); 2273 free_extent_buffer(eb);
@@ -2325,7 +2325,7 @@ static noinline void reada_for_balance(struct btrfs_root *root,
2325 2325
2326 nritems = btrfs_header_nritems(parent); 2326 nritems = btrfs_header_nritems(parent);
2327 slot = path->slots[level + 1]; 2327 slot = path->slots[level + 1];
2328 blocksize = btrfs_level_size(root, level); 2328 blocksize = root->nodesize;
2329 2329
2330 if (slot > 0) { 2330 if (slot > 0) {
2331 block1 = btrfs_node_blockptr(parent, slot - 1); 2331 block1 = btrfs_node_blockptr(parent, slot - 1);
@@ -2461,7 +2461,7 @@ read_block_for_search(struct btrfs_trans_handle *trans,
2461 2461
2462 blocknr = btrfs_node_blockptr(b, slot); 2462 blocknr = btrfs_node_blockptr(b, slot);
2463 gen = btrfs_node_ptr_generation(b, slot); 2463 gen = btrfs_node_ptr_generation(b, slot);
2464 blocksize = btrfs_level_size(root, level - 1); 2464 blocksize = root->nodesize;
2465 2465
2466 tmp = btrfs_find_tree_block(root, blocknr, blocksize); 2466 tmp = btrfs_find_tree_block(root, blocknr, blocksize);
2467 if (tmp) { 2467 if (tmp) {
@@ -4282,13 +4282,13 @@ again:
4282 else 4282 else
4283 btrfs_item_key(l, &disk_key, mid); 4283 btrfs_item_key(l, &disk_key, mid);
4284 4284
4285 right = btrfs_alloc_free_block(trans, root, root->leafsize, 0, 4285 right = btrfs_alloc_free_block(trans, root, root->nodesize, 0,
4286 root->root_key.objectid, 4286 root->root_key.objectid,
4287 &disk_key, 0, l->start, 0); 4287 &disk_key, 0, l->start, 0);
4288 if (IS_ERR(right)) 4288 if (IS_ERR(right))
4289 return PTR_ERR(right); 4289 return PTR_ERR(right);
4290 4290
4291 root_add_used(root, root->leafsize); 4291 root_add_used(root, root->nodesize);
4292 4292
4293 memset_extent_buffer(right, 0, 0, sizeof(struct btrfs_header)); 4293 memset_extent_buffer(right, 0, 0, sizeof(struct btrfs_header));
4294 btrfs_set_header_bytenr(right, right->start); 4294 btrfs_set_header_bytenr(right, right->start);
@@ -5375,7 +5375,7 @@ int btrfs_compare_trees(struct btrfs_root *left_root,
5375 goto out; 5375 goto out;
5376 } 5376 }
5377 5377
5378 tmp_buf = kmalloc(left_root->leafsize, GFP_NOFS); 5378 tmp_buf = kmalloc(left_root->nodesize, GFP_NOFS);
5379 if (!tmp_buf) { 5379 if (!tmp_buf) {
5380 ret = -ENOMEM; 5380 ret = -ENOMEM;
5381 goto out; 5381 goto out;
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index a835a548e47e..6fc16d22d27d 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -391,7 +391,7 @@ struct btrfs_header {
391 sizeof(struct btrfs_header)) / \ 391 sizeof(struct btrfs_header)) / \
392 sizeof(struct btrfs_key_ptr)) 392 sizeof(struct btrfs_key_ptr))
393#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) 393#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
394#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize)) 394#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->nodesize))
395#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ 395#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
396 sizeof(struct btrfs_item) - \ 396 sizeof(struct btrfs_item) - \
397 sizeof(struct btrfs_file_extent_item)) 397 sizeof(struct btrfs_file_extent_item))
@@ -474,7 +474,7 @@ struct btrfs_super_block {
474 __le64 num_devices; 474 __le64 num_devices;
475 __le32 sectorsize; 475 __le32 sectorsize;
476 __le32 nodesize; 476 __le32 nodesize;
477 __le32 leafsize; 477 __le32 __unused_leafsize;
478 __le32 stripesize; 478 __le32 stripesize;
479 __le32 sys_chunk_array_size; 479 __le32 sys_chunk_array_size;
480 __le64 chunk_root_generation; 480 __le64 chunk_root_generation;
@@ -1806,9 +1806,6 @@ struct btrfs_root {
1806 /* node allocations are done in nodesize units */ 1806 /* node allocations are done in nodesize units */
1807 u32 nodesize; 1807 u32 nodesize;
1808 1808
1809 /* leaf allocations are done in leafsize units */
1810 u32 leafsize;
1811
1812 u32 stripesize; 1809 u32 stripesize;
1813 1810
1814 u32 type; 1811 u32 type;
@@ -2995,8 +2992,6 @@ BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
2995 sectorsize, 32); 2992 sectorsize, 32);
2996BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, 2993BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
2997 nodesize, 32); 2994 nodesize, 32);
2998BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
2999 leafsize, 32);
3000BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, 2995BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
3001 stripesize, 32); 2996 stripesize, 32);
3002BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, 2997BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
@@ -3232,13 +3227,6 @@ static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb)
3232 return sb->s_fs_info; 3227 return sb->s_fs_info;
3233} 3228}
3234 3229
3235static inline u32 btrfs_level_size(struct btrfs_root *root, int level)
3236{
3237 if (level == 0)
3238 return root->leafsize;
3239 return root->nodesize;
3240}
3241
3242/* helper function to cast into the data area of the leaf. */ 3230/* helper function to cast into the data area of the leaf. */
3243#define btrfs_item_ptr(leaf, slot, type) \ 3231#define btrfs_item_ptr(leaf, slot, type) \
3244 ((type *)(btrfs_leaf_data(leaf) + \ 3232 ((type *)(btrfs_leaf_data(leaf) + \
@@ -3263,7 +3251,7 @@ static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
3263static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root, 3251static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
3264 unsigned num_items) 3252 unsigned num_items)
3265{ 3253{
3266 return (root->leafsize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) * 3254 return (root->nodesize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *
3267 2 * num_items; 3255 2 * num_items;
3268} 3256}
3269 3257
@@ -3274,8 +3262,7 @@ static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
3274static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_root *root, 3262static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_root *root,
3275 unsigned num_items) 3263 unsigned num_items)
3276{ 3264{
3277 return (root->leafsize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) * 3265 return root->nodesize * BTRFS_MAX_LEVEL * num_items;
3278 num_items;
3279} 3266}
3280 3267
3281int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans, 3268int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index ec32bead96a1..508bbee320f6 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1200,16 +1200,14 @@ btrfs_free_subvolume_writers(struct btrfs_subvolume_writers *writers)
1200 kfree(writers); 1200 kfree(writers);
1201} 1201}
1202 1202
1203static void __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, 1203static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
1204 u32 stripesize, struct btrfs_root *root, 1204 struct btrfs_root *root, struct btrfs_fs_info *fs_info,
1205 struct btrfs_fs_info *fs_info,
1206 u64 objectid) 1205 u64 objectid)
1207{ 1206{
1208 root->node = NULL; 1207 root->node = NULL;
1209 root->commit_root = NULL; 1208 root->commit_root = NULL;
1210 root->sectorsize = sectorsize; 1209 root->sectorsize = sectorsize;
1211 root->nodesize = nodesize; 1210 root->nodesize = nodesize;
1212 root->leafsize = leafsize;
1213 root->stripesize = stripesize; 1211 root->stripesize = stripesize;
1214 root->state = 0; 1212 root->state = 0;
1215 root->orphan_cleanup_state = 0; 1213 root->orphan_cleanup_state = 0;
@@ -1295,7 +1293,7 @@ struct btrfs_root *btrfs_alloc_dummy_root(void)
1295 root = btrfs_alloc_root(NULL); 1293 root = btrfs_alloc_root(NULL);
1296 if (!root) 1294 if (!root)
1297 return ERR_PTR(-ENOMEM); 1295 return ERR_PTR(-ENOMEM);
1298 __setup_root(4096, 4096, 4096, 4096, root, NULL, 1); 1296 __setup_root(4096, 4096, 4096, root, NULL, 1);
1299 set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state); 1297 set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state);
1300 root->alloc_bytenr = 0; 1298 root->alloc_bytenr = 0;
1301 1299
@@ -1318,14 +1316,13 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
1318 if (!root) 1316 if (!root)
1319 return ERR_PTR(-ENOMEM); 1317 return ERR_PTR(-ENOMEM);
1320 1318
1321 __setup_root(tree_root->nodesize, tree_root->leafsize, 1319 __setup_root(tree_root->nodesize, tree_root->sectorsize,
1322 tree_root->sectorsize, tree_root->stripesize, 1320 tree_root->stripesize, root, fs_info, objectid);
1323 root, fs_info, objectid);
1324 root->root_key.objectid = objectid; 1321 root->root_key.objectid = objectid;
1325 root->root_key.type = BTRFS_ROOT_ITEM_KEY; 1322 root->root_key.type = BTRFS_ROOT_ITEM_KEY;
1326 root->root_key.offset = 0; 1323 root->root_key.offset = 0;
1327 1324
1328 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 1325 leaf = btrfs_alloc_free_block(trans, root, root->nodesize,
1329 0, objectid, NULL, 0, 0, 0); 1326 0, objectid, NULL, 0, 0, 0);
1330 if (IS_ERR(leaf)) { 1327 if (IS_ERR(leaf)) {
1331 ret = PTR_ERR(leaf); 1328 ret = PTR_ERR(leaf);
@@ -1396,9 +1393,9 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1396 if (!root) 1393 if (!root)
1397 return ERR_PTR(-ENOMEM); 1394 return ERR_PTR(-ENOMEM);
1398 1395
1399 __setup_root(tree_root->nodesize, tree_root->leafsize, 1396 __setup_root(tree_root->nodesize, tree_root->sectorsize,
1400 tree_root->sectorsize, tree_root->stripesize, 1397 tree_root->stripesize, root, fs_info,
1401 root, fs_info, BTRFS_TREE_LOG_OBJECTID); 1398 BTRFS_TREE_LOG_OBJECTID);
1402 1399
1403 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID; 1400 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID;
1404 root->root_key.type = BTRFS_ROOT_ITEM_KEY; 1401 root->root_key.type = BTRFS_ROOT_ITEM_KEY;
@@ -1413,7 +1410,7 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1413 * updated (along with back refs to the log tree). 1410 * updated (along with back refs to the log tree).
1414 */ 1411 */
1415 1412
1416 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 0, 1413 leaf = btrfs_alloc_free_block(trans, root, root->nodesize, 0,
1417 BTRFS_TREE_LOG_OBJECTID, NULL, 1414 BTRFS_TREE_LOG_OBJECTID, NULL,
1418 0, 0, 0); 1415 0, 0, 0);
1419 if (IS_ERR(leaf)) { 1416 if (IS_ERR(leaf)) {
@@ -1465,7 +1462,7 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
1465 btrfs_set_stack_inode_generation(inode_item, 1); 1462 btrfs_set_stack_inode_generation(inode_item, 1);
1466 btrfs_set_stack_inode_size(inode_item, 3); 1463 btrfs_set_stack_inode_size(inode_item, 3);
1467 btrfs_set_stack_inode_nlink(inode_item, 1); 1464 btrfs_set_stack_inode_nlink(inode_item, 1);
1468 btrfs_set_stack_inode_nbytes(inode_item, root->leafsize); 1465 btrfs_set_stack_inode_nbytes(inode_item, root->nodesize);
1469 btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755); 1466 btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755);
1470 1467
1471 btrfs_set_root_node(&log_root->root_item, log_root->node); 1468 btrfs_set_root_node(&log_root->root_item, log_root->node);
@@ -1498,9 +1495,8 @@ static struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
1498 goto alloc_fail; 1495 goto alloc_fail;
1499 } 1496 }
1500 1497
1501 __setup_root(tree_root->nodesize, tree_root->leafsize, 1498 __setup_root(tree_root->nodesize, tree_root->sectorsize,
1502 tree_root->sectorsize, tree_root->stripesize, 1499 tree_root->stripesize, root, fs_info, key->objectid);
1503 root, fs_info, key->objectid);
1504 1500
1505 ret = btrfs_find_root(tree_root, key, path, 1501 ret = btrfs_find_root(tree_root, key, path,
1506 &root->root_item, &root->root_key); 1502 &root->root_item, &root->root_key);
@@ -1511,7 +1507,7 @@ static struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
1511 } 1507 }
1512 1508
1513 generation = btrfs_root_generation(&root->root_item); 1509 generation = btrfs_root_generation(&root->root_item);
1514 blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item)); 1510 blocksize = root->nodesize;
1515 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), 1511 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
1516 blocksize, generation); 1512 blocksize, generation);
1517 if (!root->node) { 1513 if (!root->node) {
@@ -2143,7 +2139,6 @@ int open_ctree(struct super_block *sb,
2143{ 2139{
2144 u32 sectorsize; 2140 u32 sectorsize;
2145 u32 nodesize; 2141 u32 nodesize;
2146 u32 leafsize;
2147 u32 blocksize; 2142 u32 blocksize;
2148 u32 stripesize; 2143 u32 stripesize;
2149 u64 generation; 2144 u64 generation;
@@ -2389,7 +2384,7 @@ int open_ctree(struct super_block *sb,
2389 goto fail_alloc; 2384 goto fail_alloc;
2390 } 2385 }
2391 2386
2392 __setup_root(4096, 4096, 4096, 4096, tree_root, 2387 __setup_root(4096, 4096, 4096, tree_root,
2393 fs_info, BTRFS_ROOT_TREE_OBJECTID); 2388 fs_info, BTRFS_ROOT_TREE_OBJECTID);
2394 2389
2395 invalidate_bdev(fs_devices->latest_bdev); 2390 invalidate_bdev(fs_devices->latest_bdev);
@@ -2469,19 +2464,22 @@ int open_ctree(struct super_block *sb,
2469 goto fail_alloc; 2464 goto fail_alloc;
2470 } 2465 }
2471 2466
2472 if (btrfs_super_leafsize(disk_super) != 2467 /*
2468 * Leafsize and nodesize were always equal, this is only a sanity check.
2469 */
2470 if (le32_to_cpu(disk_super->__unused_leafsize) !=
2473 btrfs_super_nodesize(disk_super)) { 2471 btrfs_super_nodesize(disk_super)) {
2474 printk(KERN_ERR "BTRFS: couldn't mount because metadata " 2472 printk(KERN_ERR "BTRFS: couldn't mount because metadata "
2475 "blocksizes don't match. node %d leaf %d\n", 2473 "blocksizes don't match. node %d leaf %d\n",
2476 btrfs_super_nodesize(disk_super), 2474 btrfs_super_nodesize(disk_super),
2477 btrfs_super_leafsize(disk_super)); 2475 le32_to_cpu(disk_super->__unused_leafsize));
2478 err = -EINVAL; 2476 err = -EINVAL;
2479 goto fail_alloc; 2477 goto fail_alloc;
2480 } 2478 }
2481 if (btrfs_super_leafsize(disk_super) > BTRFS_MAX_METADATA_BLOCKSIZE) { 2479 if (btrfs_super_nodesize(disk_super) > BTRFS_MAX_METADATA_BLOCKSIZE) {
2482 printk(KERN_ERR "BTRFS: couldn't mount because metadata " 2480 printk(KERN_ERR "BTRFS: couldn't mount because metadata "
2483 "blocksize (%d) was too large\n", 2481 "blocksize (%d) was too large\n",
2484 btrfs_super_leafsize(disk_super)); 2482 btrfs_super_nodesize(disk_super));
2485 err = -EINVAL; 2483 err = -EINVAL;
2486 goto fail_alloc; 2484 goto fail_alloc;
2487 } 2485 }
@@ -2498,17 +2496,16 @@ int open_ctree(struct super_block *sb,
2498 * flag our filesystem as having big metadata blocks if 2496 * flag our filesystem as having big metadata blocks if
2499 * they are bigger than the page size 2497 * they are bigger than the page size
2500 */ 2498 */
2501 if (btrfs_super_leafsize(disk_super) > PAGE_CACHE_SIZE) { 2499 if (btrfs_super_nodesize(disk_super) > PAGE_CACHE_SIZE) {
2502 if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA)) 2500 if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA))
2503 printk(KERN_INFO "BTRFS: flagging fs with big metadata feature\n"); 2501 printk(KERN_INFO "BTRFS: flagging fs with big metadata feature\n");
2504 features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA; 2502 features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA;
2505 } 2503 }
2506 2504
2507 nodesize = btrfs_super_nodesize(disk_super); 2505 nodesize = btrfs_super_nodesize(disk_super);
2508 leafsize = btrfs_super_leafsize(disk_super);
2509 sectorsize = btrfs_super_sectorsize(disk_super); 2506 sectorsize = btrfs_super_sectorsize(disk_super);
2510 stripesize = btrfs_super_stripesize(disk_super); 2507 stripesize = btrfs_super_stripesize(disk_super);
2511 fs_info->dirty_metadata_batch = leafsize * (1 + ilog2(nr_cpu_ids)); 2508 fs_info->dirty_metadata_batch = nodesize * (1 + ilog2(nr_cpu_ids));
2512 fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids)); 2509 fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids));
2513 2510
2514 /* 2511 /*
@@ -2516,7 +2513,7 @@ int open_ctree(struct super_block *sb,
2516 * extent buffers for the same range. It leads to corruptions 2513 * extent buffers for the same range. It leads to corruptions
2517 */ 2514 */
2518 if ((features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) && 2515 if ((features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) &&
2519 (sectorsize != leafsize)) { 2516 (sectorsize != nodesize)) {
2520 printk(KERN_WARNING "BTRFS: unequal leaf/node/sector sizes " 2517 printk(KERN_WARNING "BTRFS: unequal leaf/node/sector sizes "
2521 "are not allowed for mixed block groups on %s\n", 2518 "are not allowed for mixed block groups on %s\n",
2522 sb->s_id); 2519 sb->s_id);
@@ -2615,7 +2612,6 @@ int open_ctree(struct super_block *sb,
2615 4 * 1024 * 1024 / PAGE_CACHE_SIZE); 2612 4 * 1024 * 1024 / PAGE_CACHE_SIZE);
2616 2613
2617 tree_root->nodesize = nodesize; 2614 tree_root->nodesize = nodesize;
2618 tree_root->leafsize = leafsize;
2619 tree_root->sectorsize = sectorsize; 2615 tree_root->sectorsize = sectorsize;
2620 tree_root->stripesize = stripesize; 2616 tree_root->stripesize = stripesize;
2621 2617
@@ -2642,12 +2638,11 @@ int open_ctree(struct super_block *sb,
2642 goto fail_sb_buffer; 2638 goto fail_sb_buffer;
2643 } 2639 }
2644 2640
2645 blocksize = btrfs_level_size(tree_root, 2641 blocksize = tree_root->nodesize;
2646 btrfs_super_chunk_root_level(disk_super));
2647 generation = btrfs_super_chunk_root_generation(disk_super); 2642 generation = btrfs_super_chunk_root_generation(disk_super);
2648 2643
2649 __setup_root(nodesize, leafsize, sectorsize, stripesize, 2644 __setup_root(nodesize, sectorsize, stripesize, chunk_root,
2650 chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID); 2645 fs_info, BTRFS_CHUNK_TREE_OBJECTID);
2651 2646
2652 chunk_root->node = read_tree_block(chunk_root, 2647 chunk_root->node = read_tree_block(chunk_root,
2653 btrfs_super_chunk_root(disk_super), 2648 btrfs_super_chunk_root(disk_super),
@@ -2684,8 +2679,7 @@ int open_ctree(struct super_block *sb,
2684 } 2679 }
2685 2680
2686retry_root_backup: 2681retry_root_backup:
2687 blocksize = btrfs_level_size(tree_root, 2682 blocksize = tree_root->nodesize;
2688 btrfs_super_root_level(disk_super));
2689 generation = btrfs_super_generation(disk_super); 2683 generation = btrfs_super_generation(disk_super);
2690 2684
2691 tree_root->node = read_tree_block(tree_root, 2685 tree_root->node = read_tree_block(tree_root,
@@ -2859,9 +2853,7 @@ retry_root_backup:
2859 err = -EIO; 2853 err = -EIO;
2860 goto fail_qgroup; 2854 goto fail_qgroup;
2861 } 2855 }
2862 blocksize = 2856 blocksize = tree_root->nodesize;
2863 btrfs_level_size(tree_root,
2864 btrfs_super_log_root_level(disk_super));
2865 2857
2866 log_tree_root = btrfs_alloc_root(fs_info); 2858 log_tree_root = btrfs_alloc_root(fs_info);
2867 if (!log_tree_root) { 2859 if (!log_tree_root) {
@@ -2869,7 +2861,7 @@ retry_root_backup:
2869 goto fail_qgroup; 2861 goto fail_qgroup;
2870 } 2862 }
2871 2863
2872 __setup_root(nodesize, leafsize, sectorsize, stripesize, 2864 __setup_root(nodesize, sectorsize, stripesize,
2873 log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID); 2865 log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID);
2874 2866
2875 log_tree_root->node = read_tree_block(tree_root, bytenr, 2867 log_tree_root->node = read_tree_block(tree_root, bytenr,
@@ -4008,8 +4000,8 @@ static int btrfs_destroy_marked_extents(struct btrfs_root *root,
4008 clear_extent_bits(dirty_pages, start, end, mark, GFP_NOFS); 4000 clear_extent_bits(dirty_pages, start, end, mark, GFP_NOFS);
4009 while (start <= end) { 4001 while (start <= end) {
4010 eb = btrfs_find_tree_block(root, start, 4002 eb = btrfs_find_tree_block(root, start,
4011 root->leafsize); 4003 root->nodesize);
4012 start += root->leafsize; 4004 start += root->nodesize;
4013 if (!eb) 4005 if (!eb)
4014 continue; 4006 continue;
4015 wait_on_extent_buffer_writeback(eb); 4007 wait_on_extent_buffer_writeback(eb);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 4d1b50d4dc5b..d52da9628f0a 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -491,7 +491,7 @@ next:
491 key.objectid); 491 key.objectid);
492 if (key.type == BTRFS_METADATA_ITEM_KEY) 492 if (key.type == BTRFS_METADATA_ITEM_KEY)
493 last = key.objectid + 493 last = key.objectid +
494 fs_info->tree_root->leafsize; 494 fs_info->tree_root->nodesize;
495 else 495 else
496 last = key.objectid + key.offset; 496 last = key.objectid + key.offset;
497 497
@@ -765,7 +765,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
765 * different 765 * different
766 */ 766 */
767 if (metadata && !btrfs_fs_incompat(root->fs_info, SKINNY_METADATA)) { 767 if (metadata && !btrfs_fs_incompat(root->fs_info, SKINNY_METADATA)) {
768 offset = root->leafsize; 768 offset = root->nodesize;
769 metadata = 0; 769 metadata = 0;
770 } 770 }
771 771
@@ -799,13 +799,13 @@ again:
799 path->slots[0]); 799 path->slots[0]);
800 if (key.objectid == bytenr && 800 if (key.objectid == bytenr &&
801 key.type == BTRFS_EXTENT_ITEM_KEY && 801 key.type == BTRFS_EXTENT_ITEM_KEY &&
802 key.offset == root->leafsize) 802 key.offset == root->nodesize)
803 ret = 0; 803 ret = 0;
804 } 804 }
805 if (ret) { 805 if (ret) {
806 key.objectid = bytenr; 806 key.objectid = bytenr;
807 key.type = BTRFS_EXTENT_ITEM_KEY; 807 key.type = BTRFS_EXTENT_ITEM_KEY;
808 key.offset = root->leafsize; 808 key.offset = root->nodesize;
809 btrfs_release_path(path); 809 btrfs_release_path(path);
810 goto again; 810 goto again;
811 } 811 }
@@ -2651,7 +2651,7 @@ int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans,
2651 num_bytes = btrfs_calc_trans_metadata_size(root, 1); 2651 num_bytes = btrfs_calc_trans_metadata_size(root, 1);
2652 num_heads = heads_to_leaves(root, num_heads); 2652 num_heads = heads_to_leaves(root, num_heads);
2653 if (num_heads > 1) 2653 if (num_heads > 1)
2654 num_bytes += (num_heads - 1) * root->leafsize; 2654 num_bytes += (num_heads - 1) * root->nodesize;
2655 num_bytes <<= 1; 2655 num_bytes <<= 1;
2656 global_rsv = &root->fs_info->global_block_rsv; 2656 global_rsv = &root->fs_info->global_block_rsv;
2657 2657
@@ -3117,7 +3117,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
3117 goto fail; 3117 goto fail;
3118 } else { 3118 } else {
3119 bytenr = btrfs_node_blockptr(buf, i); 3119 bytenr = btrfs_node_blockptr(buf, i);
3120 num_bytes = btrfs_level_size(root, level - 1); 3120 num_bytes = root->nodesize;
3121 ret = process_func(trans, root, bytenr, num_bytes, 3121 ret = process_func(trans, root, bytenr, num_bytes,
3122 parent, ref_root, level - 1, 0, 3122 parent, ref_root, level - 1, 0,
3123 1); 3123 1);
@@ -4839,7 +4839,7 @@ static u64 calc_global_metadata_size(struct btrfs_fs_info *fs_info)
4839 if (num_bytes * 3 > meta_used) 4839 if (num_bytes * 3 > meta_used)
4840 num_bytes = div64_u64(meta_used, 3); 4840 num_bytes = div64_u64(meta_used, 3);
4841 4841
4842 return ALIGN(num_bytes, fs_info->extent_root->leafsize << 10); 4842 return ALIGN(num_bytes, fs_info->extent_root->nodesize << 10);
4843} 4843}
4844 4844
4845static void update_global_block_rsv(struct btrfs_fs_info *fs_info) 4845static void update_global_block_rsv(struct btrfs_fs_info *fs_info)
@@ -4988,7 +4988,7 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
4988 4988
4989 if (root->fs_info->quota_enabled) { 4989 if (root->fs_info->quota_enabled) {
4990 /* One for parent inode, two for dir entries */ 4990 /* One for parent inode, two for dir entries */
4991 num_bytes = 3 * root->leafsize; 4991 num_bytes = 3 * root->nodesize;
4992 ret = btrfs_qgroup_reserve(root, num_bytes); 4992 ret = btrfs_qgroup_reserve(root, num_bytes);
4993 if (ret) 4993 if (ret)
4994 return ret; 4994 return ret;
@@ -5176,7 +5176,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
5176 5176
5177 if (root->fs_info->quota_enabled) { 5177 if (root->fs_info->quota_enabled) {
5178 ret = btrfs_qgroup_reserve(root, num_bytes + 5178 ret = btrfs_qgroup_reserve(root, num_bytes +
5179 nr_extents * root->leafsize); 5179 nr_extents * root->nodesize);
5180 if (ret) 5180 if (ret)
5181 goto out_fail; 5181 goto out_fail;
5182 } 5182 }
@@ -5185,7 +5185,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
5185 if (unlikely(ret)) { 5185 if (unlikely(ret)) {
5186 if (root->fs_info->quota_enabled) 5186 if (root->fs_info->quota_enabled)
5187 btrfs_qgroup_free(root, num_bytes + 5187 btrfs_qgroup_free(root, num_bytes +
5188 nr_extents * root->leafsize); 5188 nr_extents * root->nodesize);
5189 goto out_fail; 5189 goto out_fail;
5190 } 5190 }
5191 5191
@@ -5301,7 +5301,7 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes)
5301 btrfs_ino(inode), to_free, 0); 5301 btrfs_ino(inode), to_free, 0);
5302 if (root->fs_info->quota_enabled) { 5302 if (root->fs_info->quota_enabled) {
5303 btrfs_qgroup_free(root, num_bytes + 5303 btrfs_qgroup_free(root, num_bytes +
5304 dropped * root->leafsize); 5304 dropped * root->nodesize);
5305 } 5305 }
5306 5306
5307 btrfs_block_rsv_release(root, &root->fs_info->delalloc_block_rsv, 5307 btrfs_block_rsv_release(root, &root->fs_info->delalloc_block_rsv,
@@ -7077,7 +7077,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
7077 path = btrfs_alloc_path(); 7077 path = btrfs_alloc_path();
7078 if (!path) { 7078 if (!path) {
7079 btrfs_free_and_pin_reserved_extent(root, ins->objectid, 7079 btrfs_free_and_pin_reserved_extent(root, ins->objectid,
7080 root->leafsize); 7080 root->nodesize);
7081 return -ENOMEM; 7081 return -ENOMEM;
7082 } 7082 }
7083 7083
@@ -7086,7 +7086,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
7086 ins, size); 7086 ins, size);
7087 if (ret) { 7087 if (ret) {
7088 btrfs_free_and_pin_reserved_extent(root, ins->objectid, 7088 btrfs_free_and_pin_reserved_extent(root, ins->objectid,
7089 root->leafsize); 7089 root->nodesize);
7090 btrfs_free_path(path); 7090 btrfs_free_path(path);
7091 return ret; 7091 return ret;
7092 } 7092 }
@@ -7101,7 +7101,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
7101 7101
7102 if (skinny_metadata) { 7102 if (skinny_metadata) {
7103 iref = (struct btrfs_extent_inline_ref *)(extent_item + 1); 7103 iref = (struct btrfs_extent_inline_ref *)(extent_item + 1);
7104 num_bytes = root->leafsize; 7104 num_bytes = root->nodesize;
7105 } else { 7105 } else {
7106 block_info = (struct btrfs_tree_block_info *)(extent_item + 1); 7106 block_info = (struct btrfs_tree_block_info *)(extent_item + 1);
7107 btrfs_set_tree_block_key(leaf, block_info, key); 7107 btrfs_set_tree_block_key(leaf, block_info, key);
@@ -7131,14 +7131,14 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
7131 return ret; 7131 return ret;
7132 } 7132 }
7133 7133
7134 ret = update_block_group(root, ins->objectid, root->leafsize, 1); 7134 ret = update_block_group(root, ins->objectid, root->nodesize, 1);
7135 if (ret) { /* -ENOENT, logic error */ 7135 if (ret) { /* -ENOENT, logic error */
7136 btrfs_err(fs_info, "update block group failed for %llu %llu", 7136 btrfs_err(fs_info, "update block group failed for %llu %llu",
7137 ins->objectid, ins->offset); 7137 ins->objectid, ins->offset);
7138 BUG(); 7138 BUG();
7139 } 7139 }
7140 7140
7141 trace_btrfs_reserved_extent_alloc(root, ins->objectid, root->leafsize); 7141 trace_btrfs_reserved_extent_alloc(root, ins->objectid, root->nodesize);
7142 return ret; 7142 return ret;
7143} 7143}
7144 7144
@@ -7417,7 +7417,7 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans,
7417 7417
7418 eb = path->nodes[wc->level]; 7418 eb = path->nodes[wc->level];
7419 nritems = btrfs_header_nritems(eb); 7419 nritems = btrfs_header_nritems(eb);
7420 blocksize = btrfs_level_size(root, wc->level - 1); 7420 blocksize = root->nodesize;
7421 7421
7422 for (slot = path->slots[wc->level]; slot < nritems; slot++) { 7422 for (slot = path->slots[wc->level]; slot < nritems; slot++) {
7423 if (nread >= wc->reada_count) 7423 if (nread >= wc->reada_count)
@@ -7806,7 +7806,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
7806 } 7806 }
7807 7807
7808 bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); 7808 bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]);
7809 blocksize = btrfs_level_size(root, level - 1); 7809 blocksize = root->nodesize;
7810 7810
7811 next = btrfs_find_tree_block(root, bytenr, blocksize); 7811 next = btrfs_find_tree_block(root, bytenr, blocksize);
7812 if (!next) { 7812 if (!next) {
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index a9b56e32dd8d..033f04bac85b 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1653,7 +1653,7 @@ again:
1653 cond_resched(); 1653 cond_resched();
1654 1654
1655 balance_dirty_pages_ratelimited(inode->i_mapping); 1655 balance_dirty_pages_ratelimited(inode->i_mapping);
1656 if (dirty_pages < (root->leafsize >> PAGE_CACHE_SHIFT) + 1) 1656 if (dirty_pages < (root->nodesize >> PAGE_CACHE_SHIFT) + 1)
1657 btrfs_btree_balance_dirty(root); 1657 btrfs_btree_balance_dirty(root);
1658 1658
1659 pos += copied; 1659 pos += copied;
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index b61801ac052a..d6e10d60f8ad 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -477,7 +477,7 @@ static noinline int create_subvol(struct inode *dir,
477 if (ret) 477 if (ret)
478 goto fail; 478 goto fail;
479 479
480 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 480 leaf = btrfs_alloc_free_block(trans, root, root->nodesize,
481 0, objectid, NULL, 0, 0, 0); 481 0, objectid, NULL, 0, 0, 0);
482 if (IS_ERR(leaf)) { 482 if (IS_ERR(leaf)) {
483 ret = PTR_ERR(leaf); 483 ret = PTR_ERR(leaf);
@@ -503,7 +503,7 @@ static noinline int create_subvol(struct inode *dir,
503 btrfs_set_stack_inode_generation(inode_item, 1); 503 btrfs_set_stack_inode_generation(inode_item, 1);
504 btrfs_set_stack_inode_size(inode_item, 3); 504 btrfs_set_stack_inode_size(inode_item, 3);
505 btrfs_set_stack_inode_nlink(inode_item, 1); 505 btrfs_set_stack_inode_nlink(inode_item, 1);
506 btrfs_set_stack_inode_nbytes(inode_item, root->leafsize); 506 btrfs_set_stack_inode_nbytes(inode_item, root->nodesize);
507 btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755); 507 btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755);
508 508
509 btrfs_set_root_flags(&root_item, 0); 509 btrfs_set_root_flags(&root_item, 0);
@@ -3199,7 +3199,7 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
3199 u64 last_dest_end = destoff; 3199 u64 last_dest_end = destoff;
3200 3200
3201 ret = -ENOMEM; 3201 ret = -ENOMEM;
3202 buf = vmalloc(btrfs_level_size(root, 0)); 3202 buf = vmalloc(root->nodesize);
3203 if (!buf) 3203 if (!buf)
3204 return ret; 3204 return ret;
3205 3205
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 1591620bee3d..eb309855d5c8 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -336,7 +336,7 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *c)
336 for (i = 0; i < nr; i++) { 336 for (i = 0; i < nr; i++) {
337 struct extent_buffer *next = read_tree_block(root, 337 struct extent_buffer *next = read_tree_block(root,
338 btrfs_node_blockptr(c, i), 338 btrfs_node_blockptr(c, i),
339 btrfs_level_size(root, level - 1), 339 root->nodesize,
340 btrfs_node_ptr_generation(c, i)); 340 btrfs_node_ptr_generation(c, i));
341 if (btrfs_is_leaf(next) && 341 if (btrfs_is_leaf(next) &&
342 level != 1) 342 level != 1)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index ded5c601d916..2ce4ce7b47d8 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -2237,7 +2237,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
2237 if (srcid) { 2237 if (srcid) {
2238 struct btrfs_root *srcroot; 2238 struct btrfs_root *srcroot;
2239 struct btrfs_key srckey; 2239 struct btrfs_key srckey;
2240 int srcroot_level;
2241 2240
2242 srckey.objectid = srcid; 2241 srckey.objectid = srcid;
2243 srckey.type = BTRFS_ROOT_ITEM_KEY; 2242 srckey.type = BTRFS_ROOT_ITEM_KEY;
@@ -2249,8 +2248,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
2249 } 2248 }
2250 2249
2251 rcu_read_lock(); 2250 rcu_read_lock();
2252 srcroot_level = btrfs_header_level(srcroot->node); 2251 level_size = srcroot->nodesize;
2253 level_size = btrfs_level_size(srcroot, srcroot_level);
2254 rcu_read_unlock(); 2252 rcu_read_unlock();
2255 } 2253 }
2256 2254
@@ -2566,7 +2564,7 @@ qgroup_rescan_leaf(struct btrfs_fs_info *fs_info, struct btrfs_path *path,
2566 found.type != BTRFS_METADATA_ITEM_KEY) 2564 found.type != BTRFS_METADATA_ITEM_KEY)
2567 continue; 2565 continue;
2568 if (found.type == BTRFS_METADATA_ITEM_KEY) 2566 if (found.type == BTRFS_METADATA_ITEM_KEY)
2569 num_bytes = fs_info->extent_root->leafsize; 2567 num_bytes = fs_info->extent_root->nodesize;
2570 else 2568 else
2571 num_bytes = found.offset; 2569 num_bytes = found.offset;
2572 2570
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index 20408c6b665a..b63ae20618fb 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -347,7 +347,7 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
347 if (!re) 347 if (!re)
348 return NULL; 348 return NULL;
349 349
350 blocksize = btrfs_level_size(root, level); 350 blocksize = root->nodesize;
351 re->logical = logical; 351 re->logical = logical;
352 re->blocksize = blocksize; 352 re->blocksize = blocksize;
353 re->top = *top; 353 re->top = *top;
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index b3329ad34522..2d221c46180c 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1787,7 +1787,7 @@ again:
1787 btrfs_node_key_to_cpu(parent, next_key, slot + 1); 1787 btrfs_node_key_to_cpu(parent, next_key, slot + 1);
1788 1788
1789 old_bytenr = btrfs_node_blockptr(parent, slot); 1789 old_bytenr = btrfs_node_blockptr(parent, slot);
1790 blocksize = btrfs_level_size(dest, level - 1); 1790 blocksize = dest->nodesize;
1791 old_ptr_gen = btrfs_node_ptr_generation(parent, slot); 1791 old_ptr_gen = btrfs_node_ptr_generation(parent, slot);
1792 1792
1793 if (level <= max_level) { 1793 if (level <= max_level) {
@@ -1970,7 +1970,7 @@ int walk_down_reloc_tree(struct btrfs_root *root, struct btrfs_path *path,
1970 } 1970 }
1971 1971
1972 bytenr = btrfs_node_blockptr(eb, path->slots[i]); 1972 bytenr = btrfs_node_blockptr(eb, path->slots[i]);
1973 blocksize = btrfs_level_size(root, i - 1); 1973 blocksize = root->nodesize;
1974 eb = read_tree_block(root, bytenr, blocksize, ptr_gen); 1974 eb = read_tree_block(root, bytenr, blocksize, ptr_gen);
1975 if (!eb || !extent_buffer_uptodate(eb)) { 1975 if (!eb || !extent_buffer_uptodate(eb)) {
1976 free_extent_buffer(eb); 1976 free_extent_buffer(eb);
@@ -2544,8 +2544,7 @@ u64 calcu_metadata_size(struct reloc_control *rc,
2544 if (next->processed && (reserve || next != node)) 2544 if (next->processed && (reserve || next != node))
2545 break; 2545 break;
2546 2546
2547 num_bytes += btrfs_level_size(rc->extent_root, 2547 num_bytes += rc->extent_root->nodesize;
2548 next->level);
2549 2548
2550 if (list_empty(&next->upper)) 2549 if (list_empty(&next->upper))
2551 break; 2550 break;
@@ -2679,7 +2678,7 @@ static int do_relocation(struct btrfs_trans_handle *trans,
2679 goto next; 2678 goto next;
2680 } 2679 }
2681 2680
2682 blocksize = btrfs_level_size(root, node->level); 2681 blocksize = root->nodesize;
2683 generation = btrfs_node_ptr_generation(upper->eb, slot); 2682 generation = btrfs_node_ptr_generation(upper->eb, slot);
2684 eb = read_tree_block(root, bytenr, blocksize, generation); 2683 eb = read_tree_block(root, bytenr, blocksize, generation);
2685 if (!eb || !extent_buffer_uptodate(eb)) { 2684 if (!eb || !extent_buffer_uptodate(eb)) {
@@ -2789,7 +2788,7 @@ static void __mark_block_processed(struct reloc_control *rc,
2789 u32 blocksize; 2788 u32 blocksize;
2790 if (node->level == 0 || 2789 if (node->level == 0 ||
2791 in_block_group(node->bytenr, rc->block_group)) { 2790 in_block_group(node->bytenr, rc->block_group)) {
2792 blocksize = btrfs_level_size(rc->extent_root, node->level); 2791 blocksize = rc->extent_root->nodesize;
2793 mark_block_processed(rc, node->bytenr, blocksize); 2792 mark_block_processed(rc, node->bytenr, blocksize);
2794 } 2793 }
2795 node->processed = 1; 2794 node->processed = 1;
@@ -2865,7 +2864,7 @@ static int reada_tree_block(struct reloc_control *rc,
2865 if (block->key.type == BTRFS_METADATA_ITEM_KEY) 2864 if (block->key.type == BTRFS_METADATA_ITEM_KEY)
2866 readahead_tree_block(rc->extent_root, block->bytenr, 2865 readahead_tree_block(rc->extent_root, block->bytenr,
2867 block->key.objectid, 2866 block->key.objectid,
2868 rc->extent_root->leafsize); 2867 rc->extent_root->nodesize);
2869 else 2868 else
2870 readahead_tree_block(rc->extent_root, block->bytenr, 2869 readahead_tree_block(rc->extent_root, block->bytenr,
2871 block->key.objectid, block->key.offset); 2870 block->key.objectid, block->key.offset);
@@ -3313,7 +3312,7 @@ static int add_tree_block(struct reloc_control *rc,
3313 return -ENOMEM; 3312 return -ENOMEM;
3314 3313
3315 block->bytenr = extent_key->objectid; 3314 block->bytenr = extent_key->objectid;
3316 block->key.objectid = rc->extent_root->leafsize; 3315 block->key.objectid = rc->extent_root->nodesize;
3317 block->key.offset = generation; 3316 block->key.offset = generation;
3318 block->level = level; 3317 block->level = level;
3319 block->key_ready = 0; 3318 block->key_ready = 0;
@@ -3640,7 +3639,7 @@ int add_data_references(struct reloc_control *rc,
3640 struct btrfs_extent_inline_ref *iref; 3639 struct btrfs_extent_inline_ref *iref;
3641 unsigned long ptr; 3640 unsigned long ptr;
3642 unsigned long end; 3641 unsigned long end;
3643 u32 blocksize = btrfs_level_size(rc->extent_root, 0); 3642 u32 blocksize = rc->extent_root->nodesize;
3644 int ret = 0; 3643 int ret = 0;
3645 int err = 0; 3644 int err = 0;
3646 3645
@@ -3783,7 +3782,7 @@ next:
3783 } 3782 }
3784 3783
3785 if (key.type == BTRFS_METADATA_ITEM_KEY && 3784 if (key.type == BTRFS_METADATA_ITEM_KEY &&
3786 key.objectid + rc->extent_root->leafsize <= 3785 key.objectid + rc->extent_root->nodesize <=
3787 rc->search_start) { 3786 rc->search_start) {
3788 path->slots[0]++; 3787 path->slots[0]++;
3789 goto next; 3788 goto next;
@@ -3801,7 +3800,7 @@ next:
3801 rc->search_start = key.objectid + key.offset; 3800 rc->search_start = key.objectid + key.offset;
3802 else 3801 else
3803 rc->search_start = key.objectid + 3802 rc->search_start = key.objectid +
3804 rc->extent_root->leafsize; 3803 rc->extent_root->nodesize;
3805 memcpy(extent_key, &key, sizeof(key)); 3804 memcpy(extent_key, &key, sizeof(key));
3806 return 0; 3805 return 0;
3807 } 3806 }
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 053dd000d4ef..4ae1c5feccbe 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -137,7 +137,6 @@ struct scrub_ctx {
137 int pages_per_rd_bio; 137 int pages_per_rd_bio;
138 u32 sectorsize; 138 u32 sectorsize;
139 u32 nodesize; 139 u32 nodesize;
140 u32 leafsize;
141 140
142 int is_dev_replace; 141 int is_dev_replace;
143 struct scrub_wr_ctx wr_ctx; 142 struct scrub_wr_ctx wr_ctx;
@@ -438,7 +437,6 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
438 } 437 }
439 sctx->first_free = 0; 438 sctx->first_free = 0;
440 sctx->nodesize = dev->dev_root->nodesize; 439 sctx->nodesize = dev->dev_root->nodesize;
441 sctx->leafsize = dev->dev_root->leafsize;
442 sctx->sectorsize = dev->dev_root->sectorsize; 440 sctx->sectorsize = dev->dev_root->sectorsize;
443 atomic_set(&sctx->bios_in_flight, 0); 441 atomic_set(&sctx->bios_in_flight, 0);
444 atomic_set(&sctx->workers_pending, 0); 442 atomic_set(&sctx->workers_pending, 0);
@@ -1758,7 +1756,6 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
1758 BTRFS_UUID_SIZE)) 1756 BTRFS_UUID_SIZE))
1759 ++fail; 1757 ++fail;
1760 1758
1761 WARN_ON(sctx->nodesize != sctx->leafsize);
1762 len = sctx->nodesize - BTRFS_CSUM_SIZE; 1759 len = sctx->nodesize - BTRFS_CSUM_SIZE;
1763 mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE; 1760 mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE;
1764 p = ((u8 *)mapped_buffer) + BTRFS_CSUM_SIZE; 1761 p = ((u8 *)mapped_buffer) + BTRFS_CSUM_SIZE;
@@ -2196,7 +2193,6 @@ static int scrub_extent(struct scrub_ctx *sctx, u64 logical, u64 len,
2196 sctx->stat.data_bytes_scrubbed += len; 2193 sctx->stat.data_bytes_scrubbed += len;
2197 spin_unlock(&sctx->stat_lock); 2194 spin_unlock(&sctx->stat_lock);
2198 } else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { 2195 } else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
2199 WARN_ON(sctx->nodesize != sctx->leafsize);
2200 blocksize = sctx->nodesize; 2196 blocksize = sctx->nodesize;
2201 spin_lock(&sctx->stat_lock); 2197 spin_lock(&sctx->stat_lock);
2202 sctx->stat.tree_extents_scrubbed++; 2198 sctx->stat.tree_extents_scrubbed++;
@@ -2487,7 +2483,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
2487 btrfs_item_key_to_cpu(l, &key, slot); 2483 btrfs_item_key_to_cpu(l, &key, slot);
2488 2484
2489 if (key.type == BTRFS_METADATA_ITEM_KEY) 2485 if (key.type == BTRFS_METADATA_ITEM_KEY)
2490 bytes = root->leafsize; 2486 bytes = root->nodesize;
2491 else 2487 else
2492 bytes = key.offset; 2488 bytes = key.offset;
2493 2489
@@ -2910,17 +2906,6 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
2910 if (btrfs_fs_closing(fs_info)) 2906 if (btrfs_fs_closing(fs_info))
2911 return -EINVAL; 2907 return -EINVAL;
2912 2908
2913 /*
2914 * check some assumptions
2915 */
2916 if (fs_info->chunk_root->nodesize != fs_info->chunk_root->leafsize) {
2917 btrfs_err(fs_info,
2918 "scrub: size assumption nodesize == leafsize (%d == %d) fails",
2919 fs_info->chunk_root->nodesize,
2920 fs_info->chunk_root->leafsize);
2921 return -EINVAL;
2922 }
2923
2924 if (fs_info->chunk_root->nodesize > BTRFS_STRIPE_LEN) { 2909 if (fs_info->chunk_root->nodesize > BTRFS_STRIPE_LEN) {
2925 /* 2910 /*
2926 * in this case scrub is unable to calculate the checksum 2911 * in this case scrub is unable to calculate the checksum
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 977717b45bf7..e336646508fe 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -408,7 +408,7 @@ start_transaction(struct btrfs_root *root, u64 num_items, unsigned int type,
408 if (num_items > 0 && root != root->fs_info->chunk_root) { 408 if (num_items > 0 && root != root->fs_info->chunk_root) {
409 if (root->fs_info->quota_enabled && 409 if (root->fs_info->quota_enabled &&
410 is_fstree(root->root_key.objectid)) { 410 is_fstree(root->root_key.objectid)) {
411 qgroup_reserved = num_items * root->leafsize; 411 qgroup_reserved = num_items * root->nodesize;
412 ret = btrfs_qgroup_reserve(root, qgroup_reserved); 412 ret = btrfs_qgroup_reserve(root, qgroup_reserved);
413 if (ret) 413 if (ret)
414 return ERR_PTR(ret); 414 return ERR_PTR(ret);
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 2f5000c0a87a..7b6d1428f033 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2157,7 +2157,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
2157 2157
2158 bytenr = btrfs_node_blockptr(cur, path->slots[*level]); 2158 bytenr = btrfs_node_blockptr(cur, path->slots[*level]);
2159 ptr_gen = btrfs_node_ptr_generation(cur, path->slots[*level]); 2159 ptr_gen = btrfs_node_ptr_generation(cur, path->slots[*level]);
2160 blocksize = btrfs_level_size(root, *level - 1); 2160 blocksize = root->nodesize;
2161 2161
2162 parent = path->nodes[*level]; 2162 parent = path->nodes[*level];
2163 root_owner = btrfs_header_owner(parent); 2163 root_owner = btrfs_header_owner(parent);