common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / tests / xfs / 310
1 #! /bin/bash
2 # FS QA Test No. 310
3 #
4 # Create a file with more than 2^21 blocks (the max length of a bmbt record).
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22
23 seq=`basename $0`
24 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1    # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 _cleanup()
33 {
34         cd /
35         umount $SCRATCH_MNT > /dev/null 2>&1
36         _dmhugedisk_cleanup
37         rm -rf $tmp.*
38         _scratch_mkfs >/dev/null 2>&1
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44 . ./common/dmhugedisk
45
46 # real QA test starts here
47 _supported_os Linux
48 _supported_fs xfs
49 _require_scratch
50 _require_xfs_scratch_rmapbt
51 _require_xfs_io_command "falloc"
52
53 rm -f $seqres.full
54
55 # Figure out block size
56 echo "Figure out block size"
57 _scratch_mkfs >/dev/null 2>&1
58 _scratch_mount >> $seqres.full
59
60 testdir=$SCRATCH_MNT/test-$seq
61 blksz="$(_get_block_size $SCRATCH_MNT)"
62
63 umount $SCRATCH_MNT
64
65 echo "Format huge device"
66 nr_blks=2100000 # 2^21 plus a little more
67 sectors=$(( (nr_blks * 3) * blksz / 512 )) # each AG must have > 2^21 blocks
68 _dmhugedisk_init $sectors
69 _mkfs_dev -d agcount=2 $DMHUGEDISK_DEV
70 _mount $DMHUGEDISK_DEV $SCRATCH_MNT
71 xfs_info $SCRATCH_MNT >> $seqres.full
72
73 echo "Create the original file blocks"
74 mkdir $testdir
75 blksz="$(_get_block_size $testdir)"
76 $XFS_IO_PROG -f -c "falloc 0 $((nr_blks * blksz))" $testdir/file1 >> $seqres.full
77
78 # make sure the allocator didn't allocate more than the needed two extents
79 echo "Check extent count"
80 xfs_bmap -l -p -v $testdir/file1 | grep '^[[:space:]]*2:' -q && xfs_bmap -l -p -v $testdir/file1
81 inum=$(stat -c '%i' $testdir/file1)
82 umount $SCRATCH_MNT
83
84 echo "Check bmap count"
85 nr_bmaps=$(xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV | grep 'data offset' | wc -l)
86 test $nr_bmaps -gt 1 || xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
87 #xfs_db -c "agf 0" -c p -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
88
89 echo "Check rmap count"
90 nr_rmaps=$(xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0" | wc -l)
91 test $nr_rmaps -eq 1 || xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0"
92
93 echo "Check and fake-repair huge filesystem" | tee -a $seqres.full
94 $XFS_DB_PROG -c 'check' $DMHUGEDISK_DEV
95 $XFS_REPAIR_PROG -n $DMHUGEDISK_DEV >> $seqres.full 2>&1
96 test $? -eq 0 || echo "xfs_repair -n failed, see $seqres.full"
97
98 echo "Real repair huge filesystem" | tee -a $seqres.full
99 $XFS_REPAIR_PROG $DMHUGEDISK_DEV >> $seqres.full 2>&1
100 test $? -eq 0 || echo "xfs_repair failed, see $seqres.full"
101
102 echo "Check bmap count again"
103 nr_bmaps=$(xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV | grep 'data offset' | wc -l)
104 test $nr_bmaps -gt 1 || xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
105
106 echo "Check rmap count again"
107 nr_rmaps=$(xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0" | wc -l)
108 test $nr_rmaps -eq 1 || xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0"
109
110 echo "Check and fake-repair huge filesystem again" | tee -a $seqres.full
111 $XFS_DB_PROG -c 'check' $DMHUGEDISK_DEV
112 $XFS_REPAIR_PROG -n $DMHUGEDISK_DEV >> $seqres.full 2>&1
113 _dmhugedisk_cleanup
114
115 echo "Done"
116
117 # success, all done
118 status=0
119 exit