1eda14cbcSMatt Macy#!/bin/ksh -p 2eda14cbcSMatt Macy# 3eda14cbcSMatt Macy# CDDL HEADER START 4eda14cbcSMatt Macy# 5eda14cbcSMatt Macy# The contents of this file are subject to the terms of the 6eda14cbcSMatt Macy# Common Development and Distribution License (the "License"). 7eda14cbcSMatt Macy# You may not use this file except in compliance with the License. 8eda14cbcSMatt Macy# 9eda14cbcSMatt Macy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10271171e0SMartin Matuska# or https://opensource.org/licenses/CDDL-1.0. 11eda14cbcSMatt Macy# See the License for the specific language governing permissions 12eda14cbcSMatt Macy# and limitations under the License. 13eda14cbcSMatt Macy# 14eda14cbcSMatt Macy# When distributing Covered Code, include this CDDL HEADER in each 15eda14cbcSMatt Macy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16eda14cbcSMatt Macy# If applicable, add the following below this CDDL HEADER, with the 17eda14cbcSMatt Macy# fields enclosed by brackets "[]" replaced with your own identifying 18eda14cbcSMatt Macy# information: Portions Copyright [yyyy] [name of copyright owner] 19eda14cbcSMatt Macy# 20eda14cbcSMatt Macy# CDDL HEADER END 21eda14cbcSMatt Macy# 22eda14cbcSMatt Macy 23eda14cbcSMatt Macy# 24eda14cbcSMatt Macy# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 25eda14cbcSMatt Macy# Use is subject to license terms. 26eda14cbcSMatt Macy# 27eda14cbcSMatt Macy 28eda14cbcSMatt Macy# 29eda14cbcSMatt Macy# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 30eda14cbcSMatt Macy# Copyright (c) 2020 by Lawrence Livermore National Security, LLC. 31eda14cbcSMatt Macy# 32eda14cbcSMatt Macy 33eda14cbcSMatt Macy. $STF_SUITE/include/libtest.shlib 34eda14cbcSMatt Macy. $STF_SUITE/tests/functional/replacement/replacement.cfg 35eda14cbcSMatt Macy 36eda14cbcSMatt Macy# 37eda14cbcSMatt Macy# DESCRIPTION: 38eda14cbcSMatt Macy# Attaching disks during I/O should pass for supported pools. 39eda14cbcSMatt Macy# 40eda14cbcSMatt Macy# STRATEGY: 417877fdebSMatt Macy# 1. Create multidisk pools (stripe/mirror/raidz/draid) and 42eda14cbcSMatt Macy# start some random I/O 43eda14cbcSMatt Macy# 2. Attach a disk to the pool. 44eda14cbcSMatt Macy# 3. Verify the integrity of the file system and the resilvering. 45eda14cbcSMatt Macy# 46eda14cbcSMatt Macy# NOTE: Raidz does not support the sequential resilver (-s) option. 47eda14cbcSMatt Macy# 48eda14cbcSMatt Macy 49eda14cbcSMatt Macyverify_runnable "global" 50eda14cbcSMatt Macy 51eda14cbcSMatt Macyfunction cleanup 52eda14cbcSMatt Macy{ 53eda14cbcSMatt Macy if [[ -n "$child_pids" ]]; then 54eda14cbcSMatt Macy for wait_pid in $child_pids; do 55eda14cbcSMatt Macy kill $wait_pid 56eda14cbcSMatt Macy done 57eda14cbcSMatt Macy fi 58eda14cbcSMatt Macy 59eda14cbcSMatt Macy if poolexists $TESTPOOL1; then 60eda14cbcSMatt Macy destroy_pool $TESTPOOL1 61eda14cbcSMatt Macy fi 62eda14cbcSMatt Macy 63eda14cbcSMatt Macy [[ -e $TESTDIR ]] && log_must rm -rf $TESTDIR/* 64eda14cbcSMatt Macy} 65eda14cbcSMatt Macy 66eda14cbcSMatt Macylog_assert "Replacing a disk during I/O completes." 67eda14cbcSMatt Macy 68eda14cbcSMatt Macyoptions="" 69eda14cbcSMatt Macyoptions_display="default options" 70eda14cbcSMatt Macy 71eda14cbcSMatt Macylog_onexit cleanup 72eda14cbcSMatt Macy 73eda14cbcSMatt Macy[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE " 74eda14cbcSMatt Macy 75eda14cbcSMatt Macy[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE " 76eda14cbcSMatt Macy 77eda14cbcSMatt Macy[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT " 78eda14cbcSMatt Macy 79eda14cbcSMatt Macy[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED " 80eda14cbcSMatt Macy 81eda14cbcSMatt Macy[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET " 82eda14cbcSMatt Macy 83eda14cbcSMatt Macyoptions="$options -r " 84eda14cbcSMatt Macy 85eda14cbcSMatt Macy[[ -n "$options" ]] && options_display=$options 86eda14cbcSMatt Macy 87eda14cbcSMatt Macychild_pids="" 88eda14cbcSMatt Macy 89eda14cbcSMatt Macyfunction attach_test 90eda14cbcSMatt Macy{ 91eda14cbcSMatt Macy typeset -i iters=2 92eda14cbcSMatt Macy typeset -i index=0 93eda14cbcSMatt Macy typeset opt=$1 94eda14cbcSMatt Macy typeset disk1=$2 95eda14cbcSMatt Macy typeset disk2=$3 96eda14cbcSMatt Macy 97eda14cbcSMatt Macy typeset i=0 98eda14cbcSMatt Macy while [[ $i -lt $iters ]]; do 99eda14cbcSMatt Macy log_note "Invoking file_trunc with: $options_display" 100eda14cbcSMatt Macy file_trunc $options $TESTDIR/$TESTFILE.$i & 101eda14cbcSMatt Macy typeset pid=$! 102eda14cbcSMatt Macy 103eda14cbcSMatt Macy sleep 1 104eda14cbcSMatt Macy 105eda14cbcSMatt Macy child_pids="$child_pids $pid" 106eda14cbcSMatt Macy ((i = i + 1)) 107eda14cbcSMatt Macy done 108eda14cbcSMatt Macy 109eda14cbcSMatt Macy log_must zpool attach -sw $opt $TESTPOOL1 $disk1 $disk2 110eda14cbcSMatt Macy 111eda14cbcSMatt Macy for wait_pid in $child_pids; do 112eda14cbcSMatt Macy kill $wait_pid 113eda14cbcSMatt Macy done 114eda14cbcSMatt Macy child_pids="" 115eda14cbcSMatt Macy 116eda14cbcSMatt Macy log_must zpool export $TESTPOOL1 117eda14cbcSMatt Macy log_must zpool import -d $TESTDIR $TESTPOOL1 118eda14cbcSMatt Macy log_must zfs umount $TESTPOOL1/$TESTFS1 119eda14cbcSMatt Macy log_must zdb -cdui $TESTPOOL1/$TESTFS1 120eda14cbcSMatt Macy log_must zfs mount $TESTPOOL1/$TESTFS1 121eda14cbcSMatt Macy verify_pool $TESTPOOL1 122eda14cbcSMatt Macy} 123eda14cbcSMatt Macy 124eda14cbcSMatt Macyspecials_list="" 125eda14cbcSMatt Macyi=0 126eda14cbcSMatt Macywhile [[ $i != 3 ]]; do 127eda14cbcSMatt Macy truncate -s $MINVDEVSIZE $TESTDIR/$TESTFILE1.$i 128eda14cbcSMatt Macy specials_list="$specials_list $TESTDIR/$TESTFILE1.$i" 129eda14cbcSMatt Macy 130eda14cbcSMatt Macy ((i = i + 1)) 131eda14cbcSMatt Macydone 132eda14cbcSMatt Macy 133eda14cbcSMatt Macy# 134eda14cbcSMatt Macy# Create a replacement disk special file. 135eda14cbcSMatt Macy# 136eda14cbcSMatt Macytruncate -s $MINVDEVSIZE $TESTDIR/$REPLACEFILE 137eda14cbcSMatt Macy 138eda14cbcSMatt Macyfor op in "" "-f"; do 139eda14cbcSMatt Macy create_pool $TESTPOOL1 mirror $specials_list 140eda14cbcSMatt Macy log_must zfs create $TESTPOOL1/$TESTFS1 141eda14cbcSMatt Macy log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1 142eda14cbcSMatt Macy 143eda14cbcSMatt Macy attach_test "$opt" $TESTDIR/$TESTFILE1.1 $TESTDIR/$REPLACEFILE 144eda14cbcSMatt Macy 145716fd348SMartin Matuska log_must eval "zpool iostat -v $TESTPOOL1 | grep \"$REPLACEFILE\"" 146eda14cbcSMatt Macy 147eda14cbcSMatt Macy destroy_pool $TESTPOOL1 148eda14cbcSMatt Macydone 149eda14cbcSMatt Macy 150eda14cbcSMatt Macylog_note "Verify 'zpool attach' fails with non-mirrors." 151eda14cbcSMatt Macy 1527877fdebSMatt Macyfor type in "" "raidz" "raidz1" "draid" "draid1"; do 153eda14cbcSMatt Macy for op in "" "-f"; do 154eda14cbcSMatt Macy create_pool $TESTPOOL1 $type $specials_list 155eda14cbcSMatt Macy log_must zfs create $TESTPOOL1/$TESTFS1 156eda14cbcSMatt Macy log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1 157eda14cbcSMatt Macy 158eda14cbcSMatt Macy log_mustnot zpool attach -s "$opt" $TESTDIR/$TESTFILE1.1 \ 159eda14cbcSMatt Macy $TESTDIR/$REPLACEFILE 160eda14cbcSMatt Macy 161716fd348SMartin Matuska log_mustnot eval "zpool iostat -v $TESTPOOL1 | grep \"$REPLACEFILE\"" 162eda14cbcSMatt Macy 163eda14cbcSMatt Macy destroy_pool $TESTPOOL1 164eda14cbcSMatt Macy done 165eda14cbcSMatt Macydone 166eda14cbcSMatt Macy 167eda14cbcSMatt Macylog_pass 168