common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / ext4 / 032
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Google, Inc.  All Rights Reserved.
4 #
5 # FS QA Test ext4/032
6 #
7 # Ext4 online resize tests of small and crucial resizes with bigalloc
8 # feature.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 BLK_SIZ=4096
20 CLUSTER_SIZ=4096
21
22 IMG_FILE=$SCRATCH_MNT/$seq.fs
23 IMG_MNT=$SCRATCH_MNT/$seq.mnt
24
25 ## Num clusters to blocks.
26 c2b()
27 {
28         local clusters=$1
29         echo $(($clusters * $CLUSTER_SIZ / $BLK_SIZ))
30 }
31
32 ext4_online_resize()
33 {
34         ## sizes are in number of blocks.
35         local original_size=$1
36         local final_size=$2
37         local check_if_supported=${3:-0}
38
39         ## Start with a clean image file.
40         echo "" > ${IMG_FILE}
41         echo "+++ truncate image file to $final_size" | \
42                 tee -a $seqres.full
43         $XFS_IO_PROG -f -c "truncate $(($final_size * $BLK_SIZ))" ${IMG_FILE}
44         LOOP_DEVICE=`_create_loop_device $IMG_FILE`
45
46         echo "+++ create fs on image file $original_size" | \
47                 tee -a $seqres.full
48
49         ${MKFS_PROG}.${FSTYP} -F -O bigalloc,resize_inode -C $CLUSTER_SIZ \
50                 -b $BLK_SIZ ${LOOP_DEVICE} $original_size >> \
51                 $seqres.full 2>&1 || _fail "mkfs failed"
52
53         echo "+++ mount image file" | tee -a $seqres.full
54         $MOUNT_PROG -t ${FSTYP} ${LOOP_DEVICE} ${IMG_MNT} > \
55                 /dev/null 2>&1 || _fail "mount failed"
56
57         echo "+++ resize fs to $final_size" | tee -a $seqres.full
58
59         $RESIZE2FS_PROG -f ${LOOP_DEVICE} $final_size >$tmp.resize2fs 2>&1
60         if [ $? -ne 0 ]; then
61                 if [ $check_if_supported -eq 1 ]; then
62                         grep -iq "operation not supported" $tmp.resize2fs \
63                                 && _notrun "online resizing not supported with bigalloc"
64                 fi
65                 _fail "resize failed"
66         fi
67         cat $tmp.resize2fs >> $seqres.full
68         echo "+++ umount fs" | tee -a $seqres.full
69         $UMOUNT_PROG ${IMG_MNT}
70
71         echo "+++ check fs" | tee -a $seqres.full
72         _check_generic_filesystem $LOOP_DEVICE >> $seqres.full 2>&1 || \
73                 _fail "fsck should not fail"
74         _destroy_loop_device $LOOP_DEVICE && LOOP_DEVICE=
75 }
76
77 _cleanup()
78 {
79         cd /
80         [ -n "$LOOP_DEVICE" ] && _destroy_loop_device $LOOP_DEVICE > /dev/null 2>&1
81         rm -f $tmp.*
82         $UMOUNT_PROG ${IMG_MNT} > /dev/null 2>&1
83         rm -f ${IMG_FILE} > /dev/null 2>&1
84 }
85
86 # get standard environment and checks
87 . ./common/rc
88
89 # remove previous $seqres.full before test
90 rm -f $seqres.full
91
92 # real QA test starts here
93 _supported_fs ext4
94 _supported_os Linux
95
96 _require_loop
97 _require_scratch
98 # We use resize_inode to make sure that block group descriptor table
99 # can be extended.
100 _require_scratch_ext4_feature "bigalloc,resize_inode"
101 _require_command "$RESIZE2FS_PROG" resize2fs
102
103 _scratch_mkfs >>$seqres.full 2>&1
104 _scratch_mount
105
106 rm -f $seqres.full
107
108 mkdir -p $IMG_MNT || _fail "cannot create loopback mount point"
109
110 # Check if online resizing with bigalloc is supported by the kernel
111 ext4_online_resize 4096 8192 1
112
113 ## We perform resizing to various multiples of block group sizes to
114 ## ensure that we cover maximum edge cases in the kernel code.
115 for CLUSTER_SIZ in 4096 16384 65536; do
116         echo "++ set cluster size to $CLUSTER_SIZ" | tee -a $seqres.full
117
118         ##
119         ## Extend last group tests
120         ##
121
122         ## Extending a 1/2 block group to a 2/3 block group.
123         ext4_online_resize $(c2b 16384) $(c2b 24576)
124         ## Extending a 2/3rd block group to one cluster less than a
125         ## full block group.
126         ext4_online_resize $(c2b 24576) $(c2b 32767)
127         ## Extending a 2/3rd block group to a full block group.
128         ext4_online_resize $(c2b 24576) $(c2b 32768)
129
130         ##
131         ## Extend last group and add more block groups.
132         ##
133
134         ## Extending a 2/3rd block group to 2 block groups.
135         ext4_online_resize $(c2b 24576) $(c2b 65536)
136         ## Extending a 2/3rd block group to 15 block groups and one
137         ## cluster.
138         ext4_online_resize $(c2b 24576) $(c2b 491521)
139         ## Extending a 2/3rd block group to 15 and a half block groups.
140         ext4_online_resize $(c2b 24576) $(c2b 507904)
141         ## Extending a 2/3rd block group to 16 block groups.
142         ext4_online_resize $(c2b 24576) $(c2b 524288)
143         ## Extending a 2/3rd block group to 160 block groups.
144         ext4_online_resize $(c2b 24576) $(c2b 5242880)
145
146         ##
147         ## Convert to meta_bg.
148         ##
149
150         ## Extending a 2/3rd block group to 1280 block groups.
151         ext4_online_resize $(c2b 24576) $(c2b 41943040)
152 done
153
154 status=0
155 exit