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