Files
apfstests/tests/btrfs/052
T
David Disseldorp 20bde4fef1 common: rename _require_btrfs_cloner to _require_cloner
src/cloner.c is no longer Btrfs specific, so use a generic name.

Signed-off-by: David Disseldorp <ddiss@suse.de>
Acked-by:  Steve French <smfrench@gmail.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2014-12-12 11:23:06 +11:00

172 lines
5.4 KiB
Bash
Executable File

#! /bin/bash
# FS QA Test No. btrfs/052
#
# Verify that the btrfs ioctl clone operation can operate on the same
# file as a source and target. That is, clone extents within the same
# file.
#
#-----------------------------------------------------------------------
# Copyright (c) 2014 Filipe Manana. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#-----------------------------------------------------------------------
#
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()
{
rm -fr $tmp
}
# get standard environment, filters and checks
. ./common/rc
. ./common/filter
# real QA test starts here
_supported_fs btrfs
_supported_os Linux
_require_scratch
_require_cloner
_need_to_be_root
rm -f $seqres.full
test_btrfs_clone_same_file()
{
if [ -z $1 ]; then
MOUNT_OPTIONS=""
else
MOUNT_OPTIONS="-O $1"
fi
_scratch_mkfs >/dev/null 2>&1
_scratch_mount $MOUNT_OPTIONS
# Create a file with 5 extents, 4 of 8Kb each and 1 of 64Kb.
$XFS_IO_PROG -f -c "pwrite -S 0x01 -b 8192 0 8192" $SCRATCH_MNT/foo \
| _filter_xfs_io
sync
$XFS_IO_PROG -c "pwrite -S 0x02 -b 8192 8192 8192" $SCRATCH_MNT/foo \
| _filter_xfs_io
sync
$XFS_IO_PROG -c "pwrite -S 0x03 -b 8192 16384 8192" $SCRATCH_MNT/foo \
| _filter_xfs_io
sync
$XFS_IO_PROG -c "pwrite -S 0x04 -b 8192 24576 8192" $SCRATCH_MNT/foo \
| _filter_xfs_io
sync
$XFS_IO_PROG -c "pwrite -S 0x05 -b 65536 32768 65536" $SCRATCH_MNT/foo \
| _filter_xfs_io
sync
# Digest of initial content.
md5sum $SCRATCH_MNT/foo | _filter_scratch
# Same source and target ranges - must fail.
$CLONER_PROG -s 8192 -d 8192 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
# Check file content didn't change.
md5sum $SCRATCH_MNT/foo | _filter_scratch
# Intersection between source and target ranges - must fail too.
$CLONER_PROG -s 4096 -d 8192 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
# Check file content didn't change.
md5sum $SCRATCH_MNT/foo | _filter_scratch
# Clone an entire extent from a higher range to a lower range.
$CLONER_PROG -s 24576 -d 0 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
# Check entire file, the 8Kb block at offset 0 now has the same content
# as the 8Kb block at offset 24576.
od -t x1 $SCRATCH_MNT/foo
# Clone an entire extent from a lower range to a higher range.
$CLONER_PROG -s 8192 -d 16384 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
# Check entire file, the 8Kb block at offset 0 now has the same content
# as the 8Kb block at offset 24576, and the 8Kb block at offset 16384
# now has the same content as the 8Kb block at offset 8192.
od -t x1 $SCRATCH_MNT/foo
# Now clone 1 extent and an half into the file range starting at offset
# 65536. So we get the second half of the extent at offset 16384 and the
# whole extent at 24576 cloned into the middle of the 64Kb extent that
# starts at file offset 32768. This makes the clone ioctl process more
# extent items from the b+tree and forces a split of the large 64Kb
# extent at the end of the file.
$CLONER_PROG -s 20480 -d 65536 -l 12288 $SCRATCH_MNT/foo \
$SCRATCH_MNT/foo
# Check entire file. Besides the previous changes, we now should have
# 4096 bytes with the value 0x02 at file offset 65536, and 8192 bytes
# with value 0x04 at the file offset 69632. The ranges [32768, 65536[
# and [77824, 98304[ should remain with all bytes having the value 0x05.
od -t x1 $SCRATCH_MNT/foo
# Now update 8Kb of data at offset 0. The extent at this position is a
# clone of the extent at offset 24576. Check that writing to this offset
# doesn't change data at offset 24576.
$XFS_IO_PROG -c "pwrite -S 0xff -b 8192 0 8192" $SCRATCH_MNT/foo \
| _filter_xfs_io
od -t x1 $SCRATCH_MNT/foo
# Check that after defragmenting the file and re-mounting, the file
# content remains exactly the same as before.
_run_btrfs_util_prog filesystem defragment $SCRATCH_MNT/foo
_scratch_remount
od -t x1 $SCRATCH_MNT/foo
# Verify that there are no consistency errors.
_check_scratch_fs
}
# For any of the tests below, regardless of cow/nodatacow/compression, the
# results as observed by an application/user should be exactly the same.
echo "Testing with a cow file (default)"
test_btrfs_clone_same_file
_scratch_unmount
echo "Testing with a nocow file (-O nodatacow)"
test_btrfs_clone_same_file "nodatacow"
_scratch_unmount
echo "Testing with a cow file and lzo compression"
test_btrfs_clone_same_file "compress-force=lzo"
_scratch_unmount
echo "Testing with a cow file and zlib compression"
test_btrfs_clone_same_file "compress-force=zlib"
_scratch_unmount
echo "Testing with a nocow file and lzo compression"
test_btrfs_clone_same_file "nodatacow,compress-force=lzo"
_scratch_unmount
echo "Testing with a nocow file and zlib compression"
test_btrfs_clone_same_file "nodatacow,compress-force=zlib"
status=0
exit