527ac947b768e6f10e905949922370f6cffed9f8
[xfstests-dev.git] / tests / btrfs / 034
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/034
6 #
7 # Test for a btrfs incremental send data corruption issue due to
8 # bad detection of file holes.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 tmp=`mktemp -d`
15
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21     rm -fr $tmp
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # real QA test starts here
29 _supported_fs btrfs
30 _supported_os Linux
31 _require_scratch
32
33 rm -f $seqres.full
34
35 _scratch_mkfs >/dev/null 2>&1
36 _scratch_mount
37
38 # Create a file such that its file extent items span at least 3 btree leafs.
39 # This is necessary to trigger a btrfs incremental send bug where file hole
40 # detection was not correct, leading to data corruption by overriding latest
41 # data regions of a file with zeroes.
42
43 $XFS_IO_PROG -f -c "truncate 104857600" $SCRATCH_MNT/foo
44
45 for ((i = 0; i < 940; i++))
46 do
47         OFFSET=$((32768 + i * 8192))
48         LEN=$((OFFSET + 8192))
49         $XFS_IO_PROG -c "falloc -k $OFFSET $LEN" $SCRATCH_MNT/foo
50         $XFS_IO_PROG -c "pwrite -S 0xf0 $OFFSET 4096" \
51                 $SCRATCH_MNT/foo | _filter_xfs_io
52 done
53
54 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
55
56 $XFS_IO_PROG -c "truncate 3882008" $SCRATCH_MNT/foo
57
58 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
59
60 _run_btrfs_util_prog send -f $tmp/1.snap $SCRATCH_MNT/mysnap1
61 _run_btrfs_util_prog send -f $tmp/2.snap -p $SCRATCH_MNT/mysnap1 \
62         $SCRATCH_MNT/mysnap2
63
64 md5sum $SCRATCH_MNT/foo | _filter_scratch
65 md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
66 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
67
68 _scratch_unmount
69 _check_btrfs_filesystem $SCRATCH_DEV
70 _scratch_mkfs >/dev/null 2>&1
71 _scratch_mount
72
73 _run_btrfs_util_prog receive -f $tmp/1.snap $SCRATCH_MNT
74 md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
75
76 _run_btrfs_util_prog receive -f $tmp/2.snap $SCRATCH_MNT
77 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
78
79 _scratch_unmount
80 _check_btrfs_filesystem $SCRATCH_DEV
81
82 status=0
83 exit