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