summaryrefslogtreecommitdiff
path: root/tests/xfs/186
blob: f44158e31ce389022bd573b41dea560b29bb253c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
#
# FS QA Test No. 186
#
# Test out:
# pv#979606: xfs bug in going from attr2 back to attr1
#
# Test bug in going from attr2 back to attr1 where xfs
# (due to xfs_attr_shortform_bytesfit)
# would reset the di_forkoff to the m_offset instead of
# leaving the di_forkoff alone as was intended.
#
# We create enough dirents to push us past m_attroffset,
# and create an EA so we have a fork offset
# and then turn on attr1 and add one more EA which
# will write over the shortform dirents.
#
. ./common/preamble
_begin_fstest attr auto quick

_create_dirents()
{
	start_num=$1
	end_num=$2
	cd $fork_dir
	for i in `seq $start_num $end_num`; do
		touch file.$i
	done
}

_create_eas()
{
	start_num=$1
	end_num=$2
	for i in `seq $start_num $end_num`; do
		$SETFATTR_PROG -n user.$i -v 0xbabe $fork_dir
	done
}

_rmv_eas()
{
	start_num=$1
	end_num=$2
	for i in `seq $start_num $end_num`; do
		$SETFATTR_PROG -x user.$i $fork_dir
	done
}

# If filetype is available (-n ftype=1) will get v3 dirs;
# just filter/replace to make this look the same as if we
# had v2 dirs, as we are not interested in this info.
_filter_inode()
{
	tee -a $seqres.full | \
		sed -e "s/core.forkoff/forkoff/g" | \
		grep -E '^u.sfdir2|^u.sfdir3|^a.sfattr|forkoff' | \
		grep -E -v 'inumber|parent' | \
		sed -e s/sfdir3/sfdir2/g | \
		grep -v filetype
}

_filter_version()
{
	tee -a $seqres.full | tr ',' '\n' | grep ATTR
}

_print_inode()
{
	echo ""
	echo "================================="
	_scratch_xfs_db -c "version" 2>&1 | _filter_version
	_scratch_xfs_db -c "inode $inum" -c p 2>&1 | _filter_inode
	echo "================================="
}

_do_eas()
{
	echo ""
	_scratch_mount
	if [ $1 = "-r" ]; then 
		echo "*** remove EAs start $2 end $3 ***"
		_rmv_eas $2 $3
	else
		echo "*** create EAs start $2 end $3 ***"
		_create_eas $2 $3
	fi
	echo ""
	cd /; $UMOUNT_PROG $SCRATCH_MNT
	_print_inode
}

_do_dirents()
{
	num=`expr $2 - $1 + 1`
	echo ""
	echo "*** create $num dirents ***"
	echo ""
	_scratch_mount
	_create_dirents $1 $2
	cd /; $UMOUNT_PROG $SCRATCH_MNT
	_print_inode
}

_changeto_attr1()
{
	echo ""
	echo "Try setting attr1 by db"
	echo ""
	_scratch_xfs_db -x -c "version attr1" | _filter_version
}

# Import common functions.
. ./common/filter
. ./common/attr

# real QA test starts here

# Modify as appropriate.
_supported_fs xfs

_require_scratch
_require_attrs
_require_attr_v1

_scratch_mkfs -i attr=2,size=512 -l lazy-count=1 | _filter_mkfs \
	>>$seqres.full 2>$tmp.mkfs
# import crc status and attr version
. $tmp.mkfs

# _scratch_mkfs may ignore $MKFS_OPTIONS if mkfs fails due to conflicts between
# $MKFS_OPTIONS and the provided mkfs options, which could result in creating
# an XFS we don't want. Check crc status and attr version to be sure.
if [ $_fs_has_crcs -eq 1 ]; then
	_notrun "attr v1 not supported on $SCRATCH_DEV"
fi
if [ $attr -ne 2 ]; then
	_notrun "need attr v2 on $SCRATCH_DEV"
fi

# set inum to root dir ino
# we'll add in dirents and EAs into the root directory
inum=`_scratch_xfs_get_sb_field rootino`
fork_dir=$SCRATCH_MNT
_print_inode

# add enough dirents to be inline but more
# than will fit for m_attroffset for 512b inodes
# for attr2 this is not a problem
_do_dirents 1 25 

# add 1 ea so we get our forkoff happening 
_do_eas -c 1 1

# now change back to attr1 where forkoff is constant now
_changeto_attr1

# now add another EA
# for a bug in xfs_add_shortform_bytesfit
# where it resets the forkoff to m_attroffset>>3 instead of 
# leaving as di_forkoff
# If it resets to m_attroffset which is in the middle of
# the dirents then they will get corrupted
_do_eas -c 2 2

# success, all done
status=0
exit