xfs/27[26]: force realtime on or off as needed
[xfstests-dev.git] / tests / xfs / 276
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. 276
6 #
7 # Check that getfsmap agrees with getbmap when realtime files are present.
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
28 # real QA test starts here
29 _supported_fs xfs
30 _require_realtime
31 _require_xfs_scratch_rmapbt
32 _require_xfs_io_command "fsmap"
33 _require_test_program "punch-alternating"
34
35 rm -f "$seqres.full"
36
37 echo "Format and mount"
38 _scratch_mkfs | _filter_mkfs 2> "$tmp.mkfs"
39 . $tmp.mkfs
40 cat "$tmp.mkfs" > $seqres.full
41 _scratch_mount
42
43 # Don't let the rt extent size perturb the fsmap output with unwritten
44 # extents in places we don't expect them
45 test $rtextsz -eq $dbsize || _notrun "Skipping test due to rtextsize > 1 fsb"
46
47 $XFS_IO_PROG -f -R -c 'pwrite -S 0x80 0 737373' $SCRATCH_MNT/urk >> $seqres.full
48 sync
49 $here/src/punch-alternating $SCRATCH_MNT/urk >> $seqres.full
50 ino=$(stat -c '%i' $SCRATCH_MNT/urk)
51
52 echo "Get fsmap" | tee -a $seqres.full
53 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT >> $seqres.full
54 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT | tr '[]()' '    ' > $TEST_DIR/fsmap
55
56 echo "Get bmap" | tee -a $seqres.full
57 $XFS_IO_PROG -c 'bmap -v' $SCRATCH_MNT/urk >> $seqres.full
58 $XFS_IO_PROG -c 'bmap -v' $SCRATCH_MNT/urk | grep '^[[:space:]]*[0-9]*:' | grep -v 'hole' | tr '[]()' '    ' > $TEST_DIR/bmap
59
60 echo "Check bmap and fsmap" | tee -a $seqres.full
61 cat $TEST_DIR/bmap | while read ext offrange colon blockrange ag agrange total crap; do
62         qstr="^[[:space:]]*[0-9]*:[[:space:]]*[0-9]*:[0-9]*[[:space:]]*${blockrange} :[[:space:]]*${ino}[[:space:]]*${offrange}[[:space:]]*${ag}[[:space:]]*${agrange}[[:space:]]*${total}$"
63         echo "${qstr}" >> $seqres.full
64         grep "${qstr}" $TEST_DIR/fsmap >> $seqres.full
65         found=$(grep -c "${qstr}" $TEST_DIR/fsmap)
66         test $found -eq 1 || echo "Unexpected output for offset ${offrange}."
67 done
68
69 echo "Check device field of FS metadata and realtime file"
70 data_dev=$(grep 'static fs metadata' $TEST_DIR/fsmap | head -n 1 | awk '{print $2}')
71 rt_dev=$(grep "${ino}[[:space:]]*[0-9]*\.\.[0-9]*[[:space:]]*[0-9]*$" $TEST_DIR/fsmap | head -n 1 | awk '{print $2}')
72 test "${data_dev}" != "${rt_dev}" || echo "data ${data_dev} realtime ${rt_dev}?"
73
74 # success, all done
75 status=0
76 exit