generic/563: use a loop device to avoid partition incompatibility
[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 _require_scratch
31
32 rm -f $seqres.full
33
34 _scratch_mkfs >/dev/null 2>&1
35 _scratch_mount
36
37 # Create a file such that its file extent items span at least 3 btree leafs.
38 # This is necessary to trigger a btrfs incremental send bug where file hole
39 # detection was not correct, leading to data corruption by overriding latest
40 # data regions of a file with zeroes.
41
42 $XFS_IO_PROG -f -c "truncate 104857600" $SCRATCH_MNT/foo
43
44 for ((i = 0; i < 940; i++))
45 do
46         OFFSET=$((32768 + i * 8192))
47         LEN=$((OFFSET + 8192))
48         $XFS_IO_PROG -c "falloc -k $OFFSET $LEN" $SCRATCH_MNT/foo
49         $XFS_IO_PROG -c "pwrite -S 0xf0 $OFFSET 4096" \
50                 $SCRATCH_MNT/foo | _filter_xfs_io
51 done
52
53 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
54
55 $XFS_IO_PROG -c "truncate 3882008" $SCRATCH_MNT/foo
56
57 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
58
59 _run_btrfs_util_prog send -f $tmp/1.snap $SCRATCH_MNT/mysnap1
60 _run_btrfs_util_prog send -f $tmp/2.snap -p $SCRATCH_MNT/mysnap1 \
61         $SCRATCH_MNT/mysnap2
62
63 md5sum $SCRATCH_MNT/foo | _filter_scratch
64 md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
65 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
66
67 _scratch_unmount
68 _check_btrfs_filesystem $SCRATCH_DEV
69 _scratch_mkfs >/dev/null 2>&1
70 _scratch_mount
71
72 _run_btrfs_util_prog receive -f $tmp/1.snap $SCRATCH_MNT
73 md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
74
75 _run_btrfs_util_prog receive -f $tmp/2.snap $SCRATCH_MNT
76 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
77
78 _scratch_unmount
79 _check_btrfs_filesystem $SCRATCH_DEV
80
81 status=0
82 exit