xfstests: introduce a common directory
[xfstests-dev.git] / tests / xfs / 186
1 #! /bin/bash
2 # FS QA Test No. 186
3 #
4 # Test out:
5 # pv#979606: xfs bug in going from attr2 back to attr1
6 #
7 # Test bug in going from attr2 back to attr1 where xfs
8 # (due to xfs_attr_shortform_bytesfit)
9 # would reset the di_forkoff to the m_offset instead of
10 # leaving the di_forkoff alone as was intended.
11 #
12 # We create enough dirents to push us past m_attroffset,
13 # and create an EA so we have a fork offset
14 # and then turn on attr1 and add one more EA which
15 # will write over the shortform dirents.
16 #
17 #-----------------------------------------------------------------------
18 # Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
19 #
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of the GNU General Public License as
22 # published by the Free Software Foundation.
23 #
24 # This program is distributed in the hope that it would be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 # GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write the Free Software Foundation,
31 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
32 #
33 #-----------------------------------------------------------------------
34 #
35
36 seq=`basename $0`
37 seqres=$RESULT_DIR/$seq
38 seqres=$RESULT_DIR/$seq
39 seqres=$RESULT_DIR/$seq
40 echo "QA output created by $seq"
41
42 here=`pwd`
43 tmp=/tmp/$$
44 status=1        # failure is the default!
45 trap "_cleanup; exit \$status" 0 1 2 3 15
46
47 _cleanup()
48 {
49     cd /
50     rm -f $tmp.*
51 }
52
53 _create_dirents()
54 {
55         start_num=$1
56         end_num=$2
57         cd $fork_dir
58         for i in `seq $start_num $end_num`; do
59                 touch file.$i
60         done
61 }
62
63 _create_eas()
64 {
65         start_num=$1
66         end_num=$2
67         for i in `seq $start_num $end_num`; do
68                 $SETFATTR_PROG -n user.$i -v 0xbabe $fork_dir
69         done
70 }
71
72 _rmv_eas()
73 {
74         start_num=$1
75         end_num=$2
76         for i in `seq $start_num $end_num`; do
77                 $SETFATTR_PROG -x user.$i $fork_dir
78         done
79 }
80
81 _filter_inode()
82 {
83         tee -a $here/$seqres.full | \
84                 sed -e "s/core.forkoff/forkoff/g" | \
85                 egrep '^u.sfdir2|^a.sfattr|forkoff' | \
86                 egrep -v 'inumber|parent'
87 }
88
89 _filter_version()
90 {
91         tee -a $here/$seqres.full | tr ',' '\n' | grep ATTR
92 }
93
94 _print_inode()
95 {
96         echo ""
97         echo "================================="
98         $XFS_DB_PROG -c "version" $SCRATCH_DEV 2>&1 | _filter_version
99         $XFS_DB_PROG -c "inode $inum" -c p $SCRATCH_DEV 2>&1 | _filter_inode
100         echo "================================="
101 }
102
103 _do_eas()
104 {
105         echo ""
106         _scratch_mount
107         if [ $1 = "-r" ]; then 
108                 echo "*** remove EAs start $2 end $3 ***"
109                 _rmv_eas $2 $3
110         else
111                 echo "*** create EAs start $2 end $3 ***"
112                 _create_eas $2 $3
113         fi
114         echo ""
115         cd /; $UMOUNT_PROG $SCRATCH_MNT
116         _print_inode
117 }
118
119 _do_dirents()
120 {
121         num=`expr $2 - $1 + 1`
122         echo ""
123         echo "*** create $num dirents ***"
124         echo ""
125         _scratch_mount
126         _create_dirents $1 $2
127         cd /; $UMOUNT_PROG $SCRATCH_MNT
128         _print_inode
129 }
130
131 _changeto_attr1()
132 {
133         echo ""
134         echo "Try setting attr1 by db"
135         echo ""
136         $XFS_DB_PROG -x -c "version attr1" $SCRATCH_DEV | _filter_version
137 }
138
139
140 # get standard environment, filters and checks
141 . ./common/rc
142 . ./common/filter
143 . ./common/attr
144
145 # real QA test starts here
146
147 # Modify as appropriate.
148 _supported_fs xfs
149 _supported_os Linux
150
151 _require_scratch
152 _require_attrs
153
154 rm -f $seqres.full
155
156 _scratch_mkfs -i attr=2,size=512 -l lazy-count=1 >/dev/null 2>&1
157
158 # set inum to root dir ino
159 # we'll add in dirents and EAs into the root directory
160 eval `$XFS_DB_PROG -r -c 'sb 0' -c 'p rootino' $SCRATCH_DEV | $SED_PROG 's/ //g'`
161 inum=$rootino
162 fork_dir=$SCRATCH_MNT
163 _print_inode
164
165 # add enough dirents to be inline but more
166 # than will fit for m_attroffset for 512b inodes
167 # for attr2 this is not a problem
168 _do_dirents 1 25 
169
170 # add 1 ea so we get our forkoff happening 
171 _do_eas -c 1 1
172
173 # now change back to attr1 where forkoff is constant now
174 _changeto_attr1
175
176 # now add another EA
177 # for a bug in xfs_add_shortform_bytesfit
178 # where it resets the forkoff to m_attroffset>>3 instead of 
179 # leaving as di_forkoff
180 # If it resets to m_attroffset which is in the middle of
181 # the dirents then they will get corrupted
182 _do_eas -c 2 2
183
184 # success, all done
185 status=0
186 exit