xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 274
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. 274
6 #
7 # Check that getfsmap agrees with getbmap for reflinked files.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick rmap fsmap
11
12 # Override the default cleanup function.
13 _cleanup()
14 {
15         cd /
16         rm -rf "$tmp".* $TEST_DIR/fsmap $TEST_DIR/bmap
17 }
18
19 # Import common functions.
20 . ./common/filter
21 . ./common/reflink
22
23 # real QA test starts here
24 _supported_fs xfs
25 _require_scratch_reflink
26 _require_xfs_scratch_rmapbt
27 _require_xfs_io_command "fsmap"
28 _require_test_program "punch-alternating"
29
30 rm -f "$seqres.full"
31
32 echo "Format and mount"
33 _scratch_mkfs > "$seqres.full" 2>&1
34 _scratch_mount
35
36 _pwrite_byte 0x80 0 737373 $SCRATCH_MNT/f1 >> $seqres.full
37 sync
38 $here/src/punch-alternating $SCRATCH_MNT/f1 >> $seqres.full
39 _cp_reflink $SCRATCH_MNT/f1 $SCRATCH_MNT/f2
40 ino=$(stat -c '%i' $SCRATCH_MNT/f1)
41
42 echo "Get fsmap" | tee -a $seqres.full
43 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT >> $seqres.full
44 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT | tr '[]()' '    ' > $TEST_DIR/fsmap
45
46 echo "Get f1 bmap" | tee -a $seqres.full
47 $XFS_IO_PROG -c 'bmap -v' $SCRATCH_MNT/f1 >> $seqres.full
48 $XFS_IO_PROG -c 'bmap -v' $SCRATCH_MNT/f1 | grep '^[[:space:]]*[0-9]*:' | grep -v 'hole' | tr '[]()' '    ' > $TEST_DIR/bmap
49
50 echo "Check f1 bmap and fsmap" | tee -a $seqres.full
51 cat $TEST_DIR/bmap | while read ext offrange colon blockrange ag agrange total crap; do
52         qstr="^[[:space:]]*[0-9]*:[[:space:]]*[0-9]*:[0-9]*[[:space:]]*${blockrange} :[[:space:]]*${ino}[[:space:]]*${offrange}[[:space:]]*${ag}[[:space:]]*${agrange}[[:space:]]*${total} 0100000$"
53         echo "${qstr}" >> $seqres.full
54         grep "${qstr}" $TEST_DIR/fsmap >> $seqres.full
55         found=$(grep -c "${qstr}" $TEST_DIR/fsmap)
56         test $found -eq 1 || echo "Unexpected output for offset ${offrange}."
57 done
58
59 echo "Get f2 bmap" | tee -a $seqres.full
60 $XFS_IO_PROG -c 'bmap -v' $SCRATCH_MNT/f2 >> $seqres.full
61 $XFS_IO_PROG -c 'bmap -v' $SCRATCH_MNT/f2 | grep '^[[:space:]]*[0-9]*:' | grep -v 'hole' | tr '[]()' '    ' > $TEST_DIR/bmap
62
63 echo "Check f2 bmap and fsmap" | tee -a $seqres.full
64 cat $TEST_DIR/bmap | while read ext offrange colon blockrange ag agrange total crap; do
65         qstr="^[[:space:]]*[0-9]*:[[:space:]]*[0-9]*:[0-9]*[[:space:]]*${blockrange} :[[:space:]]*${ino}[[:space:]]*${offrange}[[:space:]]*${ag}[[:space:]]*${agrange}[[:space:]]*${total} 0100000$"
66         echo "${qstr}" >> $seqres.full
67         grep "${qstr}" $TEST_DIR/fsmap >> $seqres.full
68         found=$(grep -c "${qstr}" $TEST_DIR/fsmap)
69         test $found -eq 1 || echo "Unexpected output for offset ${offrange}."
70 done
71
72 # success, all done
73 status=0
74 exit