From be957968f6fade15d0a7a6058ae270141263bd64 Mon Sep 17 00:00:00 2001 From: Ziyang Zhang Date: Mon, 12 Dec 2022 13:56:44 +0800 Subject: [PATCH] common/xfs: Add a helper to export inode core size Some xfs test cases need the number of bytes reserved for only the inode record, excluding the immediate fork areas. Now the value is hard-coded and it is not a good chioce. Add a helper in common/xfs to export the inode core size. Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Ziyang Zhang Signed-off-by: Zorro Lang --- common/xfs | 15 +++++++++++++++ tests/xfs/335 | 3 ++- tests/xfs/336 | 3 ++- tests/xfs/337 | 3 ++- tests/xfs/341 | 3 ++- tests/xfs/342 | 3 ++- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/common/xfs b/common/xfs index f466d2c4..04ae121d 100644 --- a/common/xfs +++ b/common/xfs @@ -1495,3 +1495,18 @@ _require_xfsrestore_xflag() $XFSRESTORE_PROG -h 2>&1 | grep -q -e '-x' || \ _notrun 'xfsrestore does not support -x flag.' } + +# Number of bytes reserved for only the inode record, excluding the +# immediate fork areas. +_xfs_get_inode_core_bytes() +{ + local dir="$1" + + if _xfs_has_feature "$dir" crc; then + # v5 filesystems + echo 176 + else + # v4 filesystems + echo 96 + fi +} diff --git a/tests/xfs/335 b/tests/xfs/335 index d07485b2..79d07116 100755 --- a/tests/xfs/335 +++ b/tests/xfs/335 @@ -31,7 +31,8 @@ blksz="$(_get_block_size $SCRATCH_MNT)" echo "Create a three-level rtrmapbt" # inode core size is at least 176 bytes; btree header is 56 bytes; # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes. -i_ptrs=$(( (isize - 176) / 56 )) +i_core_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)" +i_ptrs=$(( (isize - i_core_size) / 56 )) bt_ptrs=$(( (blksz - 56) / 56 )) bt_recs=$(( (blksz - 56) / 32 )) diff --git a/tests/xfs/336 b/tests/xfs/336 index ee8ec649..8d50729e 100755 --- a/tests/xfs/336 +++ b/tests/xfs/336 @@ -42,7 +42,8 @@ rm -rf $metadump_file echo "Create a three-level rtrmapbt" # inode core size is at least 176 bytes; btree header is 56 bytes; # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes. -i_ptrs=$(( (isize - 176) / 56 )) +i_core_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)" +i_ptrs=$(( (isize - i_core_size) / 56 )) bt_ptrs=$(( (blksz - 56) / 56 )) bt_recs=$(( (blksz - 56) / 32 )) diff --git a/tests/xfs/337 b/tests/xfs/337 index 8502a5ff..f74baae9 100755 --- a/tests/xfs/337 +++ b/tests/xfs/337 @@ -33,7 +33,8 @@ blksz="$(_get_block_size $SCRATCH_MNT)" # inode core size is at least 176 bytes; btree header is 56 bytes; # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes. -i_ptrs=$(( (isize - 176) / 56 )) +i_core_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)" +i_ptrs=$(( (isize - i_core_size) / 56 )) bt_ptrs=$(( (blksz - 56) / 56 )) bt_recs=$(( (blksz - 56) / 32 )) diff --git a/tests/xfs/341 b/tests/xfs/341 index 122def0f..1f734c90 100755 --- a/tests/xfs/341 +++ b/tests/xfs/341 @@ -33,7 +33,8 @@ rtextsz_blks=$((rtextsz / blksz)) # inode core size is at least 176 bytes; btree header is 56 bytes; # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes. -i_ptrs=$(( (isize - 176) / 56 )) +i_core_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)" +i_ptrs=$(( (isize - i_core_size) / 56 )) bt_recs=$(( (blksz - 56) / 32 )) blocks=$((i_ptrs * bt_recs + 1)) diff --git a/tests/xfs/342 b/tests/xfs/342 index 73f7fc04..538c8987 100755 --- a/tests/xfs/342 +++ b/tests/xfs/342 @@ -30,7 +30,8 @@ blksz="$(_get_block_size $SCRATCH_MNT)" # inode core size is at least 176 bytes; btree header is 56 bytes; # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes. -i_ptrs=$(( (isize - 176) / 56 )) +i_core_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)" +i_ptrs=$(( (isize - i_core_size) / 56 )) bt_recs=$(( (blksz - 56) / 32 )) blocks=$((i_ptrs * bt_recs + 1)) -- 2.39.5