Dont write to /dev/console explicitly, its bad form.
[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 export MKFS_OPTIONS="$MKFS_OPTIONS -i paths=1"
122 _scratch_mkfs_xfs >>$here/$seq.full 2>&1 \
123     || _fail "mkfs scratch failed"
124
125 echo "mount"
126 _scratch_mount >>$here/$seq.full 2>&1 \
127     || _fail "mount failed: $MOUNT_OPTIONS"
128
129 # real QA test starts here
130
131 verbose=false
132
133 echo ""
134 echo "--- create some files and directories to work on ---"
135 echo ""
136 cd $SCRATCH_MNT
137 d=dir2/dir3/dir4
138 mkdir -p $d
139 touch file1
140 touch dir2/file2
141 touch dir2/dir3/file3
142 touch $d/file4
143 touch $d/file5
144 touch $d/file6
145 touch $d/file7
146 touch $d/file8
147 touch $d/file9
148
149
150 _do_test()
151 {
152         echo ""
153         echo "--- check all is ok before we start ---"
154         echo ""
155         xfs_check_ipaths $SCRATCH_MNT
156         xfs_repair_ipaths -n $SCRATCH_MNT
157
158         echo ""
159         echo "--- now break some stuff ---"
160         echo ""
161         cnt=1
162
163         echo ""
164         echo "1. remove the EA"
165         echo ""
166         attr -Fl dir2/file2
167         stat_ino=`stat -iq dir2`
168         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
169         #echo "attrname = $attrname"
170         attr -Fr "$attrname" dir2/file2
171         attr -Fl dir2/file2
172
173         echo ""
174         echo "2. change the EA name"
175         echo ""
176         attr -Fl dir2/dir3/file3
177         stat_ino=100
178         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
179         attrvalue=file3
180         attr -Fs "$attrname" -V $attrvalue dir2/dir3/file3
181         attr -Fl dir2/dir3/file3
182
183         echo ""
184         echo "3. change the EA value"
185         echo ""
186         attr -Fl $d/file4
187         stat_ino=`stat -iq $d`
188         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
189         attrvalue=woopdydoo
190         attr -Fs "$attrname" -V "$attrvalue" $d/file4
191         attr -Fl $d/file4
192         attr -Fg "$attrname" $d/file4
193
194         echo ""
195         echo "4. add an extra EA - diff name, same value"
196         echo ""
197         attr -Fl $d/file5
198         stat_ino=100
199         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
200         attrvalue=file5
201         attr -Fs "$attrname" -V $attrvalue $d/file5
202         attr -Fl $d/file5
203         attr -Fg "$attrname" $d/file5
204
205         echo ""
206         echo "5. add an extra EA - diff name, diff value"
207         echo ""
208         attr -Fl $d/file6
209         stat_ino=100
210         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
211         attrvalue=file600
212         attr -Fs "$attrname" -V $attrvalue $d/file6
213         attr -Fl $d/file6
214         attr -Fg "$attrname" $d/file6
215
216         echo ""
217         echo "6. give bad fmt'ed EA name and get rid of existing name"
218         echo ""
219         attrname=woof
220         attrvalue=file7
221         attr -Fs "$attrname" -V $attrvalue $d/file7
222         # remove old attrname
223         cnt=1
224         stat_ino=`stat -iq $d`
225         attrname=`printf "%.16x %.16x" $stat_ino $cnt`
226         attr -Fr "$attrname" $d/file7
227
228         echo ""
229         echo "--- now check it ---"
230         echo ""
231
232         echo ""
233         echo "xfs_check_ipaths"
234         echo ""
235         xfs_check_ipaths $SCRATCH_MNT
236
237         echo ""
238         echo "xfs_repair_ipaths"
239         echo ""
240         xfs_repair_ipaths -n $SCRATCH_MNT
241
242         echo ""
243         echo "--- now repair it ---"
244         echo ""
245
246         echo ""
247         echo "xfs_repair_ipaths"
248         echo ""
249         xfs_repair_ipaths $SCRATCH_MNT
250
251         echo ""
252         echo "--- now check it again ---"
253         echo ""
254
255         echo ""
256         echo ""
257         echo "xfs_check_ipaths"
258         echo ""
259         xfs_check_ipaths $SCRATCH_MNT
260
261         echo ""
262         echo "xfs_repair_ipaths"
263         echo ""
264         xfs_repair_ipaths -n $SCRATCH_MNT
265 }
266
267 _do_test 2>&1 | tee $seq.full | _filter_inodes
268
269 # success, all done
270 status=0
271 exit