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