btrfs-progs: drop blocksize argument from btrfs_find_create_tree_block
authorDavid Sterba <dsterba@suse.com>
Fri, 25 Aug 2017 15:44:22 +0000 (17:44 +0200)
committerDavid Sterba <dsterba@suse.com>
Fri, 8 Sep 2017 14:15:05 +0000 (16:15 +0200)
Metadata blocks are always nodesize. When reading the
superblock::sys_array, the actual size of data is fixed to 4k and
smaller than nodesize, but otherwise everything works as before.

Signed-off-by: David Sterba <dsterba@suse.com>
btrfs-corrupt-block.c
disk-io.c
disk-io.h
extent-tree.c
volumes.c

index 297841c..83adcf8 100644 (file)
@@ -1364,7 +1364,7 @@ int main(int argc, char **argv)
                        struct extent_buffer *eb;
 
                        eb = btrfs_find_create_tree_block(root->fs_info,
-                                       logical, root->fs_info->sectorsize);
+                                       logical);
                        if (!eb) {
                                error(
                "not enough memory to allocate extent buffer for bytenr %llu",
index 6bb1b93..f05a0bf 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -182,9 +182,10 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
 }
 
 struct extent_buffer* btrfs_find_create_tree_block(
-               struct btrfs_fs_info *fs_info, u64 bytenr, u32 blocksize)
+               struct btrfs_fs_info *fs_info, u64 bytenr)
 {
-       return alloc_extent_buffer(&fs_info->extent_cache, bytenr, blocksize);
+       return alloc_extent_buffer(&fs_info->extent_cache, bytenr,
+                       fs_info->nodesize);
 }
 
 void readahead_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
@@ -306,7 +307,6 @@ struct extent_buffer* read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
        struct extent_buffer *eb;
        u64 best_transid = 0;
        u32 sectorsize = fs_info->sectorsize;
-       u32 nodesize = fs_info->nodesize;
        int mirror_num = 0;
        int good_mirror = 0;
        int num_copies;
@@ -324,7 +324,7 @@ struct extent_buffer* read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
                return ERR_PTR(-EIO);
        }
 
-       eb = btrfs_find_create_tree_block(fs_info, bytenr, nodesize);
+       eb = btrfs_find_create_tree_block(fs_info, bytenr);
        if (!eb)
                return ERR_PTR(-ENOMEM);
 
@@ -937,9 +937,7 @@ static int setup_root_or_create_block(struct btrfs_fs_info *fs_info,
                                      struct btrfs_root *info_root,
                                      u64 objectid, char *str)
 {
-       struct btrfs_super_block *sb = fs_info->super_copy;
        struct btrfs_root *root = fs_info->tree_root;
-       u32 nodesize = btrfs_super_nodesize(sb);
        int ret;
 
        ret = find_and_setup_root(root, fs_info, objectid, info_root);
@@ -952,7 +950,7 @@ static int setup_root_or_create_block(struct btrfs_fs_info *fs_info,
                 * million of places that assume a root has a valid ->node
                 */
                info_root->node =
-                       btrfs_find_create_tree_block(fs_info, 0, nodesize);
+                       btrfs_find_create_tree_block(fs_info, 0);
                if (!info_root->node)
                        return -ENOMEM;
                clear_extent_buffer_uptodate(info_root->node);
index bdf4a89..c43ab61 100644 (file)
--- a/disk-io.h
+++ b/disk-io.h
@@ -123,7 +123,7 @@ int read_extent_data(struct btrfs_fs_info *fs_info, char *data, u64 logical,
 void readahead_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
                          u32 blocksize, u64 parent_transid);
 struct extent_buffer* btrfs_find_create_tree_block(
-               struct btrfs_fs_info *fs_info, u64 bytenr, u32 blocksize);
+               struct btrfs_fs_info *fs_info, u64 bytenr);
 
 void btrfs_setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
                      u64 objectid);
index 46b8a05..81a17a3 100644 (file)
@@ -2818,8 +2818,7 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
                return ERR_PTR(ret);
        }
 
-       buf = btrfs_find_create_tree_block(root->fs_info, ins.objectid,
-                                          blocksize);
+       buf = btrfs_find_create_tree_block(root->fs_info, ins.objectid);
        if (!buf) {
                btrfs_free_extent(trans, root, ins.objectid, ins.offset,
                                  0, root->root_key.objectid, level, 0);
index 974c601..2ae2d1b 100644 (file)
--- a/volumes.c
+++ b/volumes.c
@@ -1963,9 +1963,12 @@ int btrfs_read_sys_array(struct btrfs_fs_info *fs_info)
        u32 cur_offset;
        struct btrfs_key key;
 
-       sb = btrfs_find_create_tree_block(fs_info,
-                                         BTRFS_SUPER_INFO_OFFSET,
-                                         BTRFS_SUPER_INFO_SIZE);
+       if (fs_info->nodesize < BTRFS_SUPER_INFO_SIZE) {
+               printf("ERROR: nodesize %u too small to read superblock\n",
+                               fs_info->nodesize);
+               return -EINVAL;
+       }
+       sb = btrfs_find_create_tree_block(fs_info, BTRFS_SUPER_INFO_OFFSET);
        if (!sb)
                return -ENOMEM;
        btrfs_set_buffer_uptodate(sb);