4 # Ext4 online resize tests of small and crucial resizes with bigalloc
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2018 Google, Inc. All Rights Reserved.
10 # Author: Harshad Shirwadkar <harshads@google.com>
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.
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.
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 #-----------------------------------------------------------------------
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
38 IMG_FILE=$SCRATCH_DIR/$seq.fs
39 IMG_MNT=$SCRATCH_DIR/$seq.mnt
41 ## Num clusters to blocks.
45 echo $(($clusters * $CLUSTER_SIZ / $BLK_SIZ))
50 ## sizes are in number of blocks.
51 local original_size=$1
53 local check_if_supported=${3:-0}
55 ## Start with a clean image file.
57 echo "+++ truncate image file to $final_size" | \
59 $XFS_IO_PROG -f -c "truncate $(($final_size * $BLK_SIZ))" ${IMG_FILE}
60 LOOP_DEVICE=`_create_loop_device $IMG_FILE`
62 echo "+++ create fs on image file $original_size" | \
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"
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"
73 echo "+++ resize fs to $final_size" | tee -a $seqres.full
75 $RESIZE2FS_PROG -f ${LOOP_DEVICE} $final_size >$tmp.resize2fs 2>&1
77 if [ $check_if_supported -eq 1 ]; then
78 grep -iq "operation not supported" $tmp.resize2fs \
79 && _notrun "online resizing not supported with bigalloc"
83 cat $tmp.resize2fs >> $seqres.full
84 echo "+++ umount fs" | tee -a $seqres.full
85 $UMOUNT_PROG ${IMG_MNT}
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=
96 [ -n "$LOOP_DEVICE" ] && _destroy_loop_device $LOOP_DEVICE > /dev/null 2>&1
98 $UMOUNT_PROG ${IMG_MNT} > /dev/null 2>&1
99 rm -f ${IMG_FILE} > /dev/null 2>&1
102 # get standard environment and checks
105 # remove previous $seqres.full before test
108 # real QA test starts here
114 # We use resize_inode to make sure that block group descriptor table
116 _require_scratch_ext4_feature "bigalloc,resize_inode"
117 _require_command "$RESIZE2FS_PROG" resize2fs
119 _scratch_mkfs >>$seqres.full 2>&1
124 mkdir -p $IMG_MNT || _fail "cannot create loopback mount point"
126 # Check if online resizing with bigalloc is supported by the kernel
127 ext4_online_resize 4096 8192 1
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
135 ## Extend last group tests
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
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)
147 ## Extend last group and add more block groups.
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
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)
163 ## Convert to meta_bg.
166 ## Extending a 2/3rd block group to 1280 block groups.
167 ext4_online_resize $(c2b 24576) $(c2b 41943040)