generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 188
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 188
6 #
7 # Test that an incremental send with not corrupt data when the source filesystem
8 # has the no-holes feature enabled, a file has prealloc (unwritten) extents that
9 # start after its size and hole is punched (after the first snapshot is made)
10 # that removes all extents from some offset up to the file's size.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick send prealloc punch
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18         cd /
19         rm -f $tmp.*
20         rm -fr $send_files_dir
21 }
22
23 # Import common functions.
24 . ./common/filter
25
26 # real QA test starts here
27 _supported_fs btrfs
28 _require_test
29 _require_scratch
30 _require_btrfs_fs_feature "no_holes"
31 _require_btrfs_mkfs_feature "no-holes"
32 _require_xfs_io_command "fpunch"
33 _require_xfs_io_command "falloc" "-k"
34
35 send_files_dir=$TEST_DIR/btrfs-test-$seq
36
37 rm -fr $send_files_dir
38 mkdir $send_files_dir
39
40 _scratch_mkfs "-O no-holes" >>$seqres.full 2>&1
41 _scratch_mount
42
43 # Create our test file with a prealloc extent that starts beyond its size.
44 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 500K" $SCRATCH_MNT/foobar | _filter_xfs_io
45 $XFS_IO_PROG -c "falloc -k 1200K 800K" $SCRATCH_MNT/foobar
46
47 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
48         | _filter_scratch
49
50 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
51         | _filter_scratch
52
53 # Now punch a hole that drops all the extents within the file's size.
54 $XFS_IO_PROG -c "fpunch 0 500K" $SCRATCH_MNT/foobar
55
56 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
57         | _filter_scratch
58
59 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
60         $SCRATCH_MNT/incr 2>&1 | _filter_scratch
61
62 echo "File digest in the original filesystem:"
63 md5sum $SCRATCH_MNT/incr/foobar | _filter_scratch
64
65 # Now recreate the filesystem by receiving both send streams and verify we get
66 # the same file content that the original filesystem had.
67 _scratch_unmount
68 _scratch_mkfs >>$seqres.full 2>&1
69 _scratch_mount
70
71 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
72 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
73
74 echo "File digest in the new filesystem:"
75 md5sum $SCRATCH_MNT/incr/foobar | _filter_scratch
76
77 status=0
78 exit