common/rc: add _scratch_{u}mount_idmapped() helpers
[xfstests-dev.git] / tests / generic / 519
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 519
6 #
7 # Verify if there's physical address overlap returned by FIBMAP, cover:
8 # 79b3dbe4adb3 fs: fix iomap_bmap position calculation
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33 _supported_fs generic
34 _require_scratch
35 _require_fibmap
36 _require_filefrag_options "es"
37
38 testfile="$SCRATCH_MNT/$seq-testfile"
39
40 # Use filefrag -B option to force the use of the older FIBMAP ioctl instead of
41 # the FIEMAP ioctl. Then verify if there's map overlap.
42 verify_filefrag()
43 {
44         # record details in .full file
45         ${FILEFRAG_PROG} -Bes -v $testfile >> $seqres.full
46
47         # Due to physical things can't be golden image, so only output logical
48         # information at here
49         ${FILEFRAG_PROG} -Be $testfile | _filter_filefrag | \
50                 cut -d# -f1-2 > $tmp.filefrag
51
52         # Verify there's no physical address overlay
53         awk '
54                 BEGIN {i=0}
55                 {
56                         # create a lines array of the form begin#end offsets
57                         split($0,res,"#")
58                         begin=res[1]
59                         end=begin+res[2]
60                         lines[i++]=begin"#"end
61                 }
62                 END {
63                         for (i in lines) {
64                                 for (j in lines) {
65                                         # Dont check i-th line against itself
66                                         if (i == j)
67                                                 continue
68
69                                         split(lines[i],i_line,"#")
70                                         split(lines[j],j_line,"#")
71                                         v1=i_line[1]
72                                         v2=i_line[2]
73                                         e1=j_line[1]
74                                         e2=j_line[2]
75                                         # Verify there is not:
76                                         #       [ e1 ... e2 ]
77                                         #             [ v1 ... v2 ]
78                                         # Or:
79                                         #       [ e1 ... e2 ]
80                                         # [ v1 ... v2 ]
81                                         if (! (v1 >= e2 || v2 <= e1))
82                                                 print "find physical addr overlap " lines[i] " vs " lines[j]
83                                 }
84                         }
85                 }
86         ' $tmp.filefrag
87 }
88
89 _scratch_mkfs > $seqres.full 2>&1
90 _scratch_mount
91
92 # Test
93 echo "== FIBMAP on empty file =="
94 $XFS_IO_PROG -f -c "truncate 0" $testfile > /dev/null
95 verify_filefrag
96
97 echo "== FIBMAP on sparse file =="
98 $XFS_IO_PROG -f -t -c "pwrite -S 0xaa 0 1m" \
99              -c "pwrite -S 0xaa 2m 1m" \
100              -c "pwrite -S 0xaa 4m 1m" \
101              $testfile > /dev/null
102 verify_filefrag
103
104 # success, all done
105 status=0
106 exit