Re: [PATCH v2] fstests: regression test for btrfs file range cloning

2015-04-07 Thread Josef Bacik

On 04/02/2015 06:49 AM, Filipe Manana wrote:

Test btrfs file range cloning with the same file as a source and
destination.

This tests a specific scenario where the extent layout of the file
confused the clone ioctl implementation making it return -EEXIST to
userspace. This issue was fixed by the following linux kernel patch:

Btrfs: fix range cloning when same inode used as source and destination

Signed-off-by: Filipe Manana fdman...@suse.com


Reviewed-by: Josef Bacik jba...@fb.com

Thanks,

Josef
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] fstests: regression test for btrfs file range cloning

2015-04-02 Thread Filipe Manana
Test btrfs file range cloning with the same file as a source and
destination.

This tests a specific scenario where the extent layout of the file
confused the clone ioctl implementation making it return -EEXIST to
userspace. This issue was fixed by the following linux kernel patch:

   Btrfs: fix range cloning when same inode used as source and destination

Signed-off-by: Filipe Manana fdman...@suse.com
---

V2: Rebased against latest master, which implied changing the test's number,
and added steps to test for the case where different source and destination
files are used, just to verify if produces exactly the same result as the
case where the same file is used as source and destination.

 tests/btrfs/088 | 120 
 tests/btrfs/088.out |  20 +
 tests/btrfs/group   |   1 +
 3 files changed, 141 insertions(+)
 create mode 100755 tests/btrfs/088
 create mode 100644 tests/btrfs/088.out

diff --git a/tests/btrfs/088 b/tests/btrfs/088
new file mode 100755
index 000..ac0a459
--- /dev/null
+++ b/tests/btrfs/088
@@ -0,0 +1,120 @@
+#! /bin/bash
+# FS QA Test No. btrfs/088
+#
+# Test btrfs file range cloning with the same file as a source and destination.
+#
+# This tests a specific scenario where the extent layout of the file confused
+# the clone ioctl implementation making it return -EEXIST to userspace.
+# This issue was fixed by the following linux kernel patch:
+#
+#Btrfs: fix range cloning when same inode used as source and destination
+#
+#---
+# Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
+# Author: Filipe Manana fdman...@suse.com
+#
+# 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 -f $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
+
+# Create a file with an extent layout that confused the btrfs clone ioctl
+# implementation. The first extent item that is cloned by the second call
+# to the cloner program will have only a trailing part of it referenced by
+# a new extent item, since the source offset starts in the middle of that
+# extent. This confused the clone ioctl because after inserting this new
+# extent item it would immediately after process it again thinking it
+# corresponded to an extent that existed before - this made it attempt to
+# insert a duplicated extent item pointing to the same extent again, which
+# made it return an -EEXIST error to userspace and turn the filesystem to
+# readonly mode (since the current transaction got aborted).
+test_clone()
+{
+   local bs=$1
+
+   $XFS_IO_PROG -f -c pwrite -S 0xaa $((2 * $bs)) $((2 * $bs)) \
+   $SCRATCH_MNT/foo | _filter_xfs_io
+
+   $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/foo \
+   $SCRATCH_MNT/foo
+   $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/foo \
+   $SCRATCH_MNT/foo
+
+   echo File digest after clone operations using same file as source and 
destination
+   md5sum $SCRATCH_MNT/foo | _filter_scratch
+
+   # Test cloning using different source and destination files for the
+   # same exact data - it must produce the exact same result as the case
+   # before.
+   $XFS_IO_PROG -f -c pwrite -S 0xaa $((2 * $bs)) $((2 * $bs)) \
+   $SCRATCH_MNT/a | _filter_xfs_io
+   cp $SCRATCH_MNT/a $SCRATCH_MNT/b
+
+   $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/a \
+   $SCRATCH_MNT/b
+
+   cp $SCRATCH_MNT/b $SCRATCH_MNT/foo2
+   $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/b \
+   $SCRATCH_MNT/foo2
+
+   echo File digest after clone operations using different files as 
source and destination
+   md5sum $SCRATCH_MNT/foo2 | _filter_scratch
+
+}
+
+# Make sure the test passes offsets and lengths to the btrfs clone ioctl that
+#