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 http://www.opensolaris.org/os/licensing. 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# 24# Copyright (c) 2021 by vStack. All rights reserved. 25# 26 27. $STF_SUITE/include/libtest.shlib 28. $STF_SUITE/tests/functional/cli_root/zfs_wait/zfs_wait.kshlib 29 30# 31# DESCRIPTION: 32# Check raidz expansion is able to work correctly under i/o load. 33# 34# STRATEGY: 35# 1. Create block device files for the test raidz pool 36# 2. For each parity value [1..3] 37# - create raidz pool with minimum block device files required 38# - create couple of datasets with different recordsize and fill it 39# - set a max reflow value near pool capacity 40# - wait for reflow to reach this max 41# - verify pool 42# - set reflow bytes to max value to complete the expansion 43 44typeset -r devs=10 45typeset -r dev_size_mb=256 46 47typeset -a disks 48 49embedded_slog_min_ms=$(get_tunable EMBEDDED_SLOG_MIN_MS) 50 51function cleanup 52{ 53 poolexists "$TESTPOOL" && zpool status -v "$TESTPOOL" 54 poolexists "$TESTPOOL" && log_must_busy zpool destroy "$TESTPOOL" 55 56 for i in {0..$devs}; do 57 log_must rm -f "$TEST_BASE_DIR/dev-$i" 58 done 59 60 log_must set_tunable32 EMBEDDED_SLOG_MIN_MS $embedded_slog_min_ms 61 log_must set_tunable64 RAIDZ_EXPAND_MAX_REFLOW_BYTES 0 62} 63 64function wait_expand_paused 65{ 66 oldcopied='0' 67 newcopied='1' 68 # wait until reflow copied value stops changing 69 while [[ $oldcopied != $newcopied ]]; do 70 oldcopied=$newcopied 71 sleep 1 72 newcopied=$(zpool status $TESTPOOL | \ 73 grep 'copied out of' | \ 74 awk '{print $1}') 75 done 76} 77 78log_onexit cleanup 79 80log_must set_tunable32 EMBEDDED_SLOG_MIN_MS 99999 81 82# Disk files which will be used by pool 83for i in {0..$(($devs))}; do 84 device=$TEST_BASE_DIR/dev-$i 85 log_must truncate -s ${dev_size_mb}M $device 86 disks[${#disks[*]}+1]=$device 87done 88 89nparity=$((RANDOM%(3) + 1)) 90raid=raidz$nparity 91pool=$TESTPOOL 92opts="-o cachefile=none" 93 94log_must zpool create -f $opts $pool $raid ${disks[1..$(($nparity+1))]} 95 96log_must zfs create -o recordsize=8k $pool/fs 97log_must fill_fs /$pool/fs 1 256 100 1024 R 98 99log_must zfs create -o recordsize=128k $pool/fs2 100log_must fill_fs /$pool/fs2 1 256 100 1024 R 101 102for disk in ${disks[$(($nparity+2))..$devs]}; do 103 log_must mkfile -n 400m /$pool/fs/file 104 log_bkgrnd randwritecomp /$pool/fs/file 250 105 pid0=$! 106 107 # start some random writes in the background during expansion 108 log_must mkfile -n 400m /$pool/fs2/file2 109 log_bkgrnd randwritecomp /$pool/fs2/file2 250 110 pid1=$! 111 sleep 10 112 113 # Pause at half total bytes to be copied for expansion 114 reflow_size=$(get_pool_prop allocated $pool) 115 log_note need to reflow $reflow_size bytes 116 pause=$((reflow_size/2)) 117 log_must set_tunable64 RAIDZ_EXPAND_MAX_REFLOW_BYTES $pause 118 119 log_must zpool attach $pool ${raid}-0 $disk 120 wait_expand_paused 121 122 kill_if_running $pid0 123 kill_if_running $pid1 124 125 log_must zpool scrub -w $pool 126 127 log_must check_pool_status $pool "errors" "No known data errors" 128 log_must check_pool_status $pool "scan" "with 0 errors" 129 log_must check_pool_status $pool "scan" "repaired 0B" 130 131 # Set pause past largest possible value for this pool 132 pause=$((devs*dev_size_mb*1024*1024)) 133 log_must set_tunable64 RAIDZ_EXPAND_MAX_REFLOW_BYTES $pause 134 135 log_must zpool wait -t raidz_expand $pool 136done 137 138log_must zpool destroy "$pool" 139 140log_pass "raidz expansion test succeeded." 141 142