mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
20bde4fef1
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>
166 lines
5.6 KiB
Bash
Executable File
166 lines
5.6 KiB
Bash
Executable File
#! /bin/bash
|
|
# FS QA Test No. btrfs/055
|
|
#
|
|
# Regression test for the btrfs ioctl clone operation when the source range
|
|
# contains hole(s) and the FS has the NO_HOLES feature enabled (file holes
|
|
# don't need file extent items in the btree to represent them).
|
|
#
|
|
# This issue is fixed by the following linux kernel btrfs patch:
|
|
#
|
|
# Btrfs: fix clone to deal with holes when NO_HOLES feature is enabled
|
|
#
|
|
#-----------------------------------------------------------------------
|
|
# 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
|
|
_require_btrfs_fs_feature "no_holes"
|
|
_require_btrfs_mkfs_feature "no-holes"
|
|
_need_to_be_root
|
|
|
|
rm -f $seqres.full
|
|
|
|
test_btrfs_clone_with_holes()
|
|
{
|
|
_scratch_mkfs "$1" >/dev/null 2>&1
|
|
_scratch_mount
|
|
|
|
# Create a file with 4 extents and 1 hole, all with a size of 8Kb each.
|
|
# The hole is in the range [16384, 24576[.
|
|
$XFS_IO_PROG -s -f -c "pwrite -S 0x01 -b 8192 0 8192" \
|
|
-c "pwrite -S 0x02 -b 8192 8192 8192" \
|
|
-c "pwrite -S 0x04 -b 8192 24576 8192" \
|
|
-c "pwrite -S 0x05 -b 8192 32768 8192" \
|
|
$SCRATCH_MNT/foo | _filter_xfs_io
|
|
|
|
# Clone destination file, 1 extent of 96kb.
|
|
$XFS_IO_PROG -s -f -c "pwrite -S 0xff -b 98304 0 98304" \
|
|
$SCRATCH_MNT/bar | _filter_xfs_io
|
|
|
|
# Clone 2nd extent, 8Kb hole and 3rd extent of foo into bar.
|
|
$CLONER_PROG -s 8192 -d 0 -l 24576 $SCRATCH_MNT/foo $SCRATCH_MNT/bar
|
|
|
|
# Verify both extents and the hole were cloned.
|
|
echo "1) Check both extents and the hole were cloned"
|
|
od -t x1 $SCRATCH_MNT/bar
|
|
|
|
# Cloning range starts at the middle of an hole.
|
|
$CLONER_PROG -s 20480 -d 32768 -l 12288 $SCRATCH_MNT/foo \
|
|
$SCRATCH_MNT/bar
|
|
|
|
# Verify that half of the hole and the following 8Kb extent were cloned.
|
|
echo "2) Check half hole and one 8Kb extent were cloned"
|
|
od -t x1 $SCRATCH_MNT/bar
|
|
|
|
# Cloning range ends at the middle of an hole.
|
|
$CLONER_PROG -s 0 -d 65536 -l 20480 $SCRATCH_MNT/foo $SCRATCH_MNT/bar
|
|
|
|
# Verify that 2 extents of 8kb and a 4kb hole were cloned.
|
|
echo "3) Check that 2 extents of 8kb eacg and a 4kb hole were cloned"
|
|
od -t x1 $SCRATCH_MNT/bar
|
|
|
|
# Create a 24Kb hole at the end of the source file (foo).
|
|
$XFS_IO_PROG -c "truncate 65536" $SCRATCH_MNT/foo
|
|
sync
|
|
|
|
# Now clone a range that overlaps that hole at the end of the foo file.
|
|
# It should clone the last 4Kb of the extent at offset 32768 and the
|
|
# first 8kb of the 24kb hole at the end of foo.
|
|
$CLONER_PROG -s 36864 -d 86016 -l 12288 $SCRATCH_MNT/foo \
|
|
$SCRATCH_MNT/bar
|
|
|
|
# Verify that the second half of the 8Kb extent at offset 32768 of foo
|
|
# and the first 8Kb of the 24kb hole of foo were cloned into bar.
|
|
echo "4) Check that 4kb of 1 extent and 8Kb of an hole were cloned"
|
|
od -t x1 $SCRATCH_MNT/bar
|
|
|
|
# Clone the same range as before, but clone it into a different offset
|
|
# of the target (bar) such that it increases the size of the target
|
|
# by 8Kb.
|
|
$CLONER_PROG -s 36864 -d 94208 -l 12288 $SCRATCH_MNT/foo \
|
|
$SCRATCH_MNT/bar
|
|
|
|
# Verify that the second half of the 8Kb extent at offset 32768 of foo
|
|
# and the first 8Kb of the 24kb hole of foo were cloned into bar at
|
|
# bar's offset 94208 and that bar's size increased by 8Kb.
|
|
echo "5) Check that 4kb of 1 extent and 8Kb of an hole were cloned and file size increased"
|
|
od -t x1 $SCRATCH_MNT/bar
|
|
|
|
# Create a new completely sparse file (no extents, it's a big hole).
|
|
$XFS_IO_PROG -f -c "truncate 100000" $SCRATCH_MNT/qwerty
|
|
sync
|
|
|
|
# Test cloning a range from the sparse file to the bar file without
|
|
# increasing bar's size.
|
|
$CLONER_PROG -s 4096 -d 0 -l 8192 $SCRATCH_MNT/qwerty $SCRATCH_MNT/bar
|
|
|
|
# First 8Kb of bar should now be zeroes.
|
|
echo "6) Check that 8kb of the hole were cloned"
|
|
od -t x1 $SCRATCH_MNT/bar
|
|
|
|
# Test cloning a range from the sparse file to the end of the bar file.
|
|
# The bar file currently has a size of 106496 bytes.
|
|
$CLONER_PROG -s 0 -d 106496 -l 32768 $SCRATCH_MNT/qwerty \
|
|
$SCRATCH_MNT/bar
|
|
|
|
# Verify bar's size increased to 106496 + 32768 bytes (136Kb), and its
|
|
# last 32768 bytes are all zeroes.
|
|
echo "7) Check that 32kb of the hole were cloned and the file size increased"
|
|
od -t x1 $SCRATCH_MNT/bar
|
|
|
|
# Verify that there are no consistency errors.
|
|
_check_scratch_fs
|
|
}
|
|
|
|
# Regardless of the NO_HOLES feature being enabled or not, the test results
|
|
# should be exactly the same for both cases.
|
|
|
|
echo "Testing without the NO_HOLES feature"
|
|
# As of btrfs-progs 3.14.x, the no-holes feature isn't enabled by default.
|
|
# But explicitly disable it at mkfs time as it might be enabled by default
|
|
# in future versions.
|
|
test_btrfs_clone_with_holes "-O ^no-holes"
|
|
|
|
_scratch_unmount
|
|
|
|
echo "Testing with the NO_HOLES feature enabled"
|
|
test_btrfs_clone_with_holes "-O no-holes"
|
|
|
|
status=0
|
|
exit
|