2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
7 # Verify that when a fitrim operation is made against a btrfs filesystem, the
8 # ranges [0, 64Kb[ and [68Kb, 1Mb[ of the device are not discarded, they remain
9 # with the content they had before the fitrim operation. These regions of the
10 # device are reserved for a boot loader to use at its will.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
29 # real QA test starts here
36 _scratch_mkfs >>$seqres.full 2>&1
38 # Write to the [0, 64Kb[ and [68Kb, 1Mb[ ranges of the device. These ranges are
39 # reserved for a boot loader to use (GRUB for example) and btrfs should never
40 # use them - neither for allocating metadata/data nor should trim/discard them.
41 # The range [64Kb, 68Kb[ is used for the primary superblock of the filesystem.
42 $XFS_IO_PROG -c "pwrite -S 0xfd 0 64K" $SCRATCH_DEV | _filter_xfs_io
43 $XFS_IO_PROG -c "pwrite -S 0xfd 68K 956K" $SCRATCH_DEV | _filter_xfs_io
45 # Now mount the filesystem and perform a fitrim against it.
47 _require_batched_discard $SCRATCH_MNT
48 $FSTRIM_PROG $SCRATCH_MNT
50 # Now unmount the filesystem and verify the content of the ranges was not
51 # modified (no trim/discard happened on them).
53 echo "Content of the ranges [0, 64Kb] and [68Kb, 1Mb[ after fitrim:"
54 od -t x1 -N $((64 * 1024)) $SCRATCH_DEV
55 od -t x1 -j $((68 * 1024)) -N $((956 * 1024)) $SCRATCH_DEV