generic: test deadlock on O_DIRECT|O_DSYNC
[xfstests-dev.git] / tests / generic / 062
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 062
6 #
7 # Exercises the getfattr/setfattr tools
8 # Derived from tests originally written by Andreas Gruenbacher for ext2
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
18 # get standard environment, filters and checks
19 . ./common/rc
20 . ./common/filter
21 . ./common/attr
22
23 _cleanup()
24 {
25         cd /
26         echo; echo "*** unmount"
27         _scratch_unmount 2>/dev/null
28         rm -f $tmp.*
29 }
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 getfattr()
33 {
34     _getfattr --absolute-names -dh $@ 2>&1 | _filter_scratch
35 }
36
37 setfattr()
38 {
39     $SETFATTR_PROG $@ 2>&1 | _filter_scratch
40 }
41
42 _create_test_bed()
43 {
44         echo "*** create test bed"
45         touch $SCRATCH_MNT/reg
46         mkdir -p $SCRATCH_MNT/dir
47         ln -s $SCRATCH_MNT/dir $SCRATCH_MNT/lnk
48         mkdir $SCRATCH_MNT/dev
49         mknod $SCRATCH_MNT/dev/b b 0 0
50         mknod $SCRATCH_MNT/dev/c c 1 3
51         mknod $SCRATCH_MNT/dev/p p
52         # sanity check
53         find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch | grep -v "lost+found"
54 }
55
56 # real QA test starts here
57 _supported_fs generic
58 _supported_os Linux
59
60 _require_scratch
61 _require_attrs
62 _require_symlinks
63 _require_mknod
64
65 rm -f $tmp.backup1 $tmp.backup2 $seqres.full
66
67 # real QA test starts here
68 _scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
69 _scratch_mount
70 _create_test_bed
71
72 # In kernels before 3.0, getxattr() fails with EPERM for an attribute which
73 # cannot exist.  Later kernels fail with ENODATA.  Accept both results.
74 invalid_attribute_filter() {
75         sed -e "s:\(No such attribute\|Operation not permitted\):No such attribute or operation not permitted:"
76 }
77
78 if [ "$USE_ATTR_SECURE" = yes ]; then
79     ATTR_MODES="user security trusted"
80     ATTR_FILTER="^(user|security|trusted)"
81 else
82     ATTR_MODES="user trusted"
83     ATTR_FILTER="^(user|trusted)"
84 fi
85 for nsp in $ATTR_MODES; do
86         for inode in reg dir lnk dev/b dev/c dev/p; do
87
88                 echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
89                 echo "*** set/get one initially empty attribute"
90     
91                 setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
92                 getfattr -m $nsp $SCRATCH_MNT/$inode
93
94                 echo "*** overwrite empty, set several new attributes"
95                 setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
96                 setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
97                 setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
98
99                 echo "*** fetch several attribute names and values (hex)"
100                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
101
102                 echo "*** fetch several attribute names and values (base64)"
103                 getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
104                 
105                 echo "*** shrink value of an existing attribute"
106                 setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
107                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
108
109                 echo "*** grow value of existing attribute"
110                 setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
111                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
112                 
113                 echo "*** set an empty value for second attribute"
114                 setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
115                 getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode 2>&1 | invalid_attribute_filter
116
117                 echo "*** overwrite empty value"
118                 setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
119                 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode 2>&1 | invalid_attribute_filter
120
121                 echo "*** remove attribute"
122                 setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
123                 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode 2>&1 | invalid_attribute_filter
124
125                 echo "*** final list (strings, type=$inode, nsp=$nsp)"
126                 getfattr -m $ATTR_FILTER -e hex $SCRATCH_MNT/$inode
127         
128         done
129 done
130
131
132 # Test the directory descent code
133
134 echo; echo
135
136 _extend_test_bed()
137 {
138         echo "*** extend test bed"
139         # must set some descents' attributes to be useful
140         mkdir -p $SCRATCH_MNT/here/up/ascend
141         mkdir -p $SCRATCH_MNT/descend/down/here
142         find $SCRATCH_MNT/descend | xargs setfattr -n user.x -v yz
143         find $SCRATCH_MNT/descend | xargs setfattr -n user.1 -v 23
144         find $SCRATCH_MNT/here | xargs setfattr -n trusted.a -v bc
145         find $SCRATCH_MNT/here | xargs setfattr -n trusted.9 -v 87
146         # whack a symlink in the middle, just to be difficult
147         ln -s $SCRATCH_MNT/here/up $SCRATCH_MNT/descend/and
148         # dump out our new starting point
149         find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch | grep -v "lost+found"
150 }
151
152 _extend_test_bed
153
154 echo
155 echo "*** directory descent with us following symlinks"
156 getfattr -h -L -R -m "$ATTR_FILTER" -e hex $SCRATCH_MNT | _sort_getfattr_output
157
158 echo
159 echo "*** directory descent without following symlinks"
160 getfattr -h -P -R -m "$ATTR_FILTER" -e hex $SCRATCH_MNT | _sort_getfattr_output
161
162
163 # Test the backup/restore code
164
165 echo; echo
166
167 _backup()
168 {
169         # Note: we don't filter scratch here since we need to restore too.  But
170         # we *do* sort the output by path, since it otherwise would depend on
171         # readdir order, which on some filesystems may change after re-creating
172         # the files.
173         _getfattr --absolute-names -dh -R -m $ATTR_FILTER $SCRATCH_MNT | _sort_getfattr_output >$1
174         echo BACKUP $1 >>$seqres.full
175         cat $1 >> $seqres.full
176         [ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
177 }
178
179 echo "*** backup everything"
180 _backup $tmp.backup1
181
182 echo "*** clear out the scratch device"
183 rm -rf $(find $SCRATCH_MNT/* | grep -v "lost+found")
184 echo "AFTER REMOVE" >>$seqres.full
185 getfattr -L -R -m '.' $SCRATCH_MNT >>$seqres.full
186
187 echo "*** reset test bed with no extended attributes"
188 _create_test_bed
189 _extend_test_bed
190
191 echo "*** restore everything"
192 setfattr -h --restore=$tmp.backup1
193 _backup $tmp.backup2
194
195 echo "AFTER RESTORE" >>$seqres.full
196 getfattr -L -R -m '.' $SCRATCH_MNT >>$seqres.full
197
198 echo "*** compare before and after backups"
199 diff $tmp.backup1 $tmp.backup2
200 if [ $? -ne 0 ]; then
201         echo "urk, failed - creating $seq.backup1 and $seq.backup2"
202         cp $tmp.backup1 $seq.backup1 && cp $tmp.backup2 $seq.backup2
203         status=1
204         exit
205 fi
206
207 # success, all done
208 status=0
209 exit