4 # Test s_inodes_count overflow for huge filesystems. This bug was fixed
5 # by commit "ext4: Forbid overflowing inode count when resizing".
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2018 Jan Kara, SUSE. All Rights Reserved.
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #-----------------------------------------------------------------------
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
36 umount $SCRATCH_MNT >/dev/null 2>&1
42 # get standard environment, filters and checks
47 # remove previous $seqres.full before test
50 # real QA test starts here
53 _require_scratch_nocheck
56 _require_command "$RESIZE2FS_PROG" resize2fs
58 # Figure out whether device is large enough
59 devsize=$(blockdev --getsize64 $SCRATCH_DEV)
60 if [ $devsize -lt 4294967296 ]; then
61 _notrun "Too small scratch device, need at least 4G"
64 # Figure out block size
65 echo "Figure out block size"
66 _scratch_mkfs >/dev/null 2>&1
67 _scratch_mount >> $seqres.full
68 blksz="$(_get_block_size $SCRATCH_MNT)"
71 inodes_per_group=$((blksz*8))
72 group_blocks=$((blksz*8))
74 # Number of groups to overflow s_inodes_count
75 limit_groups=$(((1<<32)/inodes_per_group))
77 # Create device huge enough so that overflowing inode count is possible.
78 # Set chunk size to 16 sectors. Group descriptors with META_BG feature
79 # are rather sparse and that leads to huge overallocation especially with
81 echo "Format huge device"
82 _dmhugedisk_init $(((limit_groups + 16)*group_blocks*(blksz/512))) 16
85 group_count=$((limit_groups - 16))
86 _mkfs_dev -N $((group_count*inodes_per_group)) -b $blksz \
87 $DMHUGEDISK_DEV $((group_count*group_blocks))
89 _mount $DMHUGEDISK_DEV $SCRATCH_MNT
91 echo "Initial fs dump" >> $seqres.full
92 $DUMPE2FS_PROG -h $DMHUGEDISK_DEV >> $seqres.full 2>&1
94 # This should fail, s_inodes_count would just overflow!
95 echo "Resizing to inode limit + 1..."
96 $RESIZE2FS_PROG $DMHUGEDISK_DEV $((limit_groups*group_blocks)) >> $seqres.full 2>&1
98 echo "Resizing succeeded but it should fail!"
102 # This should succeed, we are maxing out inodes
103 echo "Resizing to max group count..."
104 $RESIZE2FS_PROG $DMHUGEDISK_DEV $(((limit_groups-1)*group_blocks)) >> $seqres.full 2>&1
105 if [ $? -ne 0 ]; then
106 echo "Resizing failed!"
110 echo "Fs dump after resize" >> $seqres.full
111 $DUMPE2FS_PROG -h $DMHUGEDISK_DEV >> $seqres.full 2>&1
113 # This should fail, s_inodes_count would overflow by quite a bit!
114 echo "Resizing to device size..."
115 $RESIZE2FS_PROG $DMHUGEDISK_DEV >> $seqres.full 2>&1
116 if [ $? -eq 0 ]; then
117 echo "Resizing succeeded but it should fail!"