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 _begin_fstest auto quick ioctl resize
16 IMG_FILE=$SCRATCH_MNT/$seq.fs
17 IMG_MNT=$SCRATCH_MNT/$seq.mnt
19 ## Num clusters to blocks.
23 echo $(($clusters * $CLUSTER_SIZ / $BLK_SIZ))
28 ## sizes are in number of blocks.
29 local original_size=$1
31 local check_if_supported=${3:-0}
33 ## Start with a clean image file.
35 echo "+++ truncate image file to $final_size" | \
37 $XFS_IO_PROG -f -c "truncate $(($final_size * $BLK_SIZ))" ${IMG_FILE}
38 LOOP_DEVICE=`_create_loop_device $IMG_FILE`
40 echo "+++ create fs on image file $original_size" | \
43 ${MKFS_PROG} -t ${FSTYP} -F -O bigalloc,resize_inode -C $CLUSTER_SIZ \
44 -b $BLK_SIZ ${LOOP_DEVICE} $original_size >> \
45 $seqres.full 2>&1 || _fail "mkfs failed"
47 echo "+++ mount image file" | tee -a $seqres.full
48 $MOUNT_PROG -t ${FSTYP} ${LOOP_DEVICE} ${IMG_MNT} > \
49 /dev/null 2>&1 || _fail "mount failed"
51 echo "+++ resize fs to $final_size" | tee -a $seqres.full
53 $RESIZE2FS_PROG -f ${LOOP_DEVICE} $final_size >$tmp.resize2fs 2>&1
55 if [ $check_if_supported -eq 1 ]; then
56 grep -iq "operation not supported" $tmp.resize2fs \
57 && _notrun "online resizing not supported with bigalloc"
61 cat $tmp.resize2fs >> $seqres.full
62 echo "+++ umount fs" | tee -a $seqres.full
63 $UMOUNT_PROG ${IMG_MNT}
65 echo "+++ check fs" | tee -a $seqres.full
66 _check_generic_filesystem $LOOP_DEVICE >> $seqres.full 2>&1 || \
67 _fail "fsck should not fail"
68 _destroy_loop_device $LOOP_DEVICE && LOOP_DEVICE=
71 # Override the default cleanup function.
75 [ -n "$LOOP_DEVICE" ] && _destroy_loop_device $LOOP_DEVICE > /dev/null 2>&1
77 $UMOUNT_PROG ${IMG_MNT} > /dev/null 2>&1
78 rm -f ${IMG_FILE} > /dev/null 2>&1
81 # get standard environment and checks
83 # real QA test starts here
88 # We use resize_inode to make sure that block group descriptor table
90 _require_scratch_ext4_feature "bigalloc,resize_inode"
91 _require_command "$RESIZE2FS_PROG" resize2fs
93 _scratch_mkfs >>$seqres.full 2>&1
96 mkdir -p $IMG_MNT || _fail "cannot create loopback mount point"
98 # Check if online resizing with bigalloc is supported by the kernel
99 ext4_online_resize 4096 8192 1
101 ## We perform resizing to various multiples of block group sizes to
102 ## ensure that we cover maximum edge cases in the kernel code.
103 for CLUSTER_SIZ in 4096 16384 65536; do
104 echo "++ set cluster size to $CLUSTER_SIZ" | tee -a $seqres.full
107 ## Extend last group tests
110 ## Extending a 1/2 block group to a 2/3 block group.
111 ext4_online_resize $(c2b 16384) $(c2b 24576)
112 ## Extending a 2/3rd block group to one cluster less than a
114 ext4_online_resize $(c2b 24576) $(c2b 32767)
115 ## Extending a 2/3rd block group to a full block group.
116 ext4_online_resize $(c2b 24576) $(c2b 32768)
119 ## Extend last group and add more block groups.
122 ## Extending a 2/3rd block group to 2 block groups.
123 ext4_online_resize $(c2b 24576) $(c2b 65536)
124 ## Extending a 2/3rd block group to 15 block groups and one
126 ext4_online_resize $(c2b 24576) $(c2b 491521)
127 ## Extending a 2/3rd block group to 15 and a half block groups.
128 ext4_online_resize $(c2b 24576) $(c2b 507904)
129 ## Extending a 2/3rd block group to 16 block groups.
130 ext4_online_resize $(c2b 24576) $(c2b 524288)
131 ## Extending a 2/3rd block group to 160 block groups.
132 ext4_online_resize $(c2b 24576) $(c2b 5242880)
135 ## Convert to meta_bg.
138 ## Extending a 2/3rd block group to 1280 block groups.
139 ext4_online_resize $(c2b 24576) $(c2b 41943040)