2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc. All Rights Reserved.
5 # FS QA Test No. xfs/013
7 # Exercise the free inode btree (finobt). XFS allocates physical inodes in
8 # chunks of 64. Inode records with at least one free inode are stored in the
9 # finobt to optimize free inode lookup. This test runs a workload that creates
10 # and modifies a sparsely allocated set of inodes in combination with an
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
21 # get standard environment, filters and checks
27 $KILLALL_PROG -9 fsstress 2>/dev/null
30 _scratch_unmount 2>/dev/null
33 trap "_cleanup; exit \$status" 0 1 2 3 15
36 sed -e '/^.*No space left on device.*/d'
45 for i in $(seq 0 $count)
47 touch $dir/$i 2>&1 | filter_enospc
56 # replace 5% of the dataset
57 for i in $(seq 0 $((count / 20)))
59 file=$((RANDOM % count))
61 touch $dir/$file 2>&1 | filter_enospc
71 iters=$((iters - mindirs))
73 for i in $(seq 1 $iters)
75 need=$dir/dir$((i + mindirs))
79 if ! pgrep fsstress > /dev/null 2>&1; then
89 # real QA test starts here
93 _require_xfs_mkfs_finobt
95 _require_command "$KILLALL_PROG" killall
99 _scratch_mkfs_xfs "-m crc=1,finobt=1 -d agcount=2" | \
100 _filter_mkfs 2>> $seqres.full
103 COUNT=20000 # number of files per directory
104 LOOPS=15 # last loop iteration
105 MINDIRS=2 # number of dirs for the cleaner to leave trailing behind the
106 # most recent (no less than 2 to prevent an rm from trampling a
109 # create initial directory
110 _create $SCRATCH_MNT/dir1 $COUNT
112 # start background cleaner to remove old directories as new ones are created
113 _cleaner $SCRATCH_MNT $LOOPS $MINDIRS &
115 # start a background stress workload on the fs
116 $FSSTRESS_PROG -d $SCRATCH_MNT/fsstress -n 9999999 -p 2 -S t \
117 >> $seqres.full 2>&1 &
119 # Each cycle clones the current directory and makes a random file replacement
120 # pass on the new directory. The directory is copied to the next using hard
121 # links. The replacement pass then randomly removes and replaces ~5% of the
122 # content in the directory. Files replaced as such are effectively marked to be
123 # freed by the background cleaner as it moves forward and removes all of the
124 # previous hard links to the inode. Over several iterations, this workload
125 # creates a sparsely located set of a free inodes across the set and uses the
126 # finobt to allocate new inodes for replacement.
128 for i in $(seq 1 $LOOPS)
130 # hard link the content of the current directory to the next
131 while ! test -d $SCRATCH_MNT/dir$((i+1)); do
132 cp -Rl $SCRATCH_MNT/dir$i $SCRATCH_MNT/dir$((i+1)) 2>&1 | \
136 # do a random replacement of files in the new directory
137 _rand_replace $SCRATCH_MNT/dir$((i+1)) $COUNT
140 $KILLALL_PROG fsstress
143 # clean out the competing fsstress allocations, then everything else
144 rm -rf $SCRATCH_MNT/fsstress
145 rm -rf $SCRATCH_MNT/dir*