xfs/029: filter out "extended-header: cycle: 1" from output
[xfstests-dev.git] / tests / xfs / 013
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. xfs/013
6 #
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
11 # fsstress workload.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20
21 # get standard environment, filters and checks
22 . ./common/rc
23 . ./common/filter
24
25 _cleanup()
26 {
27         $KILLALL_PROG -9 fsstress 2>/dev/null
28         wait
29         cd /
30         _scratch_unmount 2>/dev/null
31         rm -f $tmp.*
32 }
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 filter_enospc() {
36         sed -e '/^.*No space left on device.*/d'
37 }
38
39 _create()
40 {
41         dir=$1
42         count=$2
43
44         mkdir -p $dir
45         for i in $(seq 0 $count)
46         do
47                 touch $dir/$i 2>&1 | filter_enospc
48         done
49 }
50
51 _rand_replace()
52 {
53         dir=$1
54         count=$2
55
56         # replace 5% of the dataset
57         for i in $(seq 0 $((count / 20)))
58         do
59                 file=$((RANDOM % count))
60                 rm -f $dir/$file
61                 touch $dir/$file 2>&1 | filter_enospc
62         done
63 }
64
65 _cleaner()
66 {
67         dir=$1
68         iters=$2
69         mindirs=$3
70
71         iters=$((iters - mindirs))
72
73         for i in $(seq 1 $iters)
74         do
75                 need=$dir/dir$((i + mindirs))
76                 while [ ! -e $need ]
77                 do
78                         sleep 3
79                         if ! pgrep fsstress > /dev/null 2>&1; then
80                                 echo "fsstress died?"
81                                 return
82                         fi
83                 done
84
85                 rm -rf $dir/dir$i
86         done
87 }
88
89 # real QA test starts here
90 _supported_fs xfs
91 _supported_os Linux
92
93 _require_scratch
94 _require_xfs_mkfs_finobt
95 _require_xfs_finobt
96 _require_command "$KILLALL_PROG" killall
97
98 rm -f $seqres.full
99
100 _scratch_mkfs_xfs "-m crc=1,finobt=1 -d agcount=2" | \
101         _filter_mkfs 2>> $seqres.full
102 _scratch_mount
103
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
108                 # clone)
109
110 # create initial directory
111 _create $SCRATCH_MNT/dir1 $COUNT
112
113 # start background cleaner to remove old directories as new ones are created
114 _cleaner $SCRATCH_MNT $LOOPS $MINDIRS &
115
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 &
119
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.
128
129 for i in $(seq 1 $LOOPS)
130 do
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 | \
134                         filter_enospc
135         done
136
137         # do a random replacement of files in the new directory
138         _rand_replace $SCRATCH_MNT/dir$((i+1)) $COUNT
139 done
140
141 $KILLALL_PROG fsstress
142 wait
143
144 # clean out the competing fsstress allocations, then everything else
145 rm -rf $SCRATCH_MNT/fsstress
146 rm -rf $SCRATCH_MNT/dir*
147
148 _scratch_unmount
149
150 status=0
151 exit