generic: test deadlock on O_DIRECT|O_DSYNC
[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 _supported_os Linux
35 _require_scratch
36 _require_fibmap
37 _require_filefrag_options "es"
38
39 testfile="$SCRATCH_MNT/$seq-testfile"
40
41 # Use filefrag -B option to force the use of the older FIBMAP ioctl instead of
42 # the FIEMAP ioctl. Then verify if there's map overlap.
43 verify_filefrag()
44 {
45         # record details in .full file
46         ${FILEFRAG_PROG} -Bes -v $testfile >> $seqres.full
47
48         # Due to physical things can't be golden image, so only output logical
49         # information at here
50         ${FILEFRAG_PROG} -Be $testfile | _filter_filefrag | \
51                 cut -d# -f1-2 > $tmp.filefrag
52
53         # Verify there's no physical address overlay
54         awk '
55                 BEGIN {i=0}
56                 {
57                         # create a lines array of the form begin#end offsets
58                         split($0,res,"#")
59                         begin=res[1]
60                         end=begin+res[2]
61                         lines[i++]=begin"#"end
62                 }
63                 END {
64                         for (i in lines) {
65                                 for (j in lines) {
66                                         # Dont check i-th line against itself
67                                         if (i == j)
68                                                 continue
69
70                                         split(lines[i],i_line,"#")
71                                         split(lines[j],j_line,"#")
72                                         v1=i_line[1]
73                                         v2=i_line[2]
74                                         e1=j_line[1]
75                                         e2=j_line[2]
76                                         # Verify there is not:
77                                         #       [ e1 ... e2 ]
78                                         #             [ v1 ... v2 ]
79                                         # Or:
80                                         #       [ e1 ... e2 ]
81                                         # [ v1 ... v2 ]
82                                         if (! (v1 >= e2 || v2 <= e1))
83                                                 print "find physical addr overlap " lines[i] " vs " lines[j]
84                                 }
85                         }
86                 }
87         ' $tmp.filefrag
88 }
89
90 _scratch_mkfs > $seqres.full 2>&1
91 _scratch_mount
92
93 # Test
94 echo "== FIBMAP on empty file =="
95 $XFS_IO_PROG -f -c "truncate 0" $testfile > /dev/null
96 verify_filefrag
97
98 echo "== FIBMAP on sparse file =="
99 $XFS_IO_PROG -f -t -c "pwrite -S 0xaa 0 1m" \
100              -c "pwrite -S 0xaa 2m 1m" \
101              -c "pwrite -S 0xaa 4m 1m" \
102              $testfile > /dev/null
103 verify_filefrag
104
105 # success, all done
106 status=0
107 exit