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