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 _begin_fstest auto rw enospc
29 FS_SIZE=$((240*1024*1024)) # 240MB
30 DEBUG=1 # set to 0 to disable debug statements in shell and c-prog
33 # Disk allocation methods
37 # Helps to build TEST_VECTORS
38 SMALL_FILE_SIZE=$((512 * 1024)) # in Bytes
39 BIG_FILE_SIZE=$((1536 * 1024)) # in Bytes
40 MIX_FILE_SIZE=$((2048 * 1024)) # (BIG + SMALL small file size)
42 # Import common functions.
45 # Modify as appropriate.
48 _require_test_program "t_enospc"
49 _require_xfs_io_command "falloc"
53 if [ $DEBUG -eq 1 ]; then
54 echo "$1" >> $seqres.full
58 # Calculate the number of threads needed to fill the disk space
60 # $1: the size of a file
61 # $2: ratio in which $1 file should be split into multiple files.
62 # $3: percentage of the disk space should be used during the test
63 # Calculate the number of threads needed to fill the disk space
66 local file_ratio_unit=$1
68 local disk_saturation=$3
73 IFS=',' read -ra fratio <<< $file_ratio
74 file_ratio_cnt=${#fratio[@]}
76 tot_avail_size=$($DF_PROG --block-size=1 $SCRATCH_MNT | $AWK_PROG 'FNR == 2 { print $5 }')
77 avail_size=$(echo $tot_avail_size*$disk_saturation | $BC_PROG)
78 thread_cnt=$(echo "$file_ratio_cnt*($avail_size/$file_ratio_unit)" | $BC_PROG)
80 debug "Total available size: $tot_avail_size"
81 debug "Available size: $avail_size"
82 debug "Thread count: $thread_cnt"
88 # $1: a string containing test configuration separated by a colon.
89 # $1 is treated as an array of arguments to the function.
90 # Description of each array element is given below.
92 # @1: name of the test
93 # @2: thread in t_enospec exerciser will allocate file of @2 size
94 # @3: defines the proportion in which the file size defined in @2
95 # should be divided into two files.
96 # (valid @3: more than two values are not allowed)
97 # values should be comma separated)
98 # sum of all values must be 1)
99 # @4: define the percentage of available memory should be used to
101 # @5: defines the disk allocation method (fallocate/ftruncate)
102 # @6: number of the test should run
105 IFS=':' read -ra args <<< $1
106 local test_name=${args[0]}
107 local file_ratio_unit=${args[1]}
108 local file_ratio=${args[2]}
109 local disk_saturation=${args[3]}
110 local disk_alloc_method=${args[4]}
111 local test_iteration_cnt=${args[5]}
115 if [ "$disk_alloc_method" == "$FALLOCATE" ]; then
116 extra_args="$extra_args -f"
119 # enable the debug statements in c program
120 if [ "$DEBUG" -eq 1 ]; then
121 extra_args="$extra_args -v"
124 debug "============ Test details start ============"
125 debug "Test name: $test_name"
126 debug "File ratio unit: $file_ratio_unit"
127 debug "File ratio: $file_ratio"
128 debug "Disk saturation $disk_saturation"
129 debug "Disk alloc method $disk_alloc_method"
130 debug "Test iteration count: $test_iteration_cnt"
131 debug "Extra arg: $extra_args"
133 for i in $(eval echo "{1..$test_iteration_cnt}"); do
135 _scratch_mkfs_sized $FS_SIZE >> $seqres.full 2>&1
138 debug "===== Test: $test_name iteration: $i starts ====="
139 thread_cnt=$(calc_thread_cnt $file_ratio_unit $file_ratio $disk_saturation)
142 $here/src/t_enospc -t $thread_cnt -s $file_ratio_unit -r $file_ratio -p $SCRATCH_MNT $extra_args >> $seqres.full
145 if [ $status -ne 0 ]; then
146 use_per=$($DF_PROG -h | grep $SCRATCH_MNT | awk '{print substr($6, 1, length($6)-1)}' | $BC_PROG)
147 alloc_per=$(echo "$FACT * 100" | $BC_PROG)
148 # We are here since t_enospc failed with an error code.
149 # If the used filesystem space is still < available space - that means
150 # the test failed due to FS wrongly reported ENOSPC.
151 if [ $(echo "$use_per < $alloc_per" | $BC_PROG) -ne 0 ]; then
152 if [ $status -eq 134 ]; then
153 # SIGABRT asserted exit code = 134
154 echo "FAIL: Aborted assertion faliure"
155 elif [ $status -eq 7 ]; then
156 # SIGBUS asserted exit code = 7
157 echo "FAIL: ENOSPC BUS faliure"
159 echo "$test_name failed at iteration count: $i"
160 echo "$($DF_PROG -h $SCRATCH_MNT)"
161 echo "Allocated: $alloc_per% Used: $use_per%"
166 # Make space for other tests
169 debug "===== Test: $test_name iteration: $i ends ====="
171 debug "============ Test details end ============="
174 declare -a TEST_VECTORS=(
175 # test-name:file-ratio-unit:file-ratio:disk-saturation:disk-alloc-method:test-iteration-cnt
176 "Small-file-fallocate-test:$SMALL_FILE_SIZE:1:$FACT:$FALLOCATE:3"
177 "Big-file-fallocate-test:$BIG_FILE_SIZE:1:$FACT:$FALLOCATE:3"
178 "Mix-file-fallocate-test:$MIX_FILE_SIZE:0.75,0.25:$FACT:$FALLOCATE:3"
179 "Small-file-ftruncate-test:$SMALL_FILE_SIZE:1:$FACT:$FTRUNCATE:3"
180 "Big-file-ftruncate-test:$BIG_FILE_SIZE:1:$FACT:$FTRUNCATE:3"
181 "Mix-file-ftruncate-test:$MIX_FILE_SIZE:0.75,0.25:$FACT:$FTRUNCATE:3"
184 # real QA test starts here
185 for i in "${TEST_VECTORS[@]}"; do
189 echo "Silence is golden"