ext4/027: Correct the right code of block and inode bitmap
[xfstests-dev.git] / tests / ext4 / 032
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Google, Inc.  All Rights Reserved.
4 #
5 # FS QA Test ext4/032
6 #
7 # Ext4 online resize tests of small and crucial resizes with bigalloc
8 # feature.
9 #
10 . ./common/preamble
11 _begin_fstest auto quick ioctl resize
12
13 BLK_SIZ=4096
14 CLUSTER_SIZ=4096
15
16 IMG_FILE=$SCRATCH_MNT/$seq.fs
17 IMG_MNT=$SCRATCH_MNT/$seq.mnt
18
19 ## Num clusters to blocks.
20 c2b()
21 {
22         local clusters=$1
23         echo $(($clusters * $CLUSTER_SIZ / $BLK_SIZ))
24 }
25
26 ext4_online_resize()
27 {
28         ## sizes are in number of blocks.
29         local original_size=$1
30         local final_size=$2
31         local check_if_supported=${3:-0}
32
33         ## Start with a clean image file.
34         echo "" > ${IMG_FILE}
35         echo "+++ truncate image file to $final_size" | \
36                 tee -a $seqres.full
37         $XFS_IO_PROG -f -c "truncate $(($final_size * $BLK_SIZ))" ${IMG_FILE}
38         LOOP_DEVICE=`_create_loop_device $IMG_FILE`
39
40         echo "+++ create fs on image file $original_size" | \
41                 tee -a $seqres.full
42
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"
46
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"
50
51         echo "+++ resize fs to $final_size" | tee -a $seqres.full
52
53         $RESIZE2FS_PROG -f ${LOOP_DEVICE} $final_size >$tmp.resize2fs 2>&1
54         if [ $? -ne 0 ]; then
55                 if [ $check_if_supported -eq 1 ]; then
56                         grep -iq "operation not supported" $tmp.resize2fs \
57                                 && _notrun "online resizing not supported with bigalloc"
58                 fi
59                 _fail "resize failed"
60         fi
61         cat $tmp.resize2fs >> $seqres.full
62         echo "+++ umount fs" | tee -a $seqres.full
63         $UMOUNT_PROG ${IMG_MNT}
64
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=
69 }
70
71 # Override the default cleanup function.
72 _cleanup()
73 {
74         cd /
75         [ -n "$LOOP_DEVICE" ] && _destroy_loop_device $LOOP_DEVICE > /dev/null 2>&1
76         rm -f $tmp.*
77         $UMOUNT_PROG ${IMG_MNT} > /dev/null 2>&1
78         rm -f ${IMG_FILE} > /dev/null 2>&1
79 }
80
81 # get standard environment and checks
82
83 # real QA test starts here
84 _supported_fs ext4
85
86 _require_loop
87 _require_scratch
88 # We use resize_inode to make sure that block group descriptor table
89 # can be extended.
90 _require_scratch_ext4_feature "bigalloc,resize_inode"
91 _require_command "$RESIZE2FS_PROG" resize2fs
92
93 _scratch_mkfs >>$seqres.full 2>&1
94 _scratch_mount
95
96 mkdir -p $IMG_MNT || _fail "cannot create loopback mount point"
97
98 # Check if online resizing with bigalloc is supported by the kernel
99 ext4_online_resize 4096 8192 1
100
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
105
106         ##
107         ## Extend last group tests
108         ##
109
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
113         ## full block group.
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)
117
118         ##
119         ## Extend last group and add more block groups.
120         ##
121
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
125         ## cluster.
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)
133
134         ##
135         ## Convert to meta_bg.
136         ##
137
138         ## Extending a 2/3rd block group to 1280 block groups.
139         ext4_online_resize $(c2b 24576) $(c2b 41943040)
140 done
141
142 status=0
143 exit