4 # Purpose of this test is to check FITRIM argument handling to make sure
5 # that the argument processing is right and that it does not overflow.
7 #-----------------------------------------------------------------------
8 # Copyright 2011 (C) Red Hat, Inc., Lukas Czerner <lczerner@redhat.com>
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #-----------------------------------------------------------------------
26 seqres=$RESULT_DIR/$seq
27 seqres=$RESULT_DIR/$seq
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
34 trap "exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
42 # real QA test starts here
49 _scratch_mkfs >/dev/null 2>&1
52 _test_batched_discard $SCRATCH_MNT || _notrun "FITRIM not supported on $SCRATCH_DEV"
54 fssize=$(df -k | grep "$SCRATCH_MNT" | grep "$SCRATCH_DEV" | awk '{print $2}')
56 beyond_eofs=$(_math "$fssize*2048")
57 max_64bit=$(_math "2^64 - 1")
59 # All these tests should return EINVAL
60 # since the start is beyond the end of
63 echo "[+] Start beyond the end of fs (should fail)"
64 out=$($FSTRIM_PROG -o $beyond_eofs $SCRATCH_MNT 2>&1)
65 [ $? -eq 0 ] && status=1
66 echo $out | _filter_scratch
68 echo "[+] Start beyond the end of fs with len set (should fail)"
69 out=$($FSTRIM_PROG -o $beyond_eofs -l1M $SCRATCH_MNT 2>&1)
70 [ $? -eq 0 ] && status=1
71 echo $out | _filter_scratch
73 echo "[+] Start = 2^64-1 (should fail)"
74 out=$($FSTRIM_PROG -o $max_64bit $SCRATCH_MNT 2>&1)
75 [ $? -eq 0 ] && status=1
76 echo $out | _filter_scratch
78 echo "[+] Start = 2^64-1 and len is set (should fail)"
79 out=$($FSTRIM_PROG -o $max_64bit -l1M $SCRATCH_MNT 2>&1)
80 [ $? -eq 0 ] && status=1
81 echo $out | _filter_scratch
84 _scratch_mkfs >/dev/null 2>&1
87 # All these tests should succeed
88 # since the length should be truncated
90 echo "[+] Default length (should succeed)"
91 $FSTRIM_PROG $SCRATCH_MNT
92 [ $? -ne 0 ] && status=1
93 echo "[+] Default length with start set (should succeed)"
94 $FSTRIM_PROG -o10M $SCRATCH_MNT
95 [ $? -ne 0 ] && status=1
96 echo "[+] Length beyond the end of fs (should succeed)"
97 $FSTRIM_PROG -l $beyond_eofs $SCRATCH_MNT
98 [ $? -ne 0 ] && status=1
99 echo "[+] Length beyond the end of fs with start set (should succeed)"
100 $FSTRIM_PROG -o10M -l $beyond_eofs $SCRATCH_MNT
101 [ $? -ne 0 ] && status=1
104 _scratch_mkfs >/dev/null 2>&1
107 # This is a bit fuzzy, but since the file system is fresh
108 # there should be at least (fssize/2) free space to trim.
109 # This is supposed to catch wrong FITRIM argument handling
110 out=$($FSTRIM_PROG -v -o10M $SCRATCH_MNT)
114 if [ $bytes -gt $(_math "$fssize*1024") ]; then
116 echo "After the full fs discard $bytes bytes were discarded"\
117 "however the file system is $(_math "$fssize*1024") bytes long."
120 # Btrfs is special and this test does not apply to it
121 # It is because btrfs does not have not-yet-used parts of the device
122 # mapped and since we got here right after the mkfs, there is not
123 # enough free extents in the root tree.
124 if [ $bytes -le $(_math "$fssize*512") ] && [ $FSTYP != "btrfs" ]; then
126 echo "After the full fs discard $bytes bytes were discarded"\
127 "however the file system is $(_math "$fssize*1024") bytes long."
130 # Now to catch overflows due to fsblk->allocation group number conversion
131 # This is different for every file system and it also apply just to some of
132 # them. In order to add check specific for file system you're interested in
133 # compute the arguments as you need and make the file system with proper
136 # (2^32-1) + 2 (this is set to overflow 32bit variable by 2)
137 base=$(_math "2^32+1")
143 start=$(_math "$base*$agsize*$bsize")
145 export MKFS_OPTIONS="-F -b $bsize -g $agsize"
150 start=$(_math "$base*$agsize*$bsize")
152 export MKFS_OPTIONS="-f -d agsize=$(_math "$agsize*$bsize") -b size=$bsize"
155 # (2^32-1) * 4096 * 65536 == 32bit max size * block size * ag size
156 start=$(_math "(2^32 - 1) * 4096 * 65536")
162 _scratch_mkfs >/dev/null 2>&1
164 # It should fail since $start is beyond the end of file system
165 $FSTRIM_PROG -o$start -l10M $SCRATCH_MNT &> /dev/null
166 if [ $? -eq 0 ]; then
168 echo "It seems that fs logic handling start"\
173 _scratch_mkfs >/dev/null 2>&1
176 # len should be big enough to cover the whole file system, so if the
177 # number of discarded bytes is smaller than file system size/2 then it
178 # most likely overflowed
179 # Btrfs is special and this test does not apply to it
180 # It is because btrfs does not have not-yet-used parts of the device
181 # mapped and since we got here right after the mkfs, there is not
182 # enough free extents in the root tree.
183 out=$($FSTRIM_PROG -v -l$len $SCRATCH_MNT)
186 if [ $bytes -le $(_math "$fssize*512") ] && [ $FSTYP != "btrfs" ]; then
188 echo "It seems that fs logic handling len argument overflows"