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