2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Check that getfsmap agrees with getbmap for reflinked files.
10 _begin_fstest auto quick rmap fsmap
12 # Override the default cleanup function.
16 rm -rf "$tmp".* $TEST_DIR/fsmap $TEST_DIR/bmap
19 # Import common functions.
23 # real QA test starts here
25 _require_scratch_reflink
26 _require_xfs_scratch_rmapbt
27 _require_xfs_io_command "fsmap"
28 _require_test_program "punch-alternating"
32 echo "Format and mount"
33 _scratch_mkfs > "$seqres.full" 2>&1
36 _pwrite_byte 0x80 0 737373 $SCRATCH_MNT/f1 >> $seqres.full
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)
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
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
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}."
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
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}."