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# A PANIC is triggered in dbuf_redirty() if we clone a file, mmap it 30# and write from the map into the file. PR#15656 fixes this scenario. 31# This scenario also causes data corruption on FreeBSD, which is fixed 32# by PR#15665. 33# 34# STRATEGY: 35# 1. Create a pool 36# 2. Create a test file 37# 3. Clone, mmap and write to the file using clone_mmap_write 38# 5. Synchronize cached writes 39# 6. Verfiy data is correctly written to the disk 40# 41 42verify_runnable "global" 43 44VDIR=$TEST_BASE_DIR/disk-bclone 45VDEV="$VDIR/a" 46 47function cleanup 48{ 49 datasetexists $TESTPOOL && destroy_pool $TESTPOOL 50 rm -rf $VDIR 51} 52 53log_onexit cleanup 54 55log_assert "Test for clone, mmap and write scenario" 56 57log_must rm -rf $VDIR 58log_must mkdir -p $VDIR 59log_must truncate -s 1G $VDEV 60 61log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $VDEV 62log_must zfs create $TESTPOOL/$TESTFS 63 64log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/file bs=1M count=512 65log_must clone_mmap_write /$TESTPOOL/$TESTFS/file /$TESTPOOL/$TESTFS/clone 66 67sync_pool $TESTPOOL 68log_must sync 69 70log_must have_same_content /$TESTPOOL/$TESTFS/file /$TESTPOOL/$TESTFS/clone 71blocks=$(get_same_blocks $TESTPOOL/$TESTFS file $TESTPOOL/$TESTFS clone) 72# FreeBSD's seq(1) leaves a trailing space, remove it with sed(1). 73log_must [ "$blocks" = "$(seq -s " " 1 4095 | sed 's/ $//')" ] 74 75log_pass "Clone, mmap and write does not cause data corruption or " \ 76 "trigger panic" 77