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