1f38cb554SJohn Wren Kennedy#!/usr/bin/ksh -p 2f38cb554SJohn Wren Kennedy# 3f38cb554SJohn Wren Kennedy# CDDL HEADER START 4f38cb554SJohn Wren Kennedy# 5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the 6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License"). 7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License. 8f38cb554SJohn Wren Kennedy# 9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing. 11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions 12f38cb554SJohn Wren Kennedy# and limitations under the License. 13f38cb554SJohn Wren Kennedy# 14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each 15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the 17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying 18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner] 19f38cb554SJohn Wren Kennedy# 20f38cb554SJohn Wren Kennedy# CDDL HEADER END 21f38cb554SJohn Wren Kennedy# 22f38cb554SJohn Wren Kennedy 23f38cb554SJohn Wren Kennedy# 24f38cb554SJohn Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 25f38cb554SJohn Wren Kennedy# Use is subject to license terms. 26f38cb554SJohn Wren Kennedy# 27f38cb554SJohn Wren Kennedy 28f38cb554SJohn Wren Kennedy# 29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 30f38cb554SJohn Wren Kennedy# 31f38cb554SJohn Wren Kennedy 32f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib 33f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/replacement/replacement.cfg 34f38cb554SJohn Wren Kennedy 35f38cb554SJohn Wren Kennedy# 36f38cb554SJohn Wren Kennedy# DESCRIPTION: 37f38cb554SJohn Wren Kennedy# Attaching disks during I/O should pass for supported pools. 38f38cb554SJohn Wren Kennedy# 39f38cb554SJohn Wren Kennedy# STRATEGY: 40f38cb554SJohn Wren Kennedy# 1. Create multidisk pools (stripe/mirror/raidz) and 41f38cb554SJohn Wren Kennedy# start some random I/O 42f38cb554SJohn Wren Kennedy# 2. Attach a disk to the pool. 43f38cb554SJohn Wren Kennedy# 3. Verify the integrity of the file system and the resilvering. 44f38cb554SJohn Wren Kennedy# 45f38cb554SJohn Wren Kennedy 46f38cb554SJohn Wren Kennedyverify_runnable "global" 47f38cb554SJohn Wren Kennedy 48f38cb554SJohn Wren Kennedyfunction cleanup 49f38cb554SJohn Wren Kennedy{ 50f38cb554SJohn Wren Kennedy if [[ -n "$child_pids" ]]; then 51f38cb554SJohn Wren Kennedy for wait_pid in $child_pids 52f38cb554SJohn Wren Kennedy do 53*1d32ba66SJohn Wren Kennedy kill $wait_pid 54f38cb554SJohn Wren Kennedy done 55f38cb554SJohn Wren Kennedy fi 56f38cb554SJohn Wren Kennedy 57f38cb554SJohn Wren Kennedy if poolexists $TESTPOOL1; then 58f38cb554SJohn Wren Kennedy destroy_pool $TESTPOOL1 59f38cb554SJohn Wren Kennedy fi 60f38cb554SJohn Wren Kennedy 61*1d32ba66SJohn Wren Kennedy [[ -e $TESTDIR ]] && log_must rm -rf $TESTDIR/* 62f38cb554SJohn Wren Kennedy} 63f38cb554SJohn Wren Kennedy 64f38cb554SJohn Wren Kennedylog_assert "Replacing a disk during I/O completes." 65f38cb554SJohn Wren Kennedy 66f38cb554SJohn Wren Kennedyoptions="" 67f38cb554SJohn Wren Kennedyoptions_display="default options" 68f38cb554SJohn Wren Kennedy 69f38cb554SJohn Wren Kennedylog_onexit cleanup 70f38cb554SJohn Wren Kennedy 71f38cb554SJohn Wren Kennedy[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE " 72f38cb554SJohn Wren Kennedy 73f38cb554SJohn Wren Kennedy[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE " 74f38cb554SJohn Wren Kennedy 75f38cb554SJohn Wren Kennedy[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT " 76f38cb554SJohn Wren Kennedy 77f38cb554SJohn Wren Kennedy[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED " 78f38cb554SJohn Wren Kennedy 79f38cb554SJohn Wren Kennedy[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET " 80f38cb554SJohn Wren Kennedy 81f38cb554SJohn Wren Kennedyoptions="$options -r " 82f38cb554SJohn Wren Kennedy 83f38cb554SJohn Wren Kennedy[[ -n "$options" ]] && options_display=$options 84f38cb554SJohn Wren Kennedy 85f38cb554SJohn Wren Kennedychild_pids="" 86f38cb554SJohn Wren Kennedy 87f38cb554SJohn Wren Kennedyfunction attach_test 88f38cb554SJohn Wren Kennedy{ 89f38cb554SJohn Wren Kennedy typeset -i iters=2 90f38cb554SJohn Wren Kennedy typeset -i index=0 91f38cb554SJohn Wren Kennedy typeset opt=$1 92f38cb554SJohn Wren Kennedy typeset disk1=$2 93f38cb554SJohn Wren Kennedy typeset disk2=$3 94f38cb554SJohn Wren Kennedy 95f38cb554SJohn Wren Kennedy typeset i=0 96f38cb554SJohn Wren Kennedy while [[ $i -lt $iters ]]; do 97*1d32ba66SJohn Wren Kennedy log_note "Invoking file_trunc with: $options_display" 98*1d32ba66SJohn Wren Kennedy file_trunc $options $TESTDIR/$TESTFILE.$i & 99f38cb554SJohn Wren Kennedy typeset pid=$! 100f38cb554SJohn Wren Kennedy 101*1d32ba66SJohn Wren Kennedy sleep 1 102*1d32ba66SJohn Wren Kennedy if ! ps -p $pid > /dev/null 2>&1; then 103*1d32ba66SJohn Wren Kennedy log_fail "file_trunc $options $TESTDIR/$TESTFILE.$i" 104f38cb554SJohn Wren Kennedy fi 105f38cb554SJohn Wren Kennedy 106f38cb554SJohn Wren Kennedy child_pids="$child_pids $pid" 107f38cb554SJohn Wren Kennedy ((i = i + 1)) 108f38cb554SJohn Wren Kennedy done 109f38cb554SJohn Wren Kennedy 110*1d32ba66SJohn Wren Kennedy log_must zpool attach $opt $TESTPOOL1 $disk1 $disk2 111f38cb554SJohn Wren Kennedy 112*1d32ba66SJohn Wren Kennedy sleep 10 113f38cb554SJohn Wren Kennedy 114f38cb554SJohn Wren Kennedy for wait_pid in $child_pids 115f38cb554SJohn Wren Kennedy do 116*1d32ba66SJohn Wren Kennedy kill $wait_pid 117f38cb554SJohn Wren Kennedy done 118f38cb554SJohn Wren Kennedy child_pids="" 119f38cb554SJohn Wren Kennedy 120*1d32ba66SJohn Wren Kennedy log_must zpool export $TESTPOOL1 121*1d32ba66SJohn Wren Kennedy log_must zpool import -d $TESTDIR $TESTPOOL1 122*1d32ba66SJohn Wren Kennedy log_must zfs umount $TESTPOOL1/$TESTFS1 123*1d32ba66SJohn Wren Kennedy log_must zdb -cdui $TESTPOOL1/$TESTFS1 124*1d32ba66SJohn Wren Kennedy log_must zfs mount $TESTPOOL1/$TESTFS1 125f38cb554SJohn Wren Kennedy 126f38cb554SJohn Wren Kennedy} 127f38cb554SJohn Wren Kennedy 128f38cb554SJohn Wren Kennedyspecials_list="" 129f38cb554SJohn Wren Kennedyi=0 130f38cb554SJohn Wren Kennedywhile [[ $i != 2 ]]; do 131*1d32ba66SJohn Wren Kennedy mkfile $MINVDEVSIZE $TESTDIR/$TESTFILE1.$i 132f38cb554SJohn Wren Kennedy specials_list="$specials_list $TESTDIR/$TESTFILE1.$i" 133f38cb554SJohn Wren Kennedy 134f38cb554SJohn Wren Kennedy ((i = i + 1)) 135f38cb554SJohn Wren Kennedydone 136f38cb554SJohn Wren Kennedy 137f38cb554SJohn Wren Kennedy# 138f38cb554SJohn Wren Kennedy# Create a replacement disk special file. 139f38cb554SJohn Wren Kennedy# 140*1d32ba66SJohn Wren Kennedymkfile $MINVDEVSIZE $TESTDIR/$REPLACEFILE 141f38cb554SJohn Wren Kennedy 142f38cb554SJohn Wren Kennedyfor op in "" "-f"; do 143f38cb554SJohn Wren Kennedy create_pool $TESTPOOL1 mirror $specials_list 144*1d32ba66SJohn Wren Kennedy log_must zfs create $TESTPOOL1/$TESTFS1 145*1d32ba66SJohn Wren Kennedy log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1 146f38cb554SJohn Wren Kennedy 147f38cb554SJohn Wren Kennedy attach_test "$opt" $TESTDIR/$TESTFILE1.1 $TESTDIR/$REPLACEFILE 148f38cb554SJohn Wren Kennedy 149*1d32ba66SJohn Wren Kennedy zpool iostat -v $TESTPOOL1 | grep "$TESTDIR/$REPLACEFILE" 150f38cb554SJohn Wren Kennedy if [[ $? -ne 0 ]]; then 151f38cb554SJohn Wren Kennedy log_fail "$REPLACEFILE is not present." 152f38cb554SJohn Wren Kennedy fi 153f38cb554SJohn Wren Kennedy 154f38cb554SJohn Wren Kennedy destroy_pool $TESTPOOL1 155f38cb554SJohn Wren Kennedydone 156f38cb554SJohn Wren Kennedy 157f38cb554SJohn Wren Kennedylog_note "Verify 'zpool attach' fails with non-mirrors." 158f38cb554SJohn Wren Kennedy 159f38cb554SJohn Wren Kennedyfor type in "" "raidz" "raidz1"; do 160f38cb554SJohn Wren Kennedy for op in "" "-f"; do 161f38cb554SJohn Wren Kennedy create_pool $TESTPOOL1 $type $specials_list 162*1d32ba66SJohn Wren Kennedy log_must zfs create $TESTPOOL1/$TESTFS1 163*1d32ba66SJohn Wren Kennedy log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1 164f38cb554SJohn Wren Kennedy 165*1d32ba66SJohn Wren Kennedy log_mustnot zpool attach "$opt" $TESTDIR/$TESTFILE1.1 \ 166f38cb554SJohn Wren Kennedy $TESTDIR/$REPLACEFILE 167f38cb554SJohn Wren Kennedy 168*1d32ba66SJohn Wren Kennedy zpool iostat -v $TESTPOOL1 | grep "$TESTDIR/$REPLACEFILE" 169f38cb554SJohn Wren Kennedy if [[ $? -eq 0 ]]; then 170f38cb554SJohn Wren Kennedy log_fail "$REPLACEFILE should not be present." 171f38cb554SJohn Wren Kennedy fi 172f38cb554SJohn Wren Kennedy 173f38cb554SJohn Wren Kennedy destroy_pool $TESTPOOL1 174f38cb554SJohn Wren Kennedy done 175f38cb554SJohn Wren Kennedydone 176f38cb554SJohn Wren Kennedy 177f38cb554SJohn Wren Kennedylog_pass 178