2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test extending of i_extra_isize code
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
26 $SETFATTR_PROG $@ 2>&1 | _filter_scratch
29 # get standard environment, filters and checks
34 # remove previous $seqres.full before test
37 # real QA test starts here
42 _require_command "$DEBUGFS_PROG" debugfs
45 # Use large inodes to have enough space for experimentation
49 # We leave this amount of bytes for xattrs
51 # We grow extra_isize by this much
53 # We grow minimum requested isize by this much
54 GROW_MIN_EXTRA_ISIZE=16
56 export MKFS_OPTIONS="-I $INODE_SIZE -b $BLOCK_SIZE"
57 _scratch_mkfs >> $seqres.full 2>&1
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))
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))
68 if [ $WANT_ISIZE -lt $ISIZE ]; then
69 _notrun "This test requires at least $XATTR_SPACE free in the inode"
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
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")
82 FILE=$SCRATCH_MNT/${FNAMES[$1]}
84 for (( i = 0; i < $2; i++ )); do
85 do_setfattr -n "user.$i" -v "aa" $FILE || break
89 # Test file without xattrs
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)
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
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
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
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]}"
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
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
128 # 10 xattrs fit into inode, rest goes into xattr block (one xattr consumes
130 create_xattr_file 7 $((10 + ($BLOCK_XATTR_SPACE - $GROW_MIN_EXTRA_ISIZE) / 24))
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
136 create_xattr_file 8 $((10 + $BLOCK_XATTR_SPACE / 24))
140 # Filesystem prepared, update extra_isize
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
147 # Dirty each inode to force expansion of extra_isize
148 for FILE in ${FNAMES[@]}; do
149 echo "aaaa" >$SCRATCH_MNT/$FILE
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
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:"