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 2008 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28# 29# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 30# Copyright (c) 2020 by Lawrence Livermore National Security, LLC. 31# 32 33. $STF_SUITE/include/libtest.shlib 34. $STF_SUITE/tests/functional/replacement/replacement.cfg 35 36# 37# DESCRIPTION: 38# Replacing disks during I/O should pass for supported pools. 39# 40# STRATEGY: 41# 1. Create multidisk pools (stripe/mirror/draid) and 42# start some random I/O 43# 2. Replace a disk in the pool with another disk. 44# 3. Verify the integrity of the file system and the rebuilding. 45# 46# NOTE: Raidz does not support the sequential resilver (-s) option. 47# 48 49verify_runnable "global" 50 51function cleanup 52{ 53 if [[ -n "$child_pids" ]]; then 54 for wait_pid in $child_pids 55 do 56 kill $wait_pid 57 done 58 fi 59 60 if poolexists $TESTPOOL1; then 61 destroy_pool $TESTPOOL1 62 fi 63 64 [[ -e $TESTDIR ]] && log_must rm -rf $TESTDIR/* 65} 66 67log_assert "Replacing a disk with -r during I/O completes." 68 69options="" 70options_display="default options" 71 72log_onexit cleanup 73 74[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE " 75 76[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE " 77 78[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT " 79 80[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED " 81 82[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET " 83 84options="$options -r " 85 86[[ -n "$options" ]] && options_display=$options 87 88child_pids="" 89 90function replace_test 91{ 92 typeset -i iters=2 93 typeset -i index=0 94 typeset opt=$1 95 typeset disk1=$2 96 typeset disk2=$3 97 98 typeset i=0 99 while [[ $i -lt $iters ]]; do 100 log_note "Invoking file_trunc with: $options_display" 101 file_trunc $options $TESTDIR/$TESTFILE.$i & 102 typeset pid=$! 103 104 sleep 1 105 106 child_pids="$child_pids $pid" 107 ((i = i + 1)) 108 done 109 110 log_must zpool replace -sw $opt $TESTPOOL1 $disk1 $disk2 111 112 for wait_pid in $child_pids 113 do 114 kill $wait_pid 115 done 116 child_pids="" 117 118 log_must zpool export $TESTPOOL1 119 log_must zpool import -d $TESTDIR $TESTPOOL1 120 log_must zfs umount $TESTPOOL1/$TESTFS1 121 log_must zdb -cdui $TESTPOOL1/$TESTFS1 122 log_must zfs mount $TESTPOOL1/$TESTFS1 123 verify_pool $TESTPOOL1 124} 125 126specials_list="" 127i=0 128while [[ $i != 3 ]]; do 129 log_must truncate -s $MINVDEVSIZE $TESTDIR/$TESTFILE1.$i 130 specials_list="$specials_list $TESTDIR/$TESTFILE1.$i" 131 132 ((i = i + 1)) 133done 134 135# 136# Create a replacement disk special file. 137# 138log_must truncate -s $MINVDEVSIZE $TESTDIR/$REPLACEFILE 139 140for type in "" "mirror" "draid"; do 141 for op in "" "-f"; do 142 create_pool $TESTPOOL1 $type $specials_list 143 log_must zfs create $TESTPOOL1/$TESTFS1 144 log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1 145 146 replace_test "$opt" $TESTDIR/$TESTFILE1.1 $TESTDIR/$REPLACEFILE 147 148 log_must eval "zpool iostat -v $TESTPOOL1 | grep \"$REPLACEFILE\"" 149 150 destroy_pool $TESTPOOL1 151 log_must rm -rf /$TESTPOOL1 152 done 153done 154 155log_pass 156