generic/607: don't break on filesystems that don't support FSGETXATTR on dirs
[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 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 _supported_fs generic
36 _supported_os Linux
37 _require_scratch
38 _require_dax_iflag
39 _require_xfs_io_command "lsattr" "-v"
40
41 # Make sure we can call FSGETXATTR on a directory...
42 output="$($XFS_IO_PROG -c "lsattr -v" $TEST_DIR 2>&1)"
43 echo "$output" | grep -q "Inappropriate ioctl for device" && \
44         _notrun "$FSTYP: FSGETXATTR not supported on directories."
45
46 # If a/ is +x, check that a's new children
47 # inherit +x from a/.
48 test_xflag_inheritance1()
49 {
50         mkdir -p a
51         $XFS_IO_PROG -c "chattr +x" a
52         mkdir -p a/b/c
53         touch a/b/c/d
54
55         _check_xflag a 1
56         _check_xflag a/b 1
57         _check_xflag a/b/c 1
58         _check_xflag a/b/c/d 1
59
60         rm -rf a
61 }
62
63 # If a/ is +x and b/ is -x, check that:
64 # 1) b's new children inherit -x from b/.
65 # 2) a's new children(b/ is old) inherit +x from a/.
66 test_xflag_inheritance2()
67 {
68         mkdir -p a/b
69         $XFS_IO_PROG -c "chattr +x" a
70         mkdir -p a/b/c a/d
71         touch a/b/c/e a/d/f
72
73         _check_xflag a 1
74         _check_xflag a/b 0
75         _check_xflag a/b/c 0
76         _check_xflag a/b/c/e 0
77         _check_xflag a/d 1
78         _check_xflag a/d/f 1
79
80         rm -rf a
81 }
82
83 # If a/ is -x and b/ is +x, check that:
84 # 1) b's new children inherit +x from b/.
85 # 2) a's new children(b/ is old) inherit -x from a/.
86 test_xflag_inheritance3()
87 {
88         mkdir -p a/b
89         $XFS_IO_PROG -c "chattr +x" a/b
90         mkdir -p a/b/c a/d
91         touch a/b/c/e a/d/f
92
93         _check_xflag a 0
94         _check_xflag a/b 1
95         _check_xflag a/b/c 1
96         _check_xflag a/b/c/e 1
97         _check_xflag a/d 0
98         _check_xflag a/d/f 0
99
100         rm -rf a
101 }
102
103 # If a/, c/ are +x and b/ is -x, check that:
104 # 1) c's new children inherit +x from c/.
105 # 2) b's new children(c/ is old) inherit -x from b/.
106 test_xflag_inheritance4()
107 {
108         mkdir -p a
109         $XFS_IO_PROG -c "chattr +x" a
110         mkdir -p a/b/c
111         $XFS_IO_PROG -c "chattr -x" a/b
112         mkdir -p a/b/c/d a/b/e
113         touch a/b/c/d/f a/b/e/g
114
115         _check_xflag a 1
116         _check_xflag a/b 0
117         _check_xflag a/b/c 1
118         _check_xflag a/b/c/d 1
119         _check_xflag a/b/c/d/f 1
120         _check_xflag a/b/e 0
121         _check_xflag a/b/e/g 0
122
123         rm -rf a
124 }
125
126 # If a/ is +x and b/ is -x, check that:
127 # 1) new b/c and b/g inherit -x from b/ by cp.
128 # 2) new a/e inherits +x from a/ by cp.
129 # 3) new b/d preserves +x from a/ by mv.
130 # 4) new a/f and a/h preserve -x from b/ by mv.
131 test_xflag_inheritance5()
132 {
133         mkdir -p a b
134         $XFS_IO_PROG -c "chattr +x" a
135         mkdir -p a/c a/d b/e b/f
136         touch a/g b/h
137
138         cp -r a/c b/
139         cp -r b/e a/
140         cp -r a/g b/
141         mv a/d b/
142         mv b/f a/
143         mv b/h a/
144
145         _check_xflag b/c 0
146         _check_xflag b/d 1
147         _check_xflag a/e 1
148         _check_xflag a/f 0
149         _check_xflag b/g 0
150         _check_xflag a/h 0
151
152         rm -rf a b
153 }
154
155 do_xflag_tests()
156 {
157         local option=$1
158
159         _scratch_mount "$option"
160         cd $SCRATCH_MNT
161
162         for i in $(seq 1 5); do
163                 test_xflag_inheritance${i}
164         done
165
166         cd - > /dev/null
167         _scratch_unmount
168 }
169
170 do_tests()
171 {
172         _scratch_mkfs >> $seqres.full 2>&1
173
174         # Mount without dax option
175         export MOUNT_OPTIONS=""
176         do_xflag_tests
177
178         # Mount with 'dax' or 'dax=always' option if fs supports it.
179         _check_scratch_dax_mountopt "dax" && do_xflag_tests "-o dax"
180
181         # Mount with 'dax=inode' and 'dax=never' options if fs supports them.
182         if _check_scratch_dax_mountopt "dax=always"; then
183                 for dax_option in "dax=inode" "dax=never"; do
184                         do_xflag_tests "-o $dax_option"
185                 done
186         fi
187 }
188
189 do_tests
190
191 # success, all done
192 echo "Silence is golden"
193 status=0
194 exit