Add GPL license plate to SGI's test files.
[xfstests-dev.git] / 115
1 #! /bin/sh
2 #
3 #-----------------------------------------------------------------------
4 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 #
19 #-----------------------------------------------------------------------
20 #
21 # FS QA Test No. 115
22 #
23 # Test out xfs_repair_ipaths
24 #
25 # creator
26 owner=tes@crackle.melbourne.sgi.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38     cd /
39     rm -f $tmp.*
40 }
41
42 # Example output:
43 #
44 # ~/attr -Fl a/b/c/d/foo
45 # Attribute "0000000000180080 0000000000000001" has a 3 byte value for a/b/c/d/foo
46 #
47 # ~/attr -Fg "0000000000180080 0000000000000001" a/b/c/d/foo
48 # Attribute "0000000000180080 0000000000000001" had a 3 byte value for a/b/c/d/foo:
49 # foo
50 #
51 # ~/attr -Pg "0000000000180080 0000000000000001" a/b/c/d/foo
52 # Attribute "0000000000180080 0000000000000001" had a 12 byte value for a/b/c/d/foo:
53 # /a/b/c/d/foo
54 #
55
56 #
57 # filter out inode numbers to ordinal numbers
58 # (assumes they come in order)
59 #
60 _filter_inodes()
61 {
62    find $SCRATCH_MNT -exec stat -iq {} \; >$tmp.inodes
63
64    sed -e 's/[()]//g' \
65        -e 's/Attribute "[0-9][0-9]*/Attribute "INODE/' \
66    | nawk -v inodefile=$tmp.inodes '
67         BEGIN {
68                 i=0
69                 while (getline < inodefile > 0) {
70                         i++
71                         inodemap[$1] = i
72                 }
73         }
74         /inode:/ {
75                 for (i = 1; i <= NF; i++) {
76                         nextone = i+1
77                         if ($i == "inode:") {
78                                 $nextone = inodemap[$nextone]
79                         }
80                         printf "%s ", $i
81                 }
82                 printf "\n"
83                 next
84         }
85         { print }
86    '
87 }
88
89 _filter()
90 {
91      sed -e 's/inode: \([0-9][0-9]*\)/inode: N/g' \
92          -e 's/Attribute "[0-9][0-9]*/Attribute "INODE/'
93 }
94
95
96 # get standard environment, filters and checks
97 . ./common.rc
98 . ./common.filter
99
100 _supported_fs xfs
101 _supported_os IRIX
102
103 _require_scratch
104
105 rm -f $here/$seq.full
106
107 echo "mkfs"
108 _scratch_mkfs_xfs >>$here/$seq.full 2>&1 \
109     || _fail "mkfs scratch failed"
110 _scratch_mkfs_xfs -i paths=1 >>$here/$seq.full 2>&1 \
111     || _notrun "i_paths not supported"
112
113 echo "mount"
114 _scratch_mount >>$here/$seq.full 2>&1 \
115     || _fail "mount failed: $MOUNT_OPTIONS"
116
117 # real QA test starts here
118
119 verbose=false
120
121 echo ""
122 echo "--- create some files and directories to work on ---"
123 echo ""
124 cd $SCRATCH_MNT
125 d=dir2/dir3/dir4
126 mkdir -p $d
127 touch file1
128 touch dir2/file2
129 touch dir2/dir3/file3
130 touch $d/file4
131 touch $d/file5
132 touch $d/file6
133 touch $d/file7
134 touch $d/file8
135 touch $d/file9
136
137
138 _do_test()
139 {
140         echo ""
141         echo "--- check all is ok before we start ---"
142         echo ""
143         xfs_check_ipaths $SCRATCH_MNT
144         xfs_repair_ipaths -n $SCRATCH_MNT
145
146         echo ""
147         echo "--- now break some stuff ---"
148         echo ""
149         cnt=1
150
151         echo ""
152         echo "1. remove the EA"
153         echo ""
154         attr -Fl dir2/file2
155         stat_ino=`stat -iq dir2`
156         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
157         #echo "attrname = $attrname"
158         attr -Fr "$attrname" dir2/file2
159         attr -Fl dir2/file2
160
161         echo ""
162         echo "2. change the EA name"
163         echo ""
164         attr -Fl dir2/dir3/file3
165         stat_ino=100
166         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
167         attrvalue=file3
168         attr -Fs "$attrname" -V $attrvalue dir2/dir3/file3
169         attr -Fl dir2/dir3/file3
170
171         echo ""
172         echo "3. change the EA value"
173         echo ""
174         attr -Fl $d/file4
175         stat_ino=`stat -iq $d`
176         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
177         attrvalue=woopdydoo
178         attr -Fs "$attrname" -V "$attrvalue" $d/file4
179         attr -Fl $d/file4
180         attr -Fg "$attrname" $d/file4
181
182         echo ""
183         echo "4. add an extra EA - diff name, same value"
184         echo ""
185         attr -Fl $d/file5
186         stat_ino=100
187         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
188         attrvalue=file5
189         attr -Fs "$attrname" -V $attrvalue $d/file5
190         attr -Fl $d/file5
191         attr -Fg "$attrname" $d/file5
192
193         echo ""
194         echo "5. add an extra EA - diff name, diff value"
195         echo ""
196         attr -Fl $d/file6
197         stat_ino=100
198         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
199         attrvalue=file600
200         attr -Fs "$attrname" -V $attrvalue $d/file6
201         attr -Fl $d/file6
202         attr -Fg "$attrname" $d/file6
203
204         echo ""
205         echo "6. give bad fmt'ed EA name and get rid of existing name"
206         echo ""
207         attrname=woof
208         attrvalue=file7
209         attr -Fs "$attrname" -V $attrvalue $d/file7
210         # remove old attrname
211         cnt=1
212         stat_ino=`stat -iq $d`
213         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
214         attr -Fr "$attrname" $d/file7
215
216         echo ""
217         echo "--- now check it ---"
218         echo ""
219
220         echo ""
221         echo "xfs_check_ipaths"
222         echo ""
223         xfs_check_ipaths $SCRATCH_MNT
224
225         echo ""
226         echo "xfs_repair_ipaths"
227         echo ""
228         xfs_repair_ipaths -n $SCRATCH_MNT
229
230         echo ""
231         echo "--- now repair it ---"
232         echo ""
233
234         echo ""
235         echo "xfs_repair_ipaths"
236         echo ""
237         xfs_repair_ipaths $SCRATCH_MNT
238
239         echo ""
240         echo "--- now check it again ---"
241         echo ""
242
243         echo ""
244         echo ""
245         echo "xfs_check_ipaths"
246         echo ""
247         xfs_check_ipaths $SCRATCH_MNT
248
249         echo ""
250         echo "xfs_repair_ipaths"
251         echo ""
252         xfs_repair_ipaths -n $SCRATCH_MNT
253 }
254
255 _do_test 2>&1 | tee $seq.full | _filter_inodes
256
257 # success, all done
258 status=0
259 exit