generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
11 _begin_fstest auto quick
12
13 # Import common functions.
14 . ./common/filter
15
16 # real QA test starts here
17 _supported_fs generic
18 _require_scratch
19 _require_fibmap
20 _require_filefrag_options "es"
21
22 testfile="$SCRATCH_MNT/$seq-testfile"
23
24 # Use filefrag -B option to force the use of the older FIBMAP ioctl instead of
25 # the FIEMAP ioctl. Then verify if there's map overlap.
26 verify_filefrag()
27 {
28         # record details in .full file
29         ${FILEFRAG_PROG} -Bes -v $testfile >> $seqres.full
30
31         # Due to physical things can't be golden image, so only output logical
32         # information at here
33         ${FILEFRAG_PROG} -Be $testfile | _filter_filefrag | \
34                 cut -d# -f1-2 > $tmp.filefrag
35
36         # Verify there's no physical address overlay
37         awk '
38                 BEGIN {i=0}
39                 {
40                         # create a lines array of the form begin#end offsets
41                         split($0,res,"#")
42                         begin=res[1]
43                         end=begin+res[2]
44                         lines[i++]=begin"#"end
45                 }
46                 END {
47                         for (i in lines) {
48                                 for (j in lines) {
49                                         # Dont check i-th line against itself
50                                         if (i == j)
51                                                 continue
52
53                                         split(lines[i],i_line,"#")
54                                         split(lines[j],j_line,"#")
55                                         v1=i_line[1]
56                                         v2=i_line[2]
57                                         e1=j_line[1]
58                                         e2=j_line[2]
59                                         # Verify there is not:
60                                         #       [ e1 ... e2 ]
61                                         #             [ v1 ... v2 ]
62                                         # Or:
63                                         #       [ e1 ... e2 ]
64                                         # [ v1 ... v2 ]
65                                         if (! (v1 >= e2 || v2 <= e1))
66                                                 print "find physical addr overlap " lines[i] " vs " lines[j]
67                                 }
68                         }
69                 }
70         ' $tmp.filefrag
71 }
72
73 _scratch_mkfs > $seqres.full 2>&1
74 _scratch_mount
75
76 # Test
77 echo "== FIBMAP on empty file =="
78 $XFS_IO_PROG -f -c "truncate 0" $testfile > /dev/null
79 verify_filefrag
80
81 echo "== FIBMAP on sparse file =="
82 $XFS_IO_PROG -f -t -c "pwrite -S 0xaa 0 1m" \
83              -c "pwrite -S 0xaa 2m 1m" \
84              -c "pwrite -S 0xaa 4m 1m" \
85              $testfile > /dev/null
86 verify_filefrag
87
88 # success, all done
89 status=0
90 exit