4 # Check if creating a sparse copy ("reflink") of a file on btrfs
5 # expectedly fails when it's done between different filesystems or
6 # different mount points of the same filesystem.
8 # For both situations, these actions are executed:
9 # - Copy a file with the reflink=auto option.
10 # A normal copy should be created.
11 # - Copy a file with the reflink=always option. Should result in
14 #-----------------------------------------------------------------------
15 # Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
17 # This program is free software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License as
19 # published by the Free Software Foundation.
21 # This program is distributed in the hope that it would be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write the Free Software Foundation,
28 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #-----------------------------------------------------------------------
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
37 status=1 # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
42 umount $SCRATCH_MNT &>/dev/null
47 # get standard environment, filters and checks
52 # real QA test starts here
60 SOURCE_DIR=$TEST_DIR/test-$seq
61 CROSS_DEV_DIR=$SCRATCH_MNT/test-$seq
62 # mount point & target for twice-mounted device
63 TEST_DIR2=$TEST_DIR/mount2
64 DUAL_MOUNT_DIR=$SCRATCH_MNT/test-bis-$seq
71 _scratch_mkfs > /dev/null 2>&1
72 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $SOURCE_DIR/original \
77 _filter_test_dir | _filter_scratch
82 # auto reflink, should fall back to non-reflink
85 cp --reflink=auto $SOURCE_DIR/original $1/copy
86 md5sum $SOURCE_DIR/original | _filter_testdirs
87 md5sum $1/copy | _filter_testdirs
89 # always reflink, should fail outright
91 echo "reflink=always:"
92 cp --reflink=always $SOURCE_DIR/original $1/copyfail > $seqres.full 2>&1 \
93 || echo "cp reflink failed"
95 # The failed target actually gets created by cp:
96 ls $1/copyfail | _filter_testdirs
99 echo "test reflinks across different devices"
101 _create_reflinks_to $CROSS_DEV_DIR
104 echo "test reflinks across different mountpoints of same device"
105 mount $TEST_DEV $SCRATCH_MNT || _fail "Couldn't double-mount $TEST_DEV"
106 _create_reflinks_to $DUAL_MOUNT_DIR