94a737ce0a5f09bf35e1e0561dbadc8c81cdefdd
[xfstests-dev.git] / tests / ext4 / 026
1 #! /bin/bash
2 # FS QA Test 026
3 #
4 # Test for ea_inode feature in ext4. Without ea_inode feature, an extended
5 # attribute in ext4 cannot be larger than the fs block size. ea_inode feature
6 # allows storing xattr values in external inodes and so raises xattr value
7 # size limit to 64k.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2017 Google, Inc.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43 . ./common/attr
44
45 # remove previous $seqres.full before test
46 rm -f $seqres.full
47
48 # real QA test starts here
49 _supported_fs ext4
50 _supported_os Linux
51 _require_scratch
52 _require_attrs
53 _require_ext4_mkfs_feature ea_inode
54
55 _scratch_mkfs_ext4 -O ea_inode >/dev/null 2>&1
56 _scratch_mount
57
58 # Sets an extended attribute on a file.
59 attr_set()
60 {
61         local file=$1 name=$2 value=$3 tmp
62
63         if [[ "$value" != "" ]]; then
64                 $SETFATTR_PROG -n $name -v "$value" $file
65         else
66                 $SETFATTR_PROG -n $name $file
67         fi
68
69         tmp=$($GETFATTR_PROG --absolute-names --only-values -n $name $file)
70         [[ "$tmp" == "$value" ]] || echo "unexpected value returned: $tmp"
71 }
72
73 # List attributes on a file.
74 attr_list()
75 {
76         $GETFATTR_PROG --absolute-names $1 | grep -v '^#'
77 }
78
79 # Removes an extended attribute from a file.
80 attr_remove()
81 {
82         local file=$1 name=$2
83
84         $SETFATTR_PROG -x $name $file
85 }
86
87 # Test files.
88 x=$SCRATCH_MNT/x
89 y=$SCRATCH_MNT/y
90 z=$SCRATCH_MNT/z
91
92 # Attribute with short name that goes into inode body.
93 name_in_ibody=user.i
94
95 # Attribute with long name that goes into xattr block.
96 name_in_block=user.$(perl -e 'print "b" x 100;')
97
98 # Set large xattr values on multiple files.
99 touch $x $y $z
100 for file in $x $y $z; do
101         for name in $name_in_ibody $name_in_block; do
102                 for size in 4096 8000 $((64*1024)); do
103                         attr_set $file $name-$size \
104                                 $(perl -e "print 'v' x $size;")
105                 done
106         done
107         attr_list $file
108 done
109 rm $x $y $z
110
111 # Set/remove.
112 touch $x
113 attr_set $x $name_in_ibody $(perl -e "print 'i' x 25000;")
114 attr_set $x $name_in_block $(perl -e "print 'b' x 25000;")
115 attr_list $x
116 attr_remove $x $name_in_ibody
117 attr_remove $x $name_in_block
118 rm $x
119
120 # Set with same value twice.
121 touch $x
122 attr_set $x $name_in_ibody $(perl -e "print 'i' x 60000;")
123 attr_set $x $name_in_ibody $(perl -e "print 'i' x 60000;")
124 attr_list $x
125 rm $x
126
127 # Repeatedly set an extended attribute with various value sizes.
128 touch $x
129 for size in 0 10 80 900 1900 3000 9000 60 10000 0 8000 3000 10 0 20 10000 5; do
130         attr_set $x user.1 $(perl -e "print 'v' x $size;")
131 done
132 attr_list $x
133 rm $x
134
135 # success, all done
136 status=0
137 exit