1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License (the "License").
8# You may not use this file except in compliance with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or https://opensource.org/licenses/CDDL-1.0.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23
24#
25# Copyright (c) 2023, Klara Inc.
26#
27
28. $STF_SUITE/include/libtest.shlib
29. $STF_SUITE/tests/functional/block_cloning/block_cloning.kshlib
30. $STF_SUITE/tests/functional/bclone/bclone_common.kshlib
31
32verify_runnable "global"
33
34verify_crossfs_block_cloning
35
36claim="The copy_file_range syscall can clone across datasets."
37
38log_assert $claim
39
40function cleanup
41{
42	datasetexists $TESTPOOL && destroy_pool $TESTPOOL
43}
44
45log_onexit cleanup
46
47log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $DISKS
48
49log_must zfs create $TESTPOOL/$TESTFS1
50log_must zfs create $TESTPOOL/$TESTFS2
51
52log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS1/file1 bs=128K count=4
53log_must sync_pool $TESTPOOL
54
55log_must \
56    clonefile -f /$TESTPOOL/$TESTFS1/file1 /$TESTPOOL/$TESTFS2/file2 0 0 524288
57log_must sync_pool $TESTPOOL
58
59log_must have_same_content /$TESTPOOL/$TESTFS1/file1 /$TESTPOOL/$TESTFS2/file2
60
61typeset blocks=$(get_same_blocks \
62  $TESTPOOL/$TESTFS1 file1 $TESTPOOL/$TESTFS2 file2)
63log_must [ "$blocks" = "0 1 2 3" ]
64
65log_pass $claim
66