1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or https://opensource.org/licenses/CDDL-1.0. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23. $STF_SUITE/include/libtest.shlib 24. $STF_SUITE/tests/functional/block_cloning/block_cloning.kshlib 25 26# 27# DESCRIPTION: 28# A PANIC is triggered in dbuf_redirty() if we clone a file, mmap it 29# and write from the map into the file. PR#15656 fixes this scenario. 30# This scenario also causes data corruption on FreeBSD, which is fixed 31# by PR#15665. 32# 33# STRATEGY: 34# 1. Create a pool 35# 2. Create a test file 36# 3. Clone, mmap and write to the file using clone_mmap_write 37# 5. Synchronize cached writes 38# 6. Verfiy data is correctly written to the disk 39# 40 41verify_runnable "global" 42 43if is_linux && [[ $(linux_version) -lt $(linux_version "4.5") ]]; then 44 log_unsupported "copy_file_range not available before Linux 4.5" 45fi 46 47VDIR=$TEST_BASE_DIR/disk-bclone 48VDEV="$VDIR/a" 49 50function cleanup 51{ 52 datasetexists $TESTPOOL && destroy_pool $TESTPOOL 53 rm -rf $VDIR 54} 55 56log_onexit cleanup 57 58log_assert "Test for clone, mmap and write scenario" 59 60log_must rm -rf $VDIR 61log_must mkdir -p $VDIR 62log_must truncate -s 1G $VDEV 63 64log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $VDEV 65log_must zfs create $TESTPOOL/$TESTFS 66 67log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/file bs=1M count=512 68log_must clone_mmap_write /$TESTPOOL/$TESTFS/file /$TESTPOOL/$TESTFS/clone 69 70sync_pool $TESTPOOL 71log_must sync 72 73log_must have_same_content /$TESTPOOL/$TESTFS/file /$TESTPOOL/$TESTFS/clone 74blocks=$(get_same_blocks $TESTPOOL/$TESTFS file $TESTPOOL/$TESTFS clone) 75# FreeBSD's seq(1) leaves a trailing space, remove it with sed(1). 76log_must [ "$blocks" = "$(seq -s " " 1 4095 | sed 's/ $//')" ] 77 78log_pass "Clone, mmap and write does not cause data corruption or " \ 79 "trigger panic" 80