common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / btrfs / 186
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. 186
6 #
7 # Test that if we have a subvolume/snapshot that is writable, has a file with
8 # unflushed delalloc (buffered writes not yet flushed), turn the subvolume to
9 # readonly mode and then use it for send a operation, the send stream will
10 # contain the delalloc data - that is, no data loss happens.
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_command "property"
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 subvolume.
47 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/sv | _filter_scratch
48
49 # Create our test file with some delalloc data.
50 $XFS_IO_PROG -f -c "pwrite -S 0xea 0 108K" $SCRATCH_MNT/sv/foo | _filter_xfs_io
51
52 # Turn our subvolume to RO so that it can be used for a send operation.
53 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv ro true
54
55 # Create the send stream.
56 $BTRFS_UTIL_PROG send -f $send_files_dir/sv.send $SCRATCH_MNT/sv 2>&1 \
57     | _filter_scratch
58
59 echo "File content in the original filesystem:"
60 od -t x1 -A d $SCRATCH_MNT/sv/foo
61
62 # Recreate the filesystem and apply the send stream and verify no data was lost.
63 _scratch_unmount
64 _scratch_mkfs >>$seqres.full 2>&1
65 _scratch_mount
66
67 $BTRFS_UTIL_PROG receive -f $send_files_dir/sv.send $SCRATCH_MNT
68
69 echo "File content in the new filesystem:"
70 od -t x1 -A d $SCRATCH_MNT/sv/foo
71
72 status=0
73 exit