Rework test 018 slightly so that its more user friendly when it fails
[xfstests-dev.git] / 062
1 #! /bin/sh
2 # XFS 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) 2001-2002 Silicon Graphics, Inc.  All Rights Reserved.
9
10 # This program is free software; you can redistribute it and/or modify it
11 # under the terms of version 2 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, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18 # Further, this software is distributed without any warranty that it is
19 # free of the rightful claim of any third person regarding infringement
20 # or the like.  Any license provided herein, whether implied or
21 # otherwise, applies only to this software file.  Patent licenses, if
22 # any, provided herein do not apply to combinations of this program with
23 # other software, or any other product whatsoever.
24
25 # You should have received a copy of the GNU General Public License along
26 # with this program; if not, write the Free Software Foundation, Inc., 59
27 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
28
29 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
30 # Mountain View, CA  94043, or:
31
32 # http://www.sgi.com 
33
34 # For further information regarding this notice, see: 
35
36 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
37 #-----------------------------------------------------------------------
38 #
39 # creator
40 owner=nathans@sgi.com
41
42 seq=`basename $0`
43 echo "QA output created by $seq"
44
45 here=`pwd`
46 tmp=/tmp/$$
47 status=1        # failure is the default!
48
49 # get standard environment, filters and checks
50 . ./common.rc
51 . ./common.filter
52
53 _cleanup()
54 {
55         echo; echo "*** unmount"
56         umount $SCRATCH_MNT 2>/dev/null
57         rm -f $tmp.*
58 }
59 trap "_cleanup; exit \$status" 0 1 2 3 15
60
61 _filter_scratch()
62 {
63         sed -e "s,$SCRATCH_MNT,SCRATCH_MNT,g"
64 }
65
66 getfattr()
67 {
68         /usr/bin/getfattr --absolute-names -dh $@ 2>&1 | _filter_scratch
69 }
70
71 setfattr()
72 {
73         /usr/bin/setfattr $@
74 }
75
76 _create_test_bed()
77 {
78         echo "*** create test bed"
79         touch $SCRATCH_MNT/reg
80         mkdir -p $SCRATCH_MNT/dir
81         ln -s $SCRATCH_MNT/dir $SCRATCH_MNT/lnk
82         mkdir $SCRATCH_MNT/dev
83         mknod $SCRATCH_MNT/dev/b b 0 0
84         mknod $SCRATCH_MNT/dev/c c 0 0
85         mknod $SCRATCH_MNT/dev/p p
86         # sanity check
87         find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
88 }
89
90 _require_scratch
91 rm -f $tmp.backup1 $tmp.backup2 $seq.full
92
93 # real QA test starts here
94 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
95 _scratch_mount || _fail "mount failed"
96 _create_test_bed
97
98 for nsp in user trusted; do
99         for inode in reg dir lnk dev/b dev/c dev/p; do
100
101                 echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
102
103                 echo "*** set/get one initially empty attribute"
104                 setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
105                 getfattr -m $nsp $SCRATCH_MNT/$inode
106
107                 echo "*** overwrite empty, set several new attributes"
108                 setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
109                 setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
110                 setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
111
112                 echo "*** fetch several attribute names and values (hex)"
113                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
114
115                 echo "*** fetch several attribute names and values (base64)"
116                 getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
117
118                 echo "*** shrink value of an existing attribute"
119                 setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
120                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
121
122                 echo "*** grow value of existing attribute"
123                 setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
124                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
125
126                 echo "*** set an empty value for second attribute"
127                 setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
128                 getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode
129
130                 echo "*** overwrite empty value"
131                 setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
132                 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
133
134                 echo "*** remove attribute"
135                 setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
136                 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
137
138                 echo "*** final list (strings, type=$inode, nsp=$nsp)"
139                 getfattr -m '^user|^trusted' -e hex $SCRATCH_MNT/$inode
140         done
141 done
142
143
144
145 # Test the directory descent code
146
147 echo; echo
148
149 _extend_test_bed()
150 {
151         echo "*** extend test bed"
152         # must set some descents' attributes to be useful
153         mkdir -p $SCRATCH_MNT/here/up/ascend
154         mkdir -p $SCRATCH_MNT/descend/down/here
155         find $SCRATCH_MNT/descend | xargs setfattr -n user.x -v yz
156         find $SCRATCH_MNT/descend | xargs setfattr -n user.1 -v 23
157         find $SCRATCH_MNT/here | xargs setfattr -n trusted.a -v bc
158         find $SCRATCH_MNT/here | xargs setfattr -n trusted.9 -v 87
159         # whack a symlink in the middle, just to be difficult
160         ln -s $SCRATCH_MNT/here/up $SCRATCH_MNT/descend/and
161         # dump out our new starting point
162         find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
163 }
164
165 _extend_test_bed
166
167 echo
168 echo "*** directory descent with us following symlinks"
169 getfattr -h -L -R -m '^user|^trusted' -e hex $SCRATCH_MNT
170
171 echo
172 echo "*** directory descent without following symlinks"
173 getfattr -h -P -R -m '^user|^trusted' -e hex $SCRATCH_MNT
174
175
176
177 # Test the backup/restore code
178
179 echo; echo
180
181 _backup()
182 {
183         # NB: no filtering of scratch here... (need to restore too)
184         /usr/bin/getfattr --absolute-names -dh -R -m '^user|^system' $SCRATCH_MNT >$1
185         echo BACKUP $1 >>$seq.full
186         cat $1 >> $seq.full
187         [ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
188 }
189
190 echo "*** backup everything"
191 _backup $tmp.backup1
192
193 echo "*** clear out the scratch device"
194 rm -fr $SCRATCH_MNT/*
195 echo "AFTER REMOVE" >>$seq.full
196 getfattr -L -R -m '^user|^trusted' $SCRATCH_MNT >>$seq.full
197
198 echo "*** reset test bed with no extended attributes"
199 _create_test_bed
200 _extend_test_bed
201
202 echo "*** restore everything"
203 setfattr -h --restore=$tmp.backup1
204 _backup $tmp.backup2
205
206 echo "AFTER RESTORE" >>$seq.full
207 getfattr -L -R -m '^user|^trusted' $SCRATCH_MNT >>$seq.full
208
209 echo "*** compare before and after backups"
210 diff $tmp.backup1 $tmp.backup2
211 if [ $? -ne 0 ]; then
212         echo "urk, failed - creating $seq.backup1 and $seq.backup2"
213         cp $tmp.backup1 $seq.backup1 && cp $tmp.backup2 $seq.backup2
214         status=1
215         exit
216 fi
217
218 # success, all done
219 status=0
220 exit