mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
f6879e8a78
A bug in file cloning/reflinking was recently found that afftected both
Btrfs and XFS, which was caused by allowing the cloning of an eof block
into the middle of a file when the eof is not aligned to the filesystem's
block size.
The fix consists of returning the errno -EINVAL to user space when the
arguments passed to the system call lead to the scenario of data
corruption. However this overlaps with some cases where the system call,
in Btrfs, returned -EOPNOTSUPP, which means we are trying to reflink
inline extents. That is unsupported in Btrfs due to the huge complexity
of supporting it (due to copying and trimming inline extents, deal with
eventual compression, etc).
We have a few btrfs test cases that verify that attempts to clone inline
extents result in a failure, and are currently expecting an -EINVAL error
message from the output of the cloner program. So create a filter that
converts error messages related to the -EOPNOTSUPP error to messages
related to the -EINVAL error, so that the test can run both on patched
and non-patched linux kernels.
The corresponding btrfs patch for the linux kernel is titled:
"Btrfs: fix data corruption due to cloning of eof block"
And the VFS change that introduces the -EINVAL error return was introduced
by the following linux kernel commit (landed in 4.20-rc1):
07d19dc9fbe9 ("vfs: avoid problematic remapping requests into partial EOF block")
The btrfs patch is not yet in Linus' tree (it was submitted around the
same time as this change) and the VFS change was introduced in 4.10-rc1.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
69 lines
2.0 KiB
Bash
Executable File
69 lines
2.0 KiB
Bash
Executable File
#! /bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
# Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
|
|
#
|
|
# FSQA Test No. 096
|
|
#
|
|
# Test that we can not clone an inline extent into a non-zero file offset.
|
|
#
|
|
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 -f $tmp.*
|
|
}
|
|
|
|
# get standard environment, filters and checks
|
|
. ./common/rc
|
|
. ./common/filter
|
|
. ./common/filter.btrfs
|
|
|
|
# real QA test starts here
|
|
_supported_fs btrfs
|
|
_supported_os Linux
|
|
_require_scratch
|
|
_require_cloner
|
|
|
|
rm -f $seqres.full
|
|
|
|
_scratch_mkfs >>$seqres.full 2>&1
|
|
_scratch_mount
|
|
|
|
BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
|
|
|
|
# Create our test files. File foo has the same 2k of data at offset $BLOCK_SIZE
|
|
# as file bar has at its offset 0.
|
|
$XFS_IO_PROG -f -s -c "pwrite -S 0xaa 0 $BLOCK_SIZE" \
|
|
-c "pwrite -S 0xbb $BLOCK_SIZE 2k" \
|
|
-c "pwrite -S 0xcc $(($BLOCK_SIZE * 2)) $BLOCK_SIZE" \
|
|
$SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
|
|
|
|
# File bar consists of a single inline extent (2k in size).
|
|
$XFS_IO_PROG -f -s -c "pwrite -S 0xbb 0 2k" \
|
|
$SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
|
|
|
|
# Now call the clone ioctl to clone the extent of file bar into file
|
|
# foo at its $BLOCK_SIZE offset. This made file foo have an inline
|
|
# extent at offset $BLOCK_SIZE, something which the btrfs code can not
|
|
# deal with in future IO operations because all inline extents are
|
|
# supposed to start at an offset of 0, resulting in all sorts of
|
|
# chaos.
|
|
# So here we validate that the clone ioctl returns an EOPNOTSUPP or
|
|
# EINVAL which is what it returns for other cases dealing with inlined
|
|
# extents.
|
|
$CLONER_PROG -s 0 -d $BLOCK_SIZE -l 2048 \
|
|
$SCRATCH_MNT/bar $SCRATCH_MNT/foo | _filter_btrfs_cloner_error
|
|
|
|
# Because of the inline extent at offset $BLOCK_SIZE, the following
|
|
# write made the kernel crash with a BUG_ON().
|
|
$XFS_IO_PROG -c "pwrite -S 0xdd $(($BLOCK_SIZE + 2048)) 2k" \
|
|
$SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
|
|
|
|
status=0
|
|
exit
|