generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 607
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Fujitsu.  All Rights Reserved.
4 #
5 # FS QA Test 607
6 #
7 # Verify the inheritance behavior of FS_XFLAG_DAX flag in various combinations.
8 # 1) New files and directories automatically inherit FS_XFLAG_DAX from their parent directory.
9 # 2) cp operation make files and directories inherit the FS_XFLAG_DAX from new parent directory.
10 # 3) mv operation make files and directories preserve the FS_XFLAG_DAX from old parent directory.
11 # In addition, setting/clearing FS_XFLAG_DAX flag is not impacted by dax mount options.
12
13 . ./common/preamble
14 _begin_fstest auto attr quick dax
15
16 # Import common functions.
17 . ./common/filter
18
19 _supported_fs generic
20 _require_scratch
21 _require_dax_iflag
22 _require_xfs_io_command "lsattr" "-v"
23
24 # Make sure we can call FSGETXATTR on a directory...
25 output="$($XFS_IO_PROG -c "lsattr -v" $TEST_DIR 2>&1)"
26 echo "$output" | grep -q "Inappropriate ioctl for device" && \
27         _notrun "$FSTYP: FSGETXATTR not supported on directories."
28
29 # If a/ is +x, check that a's new children
30 # inherit +x from a/.
31 test_xflag_inheritance1()
32 {
33         mkdir -p a
34         $XFS_IO_PROG -c "chattr +x" a
35         mkdir -p a/b/c
36         touch a/b/c/d
37
38         _check_xflag a 1
39         _check_xflag a/b 1
40         _check_xflag a/b/c 1
41         _check_xflag a/b/c/d 1
42
43         rm -rf a
44 }
45
46 # If a/ is +x and b/ is -x, check that:
47 # 1) b's new children inherit -x from b/.
48 # 2) a's new children(b/ is old) inherit +x from a/.
49 test_xflag_inheritance2()
50 {
51         mkdir -p a/b
52         $XFS_IO_PROG -c "chattr +x" a
53         mkdir -p a/b/c a/d
54         touch a/b/c/e a/d/f
55
56         _check_xflag a 1
57         _check_xflag a/b 0
58         _check_xflag a/b/c 0
59         _check_xflag a/b/c/e 0
60         _check_xflag a/d 1
61         _check_xflag a/d/f 1
62
63         rm -rf a
64 }
65
66 # If a/ is -x and b/ is +x, check that:
67 # 1) b's new children inherit +x from b/.
68 # 2) a's new children(b/ is old) inherit -x from a/.
69 test_xflag_inheritance3()
70 {
71         mkdir -p a/b
72         $XFS_IO_PROG -c "chattr +x" a/b
73         mkdir -p a/b/c a/d
74         touch a/b/c/e a/d/f
75
76         _check_xflag a 0
77         _check_xflag a/b 1
78         _check_xflag a/b/c 1
79         _check_xflag a/b/c/e 1
80         _check_xflag a/d 0
81         _check_xflag a/d/f 0
82
83         rm -rf a
84 }
85
86 # If a/, c/ are +x and b/ is -x, check that:
87 # 1) c's new children inherit +x from c/.
88 # 2) b's new children(c/ is old) inherit -x from b/.
89 test_xflag_inheritance4()
90 {
91         mkdir -p a
92         $XFS_IO_PROG -c "chattr +x" a
93         mkdir -p a/b/c
94         $XFS_IO_PROG -c "chattr -x" a/b
95         mkdir -p a/b/c/d a/b/e
96         touch a/b/c/d/f a/b/e/g
97
98         _check_xflag a 1
99         _check_xflag a/b 0
100         _check_xflag a/b/c 1
101         _check_xflag a/b/c/d 1
102         _check_xflag a/b/c/d/f 1
103         _check_xflag a/b/e 0
104         _check_xflag a/b/e/g 0
105
106         rm -rf a
107 }
108
109 # If a/ is +x and b/ is -x, check that:
110 # 1) new b/c and b/g inherit -x from b/ by cp.
111 # 2) new a/e inherits +x from a/ by cp.
112 # 3) new b/d preserves +x from a/ by mv.
113 # 4) new a/f and a/h preserve -x from b/ by mv.
114 test_xflag_inheritance5()
115 {
116         mkdir -p a b
117         $XFS_IO_PROG -c "chattr +x" a
118         mkdir -p a/c a/d b/e b/f
119         touch a/g b/h
120
121         cp -r a/c b/
122         cp -r b/e a/
123         cp -r a/g b/
124         mv a/d b/
125         mv b/f a/
126         mv b/h a/
127
128         _check_xflag b/c 0
129         _check_xflag b/d 1
130         _check_xflag a/e 1
131         _check_xflag a/f 0
132         _check_xflag b/g 0
133         _check_xflag a/h 0
134
135         rm -rf a b
136 }
137
138 do_xflag_tests()
139 {
140         local option=$1
141
142         _scratch_mount "$option"
143
144         # Make sure the root dir doesn't have FS_XFLAG_DAX set before we start.
145         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT &>> $seqres.full
146
147         cd $SCRATCH_MNT
148
149         for i in $(seq 1 5); do
150                 test_xflag_inheritance${i}
151         done
152
153         cd - > /dev/null
154         _scratch_unmount
155 }
156
157 do_tests()
158 {
159         _scratch_mkfs >> $seqres.full 2>&1
160
161         # Mount without dax option
162         export MOUNT_OPTIONS=""
163         do_xflag_tests
164
165         # Mount with 'dax' or 'dax=always' option if fs supports it.
166         _check_scratch_dax_mountopt "dax" && do_xflag_tests "-o dax"
167
168         # Mount with 'dax=inode' and 'dax=never' options if fs supports them.
169         if _check_scratch_dax_mountopt "dax=always"; then
170                 for dax_option in "dax=inode" "dax=never"; do
171                         do_xflag_tests "-o $dax_option"
172                 done
173         fi
174 }
175
176 do_tests
177
178 # success, all done
179 echo "Silence is golden"
180 status=0
181 exit