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