btrfs/139: require 2GB scratch dev
[xfstests-dev.git] / tests / btrfs / 169
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 169
6 #
7 # Test that an incremental send operation produces correct results if a file
8 # that has a prealloc (unwritten) extent beyond its EOF gets a hole punched
9 # in a section of that prealloc extent.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22         rm -fr $send_files_dir
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 _supported_os Linux
32 _require_test
33 _require_scratch
34 _require_xfs_io_command "fpunch"
35 _require_xfs_io_command "falloc" "-k"
36
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
38
39 rm -f $seqres.full
40 rm -fr $send_files_dir
41 mkdir $send_files_dir
42
43 _scratch_mkfs >>$seqres.full 2>&1
44 _scratch_mount
45
46 # Create our test file with a prealloc extent of 4Mb starting at offset 0,
47 # then write 1Mb of data into offset 0.
48 $XFS_IO_PROG -f -c "falloc -k 0 4M" \
49              -c "pwrite -S 0xea 0 1M" \
50              $SCRATCH_MNT/foobar | _filter_xfs_io
51
52 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap1 2>&1 \
53         | _filter_scratch
54 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/snap1 2>&1 \
55     | _filter_scratch
56
57 # Now punch a hole starting at an offset that corresponds to the file's current
58 # size (1Mb) and ends at an offset smaller then the end offset of the prealloc
59 # extent we allocated earlier (3Mb < 4Mb).
60 $XFS_IO_PROG -c "fpunch 1M 2M" $SCRATCH_MNT/foobar
61
62 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap2 2>&1 \
63         | _filter_scratch
64 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/snap1 -f $send_files_dir/2.snap \
65                  $SCRATCH_MNT/snap2 2>&1 | _filter_scratch
66
67 echo "File digest in the original filesystem:"
68 md5sum $SCRATCH_MNT/snap2/foobar | _filter_scratch
69
70 # Now recreate the filesystem by receiving both send streams and verify we get
71 # the same file content that the original filesystem had.
72 _scratch_unmount
73 _scratch_mkfs >>$seqres.full 2>&1
74 _scratch_mount
75
76 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
77 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
78
79 echo "File digest in the new filesystem:"
80 md5sum $SCRATCH_MNT/snap2/foobar | _filter_scratch
81
82 status=0
83 exit