summaryrefslogtreecommitdiff
path: root/tests/btrfs/311
blob: 9899396521648d7c39534361f7c98428b184e9e1 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2024 Oracle. All Rights Reserved.
#
# FS QA Test 311
#
# Mount the device twice check if the reflink works, this helps to
# ensure device is mounted as the same device.
#
. ./common/preamble
_begin_fstest auto quick subvol tempfsid

# Override the default cleanup function.
_cleanup()
{
	cd /
	$UMOUNT_PROG $mnt1 > /dev/null 2>&1
	rm -r -f $tmp.*
	rm -r -f $mnt1
}

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

_supported_fs btrfs
_require_cp_reflink
_require_scratch
_require_btrfs_fs_feature temp_fsid

mnt1=$TEST_DIR/$seq/mnt1
mkdir -p $mnt1

same_dev_mount()
{
	echo ---- $FUNCNAME ----

	_scratch_mkfs >> $seqres.full 2>&1

	_scratch_mount
	$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/foo | \
								_filter_xfs_io

	echo Mount the device again to a different mount point
	_mount $SCRATCH_DEV $mnt1

	_cp_reflink $SCRATCH_MNT/foo $mnt1/bar
	echo Checksum of reflinked files
	md5sum $SCRATCH_MNT/foo | _filter_scratch
	md5sum $mnt1/bar | _filter_test_dir

	check_fsid $SCRATCH_DEV
}

same_dev_subvol_mount()
{
	echo ---- $FUNCNAME ----
	_scratch_mkfs >> $seqres.full 2>&1

	_scratch_mount
	$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol | _filter_scratch

	$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/subvol/foo | \
								_filter_xfs_io

	echo Mounting a subvol
	_mount -o subvol=subvol $SCRATCH_DEV $mnt1

	_cp_reflink $SCRATCH_MNT/subvol/foo $mnt1/bar
	echo Checksum of reflinked files
	md5sum $SCRATCH_MNT/subvol/foo | _filter_scratch
	md5sum $mnt1/bar | _filter_test_dir

	check_fsid $SCRATCH_DEV
}

same_dev_mount

_scratch_unmount
_cleanup
mkdir -p $mnt1

same_dev_subvol_mount

# success, all done
status=0
exit