btrfs/079: fix failure to umount scratch fs due to running filefrag process
[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 _supported_os Linux
33 _require_test
34 _require_scratch
35 _require_btrfs_fs_feature "no_holes"
36 _require_btrfs_mkfs_feature "no-holes"
37 _require_xfs_io_command "fpunch"
38 _require_xfs_io_command "falloc" "-k"
39
40 send_files_dir=$TEST_DIR/btrfs-test-$seq
41
42 rm -f $seqres.full
43 rm -fr $send_files_dir
44 mkdir $send_files_dir
45
46 _scratch_mkfs "-O no-holes" >>$seqres.full 2>&1
47 _scratch_mount
48
49 # Create our test file with a prealloc extent that starts beyond its size.
50 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 500K" $SCRATCH_MNT/foobar | _filter_xfs_io
51 $XFS_IO_PROG -c "falloc -k 1200K 800K" $SCRATCH_MNT/foobar
52
53 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
54         | _filter_scratch
55
56 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
57         | _filter_scratch
58
59 # Now punch a hole that drops all the extents within the file's size.
60 $XFS_IO_PROG -c "fpunch 0 500K" $SCRATCH_MNT/foobar
61
62 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
63         | _filter_scratch
64
65 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
66         $SCRATCH_MNT/incr 2>&1 | _filter_scratch
67
68 echo "File digest in the original filesystem:"
69 md5sum $SCRATCH_MNT/incr/foobar | _filter_scratch
70
71 # Now recreate the filesystem by receiving both send streams and verify we get
72 # the same file content that the original filesystem had.
73 _scratch_unmount
74 _scratch_mkfs >>$seqres.full 2>&1
75 _scratch_mount
76
77 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
78 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
79
80 echo "File digest in the new filesystem:"
81 md5sum $SCRATCH_MNT/incr/foobar | _filter_scratch
82
83 status=0
84 exit