192a8c8225d71f68153b99c59acb44c7dba0b163
[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 echo "QA output created by $seq"
39
40 here=`pwd`
41 tmp=/tmp/$$
42 status=1        # failure is the default!
43 trap "_cleanup; exit \$status" 0 1 2 3 15
44
45 _cleanup()
46 {
47     cd /
48     rm -f $tmp.*
49 }
50
51 _create_dirents()
52 {
53         start_num=$1
54         end_num=$2
55         cd $fork_dir
56         for i in `seq $start_num $end_num`; do
57                 touch file.$i
58         done
59 }
60
61 _create_eas()
62 {
63         start_num=$1
64         end_num=$2
65         for i in `seq $start_num $end_num`; do
66                 $SETFATTR_PROG -n user.$i -v 0xbabe $fork_dir
67         done
68 }
69
70 _rmv_eas()
71 {
72         start_num=$1
73         end_num=$2
74         for i in `seq $start_num $end_num`; do
75                 $SETFATTR_PROG -x user.$i $fork_dir
76         done
77 }
78
79 # If filetype is available (-n ftype=1) will get v3 dirs;
80 # just filter/replace to make this look the same as if we
81 # had v2 dirs, as we are not interested in this info.
82 _filter_inode()
83 {
84         tee -a $seqres.full | \
85                 sed -e "s/core.forkoff/forkoff/g" | \
86                 egrep '^u.sfdir2|^u.sfdir3|^a.sfattr|forkoff' | \
87                 egrep -v 'inumber|parent' | \
88                 sed -e s/sfdir3/sfdir2/g | \
89                 grep -v filetype
90 }
91
92 _filter_version()
93 {
94         tee -a $seqres.full | tr ',' '\n' | grep ATTR
95 }
96
97 _print_inode()
98 {
99         echo ""
100         echo "================================="
101         $XFS_DB_PROG -c "version" $SCRATCH_DEV 2>&1 | _filter_version
102         $XFS_DB_PROG -c "inode $inum" -c p $SCRATCH_DEV 2>&1 | _filter_inode
103         echo "================================="
104 }
105
106 _do_eas()
107 {
108         echo ""
109         _scratch_mount
110         if [ $1 = "-r" ]; then 
111                 echo "*** remove EAs start $2 end $3 ***"
112                 _rmv_eas $2 $3
113         else
114                 echo "*** create EAs start $2 end $3 ***"
115                 _create_eas $2 $3
116         fi
117         echo ""
118         cd /; $UMOUNT_PROG $SCRATCH_MNT
119         _print_inode
120 }
121
122 _do_dirents()
123 {
124         num=`expr $2 - $1 + 1`
125         echo ""
126         echo "*** create $num dirents ***"
127         echo ""
128         _scratch_mount
129         _create_dirents $1 $2
130         cd /; $UMOUNT_PROG $SCRATCH_MNT
131         _print_inode
132 }
133
134 _changeto_attr1()
135 {
136         echo ""
137         echo "Try setting attr1 by db"
138         echo ""
139         $XFS_DB_PROG -x -c "version attr1" $SCRATCH_DEV | _filter_version
140 }
141
142 # get standard environment, filters and checks
143 . ./common/rc
144 . ./common/filter
145 . ./common/attr
146
147 # real QA test starts here
148
149 # Modify as appropriate.
150 _supported_fs xfs
151 _supported_os Linux
152
153 _require_scratch
154 _require_attrs
155 _require_attr_v1
156
157 rm -f $seqres.full
158
159 _scratch_mkfs -i attr=2,size=512 -l lazy-count=1 | _filter_mkfs \
160         >>$seqres.full 2>$tmp.mkfs
161 # import crc status and attr version
162 . $tmp.mkfs
163
164 # _scratch_mkfs may ignore $MKFS_OPTIONS if mkfs fails due to conflicts between
165 # $MKFS_OPTIONS and the provided mkfs options, which could result in creating
166 # an XFS we don't want. Check crc status and attr version to be sure.
167 if [ $_fs_has_crcs -eq 1 ]; then
168         _notrun "attr v1 not supported on $SCRATCH_DEV"
169 fi
170 if [ $attr -ne 2 ]; then
171         _notrun "need attr v2 on $SCRATCH_DEV"
172 fi
173
174 # set inum to root dir ino
175 # we'll add in dirents and EAs into the root directory
176 eval `$XFS_DB_PROG -r -c 'sb 0' -c 'p rootino' $SCRATCH_DEV | $SED_PROG 's/ //g'`
177 inum=$rootino
178 fork_dir=$SCRATCH_MNT
179 _print_inode
180
181 # add enough dirents to be inline but more
182 # than will fit for m_attroffset for 512b inodes
183 # for attr2 this is not a problem
184 _do_dirents 1 25 
185
186 # add 1 ea so we get our forkoff happening 
187 _do_eas -c 1 1
188
189 # now change back to attr1 where forkoff is constant now
190 _changeto_attr1
191
192 # now add another EA
193 # for a bug in xfs_add_shortform_bytesfit
194 # where it resets the forkoff to m_attroffset>>3 instead of 
195 # leaving as di_forkoff
196 # If it resets to m_attroffset which is in the middle of
197 # the dirents then they will get corrupted
198 _do_eas -c 2 2
199
200 # success, all done
201 status=0
202 exit