fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / ext4 / 022
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 SUSE Linux Products GmbH.  All Rights Reserved.
4 #
5 # FS QA Test 022
6 #
7 # Test extending of i_extra_isize code
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 do_setfattr()
25 {
26         $SETFATTR_PROG $@ 2>&1 | _filter_scratch
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/attr
33
34 # remove previous $seqres.full before test
35 rm -f $seqres.full
36
37 # real QA test starts here
38 _supported_fs ext4
39 _supported_os Linux
40 _require_scratch
41 _require_dumpe2fs
42 _require_command "$DEBUGFS_PROG" debugfs
43 _require_attrs
44
45 # Use large inodes to have enough space for experimentation
46 INODE_SIZE=1024
47 # Block size
48 BLOCK_SIZE=4096
49 # We leave this amount of bytes for xattrs
50 XATTR_SPACE=256
51 # We grow extra_isize by this much
52 GROW_EXTRA_ISIZE=80
53 # We grow minimum requested isize by this much
54 GROW_MIN_EXTRA_ISIZE=16
55
56 export MKFS_OPTIONS="-I $INODE_SIZE -b $BLOCK_SIZE"
57 _scratch_mkfs >> $seqres.full 2>&1
58
59 ISIZE=$($DUMPE2FS_PROG -h $SCRATCH_DEV 2>/dev/null |
60         grep "^Desired extra isize:" | awk '{print $4}')
61 # 32 bytes for header and 4 bytes for terminator
62 BLOCK_XATTR_SPACE=$(($BLOCK_SIZE - 36))
63 GOOD_OLD_ISIZE=128
64 WANT_ISIZE=$(($INODE_SIZE-$GOOD_OLD_ISIZE-$XATTR_SPACE))
65 NEW_ISIZE=$(($WANT_ISIZE+$GROW_EXTRA_ISIZE))
66 NEW_MIN_ISIZE=$(($WANT_ISIZE+$GROW_MIN_EXTRA_ISIZE))
67
68 if [ $WANT_ISIZE -lt $ISIZE ]; then
69         _notrun "This test requires at least $XATTR_SPACE free in the inode"
70 fi
71
72 $DEBUGFS_PROG -w -R "ssv want_extra_isize $WANT_ISIZE" $SCRATCH_DEV >> $seqres.full 2>&1
73 $DEBUGFS_PROG -w -R "ssv min_extra_isize $WANT_ISIZE" $SCRATCH_DEV >> $seqres.full 2>&1
74
75 _scratch_mount
76
77 FNAMES=("empty" "couple_xattrs" "just_enough_xattrs" "one_extra_xattr"
78         "full_xattrs" "one_extra_xattr_ext" "full_xattrs_ext"
79         "full_xattrs_almost_full_ext" "full_xattrs_full_ext")
80 create_xattr_file()
81 {
82         FILE=$SCRATCH_MNT/${FNAMES[$1]}
83         touch $FILE
84         for (( i = 0; i < $2; i++ )); do
85                 do_setfattr -n "user.$i" -v "aa" $FILE || break
86         done
87 }
88
89 # Test file without xattrs
90 create_xattr_file 0 0
91
92 # Test file with couple of xattrs but which still has enough space
93 # One xattr consumes 24 bytes + 4 bytes for header + 4 bytes for terminator
94 # => 104 bytes consumed (152 bytes still free)
95 create_xattr_file 1 4
96
97 # Test file with xattrs which still has just enough space
98 # One xattr consumes 24 bytes + 4 bytes for header + 4 bytes for terminator
99 # => 176 bytes consumed (80 bytes still free)
100 create_xattr_file 2 7
101
102 # Test file with xattrs which has one xattr which needs moving
103 # One xattr consumes 24 bytes + 4 bytes for header + 4 bytes for terminator
104 # => 200 bytes consumed (56 bytes still free)
105 create_xattr_file 3 8
106
107 # Test file with xattrs which has xattr space almost full
108 # One xattr consumes 24 bytes + 4 bytes for header + 4 bytes for terminator
109 # => 248 bytes consumed (8 bytes still free)
110 create_xattr_file 4 10
111
112 # Test file with xattrs which has one xattr which needs moving and external
113 # xattr block allocated
114 # One xattr consumes 24 bytes + 4 bytes for header + 4 bytes for terminator
115 # => 200 bytes consumed (56 bytes still free)
116 create_xattr_file 5 8
117 do_setfattr -n "user.e0" -v "01234567890123456789012345678901234567890123456789" "$SCRATCH_MNT/${FNAMES[5]}"
118
119 # Test file with xattrs which has xattr space in inode almost full and external
120 # xattr block allocated
121 # One xattr consumes 24 bytes + 4 bytes for header + 4 bytes for terminator
122 # => 248 bytes consumed (8 bytes still free)
123 create_xattr_file 6 11
124
125 # Test file with xattrs which has xattr space in inode almost full and external
126 # xattr block allocated and almost full so that inode can still expand to
127 # s_min_extra_isize
128 # 10 xattrs fit into inode, rest goes into xattr block (one xattr consumes
129 # 24 bytes)
130 create_xattr_file 7 $((10 + ($BLOCK_XATTR_SPACE - $GROW_MIN_EXTRA_ISIZE) / 24))
131
132 # Test file with xattrs which has xattr space in inode almost full and external
133 # xattr block allocated and full
134 # 10 xattrs fit into inode, rest goes into xattr block (one xattr consumes
135 # 24 bytes)
136 create_xattr_file 8 $((10 + $BLOCK_XATTR_SPACE / 24))
137
138 _scratch_unmount
139
140 # Filesystem prepared, update extra_isize
141
142 $DEBUGFS_PROG -w -R "ssv want_extra_isize $NEW_ISIZE" $SCRATCH_DEV >> $seqres.full 2>&1
143 $DEBUGFS_PROG -w -R "ssv min_extra_isize $NEW_MIN_ISIZE" $SCRATCH_DEV >> $seqres.full 2>&1
144
145 _scratch_mount
146
147 # Dirty each inode to force expansion of extra_isize
148 for FILE in ${FNAMES[@]}; do
149         echo "aaaa" >$SCRATCH_MNT/$FILE
150 done
151
152 # Dump all xattrs to see whether nothing broke
153 for FILE in ${FNAMES[@]}; do
154         $GETFATTR_PROG -h -d --absolute-names $SCRATCH_MNT/$FILE 2>/dev/null | \
155                 _filter_scratch | sort
156 done
157
158 _scratch_unmount
159
160 # Dump everything via debugfs to check whether sizes got extended as expected
161 for FILE in ${FNAMES[@]}; do
162         $DEBUGFS_PROG -R "stat $FILE" $SCRATCH_DEV 2>/dev/null | \
163                 grep "^Size of extra inode fields:"
164 done
165
166 # success, all done
167 status=0
168 exit