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# 31eda14cbcSMatt Macy 32eda14cbcSMatt Macy. $STF_SUITE/include/libtest.shlib 33eda14cbcSMatt Macy. $STF_SUITE/tests/functional/replacement/replacement.cfg 34eda14cbcSMatt Macy 35eda14cbcSMatt Macy# 36eda14cbcSMatt Macy# DESCRIPTION: 37eda14cbcSMatt Macy# Attaching disks during I/O should pass for supported pools. 38eda14cbcSMatt Macy# 39eda14cbcSMatt Macy# STRATEGY: 407877fdebSMatt Macy# 1. Create multidisk pools (stripe/mirror/raidz/draid) and 41eda14cbcSMatt Macy# start some random I/O 42eda14cbcSMatt Macy# 2. Attach a disk to the pool. 43eda14cbcSMatt Macy# 3. Verify the integrity of the file system and the resilvering. 44eda14cbcSMatt Macy# 45eda14cbcSMatt Macy 46eda14cbcSMatt Macyverify_runnable "global" 47eda14cbcSMatt Macy 48eda14cbcSMatt Macyfunction cleanup 49eda14cbcSMatt Macy{ 50eda14cbcSMatt Macy if [[ -n "$child_pids" ]]; then 51eda14cbcSMatt Macy for wait_pid in $child_pids 52eda14cbcSMatt Macy do 53eda14cbcSMatt Macy kill $wait_pid 54eda14cbcSMatt Macy done 55eda14cbcSMatt Macy fi 56eda14cbcSMatt Macy 57eda14cbcSMatt Macy if poolexists $TESTPOOL1; then 58eda14cbcSMatt Macy destroy_pool $TESTPOOL1 59eda14cbcSMatt Macy fi 60eda14cbcSMatt Macy 61eda14cbcSMatt Macy [[ -e $TESTDIR ]] && log_must rm -rf $TESTDIR/* 62eda14cbcSMatt Macy} 63eda14cbcSMatt Macy 64eda14cbcSMatt Macylog_assert "Replacing a disk during I/O completes." 65eda14cbcSMatt Macy 66eda14cbcSMatt Macyoptions="" 67eda14cbcSMatt Macyoptions_display="default options" 68eda14cbcSMatt Macy 69eda14cbcSMatt Macylog_onexit cleanup 70eda14cbcSMatt Macy 71eda14cbcSMatt Macy[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE " 72eda14cbcSMatt Macy 73eda14cbcSMatt Macy[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE " 74eda14cbcSMatt Macy 75eda14cbcSMatt Macy[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT " 76eda14cbcSMatt Macy 77eda14cbcSMatt Macy[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED " 78eda14cbcSMatt Macy 79eda14cbcSMatt Macy[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET " 80eda14cbcSMatt Macy 81eda14cbcSMatt Macyoptions="$options -r " 82eda14cbcSMatt Macy 83eda14cbcSMatt Macy[[ -n "$options" ]] && options_display=$options 84eda14cbcSMatt Macy 85eda14cbcSMatt Macychild_pids="" 86eda14cbcSMatt Macy 87eda14cbcSMatt Macyfunction attach_test 88eda14cbcSMatt Macy{ 89eda14cbcSMatt Macy typeset -i iters=2 90eda14cbcSMatt Macy typeset -i index=0 91eda14cbcSMatt Macy typeset opt=$1 92eda14cbcSMatt Macy typeset disk1=$2 93eda14cbcSMatt Macy typeset disk2=$3 94eda14cbcSMatt Macy 95eda14cbcSMatt Macy typeset i=0 96eda14cbcSMatt Macy while [[ $i -lt $iters ]]; do 97eda14cbcSMatt Macy log_note "Invoking file_trunc with: $options_display" 98eda14cbcSMatt Macy file_trunc $options $TESTDIR/$TESTFILE.$i & 99eda14cbcSMatt Macy typeset pid=$! 100eda14cbcSMatt Macy 101eda14cbcSMatt Macy sleep 1 102eda14cbcSMatt Macy 103eda14cbcSMatt Macy child_pids="$child_pids $pid" 104eda14cbcSMatt Macy ((i = i + 1)) 105eda14cbcSMatt Macy done 106eda14cbcSMatt Macy 107eda14cbcSMatt Macy log_must zpool attach -w $opt $TESTPOOL1 $disk1 $disk2 108eda14cbcSMatt Macy 109eda14cbcSMatt Macy for wait_pid in $child_pids 110eda14cbcSMatt Macy do 111eda14cbcSMatt Macy kill $wait_pid 112eda14cbcSMatt Macy done 113eda14cbcSMatt Macy child_pids="" 114eda14cbcSMatt Macy 115eda14cbcSMatt Macy log_must zpool export $TESTPOOL1 116eda14cbcSMatt Macy log_must zpool import -d $TESTDIR $TESTPOOL1 117eda14cbcSMatt Macy log_must zfs umount $TESTPOOL1/$TESTFS1 118eda14cbcSMatt Macy log_must zdb -cdui $TESTPOOL1/$TESTFS1 119eda14cbcSMatt Macy log_must zfs mount $TESTPOOL1/$TESTFS1 120eda14cbcSMatt Macy verify_pool $TESTPOOL1 121eda14cbcSMatt Macy} 122eda14cbcSMatt Macy 123eda14cbcSMatt Macyspecials_list="" 124eda14cbcSMatt Macyi=0 125eda14cbcSMatt Macywhile [[ $i != 3 ]]; do 126eda14cbcSMatt Macy truncate -s $MINVDEVSIZE $TESTDIR/$TESTFILE1.$i 127eda14cbcSMatt Macy specials_list="$specials_list $TESTDIR/$TESTFILE1.$i" 128eda14cbcSMatt Macy 129eda14cbcSMatt Macy ((i = i + 1)) 130eda14cbcSMatt Macydone 131eda14cbcSMatt Macy 132eda14cbcSMatt Macy# 133eda14cbcSMatt Macy# Create a replacement disk special file. 134eda14cbcSMatt Macy# 135eda14cbcSMatt Macytruncate -s $MINVDEVSIZE $TESTDIR/$REPLACEFILE 136eda14cbcSMatt Macy 137eda14cbcSMatt Macyfor op in "" "-f"; do 138eda14cbcSMatt Macy create_pool $TESTPOOL1 mirror $specials_list 139eda14cbcSMatt Macy log_must zfs create $TESTPOOL1/$TESTFS1 140eda14cbcSMatt Macy log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1 141eda14cbcSMatt Macy 142eda14cbcSMatt Macy attach_test "$opt" $TESTDIR/$TESTFILE1.1 $TESTDIR/$REPLACEFILE 143eda14cbcSMatt Macy 144716fd348SMartin Matuska log_must eval "zpool iostat -v $TESTPOOL1 | grep \"$REPLACEFILE\"" 145eda14cbcSMatt Macy 146eda14cbcSMatt Macy destroy_pool $TESTPOOL1 147eda14cbcSMatt Macydone 148eda14cbcSMatt Macy 149eda14cbcSMatt Macylog_note "Verify 'zpool attach' fails with non-mirrors." 150eda14cbcSMatt Macy 1517877fdebSMatt Macyfor type in "" "raidz" "raidz1" "draid"; do 152eda14cbcSMatt Macy for op in "" "-f"; do 153eda14cbcSMatt Macy create_pool $TESTPOOL1 $type $specials_list 154eda14cbcSMatt Macy log_must zfs create $TESTPOOL1/$TESTFS1 155eda14cbcSMatt Macy log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1 156eda14cbcSMatt Macy 157eda14cbcSMatt Macy log_mustnot zpool attach "$opt" $TESTDIR/$TESTFILE1.1 \ 158eda14cbcSMatt Macy $TESTDIR/$REPLACEFILE 159eda14cbcSMatt Macy 160716fd348SMartin Matuska log_mustnot eval "zpool iostat -v $TESTPOOL1 | grep \"$REPLACEFILE\"" 161eda14cbcSMatt Macy 162eda14cbcSMatt Macy destroy_pool $TESTPOOL1 163eda14cbcSMatt Macy done 164eda14cbcSMatt Macydone 165eda14cbcSMatt Macy 166eda14cbcSMatt Macylog_pass 167