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