btrfs: test incremental send after removing a directory and all its files
[xfstests-dev.git] / tests / btrfs / 116
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 116
6 #
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.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_fs btrfs
31 _require_scratch
32
33 rm -f $seqres.full
34
35 _scratch_mkfs >>$seqres.full 2>&1
36
37 # Write to the [0, 64Kb[ and [68Kb, 1Mb[ ranges of the device. These ranges are
38 # reserved for a boot loader to use (GRUB for example) and btrfs should never
39 # use them - neither for allocating metadata/data nor should trim/discard them.
40 # The range [64Kb, 68Kb[ is used for the primary superblock of the filesystem.
41 $XFS_IO_PROG -c "pwrite -S 0xfd 0 64K" $SCRATCH_DEV | _filter_xfs_io
42 $XFS_IO_PROG -c "pwrite -S 0xfd 68K 956K" $SCRATCH_DEV | _filter_xfs_io
43
44 # Now mount the filesystem and perform a fitrim against it.
45 _scratch_mount
46 _require_batched_discard $SCRATCH_MNT
47 $FSTRIM_PROG $SCRATCH_MNT
48
49 # Now unmount the filesystem and verify the content of the ranges was not
50 # modified (no trim/discard happened on them).
51 _scratch_unmount
52 echo "Content of the ranges [0, 64Kb] and [68Kb, 1Mb[ after fitrim:"
53 od -t x1 -N $((64 * 1024)) $SCRATCH_DEV
54 od -t x1 -j $((68 * 1024)) -N $((956 * 1024)) $SCRATCH_DEV
55
56 status=0
57 exit