summaryrefslogtreecommitdiff
path: root/tests/btrfs/031
blob: 83a28e4cce5e82eeef47cc092574423f258e28b1 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2014, Oracle and/or its affiliates.  All Rights Reserved.
#
# FS QA Test No. 031
#
# Testing cross-subvolume sparse copy on btrfs
#    - Create two subvolumes, mount one of them
#    - Create a file on each (sub/root)volume,
#      reflink them on the other volumes
#    - Change one original and two reflinked files
#    - Move reflinked files between subvolumes
#
. ./common/preamble
_begin_fstest auto quick subvol clone

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

_supported_fs btrfs

_require_test
_require_scratch
_require_cp_reflink

_checksum_files()
{
	for f in file1 file2 file3; do
		echo "$f:"
		for d in $testdir1 $cross_mount_test_dir $subvol2; do
			_md5_checksum $d/$f
		done
	done
}

testdir1=$SCRATCH_MNT/test-$seq-1
testdir2=$SCRATCH_MNT/test-$seq-2
subvol1=$SCRATCH_MNT/subvol-$seq-1
subvol2=$SCRATCH_MNT/subvol-$seq-2
cross_mount_test_dir=$TEST_DIR/test-$seq

_scratch_mkfs > /dev/null 2>&1
_scratch_mount

mkdir $testdir1
mkdir $testdir2
$BTRFS_UTIL_PROG subvolume create $subvol1 >> $seqres.full
$BTRFS_UTIL_PROG subvolume create $subvol2 >> $seqres.full
rm -rf $cross_mount_test_dir
mkdir $cross_mount_test_dir

_mount -t btrfs -o subvol=subvol-$seq-1 $SCRATCH_DEV $cross_mount_test_dir

echo "Create initial files"
# #testdir1/file1 is very small and will be inlined
$XFS_IO_PROG -f -c 'pwrite -S 0x61 0 10' $testdir1/file1 \
    >> $seqres.full
$XFS_IO_PROG -f -c 'pwrite -S 0x62 0 13000' $cross_mount_test_dir/file2 \
    >> $seqres.full
$XFS_IO_PROG -f -c 'pwrite -S 0x63 0 17000' $subvol2/file3 \
    >> $seqres.full

echo "Create reflinks to the initial files on other subvolumes"
cp --reflink=always $testdir1/file1 $subvol1
cp --reflink=always $testdir1/file1 $subvol2
cp --reflink=always $subvol1/file2 $testdir1/
cp --reflink=always $subvol1/file2 $subvol2
cp --reflink=always $subvol2/file3 $testdir1/
cp --reflink=always $subvol2/file3 $subvol1

echo "Verify the reflinks"
_verify_reflink $cross_mount_test_dir/file2 $testdir1/file2
_verify_reflink $cross_mount_test_dir/file2 $subvol2/file2
_verify_reflink $subvol2/file3 $testdir1/file3
_verify_reflink $subvol2/file3 $cross_mount_test_dir/file3
echo "Verify the file contents:"
_checksum_files

echo -e "---\nOverwrite some files with new content"
$XFS_IO_PROG -c 'pwrite -S 0x64 0 20' $testdir1/file1 >> $seqres.full
$XFS_IO_PROG -c 'pwrite -S 0x66 0 21000' $subvol2/file2 >> $seqres.full
$XFS_IO_PROG -c 'pwrite -S 0x65 5000 5000' $cross_mount_test_dir/file3 \
    >> $seqres.full

echo -n "Verify that non-overwritten reflinks "
echo "still have the same data blocks"
_verify_reflink $testdir1/file2 $cross_mount_test_dir/file2
_verify_reflink $testdir1/file3 $subvol2/file3
echo "Verify the file contents:"
_checksum_files

echo -e "---\nShuffle files between directories"
mv $testdir1/file* $testdir2
mv $cross_mount_test_dir/file* $testdir1/
mv $subvol2/file* $cross_mount_test_dir/
mv $testdir2/file* $subvol2/

# No _verify_reflink here as data is copied when moving files
# between subvols
echo "Verify the file contents:"
_checksum_files

$UMOUNT_PROG $cross_mount_test_dir

# success, all done
status=0
exit