2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Google, Inc. All Rights Reserved.
7 # Ext4 online resize tests of small and crucial resizes with bigalloc
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
22 IMG_FILE=$SCRATCH_DIR/$seq.fs
23 IMG_MNT=$SCRATCH_DIR/$seq.mnt
25 ## Num clusters to blocks.
29 echo $(($clusters * $CLUSTER_SIZ / $BLK_SIZ))
34 ## sizes are in number of blocks.
35 local original_size=$1
37 local check_if_supported=${3:-0}
39 ## Start with a clean image file.
41 echo "+++ truncate image file to $final_size" | \
43 $XFS_IO_PROG -f -c "truncate $(($final_size * $BLK_SIZ))" ${IMG_FILE}
44 LOOP_DEVICE=`_create_loop_device $IMG_FILE`
46 echo "+++ create fs on image file $original_size" | \
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"
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"
57 echo "+++ resize fs to $final_size" | tee -a $seqres.full
59 $RESIZE2FS_PROG -f ${LOOP_DEVICE} $final_size >$tmp.resize2fs 2>&1
61 if [ $check_if_supported -eq 1 ]; then
62 grep -iq "operation not supported" $tmp.resize2fs \
63 && _notrun "online resizing not supported with bigalloc"
67 cat $tmp.resize2fs >> $seqres.full
68 echo "+++ umount fs" | tee -a $seqres.full
69 $UMOUNT_PROG ${IMG_MNT}
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=
80 [ -n "$LOOP_DEVICE" ] && _destroy_loop_device $LOOP_DEVICE > /dev/null 2>&1
82 $UMOUNT_PROG ${IMG_MNT} > /dev/null 2>&1
83 rm -f ${IMG_FILE} > /dev/null 2>&1
86 # get standard environment and checks
89 # remove previous $seqres.full before test
92 # real QA test starts here
98 # We use resize_inode to make sure that block group descriptor table
100 _require_scratch_ext4_feature "bigalloc,resize_inode"
101 _require_command "$RESIZE2FS_PROG" resize2fs
103 _scratch_mkfs >>$seqres.full 2>&1
108 mkdir -p $IMG_MNT || _fail "cannot create loopback mount point"
110 # Check if online resizing with bigalloc is supported by the kernel
111 ext4_online_resize 4096 8192 1
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
119 ## Extend last group tests
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
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)
131 ## Extend last group and add more block groups.
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
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)
147 ## Convert to meta_bg.
150 ## Extending a 2/3rd block group to 1280 block groups.
151 ext4_online_resize $(c2b 24576) $(c2b 41943040)