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# Copyright (c) 2023, Rob Norris <robn@despairlabs.com> 27# 28 29. $STF_SUITE/include/libtest.shlib 30. $STF_SUITE/tests/functional/block_cloning/block_cloning.kshlib 31 32verify_runnable "global" 33 34claim="copy_file_range will fall back to copy when cloning not possible." 35 36log_assert $claim 37 38function cleanup 39{ 40 datasetexists $TESTPOOL && destroy_pool $TESTPOOL 41} 42 43log_onexit cleanup 44 45log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $DISKS 46 47log_must dd if=/dev/urandom of=/$TESTPOOL/file bs=128K count=4 48log_must sync_pool $TESTPOOL 49 50 51log_note "Copying entire file with copy_file_range" 52 53log_must clonefile -f /$TESTPOOL/file /$TESTPOOL/clone 0 0 524288 54log_must sync_pool $TESTPOOL 55 56log_must have_same_content /$TESTPOOL/file /$TESTPOOL/clone 57 58typeset blocks=$(get_same_blocks $TESTPOOL file $TESTPOOL clone) 59log_must [ "$blocks" = "0 1 2 3" ] 60 61 62log_note "Copying within a block with copy_file_range" 63 64log_must clonefile -f /$TESTPOOL/file /$TESTPOOL/clone 32768 32768 65536 65log_must sync_pool $TESTPOOL 66 67log_must have_same_content /$TESTPOOL/file /$TESTPOOL/clone 68 69typeset blocks=$(get_same_blocks $TESTPOOL file $TESTPOOL clone) 70log_must [ "$blocks" = "1 2 3" ] 71 72 73log_note "Copying across a block with copy_file_range" 74 75log_must clonefile -f /$TESTPOOL/file /$TESTPOOL/clone 327680 327680 131072 76log_must sync_pool $TESTPOOL 77 78log_must have_same_content /$TESTPOOL/file /$TESTPOOL/clone 79 80typeset blocks=$(get_same_blocks $TESTPOOL file $TESTPOOL clone) 81log_must [ "$blocks" = "1" ] 82 83log_pass $claim 84