2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
7 # Check if creating a sparse copy ("reflink") of a file on btrfs
8 # expectedly fails when it's done between different filesystems or
9 # different mount points of the same filesystem.
11 # For both situations, these actions are executed:
12 # - Copy a file with the reflink=auto option.
13 # A normal copy should be created.
14 # - Copy a file with the reflink=always option. Should result in
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
23 status=1 # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
32 # get standard environment, filters and checks
37 # real QA test starts here
45 reflink_test_dir=$TEST_DIR/test-$seq
46 rm -rf $reflink_test_dir
47 mkdir $reflink_test_dir
51 _scratch_mkfs > /dev/null 2>&1
53 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/original >> $seqres.full
57 # auto reflink, should fall back to non-reflink
60 cp --reflink=auto $1 $2
61 md5sum $1 | _filter_testdir_and_scratch
62 md5sum $2 | _filter_testdir_and_scratch
64 # always reflink, should fail outright
66 echo "reflink=always:"
67 cp --reflink=always $1 $2 >> $seqres.full 2>&1 || echo "cp reflink failed"
69 # The failed target actually gets created by cp:
70 ls $2 | _filter_testdir_and_scratch
73 echo "test reflinks across different devices"
74 _create_reflinks $SCRATCH_MNT/original $reflink_test_dir/copy
76 echo "test reflinks across different mountpoints of same device"
77 rm -rf $reflink_test_dir/*
78 _mount $SCRATCH_DEV $reflink_test_dir
79 _create_reflinks $SCRATCH_MNT/original $reflink_test_dir/copy
80 $UMOUNT_PROG $reflink_test_dir