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_MNT/$seq.fs
23 IMG_MNT=$SCRATCH_MNT/$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} -t ${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
97 # We use resize_inode to make sure that block group descriptor table
99 _require_scratch_ext4_feature "bigalloc,resize_inode"
100 _require_command "$RESIZE2FS_PROG" resize2fs
102 _scratch_mkfs >>$seqres.full 2>&1
107 mkdir -p $IMG_MNT || _fail "cannot create loopback mount point"
109 # Check if online resizing with bigalloc is supported by the kernel
110 ext4_online_resize 4096 8192 1
112 ## We perform resizing to various multiples of block group sizes to
113 ## ensure that we cover maximum edge cases in the kernel code.
114 for CLUSTER_SIZ in 4096 16384 65536; do
115 echo "++ set cluster size to $CLUSTER_SIZ" | tee -a $seqres.full
118 ## Extend last group tests
121 ## Extending a 1/2 block group to a 2/3 block group.
122 ext4_online_resize $(c2b 16384) $(c2b 24576)
123 ## Extending a 2/3rd block group to one cluster less than a
125 ext4_online_resize $(c2b 24576) $(c2b 32767)
126 ## Extending a 2/3rd block group to a full block group.
127 ext4_online_resize $(c2b 24576) $(c2b 32768)
130 ## Extend last group and add more block groups.
133 ## Extending a 2/3rd block group to 2 block groups.
134 ext4_online_resize $(c2b 24576) $(c2b 65536)
135 ## Extending a 2/3rd block group to 15 block groups and one
137 ext4_online_resize $(c2b 24576) $(c2b 491521)
138 ## Extending a 2/3rd block group to 15 and a half block groups.
139 ext4_online_resize $(c2b 24576) $(c2b 507904)
140 ## Extending a 2/3rd block group to 16 block groups.
141 ext4_online_resize $(c2b 24576) $(c2b 524288)
142 ## Extending a 2/3rd block group to 160 block groups.
143 ext4_online_resize $(c2b 24576) $(c2b 5242880)
146 ## Convert to meta_bg.
149 ## Extending a 2/3rd block group to 1280 block groups.
150 ext4_online_resize $(c2b 24576) $(c2b 41943040)