4 # Verify that when a fitrim operation is made against a btrfs filesystem, the
5 # ranges [0, 64Kb[ and [68Kb, 1Mb[ of the device are not discarded, they remain
6 # with the content they had before the fitrim operation. These regions of the
7 # device are reserved for a boot loader to use at its will.
9 #-----------------------------------------------------------------------
11 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
12 # Author: Filipe Manana <fdmanana@suse.com>
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #-----------------------------------------------------------------------
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
33 status=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
42 # get standard environment, filters and checks
46 # real QA test starts here
53 _scratch_mkfs >>$seqres.full 2>&1
55 # Write to the [0, 64Kb[ and [68Kb, 1Mb[ ranges of the device. These ranges are
56 # reserved for a boot loader to use (GRUB for example) and btrfs should never
57 # use them - neither for allocating metadata/data nor should trim/discard them.
58 # The range [64Kb, 68Kb[ is used for the primary superblock of the filesystem.
59 $XFS_IO_PROG -c "pwrite -S 0xfd 0 64K" $SCRATCH_DEV | _filter_xfs_io
60 $XFS_IO_PROG -c "pwrite -S 0xfd 68K 956K" $SCRATCH_DEV | _filter_xfs_io
62 # Now mount the filesystem and perform a fitrim against it.
64 _require_batched_discard $SCRATCH_MNT
65 $FSTRIM_PROG $SCRATCH_MNT
67 # Now unmount the filesystem and verify the content of the ranges was not
68 # modified (no trim/discard happened on them).
70 echo "Content of the ranges [0, 64Kb] and [68Kb, 1Mb[ after fitrim:"
71 od -t x1 -N $((64 * 1024)) $SCRATCH_DEV
72 od -t x1 -j $((68 * 1024)) -N $((956 * 1024)) $SCRATCH_DEV