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 40if is_linux && [[ $(linux_version) -lt $(linux_version "4.5") ]]; then 41 log_unsupported "copy_file_range not available before Linux 4.5" 42fi 43 44claim="The first clone at a large offset is functional" 45 46log_assert $claim 47 48function cleanup 49{ 50 datasetexists $TESTPOOL && destroy_pool $TESTPOOL 51} 52 53log_onexit cleanup 54 55# 56# 1. Create dataset. 57# 58log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $DISKS 59sync_pool $TESTPOOL 60 61# 62# 2. Populate the source file with 1024 blocks at 1024 block offset. 63# 64log_must dd if=/dev/urandom of=/$TESTPOOL/file1 \ 65 oflag=sync bs=128k count=1024 seek=1024 66sync_pool $TESTPOOL 67 68# 69# 3. Clone 1024 blocks at a 1024-block offset. 70# 71log_must clonefile -f /$TESTPOOL/file1 /$TESTPOOL/file2 134217728 134217728 \ 72 134217728 73sync_pool $TESTPOOL 74 75# 76# 4. Compare the cloned file with the original file. 77# 78log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2 79typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2) 80 81# FreeBSD's seq(1) leaves a trailing space, remove it with sed(1). 82log_must [ "$blocks" = "$(seq -s " " 0 1023 | sed 's/ $//')" ] 83 84log_pass $claim 85