2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Create a file with more than 2^21 blocks (the max length of a bmbt record).
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
21 umount $SCRATCH_MNT > /dev/null 2>&1
26 # get standard environment, filters and checks
31 # real QA test starts here
34 _require_xfs_scratch_rmapbt
35 _require_scratch_nocheck
36 _require_xfs_io_command "falloc"
40 # Figure out block size
41 echo "Figure out block size"
42 _scratch_mkfs >/dev/null 2>&1
43 _scratch_mount >> $seqres.full
45 testdir=$SCRATCH_MNT/test-$seq
46 blksz="$(_get_block_size $SCRATCH_MNT)"
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
58 echo "Create the original file blocks"
60 blksz="$(_get_block_size $testdir)"
61 $XFS_IO_PROG -f -c "falloc 0 $((nr_blks * blksz))" $testdir/file1 >> $seqres.full
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)
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
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"
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"
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"
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
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"
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