fstests: check for filesystem FS_IOC_FSSETXATTR support
[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 seq=`basename "$0"`
10 seqres="$RESULT_DIR/$seq"
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -rf "$tmp".* $TEST_DIR/fsmap $TEST_DIR/bmap
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/reflink
28
29 # real QA test starts here
30 _supported_os Linux
31 _supported_fs xfs
32 _require_scratch_reflink
33 _require_xfs_scratch_rmapbt
34 _require_xfs_io_command "fsmap"
35 _require_test_program "punch-alternating"
36
37 rm -f "$seqres.full"
38
39 echo "Format and mount"
40 _scratch_mkfs > "$seqres.full" 2>&1
41 _scratch_mount
42
43 _pwrite_byte 0x80 0 737373 $SCRATCH_MNT/f1 >> $seqres.full
44 sync
45 ./src/punch-alternating $SCRATCH_MNT/f1 >> $seqres.full
46 _cp_reflink $SCRATCH_MNT/f1 $SCRATCH_MNT/f2
47 ino=$(stat -c '%i' $SCRATCH_MNT/f1)
48
49 echo "Get fsmap" | tee -a $seqres.full
50 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT >> $seqres.full
51 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT | tr '[]()' '    ' > $TEST_DIR/fsmap
52
53 echo "Get f1 bmap" | tee -a $seqres.full
54 $XFS_IO_PROG -c 'bmap -v' $SCRATCH_MNT/f1 >> $seqres.full
55 $XFS_IO_PROG -c 'bmap -v' $SCRATCH_MNT/f1 | grep '^[[:space:]]*[0-9]*:' | grep -v 'hole' | tr '[]()' '    ' > $TEST_DIR/bmap
56
57 echo "Check f1 bmap and fsmap" | tee -a $seqres.full
58 cat $TEST_DIR/bmap | while read ext offrange colon blockrange ag agrange total crap; do
59         qstr="^[[:space:]]*[0-9]*:[[:space:]]*[0-9]*:[0-9]*[[:space:]]*${blockrange} :[[:space:]]*${ino}[[:space:]]*${offrange}[[:space:]]*${ag}[[:space:]]*${agrange}[[:space:]]*${total} 0100000$"
60         echo "${qstr}" >> $seqres.full
61         grep "${qstr}" $TEST_DIR/fsmap >> $seqres.full
62         found=$(grep -c "${qstr}" $TEST_DIR/fsmap)
63         test $found -eq 1 || echo "Unexpected output for offset ${offrange}."
64 done
65
66 echo "Get f2 bmap" | tee -a $seqres.full
67 $XFS_IO_PROG -c 'bmap -v' $SCRATCH_MNT/f2 >> $seqres.full
68 $XFS_IO_PROG -c 'bmap -v' $SCRATCH_MNT/f2 | grep '^[[:space:]]*[0-9]*:' | grep -v 'hole' | tr '[]()' '    ' > $TEST_DIR/bmap
69
70 echo "Check f2 bmap and fsmap" | tee -a $seqres.full
71 cat $TEST_DIR/bmap | while read ext offrange colon blockrange ag agrange total crap; do
72         qstr="^[[:space:]]*[0-9]*:[[:space:]]*[0-9]*:[0-9]*[[:space:]]*${blockrange} :[[:space:]]*${ino}[[:space:]]*${offrange}[[:space:]]*${ag}[[:space:]]*${agrange}[[:space:]]*${total} 0100000$"
73         echo "${qstr}" >> $seqres.full
74         grep "${qstr}" $TEST_DIR/fsmap >> $seqres.full
75         found=$(grep -c "${qstr}" $TEST_DIR/fsmap)
76         test $found -eq 1 || echo "Unexpected output for offset ${offrange}."
77 done
78
79 # success, all done
80 status=0
81 exit