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