1#!/usr/local/bin/ksh93 -p 2# vim: filetype=sh 3# 4# CDDL HEADER START 5# 6# The contents of this file are subject to the terms of the 7# Common Development and Distribution License (the "License"). 8# You may not use this file except in compliance with the License. 9# 10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11# or http://www.opensolaris.org/os/licensing. 12# See the License for the specific language governing permissions 13# and limitations under the License. 14# 15# When distributing Covered Code, include this CDDL HEADER in each 16# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17# If applicable, add the following below this CDDL HEADER, with the 18# fields enclosed by brackets "[]" replaced with your own identifying 19# information: Portions Copyright [yyyy] [name of copyright owner] 20# 21# CDDL HEADER END 22# 23 24# $FreeBSD$ 25 26# 27# Copyright 2013 Spectra Logic. All rights reserved. 28# Use is subject to license terms. 29# 30 31# Common routines used by multiple zfsd tests 32 33function wait_for_pool_dev_state_change 34{ 35 typeset -i timeout=$1 36 typeset disk=$2 37 typeset state=$3 38 39 log_note "Waiting up to $timeout seconds for $disk to become $state ..." 40 for ((; $timeout > 0; timeout=$timeout-1)); do 41 check_state $TESTPOOL "$disk" "$state" 42 [ $? -eq 0 ] && return 43 $SLEEP 1 44 done 45 log_must $ZPOOL status $TESTPOOL 46 log_fail "ERROR: Disk $disk not marked as $state in $TESTPOOL" 47} 48 49function wait_for_pool_removal 50{ 51 typeset -i timeout=$1 52 wait_for_pool_dev_state_change $timeout $REMOVAL_DISK "REMOVED|UNAVAIL" 53} 54 55function wait_until_scrubbed 56{ 57 typeset pool=$1 58 59 while is_pool_scrubbing $pool; do 60 log_note "$pool still scrubbing..." 61 $SLEEP 1 62 done 63} 64 65function corrupt_pool_vdev 66{ 67 typeset pool=$1 68 typeset vdev=$2 69 typeset file=$3 70 71 # do some IO on the pool 72 log_must $DD if=/dev/zero of=$file bs=1024k count=64 73 $FSYNC $file 74 75 # scribble on the underlying file to corrupt the vdev 76 log_must $DD if=/dev/urandom of=$vdev bs=1024k count=64 conv=notrunc 77 78 # Scrub the pool to detect the corruption 79 log_must $ZPOOL scrub $pool 80 wait_until_scrubbed $pool 81 82 # ZFSD can take up to 60 seconds to degrade an array in response to 83 # errors (though it's usually faster). 84 wait_for_pool_dev_state_change 60 $vdev DEGRADED 85} 86