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 by iXsystems, Inc. All rights reserved. 26# 27 28. $STF_SUITE/include/libtest.shlib 29. $STF_SUITE/tests/functional/block_cloning/block_cloning.kshlib 30 31# 32# DESCRIPTION: 33# Test for LWB buffer overflow with multiple VDEVs ZIL when 128KB 34# block write is split into two 68KB ones, trying to write maximum 35# sizes 128KB TX_CLONE_RANGE record with 1022 block pointers into 36# 68KB buffer. 37# 38# STRATEGY: 39# 1. Create a pool with multiple VDEVs ZIL 40# 2. Write maximum sizes TX_CLONE_RANGE record with 1022 block 41# pointers into 68KB buffer 42# 3. Sync TXG 43# 4. Clone the file 44# 5. Synchronize cached writes 45# 46 47verify_runnable "global" 48 49VDIR=$TEST_BASE_DIR/disk-bclone 50VDEV="$VDIR/a $VDIR/b $VDIR/c" 51LDEV="$VDIR/e $VDIR/f" 52 53function cleanup 54{ 55 datasetexists $TESTPOOL && destroy_pool $TESTPOOL 56 rm -rf $VDIR 57} 58 59log_onexit cleanup 60 61log_assert "Test for LWB buffer overflow with multiple VDEVs ZIL" 62 63log_must rm -rf $VDIR 64log_must mkdir -p $VDIR 65log_must truncate -s $MINVDEVSIZE $VDEV $LDEV 66 67log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $VDEV \ 68 log mirror $LDEV 69log_must zfs create -o recordsize=32K $TESTPOOL/$TESTFS 70# Each ZIL log entry can fit 130816 bytes for a block cloning operation, 71# so it can store 1022 block pointers. When LWB optimization is enabled, 72# an assert is hit when 128KB block write is split into two 68KB ones 73# for 2 SLOG devices 74log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/file1 bs=32K count=1022 \ 75 conv=fsync 76sync_pool $TESTPOOL 77log_must clonefile -f /$TESTPOOL/$TESTFS/file1 /$TESTPOOL/$TESTFS/file2 78log_must sync 79 80sync_pool $TESTPOOL 81log_must have_same_content /$TESTPOOL/$TESTFS/file1 /$TESTPOOL/$TESTFS/file2 82typeset blocks=$(get_same_blocks $TESTPOOL/$TESTFS file1 $TESTPOOL/$TESTFS file2) 83# FreeBSD's seq(1) leaves a trailing space, remove it with sed(1). 84log_must [ "$blocks" = "$(seq -s " " 0 1021 | sed 's/ $//')" ] 85 86log_pass "LWB buffer overflow is not triggered with multiple VDEVs ZIL" 87 88