2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
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.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
23 rm -fr $send_files_dir
26 # get standard environment, filters and checks
30 # real QA test starts here
34 _require_btrfs_command "property"
36 send_files_dir=$TEST_DIR/btrfs-test-$seq
39 rm -fr $send_files_dir
42 _scratch_mkfs >>$seqres.full 2>&1
45 # Create our test subvolume.
46 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/sv | _filter_scratch
48 # Create our test file with some delalloc data.
49 $XFS_IO_PROG -f -c "pwrite -S 0xea 0 108K" $SCRATCH_MNT/sv/foo | _filter_xfs_io
51 # Turn our subvolume to RO so that it can be used for a send operation.
52 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv ro true
54 # Create the send stream.
55 $BTRFS_UTIL_PROG send -f $send_files_dir/sv.send $SCRATCH_MNT/sv 2>&1 \
58 echo "File content in the original filesystem:"
59 od -t x1 -A d $SCRATCH_MNT/sv/foo
61 # Recreate the filesystem and apply the send stream and verify no data was lost.
63 _scratch_mkfs >>$seqres.full 2>&1
66 $BTRFS_UTIL_PROG receive -f $send_files_dir/sv.send $SCRATCH_MNT
68 echo "File content in the new filesystem:"
69 od -t x1 -A d $SCRATCH_MNT/sv/foo