summaryrefslogtreecommitdiff
path: root/tests/btrfs/029
blob: 9b56cc73f818a09db1e11139e97aa03c560ef1b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2014, Oracle and/or its affiliates.  All Rights Reserved.
#
# FS QA Test No. 029
#
# Check if creating a sparse copy ("reflink") of a file on btrfs
# expectedly fails when it's done between different filesystems but
# not for different mount points of the same filesystem.
#
# For both situations, these actions are executed:
#    - Copy a file with the reflink=auto option.
#      A normal copy should be created.
#    - Copy a file with the reflink=always option. Should result in
#      error for different file systems, but succeed for the same fs
#      but different mount points.
#
. ./common/preamble
_begin_fstest auto quick clone

. ./common/filter
. ./common/reflink

_supported_fs btrfs

_require_test
_require_scratch
_require_cp_reflink

reflink_test_dir=$TEST_DIR/test-$seq
rm -rf $reflink_test_dir
mkdir $reflink_test_dir
orig_file=$SCRATCH_MNT/original
copy_file=$reflink_test_dir/copy

_scratch_mkfs > /dev/null 2>&1
_scratch_mount
$XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $orig_file >> $seqres.full

echo "test reflinks across different devices"
# auto reflink, should fall back to non-reflink
rm -rf $copy_file
echo "reflink=auto:"
cp --reflink=auto $orig_file $copy_file
md5sum $orig_file | _filter_testdir_and_scratch
md5sum $copy_file | _filter_testdir_and_scratch

# always reflink, should fail outright
rm -rf $copy_file
echo "reflink=always:"
cp --reflink=always $orig_file $copy_file >> $seqres.full 2>&1 || echo "cp reflink failed"

# The failed target gets created with zero sizes by cp(1) version 8.32. But in
# older cp(1) version 8.30 target file is not created when the cp
# --reflink=always fails.
ls $copy_file >> $seqres.full 2>&1

echo "test reflinks across different mountpoints of same device"
rm -rf $reflink_test_dir/*
_mount $SCRATCH_DEV $reflink_test_dir

echo "reflink=auto:"
cp --reflink=auto $orig_file $copy_file
md5sum $orig_file | _filter_testdir_and_scratch
md5sum $copy_file | _filter_testdir_and_scratch

# always reflink, should fail outright
rm -rf $copy_file
echo "reflink=always:"
cp --reflink=always $orig_file $copy_file >> $seqres.full 2>&1 || echo "cp reflink failed"
md5sum $orig_file | _filter_testdir_and_scratch
md5sum $copy_file | _filter_testdir_and_scratch

$UMOUNT_PROG $reflink_test_dir

# success, all done
status=0
exit