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