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
94 _require_xfs_mkfs_finobt
96 _require_command "$KILLALL_PROG" killall
100 _scratch_mkfs_xfs "-m crc=1,finobt=1 -d agcount=2" | \
101 _filter_mkfs 2>> $seqres.full
104 COUNT=20000 # number of files per directory
105 LOOPS=15 # last loop iteration
106 MINDIRS=2 # number of dirs for the cleaner to leave trailing behind the
107 # most recent (no less than 2 to prevent an rm from trampling a
110 # create initial directory
111 _create $SCRATCH_MNT/dir1 $COUNT
113 # start background cleaner to remove old directories as new ones are created
114 _cleaner $SCRATCH_MNT $LOOPS $MINDIRS &
116 # start a background stress workload on the fs
117 $FSSTRESS_PROG -d $SCRATCH_MNT/fsstress -n 9999999 -p 2 -S t \
118 >> $seqres.full 2>&1 &
120 # Each cycle clones the current directory and makes a random file replacement
121 # pass on the new directory. The directory is copied to the next using hard
122 # links. The replacement pass then randomly removes and replaces ~5% of the
123 # content in the directory. Files replaced as such are effectively marked to be
124 # freed by the background cleaner as it moves forward and removes all of the
125 # previous hard links to the inode. Over several iterations, this workload
126 # creates a sparsely located set of a free inodes across the set and uses the
127 # finobt to allocate new inodes for replacement.
129 for i in $(seq 1 $LOOPS)
131 # hard link the content of the current directory to the next
132 while ! test -d $SCRATCH_MNT/dir$((i+1)); do
133 cp -Rl $SCRATCH_MNT/dir$i $SCRATCH_MNT/dir$((i+1)) 2>&1 | \
137 # do a random replacement of files in the new directory
138 _rand_replace $SCRATCH_MNT/dir$((i+1)) $COUNT
141 $KILLALL_PROG fsstress
144 # clean out the competing fsstress allocations, then everything else
145 rm -rf $SCRATCH_MNT/fsstress
146 rm -rf $SCRATCH_MNT/dir*