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# When the destination file is mmaped and is already cached we need to 30# update mmaped pages after successful clone. 31# 32# STRATEGY: 33# 1. Create a pool. 34# 2. Create a two test files with random content. 35# 3. mmap the files, read them and clone from one to the other using 36# clone_mmap_cached. 37# 4. clone_mmap_cached also verifies if the content of the destination 38# file was updated while reading it from mmaped memory. 39# 40 41verify_runnable "global" 42 43VDIR=$TEST_BASE_DIR/disk-bclone 44VDEV="$VDIR/a" 45 46function cleanup 47{ 48 datasetexists $TESTPOOL && destroy_pool $TESTPOOL 49 rm -rf $VDIR 50} 51 52log_onexit cleanup 53 54log_assert "Test for clone into mmaped and cached file" 55 56log_must rm -rf $VDIR 57log_must mkdir -p $VDIR 58log_must truncate -s 1G $VDEV 59 60log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $VDEV 61log_must zfs create $TESTPOOL/$TESTFS 62 63for opts in "--" "-i" "-o" "-io" 64do 65 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/src bs=1M count=1 66 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/dst bs=1M count=1 67 68 # Clear cache. 69 log_must zpool export $TESTPOOL 70 log_must zpool import -d $VDIR $TESTPOOL 71 72 log_must clone_mmap_cached $opts /$TESTPOOL/$TESTFS/src /$TESTPOOL/$TESTFS/dst 73 74 sync_pool $TESTPOOL 75 log_must sync 76 77 log_must have_same_content /$TESTPOOL/$TESTFS/src /$TESTPOOL/$TESTFS/dst 78 blocks=$(get_same_blocks $TESTPOOL/$TESTFS src $TESTPOOL/$TESTFS dst) 79 # FreeBSD's seq(1) leaves a trailing space, remove it with sed(1). 80 log_must [ "$blocks" = "$(seq -s " " 0 7 | sed 's/ $//')" ] 81done 82 83log_pass "Clone properly updates mmapped and cached pages" 84