xfs: Check for extent overflow when trivally adding a new extent
[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 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23         rm -fr $send_files_dir
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # real QA test starts here
31 _supported_fs btrfs
32 _require_test
33 _require_scratch
34 _require_btrfs_fs_feature "no_holes"
35 _require_btrfs_mkfs_feature "no-holes"
36 _require_xfs_io_command "fpunch"
37 _require_xfs_io_command "falloc" "-k"
38
39 send_files_dir=$TEST_DIR/btrfs-test-$seq
40
41 rm -f $seqres.full
42 rm -fr $send_files_dir
43 mkdir $send_files_dir
44
45 _scratch_mkfs "-O no-holes" >>$seqres.full 2>&1
46 _scratch_mount
47
48 # Create our test file with a prealloc extent that starts beyond its size.
49 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 500K" $SCRATCH_MNT/foobar | _filter_xfs_io
50 $XFS_IO_PROG -c "falloc -k 1200K 800K" $SCRATCH_MNT/foobar
51
52 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
53         | _filter_scratch
54
55 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
56         | _filter_scratch
57
58 # Now punch a hole that drops all the extents within the file's size.
59 $XFS_IO_PROG -c "fpunch 0 500K" $SCRATCH_MNT/foobar
60
61 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
62         | _filter_scratch
63
64 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
65         $SCRATCH_MNT/incr 2>&1 | _filter_scratch
66
67 echo "File digest in the original filesystem:"
68 md5sum $SCRATCH_MNT/incr/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/incr/foobar | _filter_scratch
81
82 status=0
83 exit