xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / xfs / 310
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 310
6 #
7 # Create a file with more than 2^21 blocks (the max length of a bmbt record).
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         umount $SCRATCH_MNT > /dev/null 2>&1
22         _dmhugedisk_cleanup
23         rm -rf $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/dmhugedisk
30
31 # real QA test starts here
32 _supported_fs xfs
33 _require_xfs_scratch_rmapbt
34 _require_scratch_nocheck
35 _require_xfs_io_command "falloc"
36
37 rm -f $seqres.full
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
44 testdir=$SCRATCH_MNT/test-$seq
45 blksz="$(_get_block_size $SCRATCH_MNT)"
46
47 _scratch_unmount
48
49 echo "Format huge device"
50 nr_blks=2100000 # 2^21 plus a little more
51 sectors=$(( (nr_blks * 3) * blksz / 512 )) # each AG must have > 2^21 blocks
52 _dmhugedisk_init $sectors
53 _mkfs_dev -d agcount=2 $DMHUGEDISK_DEV
54 _mount $DMHUGEDISK_DEV $SCRATCH_MNT
55 $XFS_INFO_PROG $SCRATCH_MNT >> $seqres.full
56
57 echo "Create the original file blocks"
58 mkdir $testdir
59 blksz="$(_get_block_size $testdir)"
60 $XFS_IO_PROG -f -c "falloc 0 $((nr_blks * blksz))" $testdir/file1 >> $seqres.full
61
62 # make sure the allocator didn't allocate more than the needed two extents
63 echo "Check extent count"
64 xfs_bmap -l -p -v $testdir/file1 | grep '^[[:space:]]*2:' -q && xfs_bmap -l -p -v $testdir/file1
65 inum=$(stat -c '%i' $testdir/file1)
66 umount $SCRATCH_MNT
67
68 echo "Check bmap count"
69 nr_bmaps=$(xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV | grep 'data offset' | wc -l)
70 test $nr_bmaps -gt 1 || xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
71 #xfs_db -c "agf 0" -c p -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
72
73 echo "Check rmap count"
74 nr_rmaps=$(xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0" | wc -l)
75 test $nr_rmaps -eq 1 || xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0"
76
77 echo "Check and fake-repair huge filesystem" | tee -a $seqres.full
78 $XFS_DB_PROG -c 'check' $DMHUGEDISK_DEV
79 $XFS_REPAIR_PROG -n $DMHUGEDISK_DEV >> $seqres.full 2>&1
80 test $? -eq 0 || echo "xfs_repair -n failed, see $seqres.full"
81
82 echo "Real repair huge filesystem" | tee -a $seqres.full
83 $XFS_REPAIR_PROG $DMHUGEDISK_DEV >> $seqres.full 2>&1
84 test $? -eq 0 || echo "xfs_repair failed, see $seqres.full"
85
86 echo "Check bmap count again"
87 nr_bmaps=$(xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV | grep 'data offset' | wc -l)
88 test $nr_bmaps -gt 1 || xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
89
90 echo "Check rmap count again"
91 nr_rmaps=$(xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0" | wc -l)
92 test $nr_rmaps -eq 1 || xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0"
93
94 echo "Check and fake-repair huge filesystem again" | tee -a $seqres.full
95 $XFS_DB_PROG -c 'check' $DMHUGEDISK_DEV
96 $XFS_REPAIR_PROG -n $DMHUGEDISK_DEV >> $seqres.full 2>&1
97
98 echo "Done"
99
100 # success, all done
101 status=0
102 exit