summaryrefslogtreecommitdiff
path: root/common/xfs
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2023-02-24 13:48:11 +0800
committerZorro Lang <zlang@kernel.org>2023-02-25 21:14:43 +0800
commitc63c8677b97ac5ab4abd16e462cddfa4b7bf298c (patch)
treeea50ad9adf2ac931116407c85bd8a4eb7e7ed570 /common/xfs
parent6b5b9b1e6fc28099c66b63d8bccb1f0049736343 (diff)
fuzzy: for fuzzing ag btrees, find the path to the AG header
The fs population code creates various btrees in /some/ allocation group with at least two levels. These btrees aren't necessarily created in agno 0, so we need to find it programmatically. While we're at it, fix a few of the comments that failed to mention when we're fuzzing interior nodes and not leaves. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Zorro Lang <zlang@redhat.com> Signed-off-by: Zorro Lang <zlang@kernel.org>
Diffstat (limited to 'common/xfs')
-rw-r--r--common/xfs37
1 files changed, 37 insertions, 0 deletions
diff --git a/common/xfs b/common/xfs
index 220a1cba..b93a72c3 100644
--- a/common/xfs
+++ b/common/xfs
@@ -1716,3 +1716,40 @@ _scratch_xfs_create_fake_root()
echo "$root_inum $inum"
}
+
+# Find us the path to the AG header containing a per-AG btree with a specific
+# height.
+_scratch_xfs_find_agbtree_height() {
+ local bt_type="$1"
+ local bt_height="$2"
+ local agcount=$(_xfs_mount_agcount $SCRATCH_DEV)
+
+ case "${bt_type}" in
+ "bno"|"cnt"|"rmap"|"refcnt")
+ hdr="agf"
+ bt_prefix="${bt_type}"
+ ;;
+ "ino")
+ hdr="agi"
+ bt_prefix=""
+ ;;
+ "fino")
+ hdr="agi"
+ bt_prefix="free_"
+ ;;
+ *)
+ _fail "Don't know about AG btree ${bt_type}"
+ ;;
+ esac
+
+ for ((agno = 0; agno < agcount; agno++)); do
+ bt_level=$(_scratch_xfs_db -c "${hdr} ${agno}" -c "p ${bt_prefix}level" | awk '{print $3}')
+ # "level" is really the btree height
+ if [ "${bt_level}" -eq "${bt_height}" ]; then
+ echo "${hdr} ${agno}"
+ return 0
+ fi
+ done
+
+ return 1
+}