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