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