#! /bin/bash # SPDX-License-Identifier: GPL-2.0 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved. # # FS QA Test No. 203 # # Test that an incremental send operation works correctly when a file has shared # extents with itself in the send snapshot, with a hole between them, and the # file size has increased in the send snapshot. # seq=`basename $0` seqres=$RESULT_DIR/$seq echo "QA output created by $seq" tmp=/tmp/$$ status=1 # failure is the default! trap "_cleanup; exit \$status" 0 1 2 3 15 _cleanup() { cd / rm -f $tmp.* rm -fr $send_files_dir } # get standard environment, filters and checks . ./common/rc . ./common/filter . ./common/reflink # real QA test starts here _supported_fs btrfs _require_test _require_scratch_reflink send_files_dir=$TEST_DIR/btrfs-test-$seq rm -f $seqres.full rm -fr $send_files_dir mkdir $send_files_dir _scratch_mkfs >>$seqres.full 2>&1 _scratch_mount # Create our test file with a size of 64K in the parent snapshot. # After the parent snapshot is created, we will increase its size and then clone # one of its extents into a different offset and leave a hole between the shared # extents. The shared extents will be located at offsets greater then size of the # file in the parent snapshot. $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 64K" $SCRATCH_MNT/foobar | _filter_xfs_io $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \ | _filter_scratch $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \ | _filter_scratch # Create a 320K extent at file offset 512K, with chunks of 64K having different # content (to check cloning operations from send refer to the correct ranges). # After that clone a range that includes a hole and a part of the extent created # before - the clone range starts at an offset (448K) lower then the extent's # offset (512K). We want to see the existence of the hole doesn't confuse the # kernel's send code to send an invalid clone operation (with a source range # going beyond the file's current size). The hole that confused send to issue # an invalid clone operation spans the file range from offset 384K to 512K. # # Use offsets and ranges that are aligned to 64K, so that the test can run on # machines with any page size (and therefore block size). # $XFS_IO_PROG -c "pwrite -S 0xab 512K 64K" \ -c "pwrite -S 0xcd 576K 64K" \ -c "pwrite -S 0xef 640K 64K" \ -c "pwrite -S 0x64 704K 64K" \ -c "pwrite -S 0x73 768K 64K" \ -c "reflink $SCRATCH_MNT/foobar 448K 192K 192K" \ $SCRATCH_MNT/foobar | _filter_xfs_io $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \ | _filter_scratch $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \ $SCRATCH_MNT/incr 2>&1 | _filter_scratch echo "File foobar digest in the original filesystem:" _md5_checksum $SCRATCH_MNT/incr/foobar # Now recreate the filesystem by receiving both send streams and verify we get # the same file contents that the original filesystem had. _scratch_unmount _scratch_mkfs >>$seqres.full 2>&1 _scratch_mount $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT echo "File foobar digest in the new filesystem:" _md5_checksum $SCRATCH_MNT/incr/foobar status=0 exit