xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[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 . ./common/preamble
10 _begin_fstest auto clone rmap
11
12 # Override the default cleanup function.
13 _cleanup()
14 {
15         cd /
16         umount $SCRATCH_MNT > /dev/null 2>&1
17         _dmhugedisk_cleanup
18         rm -rf $tmp.*
19 }
20
21 # Import common functions.
22 . ./common/filter
23 . ./common/dmhugedisk
24
25 # real QA test starts here
26 _supported_fs xfs
27 _require_xfs_scratch_rmapbt
28 _require_scratch_nocheck
29 _require_xfs_io_command "falloc"
30
31 # Figure out block size
32 echo "Figure out block size"
33 _scratch_mkfs >/dev/null 2>&1
34 _scratch_mount >> $seqres.full
35
36 testdir=$SCRATCH_MNT/test-$seq
37 blksz="$(_get_block_size $SCRATCH_MNT)"
38
39 _scratch_unmount
40
41 echo "Format huge device"
42 nr_blks=2100000 # 2^21 plus a little more
43 sectors=$(( (nr_blks * 3) * blksz / 512 )) # each AG must have > 2^21 blocks
44 _dmhugedisk_init $sectors
45 _mkfs_dev -d agcount=2 $DMHUGEDISK_DEV
46 _mount $DMHUGEDISK_DEV $SCRATCH_MNT
47 $XFS_INFO_PROG $SCRATCH_MNT >> $seqres.full
48
49 echo "Create the original file blocks"
50 mkdir $testdir
51 blksz="$(_get_block_size $testdir)"
52 $XFS_IO_PROG -f -c "falloc 0 $((nr_blks * blksz))" $testdir/file1 >> $seqres.full
53
54 # make sure the allocator didn't allocate more than the needed two extents
55 echo "Check extent count"
56 xfs_bmap -l -p -v $testdir/file1 | grep '^[[:space:]]*2:' -q && xfs_bmap -l -p -v $testdir/file1
57 inum=$(stat -c '%i' $testdir/file1)
58 umount $SCRATCH_MNT
59
60 echo "Check bmap count"
61 nr_bmaps=$(xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV | grep 'data offset' | wc -l)
62 test $nr_bmaps -gt 1 || xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
63 #xfs_db -c "agf 0" -c p -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
64
65 echo "Check rmap count"
66 nr_rmaps=$(xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0" | wc -l)
67 test $nr_rmaps -eq 1 || xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0"
68
69 echo "Check and fake-repair huge filesystem" | tee -a $seqres.full
70 $XFS_DB_PROG -c 'check' $DMHUGEDISK_DEV
71 $XFS_REPAIR_PROG -n $DMHUGEDISK_DEV >> $seqres.full 2>&1
72 test $? -eq 0 || echo "xfs_repair -n failed, see $seqres.full"
73
74 echo "Real repair huge filesystem" | tee -a $seqres.full
75 $XFS_REPAIR_PROG $DMHUGEDISK_DEV >> $seqres.full 2>&1
76 test $? -eq 0 || echo "xfs_repair failed, see $seqres.full"
77
78 echo "Check bmap count again"
79 nr_bmaps=$(xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV | grep 'data offset' | wc -l)
80 test $nr_bmaps -gt 1 || xfs_db -c "inode $inum" -c "bmap" $DMHUGEDISK_DEV
81
82 echo "Check rmap count again"
83 nr_rmaps=$(xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0" | wc -l)
84 test $nr_rmaps -eq 1 || xfs_db -c 'agf 0' -c 'addr rmaproot' -c 'p' $DMHUGEDISK_DEV | grep ",$inum,[0-9]*,1,0,0"
85
86 echo "Check and fake-repair huge filesystem again" | tee -a $seqres.full
87 $XFS_DB_PROG -c 'check' $DMHUGEDISK_DEV
88 $XFS_REPAIR_PROG -n $DMHUGEDISK_DEV >> $seqres.full 2>&1
89
90 echo "Done"
91
92 # success, all done
93 status=0
94 exit