fstests: move test group info to test files
[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 . ./common/preamble
11 _begin_fstest auto quick send
12
13 tmp=`mktemp -d`
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18     rm -fr $tmp
19 }
20
21 # Import common functions.
22 . ./common/filter
23
24 # real QA test starts here
25 _supported_fs btrfs
26 _require_scratch
27 _require_xfs_io_command "falloc"
28
29 _scratch_mkfs >/dev/null 2>&1
30 _scratch_mount
31
32 # Create a file such that its file extent items span at least 3 btree leafs.
33 # This is necessary to trigger a btrfs incremental send bug where file hole
34 # detection was not correct, leading to data corruption by overriding latest
35 # data regions of a file with zeroes.
36
37 $XFS_IO_PROG -f -c "truncate 104857600" $SCRATCH_MNT/foo
38
39 for ((i = 0; i < 940; i++))
40 do
41         OFFSET=$((32768 + i * 8192))
42         LEN=$((OFFSET + 8192))
43         $XFS_IO_PROG -c "falloc -k $OFFSET $LEN" $SCRATCH_MNT/foo
44         $XFS_IO_PROG -c "pwrite -S 0xf0 $OFFSET 4096" \
45                 $SCRATCH_MNT/foo | _filter_xfs_io
46 done
47
48 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
49
50 $XFS_IO_PROG -c "truncate 3882008" $SCRATCH_MNT/foo
51
52 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
53
54 _run_btrfs_util_prog send -f $tmp/1.snap $SCRATCH_MNT/mysnap1
55 _run_btrfs_util_prog send -f $tmp/2.snap -p $SCRATCH_MNT/mysnap1 \
56         $SCRATCH_MNT/mysnap2
57
58 md5sum $SCRATCH_MNT/foo | _filter_scratch
59 md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
60 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
61
62 _scratch_unmount
63 _check_btrfs_filesystem $SCRATCH_DEV
64 _scratch_mkfs >/dev/null 2>&1
65 _scratch_mount
66
67 _run_btrfs_util_prog receive -f $tmp/1.snap $SCRATCH_MNT
68 md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
69
70 _run_btrfs_util_prog receive -f $tmp/2.snap $SCRATCH_MNT
71 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
72
73 _scratch_unmount
74 _check_btrfs_filesystem $SCRATCH_DEV
75
76 status=0
77 exit