generic: test for non-zero used blocks while writing into a file
[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 _require_test
32 _require_scratch
33 _require_xfs_io_command "fpunch"
34 _require_xfs_io_command "falloc" "-k"
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 our test file with a prealloc extent of 4Mb starting at offset 0,
46 # then write 1Mb of data into offset 0.
47 $XFS_IO_PROG -f -c "falloc -k 0 4M" \
48              -c "pwrite -S 0xea 0 1M" \
49              $SCRATCH_MNT/foobar | _filter_xfs_io
50
51 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap1 2>&1 \
52         | _filter_scratch
53 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/snap1 2>&1 \
54     | _filter_scratch
55
56 # Now punch a hole starting at an offset that corresponds to the file's current
57 # size (1Mb) and ends at an offset smaller then the end offset of the prealloc
58 # extent we allocated earlier (3Mb < 4Mb).
59 $XFS_IO_PROG -c "fpunch 1M 2M" $SCRATCH_MNT/foobar
60
61 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap2 2>&1 \
62         | _filter_scratch
63 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/snap1 -f $send_files_dir/2.snap \
64                  $SCRATCH_MNT/snap2 2>&1 | _filter_scratch
65
66 echo "File digest in the original filesystem:"
67 md5sum $SCRATCH_MNT/snap2/foobar | _filter_scratch
68
69 # Now recreate the filesystem by receiving both send streams and verify we get
70 # the same file content that the original filesystem had.
71 _scratch_unmount
72 _scratch_mkfs >>$seqres.full 2>&1
73 _scratch_mount
74
75 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
76 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
77
78 echo "File digest in the new filesystem:"
79 md5sum $SCRATCH_MNT/snap2/foobar | _filter_scratch
80
81 status=0
82 exit