btrfs/139: require 2GB scratch dev
[xfstests-dev.git] / tests / btrfs / 137
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/137
6 #
7 # Test that both incremental and full send operations preserve file holes.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         cd /
20         rm -fr $send_files_dir
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/punch
28
29 # real QA test starts here
30 _supported_fs btrfs
31 _supported_os Linux
32 _require_test
33 _require_scratch
34 _require_xfs_io_command "fiemap"
35
36 send_files_dir=$TEST_DIR/btrfs-test-$seq
37
38 rm -f $seqres.full
39 rm -fr $send_files_dir
40 mkdir $send_files_dir
41
42 _scratch_mkfs >>$seqres.full 2>&1
43 _scratch_mount
44
45 # Create the first test file.
46 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 4K" $SCRATCH_MNT/foo | _filter_xfs_io
47
48 # Create a second test file with a 1Mb hole.
49 $XFS_IO_PROG -f \
50      -c "pwrite -S 0xaa 0 4K" \
51      -c "pwrite -S 0xbb 1028K 4K" \
52      $SCRATCH_MNT/bar | _filter_xfs_io
53
54 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
55         $SCRATCH_MNT/snap1 >/dev/null
56
57 # Now add one new extent to our first test file, increasing its size and leaving
58 # a 1Mb hole between the first extent and this new extent.
59 $XFS_IO_PROG -c "pwrite -S 0xbb 1028K 4K" $SCRATCH_MNT/foo | _filter_xfs_io
60
61 # Now overwrite the last extent of our second test file.
62 $XFS_IO_PROG -c "pwrite -S 0xcc 1028K 4K" $SCRATCH_MNT/bar | _filter_xfs_io
63
64 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
65                  $SCRATCH_MNT/snap2 >/dev/null
66
67 echo
68 echo "File digests in the original filesystem:"
69 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
70 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
71 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
72 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
73
74 echo
75 echo "File snap1/foo fiemap results in the original filesystem:"
76 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
77 echo
78 echo "File snap1/bar fiemap results in the original filesystem:"
79 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
80 echo
81 echo "File snap2/foo fiemap results in the original filesystem:"
82 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
83 echo
84 echo "File snap2/bar fiemap results in the original filesystem:"
85 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap
86 echo
87
88 # Create the send streams to apply later on a new filesystem.
89 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/snap1 2>&1 \
90         | _filter_scratch
91 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/snap1 -f $send_files_dir/2.snap \
92         $SCRATCH_MNT/snap2 2>&1 | _filter_scratch
93
94 # Create a new filesystem, receive the send streams and verify that the file
95 # contents are the same as in the original filesystem and that the file holes
96 # exists in both snapshots.
97 _scratch_unmount
98 _scratch_mkfs >>$seqres.full 2>&1
99 _scratch_mount
100 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT >/dev/null
101 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT >/dev/null
102
103 echo
104 echo "File digests in the new filesystem:"
105 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
106 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
107 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
108 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
109
110 echo
111 echo "File snap1/foo fiemap results in the new filesystem:"
112 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
113 echo
114 echo "File snap1/bar fiemap results in the new filesystem:"
115 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
116 echo
117 echo "File snap2/foo fiemap results in the new filesystem:"
118 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
119 echo
120 echo "File snap2/bar fiemap results in the new filesystem:"
121 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap
122
123 status=0
124 exit