btrfs/012: check free size of scratch device before copying 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 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         umount $SCRATCH_MNT >/dev/null 2>&1
22         _dmhugedisk_cleanup
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/dmhugedisk
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # real QA test starts here
36 _supported_fs ext4
37 _require_scratch_nocheck
38 _require_dmhugedisk
39 _require_dumpe2fs
40 _require_command "$RESIZE2FS_PROG" resize2fs
41
42 # Figure out whether device is large enough
43 devsize=$(blockdev --getsize64 $SCRATCH_DEV)
44 if [ $devsize -lt 4294967296 ]; then
45         _notrun "Too small scratch device, need at least 4G"
46 fi
47
48 # Figure out block size
49 echo "Figure out block size"
50 _scratch_mkfs >/dev/null 2>&1
51 _scratch_mount >> $seqres.full
52 blksz="$(_get_block_size $SCRATCH_MNT)"
53 _scratch_unmount
54
55 inodes_per_group=$((blksz*8))
56 group_blocks=$((blksz*8))
57
58 # Number of groups to overflow s_inodes_count
59 limit_groups=$(((1<<32)/inodes_per_group))
60
61 # Create device huge enough so that overflowing inode count is possible.
62 # Set chunk size to 16 sectors. Group descriptors with META_BG feature
63 # are rather sparse and that leads to huge overallocation especially with
64 # 1k blocksize.
65 echo "Format huge device"
66 _dmhugedisk_init $(((limit_groups + 16)*group_blocks*(blksz/512))) 16
67
68 # Start with small fs
69 group_count=$((limit_groups - 16))
70 _mkfs_dev -N $((group_count*inodes_per_group)) -b $blksz \
71         $DMHUGEDISK_DEV $((group_count*group_blocks))
72
73 _mount $DMHUGEDISK_DEV $SCRATCH_MNT
74
75 echo "Initial fs dump" >> $seqres.full
76 $DUMPE2FS_PROG -h $DMHUGEDISK_DEV >> $seqres.full 2>&1
77
78 # This should fail, s_inodes_count would just overflow!
79 echo "Resizing to inode limit + 1..."
80 $RESIZE2FS_PROG $DMHUGEDISK_DEV $((limit_groups*group_blocks)) >> $seqres.full 2>&1
81 if [ $? -eq 0 ]; then
82         echo "Resizing succeeded but it should fail!"
83         exit
84 fi
85
86 # This should succeed, we are maxing out inodes
87 echo "Resizing to max group count..."
88 $RESIZE2FS_PROG $DMHUGEDISK_DEV $(((limit_groups-1)*group_blocks)) >> $seqres.full 2>&1
89 if [ $? -ne 0 ]; then
90         echo "Resizing failed!"
91         exit
92 fi
93
94 echo "Fs dump after resize" >> $seqres.full
95 $DUMPE2FS_PROG -h $DMHUGEDISK_DEV >> $seqres.full 2>&1
96
97 # This should fail, s_inodes_count would overflow by quite a bit!
98 echo "Resizing to device size..."
99 $RESIZE2FS_PROG $DMHUGEDISK_DEV >> $seqres.full 2>&1
100 if [ $? -eq 0 ]; then
101         echo "Resizing succeeded but it should fail!"
102         exit
103 fi
104
105 # success, all done
106 status=0
107 exit