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
51 # real QA test starts here
58 SOURCE_DIR=$TEST_DIR/test-$seq
59 CROSS_DEV_DIR=$SCRATCH_MNT/test-$seq
60 # mount point & target for twice-mounted device
61 TEST_DIR2=$TEST_DIR/mount2
62 DUAL_MOUNT_DIR=$SCRATCH_MNT/test-bis-$seq
70 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $SOURCE_DIR/original \
75 _filter_test_dir | _filter_scratch
80 # auto reflink, should fall back to non-reflink
83 cp --reflink=auto $SOURCE_DIR/original $1/copy
84 md5sum $SOURCE_DIR/original | _filter_testdirs
85 md5sum $1/copy | _filter_testdirs
87 # always reflink, should fail outright
89 echo "reflink=always:"
90 cp --reflink=always $SOURCE_DIR/original $1/copyfail \
91 2>&1 | _filter_testdirs
93 # The failed target actually gets created by cp:
94 ls $1/copyfail | _filter_testdirs
97 echo "test reflinks across different devices"
99 _create_reflinks_to $CROSS_DEV_DIR
102 echo "test reflinks across different mountpoints of same device"
103 mount $TEST_DEV $SCRATCH_MNT || _fail "Couldn't double-mount $TEST_DEV"
104 _create_reflinks_to $DUAL_MOUNT_DIR