2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Jan Kara, SUSE. All Rights Reserved.
7 # Test s_inodes_count overflow for huge filesystems. This bug was fixed
8 # by commit "ext4: Forbid overflowing inode count when resizing".
11 _begin_fstest auto ioctl resize
13 # Override the default cleanup function.
16 umount $SCRATCH_MNT >/dev/null 2>&1
22 # Import common functions.
26 # real QA test starts here
28 _require_scratch_nocheck
31 _require_command "$RESIZE2FS_PROG" resize2fs
33 # Figure out whether device is large enough
34 devsize=$(blockdev --getsize64 $SCRATCH_DEV)
35 if [ $devsize -lt 4294967296 ]; then
36 _notrun "Too small scratch device, need at least 4G"
39 # Figure out block size
40 echo "Figure out block size"
41 _scratch_mkfs >/dev/null 2>&1
42 _scratch_mount >> $seqres.full
43 blksz="$(_get_block_size $SCRATCH_MNT)"
46 inodes_per_group=$((blksz*8))
47 group_blocks=$((blksz*8))
49 # Number of groups to overflow s_inodes_count
50 limit_groups=$(((1<<32)/inodes_per_group))
52 # Create device huge enough so that overflowing inode count is possible.
53 # Set chunk size to 16 sectors. Group descriptors with META_BG feature
54 # are rather sparse and that leads to huge overallocation especially with
56 echo "Format huge device"
57 _dmhugedisk_init $(((limit_groups + 16)*group_blocks*(blksz/512))) 16
60 group_count=$((limit_groups - 16))
61 _mkfs_dev -N $((group_count*inodes_per_group)) -b $blksz \
62 $DMHUGEDISK_DEV $((group_count*group_blocks))
64 _mount $DMHUGEDISK_DEV $SCRATCH_MNT
66 echo "Initial fs dump" >> $seqres.full
67 $DUMPE2FS_PROG -h $DMHUGEDISK_DEV >> $seqres.full 2>&1
69 # This should fail, s_inodes_count would just overflow!
70 echo "Resizing to inode limit + 1..."
71 $RESIZE2FS_PROG $DMHUGEDISK_DEV $((limit_groups*group_blocks)) >> $seqres.full 2>&1
73 echo "Resizing succeeded but it should fail!"
77 # This should succeed, we are maxing out inodes
78 echo "Resizing to max group count..."
79 $RESIZE2FS_PROG $DMHUGEDISK_DEV $(((limit_groups-1)*group_blocks)) >> $seqres.full 2>&1
81 echo "Resizing failed!"
85 echo "Fs dump after resize" >> $seqres.full
86 $DUMPE2FS_PROG -h $DMHUGEDISK_DEV >> $seqres.full 2>&1
88 # This should fail, s_inodes_count would overflow by quite a bit!
89 echo "Resizing to device size..."
90 $RESIZE2FS_PROG $DMHUGEDISK_DEV >> $seqres.full 2>&1
92 echo "Resizing succeeded but it should fail!"