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. $STF_SUITE/include/libtest.shlib
25. $STF_SUITE/tests/functional/block_cloning/block_cloning.kshlib
26
27#
28# DESCRIPTION:
29#	Verify that cloning a file at a large offset is possible.
30#
31# STRATEGY:
32#   1. Create dataset.
33#   2. Populate the source file with 1024 blocks at 1024 block offset.
34#   3. Clone 1024 blocks at a 1024-block offset.
35#   4. Compare the cloned file with the original file.
36#
37
38verify_runnable "global"
39
40claim="The first clone at a large offset is functional"
41
42log_assert $claim
43
44function cleanup
45{
46	datasetexists $TESTPOOL && destroy_pool $TESTPOOL
47}
48
49log_onexit cleanup
50
51#
52# 1. Create dataset.
53#
54log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $DISKS
55sync_pool $TESTPOOL
56
57#
58# 2. Populate the source file with 1024 blocks at 1024 block offset.
59#
60log_must dd if=/dev/urandom of=/$TESTPOOL/file1 \
61    oflag=sync bs=128k count=1024 seek=1024
62sync_pool $TESTPOOL
63
64#
65# 3. Clone 1024 blocks at a 1024-block offset.
66#
67log_must clonefile -f /$TESTPOOL/file1 /$TESTPOOL/file2 134217728 134217728 \
68    134217728
69sync_pool $TESTPOOL
70
71#
72# 4. Compare the cloned file with the original file.
73#
74log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2
75typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2)
76
77# FreeBSD's seq(1) leaves a trailing space, remove it with sed(1).
78log_must [ "$blocks" = "$(seq -s " " 0 1023 | sed 's/ $//')" ]
79
80log_pass $claim
81