check: use generated group files
[xfstests-dev.git] / tests / ext4 / 033
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Jan Kara, SUSE.  All Rights Reserved.
4 #
5 # FS QA Test 033
6 #
7 # Test s_inodes_count overflow for huge filesystems. This bug was fixed
8 # by commit "ext4: Forbid overflowing inode count when resizing".
9 #
10 . ./common/preamble
11 _begin_fstest auto ioctl resize
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16         umount $SCRATCH_MNT >/dev/null 2>&1
17         _dmhugedisk_cleanup
18         cd /
19         rm -f $tmp.*
20 }
21
22 # Import common functions.
23 . ./common/filter
24 . ./common/dmhugedisk
25
26 # real QA test starts here
27 _supported_fs ext4
28 _require_scratch_nocheck
29 _require_dmhugedisk
30 _require_dumpe2fs
31 _require_command "$RESIZE2FS_PROG" resize2fs
32
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"
37 fi
38
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)"
44 _scratch_unmount
45
46 inodes_per_group=$((blksz*8))
47 group_blocks=$((blksz*8))
48
49 # Number of groups to overflow s_inodes_count
50 limit_groups=$(((1<<32)/inodes_per_group))
51
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
55 # 1k blocksize.
56 echo "Format huge device"
57 _dmhugedisk_init $(((limit_groups + 16)*group_blocks*(blksz/512))) 16
58
59 # Start with small fs
60 group_count=$((limit_groups - 16))
61 _mkfs_dev -N $((group_count*inodes_per_group)) -b $blksz \
62         $DMHUGEDISK_DEV $((group_count*group_blocks))
63
64 _mount $DMHUGEDISK_DEV $SCRATCH_MNT
65
66 echo "Initial fs dump" >> $seqres.full
67 $DUMPE2FS_PROG -h $DMHUGEDISK_DEV >> $seqres.full 2>&1
68
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
72 if [ $? -eq 0 ]; then
73         echo "Resizing succeeded but it should fail!"
74         exit
75 fi
76
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
80 if [ $? -ne 0 ]; then
81         echo "Resizing failed!"
82         exit
83 fi
84
85 echo "Fs dump after resize" >> $seqres.full
86 $DUMPE2FS_PROG -h $DMHUGEDISK_DEV >> $seqres.full 2>&1
87
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
91 if [ $? -eq 0 ]; then
92         echo "Resizing succeeded but it should fail!"
93         exit
94 fi
95
96 # success, all done
97 status=0
98 exit