2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc. All Rights Reserved.
4 # Copyright (c) 2019 Oracle, Inc. All Rights Reserved.
8 # Use the xfs_io bulkstat utility to verify bulkstat finds all inodes in a
9 # filesystem. Test under various inode counts, inobt record layouts and
10 # bulkstat batch sizes. Test v1 and v5 ioctls explicitly, as well as the
11 # ioctl version autodetection code in libfrog.
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
32 if [ -n "$has_v5" ]; then
39 # Print the number of inodes counted by bulkstat
45 bstat_versions | while read v_tag v_flag; do
46 echo "$tag($v_tag): passing \"$v_flag\" to bulkstat" >> $seqres.full
47 echo -n "bulkstat $tag($v_tag): "
48 $XFS_IO_PROG -c "bulkstat -n $batchsize $v_flag" $SCRATCH_MNT | grep ino | wc -l
52 # Print the number of inodes counted by per-ag bulkstat
58 local agcount=$(_xfs_mount_agcount $SCRATCH_MNT)
60 bstat_versions | while read v_tag v_flag; do
61 echo -n "bulkstat $tag($v_tag): "
62 seq 0 $((agcount - 1)) | while read ag; do
63 $XFS_IO_PROG -c "bulkstat -a $ag -n $batchsize $v_flag" $SCRATCH_MNT
64 done | grep ino | wc -l
68 # Sum the number of allocated inodes in each AG in a fs.
76 seq 0 $((agcount - 1)) | while read ag; do
77 $XFS_IO_PROG -c "inumbers -a $ag -n $batchsize $v_flag" $mount
78 done | grep alloccount | awk '{x += $3} END { print(x) }'
81 # Sum the number of allocated inodes in the whole fs all at once.
87 $XFS_IO_PROG -c "inumbers $v_flag" "$dir" | grep alloccount | \
88 awk '{x += $3} END { print(x) }'
91 # Print the number of inodes counted by inumbers
96 # There probably aren't more than 10 hidden inodes, right?
99 # Force all background unlinked inode cleanup to run so that we don't
100 # race changes to the inode btree with our inumbers query.
103 bstat_versions | while read v_tag v_flag; do
104 echo -n "inumbers all($v_tag): "
105 nr=$(inumbers_fs $SCRATCH_MNT $v_flag)
106 _within_tolerance "inumbers" $nr $expect $tolerance -v
108 local agcount=$(_xfs_mount_agcount $SCRATCH_MNT)
109 for batchsize in 71 2 1; do
110 echo -n "inumbers $batchsize($v_tag): "
111 nr=$(inumbers_ag $agcount $batchsize $SCRATCH_MNT $v_flag)
112 _within_tolerance "inumbers" $nr $expect $tolerance -v
117 # Compare the src/bstat output against the xfs_io bstat output.
118 # This compares the actual inode numbers output by one tool against another,
119 # so we can't easily put the output in the golden output.
122 bstat_versions | while read v_tag v_flag; do
123 diff -u <($here/src/bstat $SCRATCH_MNT | grep ino | awk '{print $2}') \
124 <($XFS_IO_PROG -c "bulkstat $v_flag" $SCRATCH_MNT | grep ino | awk '{print $3}')
128 # Print bulkstat counts using varied batch sizes
131 expect=`find $SCRATCH_MNT -print | wc -l`
133 echo "expect $expect"
135 for sz in 4096 71 32 1; do
136 bstat_count $sz "$sz all"
137 bstat_perag_count $sz "$sz perag"
139 inumbers_count $expect
143 # Get standard environment, filters and checks
148 _require_xfs_io_command bulkstat
149 _require_xfs_io_command bulkstat_single
150 _require_xfs_io_command inumbers
152 # Real QA test starts here
159 INOCOUNT=$((2048 / DIRCOUNT))
161 _scratch_mkfs "-d agcount=$DIRCOUNT" >> $seqres.full 2>&1 || _fail "mkfs failed"
164 # Figure out if we have v5 bulkstat/inumbers ioctls.
166 bs_root_out="$($XFS_IO_PROG -c 'bulkstat_single root' $SCRATCH_MNT 2>>$seqres.full)"
167 test -n "$bs_root_out" && has_v5=1
169 echo "this will be 1 if we have v5 bulkstat: $has_v5" >> $seqres.full
171 # If v5 bulkstat is present, query the root inode and compare it to the stat
172 # output of $SCRATCH_MNT to make sure it gave us the correct number
173 if [ -n "$has_v5" ]; then
174 bs_root=$(echo "$bs_root_out" | grep ino | awk '{print $3}')
175 stat_root=$(stat -c '%i' $SCRATCH_MNT)
176 if [ "$stat_root" -ne "$bs_root" ]; then
177 echo "stat says root is $stat_root but bulkstat says $bs_root"
181 # Create a set of directories and fill each with a fixed number of files
182 for dir in $(seq 1 $DIRCOUNT); do
183 mkdir -p $SCRATCH_MNT/$dir
184 for i in $(seq 1 $INOCOUNT); do
185 touch $SCRATCH_MNT/$dir/$i
190 # Remove every other file from each dir
191 for dir in $(seq 1 $DIRCOUNT); do
192 for i in $(seq 2 2 $INOCOUNT); do
193 rm -f $SCRATCH_MNT/$dir/$i
198 # Remove the entire second half of files
199 for dir in $(seq 1 $DIRCOUNT); do
200 for i in $(seq $((INOCOUNT / 2)) $INOCOUNT); do
201 rm -f $SCRATCH_MNT/$dir/$i
206 # Remove all regular files
207 for dir in $(seq 1 $DIRCOUNT); do
208 rm -f $SCRATCH_MNT/$dir/*