xfs: convert tests to SPDX license tags
[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_os Linux
33 _supported_fs xfs
34 _require_xfs_scratch_rmapbt
35 _require_scratch_nocheck
36 _require_xfs_io_command "falloc"
37
38 rm -f $seqres.full
39
40 # Figure out block size
41 echo "Figure out block size"
42 _scratch_mkfs >/dev/null 2>&1
43 _scratch_mount >> $seqres.full
44
45 testdir=$SCRATCH_MNT/test-$seq
46 blksz="$(_get_block_size $SCRATCH_MNT)"
47
48 _scratch_unmount
49
50 echo "Format huge device"
51 nr_blks=2100000 # 2^21 plus a little more
52 sectors=$(( (nr_blks * 3) * blksz / 512 )) # each AG must have > 2^21 blocks
53 _dmhugedisk_init $sectors
54 _mkfs_dev -d agcount=2 $DMHUGEDISK_DEV
55 _mount $DMHUGEDISK_DEV $SCRATCH_MNT
56 $XFS_INFO_PROG $SCRATCH_MNT >> $seqres.full
57
58 echo "Create the original file blocks"
59 mkdir $testdir
60 blksz="$(_get_block_size $testdir)"
61 $XFS_IO_PROG -f -c "falloc 0 $((nr_blks * blksz))" $testdir/file1 >> $seqres.full
62
63 # make sure the allocator didn't allocate more than the needed two extents
64 echo "Check extent count"
65 xfs_bmap -l -p -v $testdir/file1 | grep '^[[:space:]]*2:' -q && xfs_bmap -l -p -v $testdir/file1
66 inum=$(stat -c '%i' $testdir/file1)
67 umount $SCRATCH_MNT
68
69 echo "Check bmap count"
70 nr_bmaps=$(xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV | grep 'data offset' | wc -l)
71 test $nr_bmaps -gt 1 || xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
72 #xfs_db -c "agf 0" -c p -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
73
74 echo "Check rmap count"
75 nr_rmaps=$(xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0" | wc -l)
76 test $nr_rmaps -eq 1 || xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0"
77
78 echo "Check and fake-repair huge filesystem" | tee -a $seqres.full
79 $XFS_DB_PROG -c 'check' $DMHUGEDISK_DEV
80 $XFS_REPAIR_PROG -n $DMHUGEDISK_DEV >> $seqres.full 2>&1
81 test $? -eq 0 || echo "xfs_repair -n failed, see $seqres.full"
82
83 echo "Real repair huge filesystem" | tee -a $seqres.full
84 $XFS_REPAIR_PROG $DMHUGEDISK_DEV >> $seqres.full 2>&1
85 test $? -eq 0 || echo "xfs_repair failed, see $seqres.full"
86
87 echo "Check bmap count again"
88 nr_bmaps=$(xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV | grep 'data offset' | wc -l)
89 test $nr_bmaps -gt 1 || xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
90
91 echo "Check rmap count again"
92 nr_rmaps=$(xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0" | wc -l)
93 test $nr_rmaps -eq 1 || xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0"
94
95 echo "Check and fake-repair huge filesystem again" | tee -a $seqres.full
96 $XFS_DB_PROG -c 'check' $DMHUGEDISK_DEV
97 $XFS_REPAIR_PROG -n $DMHUGEDISK_DEV >> $seqres.full 2>&1
98
99 echo "Done"
100
101 # success, all done
102 status=0
103 exit