4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
28 # Copyright (c) 2013 by Delphix. All rights reserved.
31 . $STF_SUITE/include/libtest.shlib
32 . $STF_SUITE/tests/functional/redundancy/redundancy.cfg
36 if poolexists $TESTPOOL; then
37 destroy_pool $TESTPOOL
40 for dir in $TESTDIR $BASEDIR; do
41 if [[ -d $dir ]]; then
48 # Get random number between min and max number.
60 ((value = RANDOM % (max + 1)))
61 if ((value >= min)); then
70 # Record the directories construction and checksum all the files which reside
71 # within the specified pool
73 # $1 The specified pool
74 # $2 The file which save the record.
81 [[ -z $pool ]] && log_fail "No specified pool."
82 [[ -f $recordfile ]] && log_must $RM -f $recordfile
85 mntpnt=$(get_prop mountpoint $pool)
86 log_must eval "$DU -a $mntpnt > $recordfile 2>&1"
88 # When the data was damaged, checksum is failing and return 1
89 # So, will not use log_must
91 $FIND $mntpnt -type f -exec $CKSUM {} + >> $recordfile 2>&1
95 # Create test pool and fill with files and directories.
99 # $3 virtual devices number
101 function setup_test_env
105 typeset -i vdev_cnt=$3
109 while (( i < vdev_cnt )); do
110 vdevs="$vdevs $BASEDIR/vdev$i"
114 if [[ ! -d $BASEDIR ]]; then
115 log_must $MKDIR $BASEDIR
118 if poolexists $pool ; then
122 log_must $MKFILE $DEV_SIZE $vdevs
124 log_must $ZPOOL create -m $TESTDIR $pool $keyword $vdevs
126 log_note "Filling up the filesystem ..."
129 typeset file=$TESTDIR/file
131 $FILE_WRITE -o create -f $file.$i \
132 -b $BLOCKSZ -c $NUM_WRITES
134 (( $ret != 0 )) && break
137 (($ret != 28 )) && log_note "$FILE_WRITE return value($ret) is unexpected."
139 record_data $TESTPOOL $PRE_RECORD_FILE
143 # Check pool status is healthy
151 typeset healthy_output="pool '$pool' is healthy"
152 typeset real_output=$($ZPOOL status -x $pool)
154 if [[ "$real_output" == "$healthy_output" ]]; then
158 $ZPOOL status -x $pool | $GREP "state:" | \
159 $GREP "FAULTED" >/dev/null 2>&1
161 (( $ret == 0 )) && return 1
164 l_scan=$($ZPOOL status -x $pool | $GREP "scan:")
165 l_scan=${l_scan##*"with"}
166 errnum=$($ECHO $l_scan | $AWK '{print $1}')
173 # Check pool data is valid
177 function is_data_valid
181 record_data $pool $PST_RECORD_FILE
182 if ! $DIFF $PRE_RECORD_FILE $PST_RECORD_FILE > /dev/null 2>&1; then
190 # Get the specified count devices name
195 function get_vdevs #pool cnt
200 typeset all_devs=$($ZPOOL iostat -v $pool | $AWK '{print $1}'| \
201 $EGREP -v "^pool$|^capacity$|^mirror$|^raidz1$|^raidz2$|---" | \
202 $EGREP -v "/old$|^$pool$")
205 while ((i < cnt)); do
206 typeset dev=$($ECHO $all_devs | $AWK '{print $1}')
207 eval all_devs=\${all_devs##*$dev}
217 # Synchronize all the data in pool
221 function sync_pool #pool
227 # Flush all the pool data.
229 $ZPOOL scrub $pool >/dev/null 2>&1
232 log_fail "$ZPOOL scrub $pool failed."
234 while ! is_pool_scrubbed $pool; do
235 if is_pool_resilvered $pool ; then
236 log_fail "$pool should not be resilver completed."
243 # Create and replace the same name virtual device files
246 # $2-n virtual device files
248 function replace_missing_devs
255 log_must $MKFILE $DEV_SIZE $vdev
256 log_must $ZPOOL replace -f $pool $vdev $vdev
258 if ! is_pool_resilvered $pool ; then
268 # Damage the pool's virtual device files.
271 # $2 Failing devices count
272 # $3 damage vdevs method, if not null, we keep
273 # the label for the vdevs
283 vdevs=$(get_vdevs $pool $cnt)
284 if [[ -n $label ]]; then
286 for dev in $vdevs; do
287 bs_count=$($LS -l $dev | $AWK '{print $5}')
288 (( bs_count = bs_count/1024 - 512 ))
289 $DD if=/dev/zero of=$dev seek=512 bs=1024 \
290 count=$bs_count conv=notrunc >/dev/null 2>&1
293 log_must $MKFILE $DEV_SIZE $vdevs
300 # Clear errors in the pool caused by data corruptions
304 function clear_errors
308 log_must $ZPOOL clear $pool
310 if ! is_healthy $pool ; then
311 log_note "$pool should be healthy."
314 if ! is_data_valid $pool ; then
315 log_note "Data should be valid in $pool."
323 # Remove the specified pool's virtual device files
326 # $2 Missing devices count
334 vdevs=$(get_vdevs $pool $cnt)
335 log_must $RM -f $vdevs
341 # Recover the bad or missing device files in the pool
344 # $2 Missing devices count
346 function recover_bad_missing_devs
352 vdevs=$(get_vdevs $pool $cnt)
353 replace_missing_devs $pool $vdevs
355 if ! is_healthy $pool ; then
356 log_note "$pool should be healthy."
359 if ! is_data_valid $pool ; then
360 log_note "Data should be valid in $pool."