xfstests: use a common _filter_test_dir function
[xfstests-dev.git] / 062
1 #! /bin/bash
2 # FS QA Test No. 062
3 #
4 # Exercises the getfattr/setfattr tools
5 # Derived from tests originally written by Andreas Gruenbacher for ext2
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25 # creator
26 owner=nathans@sgi.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38 . ./common.attr
39
40 _cleanup()
41 {
42         cd /
43         echo; echo "*** unmount"
44         umount $SCRATCH_MNT 2>/dev/null
45         rm -f $tmp.*
46 }
47 trap "_cleanup; exit \$status" 0 1 2 3 15
48
49 _linux_attr_calls()
50 {
51     echo "*** set/get one initially empty attribute"
52     setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
53     getfattr -m $nsp $SCRATCH_MNT/$inode
54
55     echo "*** overwrite empty, set several new attributes"
56     setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
57     setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
58     setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
59
60     echo "*** fetch several attribute names and values (hex)"
61     getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
62
63     echo "*** fetch several attribute names and values (base64)"
64     getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
65
66     echo "*** shrink value of an existing attribute"
67     setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
68     getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
69
70     echo "*** grow value of existing attribute"
71     setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
72     getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
73
74     echo "*** set an empty value for second attribute"
75     setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
76     getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode
77
78     echo "*** overwrite empty value"
79     setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
80     getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
81
82     echo "*** remove attribute"
83     setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
84     getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
85
86     echo "*** final list (strings, type=$inode, nsp=$nsp)"
87     getfattr -m '.' -e hex $SCRATCH_MNT/$inode
88 }
89
90 getfattr()
91 {
92     $GETFATTR_PROG --absolute-names -dh $@ 2>&1 | _filter_scratch
93 }
94
95 setfattr()
96 {
97     $SETFATTR_PROG $@ 2>&1 | _filter_scratch
98 }
99
100 _create_test_bed()
101 {
102         echo "*** create test bed"
103         touch $SCRATCH_MNT/reg
104         mkdir -p $SCRATCH_MNT/dir
105         ln -s $SCRATCH_MNT/dir $SCRATCH_MNT/lnk
106         mkdir $SCRATCH_MNT/dev
107         mknod $SCRATCH_MNT/dev/b b 0 0
108         mknod $SCRATCH_MNT/dev/c c 0 0
109         mknod $SCRATCH_MNT/dev/p p
110         # sanity check
111         find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
112 }
113
114 # real QA test starts here
115 _supported_fs xfs udf nfs
116 _supported_os Linux
117
118 _require_scratch
119 _require_attrs
120
121 rm -f $tmp.backup1 $tmp.backup2 $seq.full
122
123 # real QA test starts here
124 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
125 _scratch_mount || _fail "mount failed"
126 _create_test_bed
127
128 if [ "$USE_ATTR_SECURE" = yes ]; then
129     ATTR_MODES="user security trusted"
130 else
131     ATTR_MODES="user trusted"
132 fi
133 for nsp in $ATTR_MODES; do
134         for inode in reg dir lnk dev/b dev/c dev/p; do
135
136                 echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
137                 echo "*** set/get one initially empty attribute"
138     
139                 setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
140                 getfattr -m $nsp $SCRATCH_MNT/$inode
141
142                 echo "*** overwrite empty, set several new attributes"
143                 setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
144                 setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
145                 setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
146
147                 echo "*** fetch several attribute names and values (hex)"
148                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
149
150                 echo "*** fetch several attribute names and values (base64)"
151                 getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
152                 
153                 echo "*** shrink value of an existing attribute"
154                 setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
155                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
156
157                 echo "*** grow value of existing attribute"
158                 setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
159                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
160                 
161                 echo "*** set an empty value for second attribute"
162                 setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
163                 getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode
164
165                 echo "*** overwrite empty value"
166                 setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
167                 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
168
169                 echo "*** remove attribute"
170                 setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
171                 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
172
173                 echo "*** final list (strings, type=$inode, nsp=$nsp)"
174                 getfattr -m '.' -e hex $SCRATCH_MNT/$inode
175         
176         done
177 done
178
179
180
181 # Test the directory descent code
182
183 echo; echo
184
185 _extend_test_bed()
186 {
187         echo "*** extend test bed"
188         # must set some descents' attributes to be useful
189         mkdir -p $SCRATCH_MNT/here/up/ascend
190         mkdir -p $SCRATCH_MNT/descend/down/here
191         find $SCRATCH_MNT/descend | xargs setfattr -n user.x -v yz
192         find $SCRATCH_MNT/descend | xargs setfattr -n user.1 -v 23
193         find $SCRATCH_MNT/here | xargs setfattr -n trusted.a -v bc
194         find $SCRATCH_MNT/here | xargs setfattr -n trusted.9 -v 87
195         # whack a symlink in the middle, just to be difficult
196         ln -s $SCRATCH_MNT/here/up $SCRATCH_MNT/descend/and
197         # dump out our new starting point
198         find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
199 }
200
201 _extend_test_bed
202
203 echo
204 echo "*** directory descent with us following symlinks"
205 getfattr -h -L -R -m '.' -e hex $SCRATCH_MNT
206
207 echo
208 echo "*** directory descent without following symlinks"
209 getfattr -h -P -R -m '.' -e hex $SCRATCH_MNT
210
211
212
213 # Test the backup/restore code
214
215 echo; echo
216
217 _backup()
218 {
219         # NB: no filtering of scratch here... (need to restore too)
220         $GETFATTR_PROG --absolute-names -dh -R -m '.' $SCRATCH_MNT >$1
221         echo BACKUP $1 >>$seq.full
222         cat $1 >> $seq.full
223         [ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
224 }
225
226 echo "*** backup everything"
227 _backup $tmp.backup1
228
229 echo "*** clear out the scratch device"
230 rm -fr $SCRATCH_MNT/*
231 echo "AFTER REMOVE" >>$seq.full
232 getfattr -L -R -m '.' $SCRATCH_MNT >>$seq.full
233
234 echo "*** reset test bed with no extended attributes"
235 _create_test_bed
236 _extend_test_bed
237
238 echo "*** restore everything"
239 setfattr -h --restore=$tmp.backup1
240 _backup $tmp.backup2
241
242 echo "AFTER RESTORE" >>$seq.full
243 getfattr -L -R -m '.' $SCRATCH_MNT >>$seq.full
244
245 echo "*** compare before and after backups"
246 diff $tmp.backup1 $tmp.backup2
247 if [ $? -ne 0 ]; then
248         echo "urk, failed - creating $seq.backup1 and $seq.backup2"
249         cp $tmp.backup1 $seq.backup1 && cp $tmp.backup2 $seq.backup2
250         status=1
251         exit
252 fi
253
254 # success, all done
255 status=0
256 exit