diff mbox series

[06/15] btrfs-progs: fix item check to use the size helpers

Message ID 19014616da62a01712410885ecf4d43911da151b.1646691255.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: initial snapshot_id support | expand

Commit Message

Josef Bacik March 7, 2022, 10:17 p.m. UTC
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(-)
diff mbox series

Patch

diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index e5ad2c82..bd316b46 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -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 */