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 31verify_runnable "global" 32 33claim="The copy_file_range syscall can clone parts of a file." 34 35log_assert $claim 36 37function cleanup 38{ 39 datasetexists $TESTPOOL && destroy_pool $TESTPOOL 40} 41 42log_onexit cleanup 43 44log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $DISKS 45 46log_must dd if=/dev/urandom of=/$TESTPOOL/file1 bs=128K count=4 47log_must sync_pool $TESTPOOL 48 49log_must dd if=/$TESTPOOL/file1 of=/$TESTPOOL/file2 bs=128K count=4 50log_must sync_pool $TESTPOOL 51 52log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2 53 54typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2) 55log_must [ "$blocks" = "" ] 56 57log_must clonefile -f /$TESTPOOL/file1 /$TESTPOOL/file2 131072 131072 262144 58log_must sync_pool $TESTPOOL 59 60log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2 61 62typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2) 63log_must [ "$blocks" = "1 2" ] 64 65log_pass $claim 66