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