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