xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 186
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 186
6 #
7 # Test out:
8 # pv#979606: xfs bug in going from attr2 back to attr1
9 #
10 # Test bug in going from attr2 back to attr1 where xfs
11 # (due to xfs_attr_shortform_bytesfit)
12 # would reset the di_forkoff to the m_offset instead of
13 # leaving the di_forkoff alone as was intended.
14 #
15 # We create enough dirents to push us past m_attroffset,
16 # and create an EA so we have a fork offset
17 # and then turn on attr1 and add one more EA which
18 # will write over the shortform dirents.
19 #
20 . ./common/preamble
21 _begin_fstest attr auto quick
22
23 _create_dirents()
24 {
25         start_num=$1
26         end_num=$2
27         cd $fork_dir
28         for i in `seq $start_num $end_num`; do
29                 touch file.$i
30         done
31 }
32
33 _create_eas()
34 {
35         start_num=$1
36         end_num=$2
37         for i in `seq $start_num $end_num`; do
38                 $SETFATTR_PROG -n user.$i -v 0xbabe $fork_dir
39         done
40 }
41
42 _rmv_eas()
43 {
44         start_num=$1
45         end_num=$2
46         for i in `seq $start_num $end_num`; do
47                 $SETFATTR_PROG -x user.$i $fork_dir
48         done
49 }
50
51 # If filetype is available (-n ftype=1) will get v3 dirs;
52 # just filter/replace to make this look the same as if we
53 # had v2 dirs, as we are not interested in this info.
54 _filter_inode()
55 {
56         tee -a $seqres.full | \
57                 sed -e "s/core.forkoff/forkoff/g" | \
58                 egrep '^u.sfdir2|^u.sfdir3|^a.sfattr|forkoff' | \
59                 egrep -v 'inumber|parent' | \
60                 sed -e s/sfdir3/sfdir2/g | \
61                 grep -v filetype
62 }
63
64 _filter_version()
65 {
66         tee -a $seqres.full | tr ',' '\n' | grep ATTR
67 }
68
69 _print_inode()
70 {
71         echo ""
72         echo "================================="
73         _scratch_xfs_db -c "version" 2>&1 | _filter_version
74         _scratch_xfs_db -c "inode $inum" -c p 2>&1 | _filter_inode
75         echo "================================="
76 }
77
78 _do_eas()
79 {
80         echo ""
81         _scratch_mount
82         if [ $1 = "-r" ]; then 
83                 echo "*** remove EAs start $2 end $3 ***"
84                 _rmv_eas $2 $3
85         else
86                 echo "*** create EAs start $2 end $3 ***"
87                 _create_eas $2 $3
88         fi
89         echo ""
90         cd /; $UMOUNT_PROG $SCRATCH_MNT
91         _print_inode
92 }
93
94 _do_dirents()
95 {
96         num=`expr $2 - $1 + 1`
97         echo ""
98         echo "*** create $num dirents ***"
99         echo ""
100         _scratch_mount
101         _create_dirents $1 $2
102         cd /; $UMOUNT_PROG $SCRATCH_MNT
103         _print_inode
104 }
105
106 _changeto_attr1()
107 {
108         echo ""
109         echo "Try setting attr1 by db"
110         echo ""
111         _scratch_xfs_db -x -c "version attr1" | _filter_version
112 }
113
114 # Import common functions.
115 . ./common/filter
116 . ./common/attr
117
118 # real QA test starts here
119
120 # Modify as appropriate.
121 _supported_fs xfs
122
123 _require_scratch
124 _require_attrs
125 _require_attr_v1
126
127 _scratch_mkfs -i attr=2,size=512 -l lazy-count=1 | _filter_mkfs \
128         >>$seqres.full 2>$tmp.mkfs
129 # import crc status and attr version
130 . $tmp.mkfs
131
132 # _scratch_mkfs may ignore $MKFS_OPTIONS if mkfs fails due to conflicts between
133 # $MKFS_OPTIONS and the provided mkfs options, which could result in creating
134 # an XFS we don't want. Check crc status and attr version to be sure.
135 if [ $_fs_has_crcs -eq 1 ]; then
136         _notrun "attr v1 not supported on $SCRATCH_DEV"
137 fi
138 if [ $attr -ne 2 ]; then
139         _notrun "need attr v2 on $SCRATCH_DEV"
140 fi
141
142 # set inum to root dir ino
143 # we'll add in dirents and EAs into the root directory
144 inum=`_scratch_xfs_get_sb_field rootino`
145 fork_dir=$SCRATCH_MNT
146 _print_inode
147
148 # add enough dirents to be inline but more
149 # than will fit for m_attroffset for 512b inodes
150 # for attr2 this is not a problem
151 _do_dirents 1 25 
152
153 # add 1 ea so we get our forkoff happening 
154 _do_eas -c 1 1
155
156 # now change back to attr1 where forkoff is constant now
157 _changeto_attr1
158
159 # now add another EA
160 # for a bug in xfs_add_shortform_bytesfit
161 # where it resets the forkoff to m_attroffset>>3 instead of 
162 # leaving as di_forkoff
163 # If it resets to m_attroffset which is in the middle of
164 # the dirents then they will get corrupted
165 _do_eas -c 2 2
166
167 # success, all done
168 status=0
169 exit