2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 IBM Corporation. All Rights Reserved.
7 # ENOSPC regression test in a multi-threaded scenario. Test allocation
8 # strategies of the file system and validate space anomalies as reported by
9 # the system versus the allocated by the program.
11 # The test is motivated by a bug in ext4 systems where-in ENOSPC is
12 # reported by the file system even though enough space for allocations is
14 # [1]: https://patchwork.ozlabs.org/patch/1294003
16 # Linux kernel patch series that fixes the above regression:
17 # 53f86b170dfa ("ext4: mballoc: add blocks to PA list under same spinlock
18 # after allocating blocks")
19 # cf5e2ca6c990 ("ext4: mballoc: refactor ext4_mb_discard_preallocations()")
20 # 07b5b8e1ac40 ("ext4: mballoc: introduce pcpu seqcnt for freeing PA to
21 # improve ENOSPC handling")
22 # 8ef123fe02ca ("ext4: mballoc: refactor ext4_mb_good_group()")
23 # 993778306e79 ("ext4: mballoc: use lock for checking free blocks while
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
32 status=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
35 FS_SIZE=$((240*1024*1024)) # 240MB
36 DEBUG=1 # set to 0 to disable debug statements in shell and c-prog
39 # Disk allocation methods
43 # Helps to build TEST_VECTORS
44 SMALL_FILE_SIZE=$((512 * 1024)) # in Bytes
45 BIG_FILE_SIZE=$((1536 * 1024)) # in Bytes
46 MIX_FILE_SIZE=$((2048 * 1024)) # (BIG + SMALL small file size)
54 # get standard environment, filters and checks
58 # remove previous $seqres.full before test
61 # Modify as appropriate.
64 _require_test_program "t_enospc"
65 _require_xfs_io_command "falloc"
69 if [ $DEBUG -eq 1 ]; then
70 echo "$1" >> $seqres.full
74 # Calculate the number of threads needed to fill the disk space
76 # $1: the size of a file
77 # $2: ratio in which $1 file should be split into multiple files.
78 # $3: percentage of the disk space should be used during the test
79 # Calculate the number of threads needed to fill the disk space
82 local file_ratio_unit=$1
84 local disk_saturation=$3
89 IFS=',' read -ra fratio <<< $file_ratio
90 file_ratio_cnt=${#fratio[@]}
92 tot_avail_size=$($DF_PROG --block-size=1 $SCRATCH_MNT | $AWK_PROG 'FNR == 2 { print $5 }')
93 avail_size=$(echo $tot_avail_size*$disk_saturation | $BC_PROG)
94 thread_cnt=$(echo "$file_ratio_cnt*($avail_size/$file_ratio_unit)" | $BC_PROG)
96 debug "Total available size: $tot_avail_size"
97 debug "Available size: $avail_size"
98 debug "Thread count: $thread_cnt"
104 # $1: a string containing test configuration separated by a colon.
105 # $1 is treated as an array of arguments to the function.
106 # Description of each array element is given below.
108 # @1: name of the test
109 # @2: thread in t_enospec exerciser will allocate file of @2 size
110 # @3: defines the proportion in which the file size defined in @2
111 # should be divided into two files.
112 # (valid @3: more than two values are not allowed)
113 # values should be comma separated)
114 # sum of all values must be 1)
115 # @4: define the percentage of available memory should be used to
117 # @5: defines the disk allocation method (fallocate/ftruncate)
118 # @6: number of the test should run
121 IFS=':' read -ra args <<< $1
122 local test_name=${args[0]}
123 local file_ratio_unit=${args[1]}
124 local file_ratio=${args[2]}
125 local disk_saturation=${args[3]}
126 local disk_alloc_method=${args[4]}
127 local test_iteration_cnt=${args[5]}
131 if [ "$disk_alloc_method" == "$FALLOCATE" ]; then
132 extra_args="$extra_args -f"
135 # enable the debug statements in c program
136 if [ "$DEBUG" -eq 1 ]; then
137 extra_args="$extra_args -v"
140 debug "============ Test details start ============"
141 debug "Test name: $test_name"
142 debug "File ratio unit: $file_ratio_unit"
143 debug "File ratio: $file_ratio"
144 debug "Disk saturation $disk_saturation"
145 debug "Disk alloc method $disk_alloc_method"
146 debug "Test iteration count: $test_iteration_cnt"
147 debug "Extra arg: $extra_args"
149 for i in $(eval echo "{1..$test_iteration_cnt}"); do
151 _scratch_mkfs_sized $FS_SIZE >> $seqres.full 2>&1
154 debug "===== Test: $test_name iteration: $i starts ====="
155 thread_cnt=$(calc_thread_cnt $file_ratio_unit $file_ratio $disk_saturation)
158 $here/src/t_enospc -t $thread_cnt -s $file_ratio_unit -r $file_ratio -p $SCRATCH_MNT $extra_args >> $seqres.full
161 if [ $status -ne 0 ]; then
162 use_per=$($DF_PROG -h | grep $SCRATCH_MNT | awk '{print substr($6, 1, length($6)-1)}' | $BC_PROG)
163 alloc_per=$(echo "$FACT * 100" | $BC_PROG)
164 # We are here since t_enospc failed with an error code.
165 # If the used filesystem space is still < available space - that means
166 # the test failed due to FS wrongly reported ENOSPC.
167 if [ $(echo "$use_per < $alloc_per" | $BC_PROG) -ne 0 ]; then
168 if [ $status -eq 134 ]; then
169 # SIGABRT asserted exit code = 134
170 echo "FAIL: Aborted assertion faliure"
171 elif [ $status -eq 7 ]; then
172 # SIGBUS asserted exit code = 7
173 echo "FAIL: ENOSPC BUS faliure"
175 echo "$test_name failed at iteration count: $i"
176 echo "$($DF_PROG -h $SCRATCH_MNT)"
177 echo "Allocated: $alloc_per% Used: $use_per%"
182 # Make space for other tests
185 debug "===== Test: $test_name iteration: $i ends ====="
187 debug "============ Test details end ============="
190 declare -a TEST_VECTORS=(
191 # test-name:file-ratio-unit:file-ratio:disk-saturation:disk-alloc-method:test-iteration-cnt
192 "Small-file-fallocate-test:$SMALL_FILE_SIZE:1:$FACT:$FALLOCATE:3"
193 "Big-file-fallocate-test:$BIG_FILE_SIZE:1:$FACT:$FALLOCATE:3"
194 "Mix-file-fallocate-test:$MIX_FILE_SIZE:0.75,0.25:$FACT:$FALLOCATE:3"
195 "Small-file-ftruncate-test:$SMALL_FILE_SIZE:1:$FACT:$FTRUNCATE:3"
196 "Big-file-ftruncate-test:$BIG_FILE_SIZE:1:$FACT:$FTRUNCATE:3"
197 "Mix-file-ftruncate-test:$MIX_FILE_SIZE:0.75,0.25:$FACT:$FTRUNCATE:3"
200 # real QA test starts here
201 for i in "${TEST_VECTORS[@]}"; do
205 echo "Silence is golden"