@@ -45,14 +45,13 @@
#define BTRFS_BAD_NRITEMS (-4)
/* Calculate max possible nritems for a leaf/node */
-static u32 max_nritems(u8 level, u32 nodesize)
+static u32 max_nritems(struct btrfs_fs_info *fs_info, u8 level)
{
if (level == 0)
- return ((nodesize - sizeof(struct btrfs_header)) /
- sizeof(struct btrfs_item));
- return ((nodesize - sizeof(struct btrfs_header)) /
- sizeof(struct btrfs_key_ptr));
+ return BTRFS_LEAF_DATA_SIZE(fs_info) /
+ sizeof(struct btrfs_item);
+ return BTRFS_NODEPTRS_PER_BLOCK(fs_info);
}
static int check_tree_block(struct btrfs_fs_info *fs_info,
@@ -60,7 +59,6 @@ static int check_tree_block(struct btrfs_fs_info *fs_info,
{
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
- u32 nodesize = fs_info->nodesize;
bool fsid_match = false;
int ret = BTRFS_BAD_FSID;
@@ -68,8 +66,8 @@ static int check_tree_block(struct btrfs_fs_info *fs_info,
return BTRFS_BAD_BYTENR;
if (btrfs_header_level(buf) >= BTRFS_MAX_LEVEL)
return BTRFS_BAD_LEVEL;
- if (btrfs_header_nritems(buf) > max_nritems(btrfs_header_level(buf),
- nodesize))
+ if (btrfs_header_nritems(buf) > max_nritems(fs_info,
+ btrfs_header_level(buf)))
return BTRFS_BAD_NRITEMS;
/* Only leaf can be empty */
Right now we're duplicating the math to figure out the maximum number of items a leaf/node can hold for the sanity checks. Instead convert this to use the appropriate helpers to that it does the correct thing with extent tree v2. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- kernel-shared/disk-io.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)