Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy.kshlib =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy.kshlib (revision 292299) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy.kshlib (revision 292300) @@ -1,361 +1,327 @@ # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)redundancy.kshlib 1.8 09/01/12 SMI" # . ${STF_SUITE}/include/libtest.kshlib function cleanup { - if poolexists $TESTPOOL; then - destroy_pool $TESTPOOL - fi + destroy_pool $TESTPOOL typeset dir for dir in $TESTDIR $BASEDIR; do if [[ -d $dir ]]; then log_must $RM -rf $dir fi done } # -# Get random number between min and max number. -# -# $1 Minimal value -# $2 Maximal value -# -function random -{ - typeset -i min=$1 - typeset -i max=$2 - typeset -i value - - while true; do - ((value = RANDOM % (max + 1))) - if ((value >= min)); then - break - fi - done - - $ECHO $value -} - -# # Record the directories construction and checksum all the files which reside # within the specified pool # # $1 The specified pool # $2 The file which save the record. # function record_data { typeset pool=$1 typeset recordfile=$2 [[ -z $pool ]] && log_fail "No specified pool." [[ -f $recordfile ]] && log_must $RM -f $recordfile typeset mntpnt mntpnt=$(get_prop mountpoint $pool) log_must eval "$DU -a $mntpnt > $recordfile 2>&1" # # When the data was damaged, checksum is failing and return 1 # So, will not use log_must # $FIND $mntpnt -type f -exec $CKSUM {} + >> $recordfile 2>&1 } # # Create test pool and fill with files and directories. # # $1 pool name # $2 pool type # $3 virtual devices number # function setup_test_env { typeset pool=$1 typeset keyword=$2 typeset -i vdev_cnt=$3 typeset vdevs typeset -i i=0 while (( i < vdev_cnt )); do vdevs="$vdevs $BASEDIR/vdev$i" ((i += 1)) done - if [[ ! -d $BASEDIR ]]; then - log_must $MKDIR $BASEDIR - fi - - if poolexists $pool ; then - destroy_pool $pool - fi - + log_must $MKDIR -p $BASEDIR + destroy_pool $pool log_must $MKFILE $DEV_SIZE $vdevs $ECHO $vdevs | tr ' ' '\n' > $BASEDIR/vdevs log_must $ZPOOL create -m $TESTDIR $pool $keyword $vdevs - log_note "Filling up the filesystem ..." + log_note "Pool $pool created with $vdev_cnt vdevs, filling up..." typeset -i ret=0 typeset -i i=0 typeset file=$TESTDIR/file while $TRUE ; do $FILE_WRITE -o create -f $file.$i \ -b $BLOCKSZ -c $NUM_WRITES ret=$? (( $ret != 0 )) && break (( i = i + 1 )) done (($ret != 28 )) && log_note "$FILE_WRITE return value($ret) is unexpected." record_data $TESTPOOL $PRE_RECORD_FILE } # # Check pool status is healthy # # $1 pool # function is_healthy { typeset pool=$1 typeset healthy_output="pool '$pool' is healthy" typeset real_output=$($ZPOOL status -x $pool) if [[ "$real_output" == "$healthy_output" ]]; then return 0 else typeset -i ret $ZPOOL status -x $pool | $GREP "state:" | \ $GREP "FAULTED" >/dev/null 2>&1 ret=$? (( $ret == 0 )) && return 1 typeset l_scan typeset errnum l_scan=$($ZPOOL status -x $pool | $GREP "scan:") l_scan=${l_scan##*"with"} errnum=$($ECHO $l_scan | $AWK '{print $1}') if [ "$errnum" != "0" ]; then return 1 else return 0 fi fi } # # Check pool data is valid # # $1 pool # function is_data_valid { typeset pool=$1 record_data $pool $PST_RECORD_FILE if ! $DIFF $PRE_RECORD_FILE $PST_RECORD_FILE > /dev/null 2>&1; then return 1 fi return 0 } # # Get the specified count devices name # # $1 pool name # $2 devices count # function get_vdevs #pool cnt { typeset pool=$1 typeset -i cnt=$2 head -$cnt $BASEDIR/vdevs | tr ' ' '\n' } # # Synchronize all the data in pool # # $1 pool name # function sync_pool #pool { typeset pool=$1 log_must $SYNC log_must $SLEEP 2 # Flush all the pool data. typeset -i ret # If the OS has detected corruption on the pool, it will have # automatically initiated a scrub. In that case, our "zpool scrub" # command will fail. So we ignore its exit status and just check that # the pool is scrubbing or has been scrubbed. $ZPOOL scrub $pool >/dev/null 2>&1 is_pool_scrubbing $pool || is_pool_scrubbed $pool || \ log_fail "$ZPOOL scrub $pool failed." - while ! is_pool_scrubbed $pool; do - if is_pool_resilvered $pool ; then - log_fail "$pool should not be resilver completed." - fi + # The pool has been damaged; the sync should notice this fact. + log_note "Waiting for pool to sync..." + while ! is_pool_scrubbed $pool || is_pool_resilvered $pool; do log_must $SLEEP 2 done } # # Create and replace the same name virtual device files # # $1 pool name # $2-n virtual device files # function replace_missing_devs { typeset pool=$1 shift typeset vdev for vdev in $@; do log_must $MKFILE $DEV_SIZE $vdev log_must $ZPOOL replace -f $pool $vdev $vdev - while true; do - if ! is_pool_resilvered $pool ; then - log_must $SLEEP 2 - else - break - fi + while ! is_pool_resilvered $pool; do + log_must $SLEEP 2 done done } # # Damage the pool's virtual device files. # # $1 pool name # $2 Failing devices count # $3 damage vdevs method, if not null, we keep # the label for the vdevs # function damage_devs { typeset pool=$1 typeset -i cnt=$2 typeset label="$3" typeset vdevs typeset -i bs_count vdevs=$(get_vdevs $pool $cnt) log_note "Damaging pool $pool devices: $vdevs" if [[ -n $label ]]; then typeset dev for dev in $vdevs; do bs_count=$($LS -l $dev | $AWK '{print $5}') (( bs_count = bs_count/1024 - 512 )) $DD if=/dev/zero of=$dev seek=512 bs=1024 \ count=$bs_count conv=notrunc >/dev/null 2>&1 done else log_must $MKFILE $DEV_SIZE $vdevs fi sync_pool $pool + log_note "Pool $pool vdevs $vdevs damage completed." } # # Clear errors in the pool caused by data corruptions # # $1 pool name # function clear_errors { typeset pool=$1 log_must $ZPOOL clear $pool if ! is_healthy $pool ; then $ZPOOL status -x $pool log_note "$pool should be healthy." return 1 fi if ! is_data_valid $pool ; then $ZPOOL status -x $pool log_note "Data should be valid in $pool." return 1 fi return 0 } # # Remove the specified pool's virtual device files # # $1 Pool name # $2 Missing devices count # function remove_devs { typeset pool=$1 typeset -i cnt=$2 typeset vdevs vdevs=$(get_vdevs $pool $cnt) log_note "Removing pool $pool vdevs: $vdevs" log_must $RM -f $vdevs sync_pool $pool } # # Recover the bad or missing device files in the pool # # $1 Pool name # $2 Missing devices count # function recover_bad_missing_devs { typeset pool=$1 typeset -i cnt=$2 typeset vdevs vdevs=$(get_vdevs $pool $cnt) log_note "Replacing missing pool $pool vdevs: $vdevs" replace_missing_devs $pool $vdevs if ! is_healthy $pool ; then log_note "$pool should be healthy." return 1 fi if ! is_data_valid $pool ; then log_note "Data should be valid in $pool." return 1 fi return 0 } Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_001_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_001_pos.ksh (revision 292299) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_001_pos.ksh (revision 292300) @@ -1,88 +1,89 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)redundancy_001_pos.ksh 1.3 07/05/25 SMI" # . $STF_SUITE/tests/redundancy/redundancy.kshlib ################################################################################# # # __stc_assertion_start # # ID: redundancy_001_pos # # DESCRIPTION: # A raidz pool can withstand at most 1 device failing or missing. # # STRATEGY: # 1. Create N(>2,<5) virtual disk files. # 2. Create raidz pool based on the virtual disk files. # 3. Fill the filesystem with directories and files. # 4. Record all the files and directories checksum information. # 5. Damaged one of the virtual disk file. # 6. Verify the data is correct to prove raidz can withstand 1 devicd is # failing. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2005-08-21) # # __stc_assertion_end # ################################################################################ verify_runnable "global" log_assert "Verify raidz pool can withstand one device is failing." log_onexit cleanup -typeset -i cnt=$(random 2 5) -setup_test_env $TESTPOOL raidz $cnt +for cnt in 3 2; do + setup_test_env $TESTPOOL raidz $cnt -# -# Inject data corruption error for raidz pool -# -damage_devs $TESTPOOL 1 "label" -log_must is_data_valid $TESTPOOL -log_must clear_errors $TESTPOOL + # + # Inject data corruption error for raidz pool + # + damage_devs $TESTPOOL 1 "label" + log_must is_data_valid $TESTPOOL + log_must clear_errors $TESTPOOL -# -# Inject bad device error for raidz pool -# -damage_devs $TESTPOOL 1 -log_must is_data_valid $TESTPOOL -log_must recover_bad_missing_devs $TESTPOOL 1 + # + # Inject bad device error for raidz pool + # + damage_devs $TESTPOOL 1 + log_must is_data_valid $TESTPOOL + log_must recover_bad_missing_devs $TESTPOOL 1 -# -# Inject missing device error for raidz pool -# -remove_devs $TESTPOOL 1 -log_must is_data_valid $TESTPOOL + # + # Inject missing device error for raidz pool + # + remove_devs $TESTPOOL 1 + log_must is_data_valid $TESTPOOL +done log_pass "Raidz pool can withstand one devices is failing passed." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_002_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_002_pos.ksh (revision 292299) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_002_pos.ksh (revision 292300) @@ -1,95 +1,96 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)redundancy_002_pos.ksh 1.3 07/05/25 SMI" # . $STF_SUITE/tests/redundancy/redundancy.kshlib ################################################################################# # # __stc_assertion_start # # ID: redundancy_002_pos # # DESCRIPTION: # A raidz2 pool can withstand 2 devices are failing or missing. # # STRATEGY: # 1. Create N(>3,<5) virtual disk files. # 2. Create raidz2 pool based on the virtual disk files. # 3. Fill the filesystem with directories and files. # 4. Record all the files and directories checksum information. # 5. Damaged at most two of the virtual disk files. # 6. Verify the data is correct to prove raidz2 can withstand 2 devices # are failing. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2006-08-21) # # __stc_assertion_end # ################################################################################ verify_runnable "global" log_assert "Verify raidz2 pool can withstand two devices are failing." log_onexit cleanup -typeset -i cnt=$(random 3 5) -setup_test_env $TESTPOOL raidz2 $cnt +for cnt in 3 4; do + setup_test_env $TESTPOOL raidz2 $cnt -# -# Inject data corruption errors for raidz2 pool -# -for i in 1 2; do - damage_devs $TESTPOOL $i "label" - log_must is_data_valid $TESTPOOL - log_must clear_errors $TESTPOOL -done + # + # Inject data corruption errors for raidz2 pool + # + for i in 1 2; do + damage_devs $TESTPOOL $i "label" + log_must is_data_valid $TESTPOOL + log_must clear_errors $TESTPOOL + done -# -# Inject bad devices errors for raidz2 pool -# -for i in 1 2; do - damage_devs $TESTPOOL $i - log_must is_data_valid $TESTPOOL - log_must recover_bad_missing_devs $TESTPOOL $i -done + # + # Inject bad devices errors for raidz2 pool + # + for i in 1 2; do + damage_devs $TESTPOOL $i + log_must is_data_valid $TESTPOOL + log_must recover_bad_missing_devs $TESTPOOL $i + done -# -# Inject missing device errors for raidz2 pool -# -for i in 1 2; do - remove_devs $TESTPOOL $i - log_must is_data_valid $TESTPOOL - log_must recover_bad_missing_devs $TESTPOOL $i + # + # Inject missing device errors for raidz2 pool + # + for i in 1 2; do + remove_devs $TESTPOOL $i + log_must is_data_valid $TESTPOOL + log_must recover_bad_missing_devs $TESTPOOL $i + done done log_pass "Raidz2 pool can withstand two devices are failing passed." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_003_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_003_pos.ksh (revision 292299) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_003_pos.ksh (revision 292300) @@ -1,105 +1,106 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)redundancy_003_pos.ksh 1.4 07/06/05 SMI" # . $STF_SUITE/tests/redundancy/redundancy.kshlib ################################################################################# # # __stc_assertion_start # # ID: redundancy_003_pos # # DESCRIPTION: # A mirrored pool can withstand N-1 device are failing or missing. # # STRATEGY: # 1. Create N(>2,<5) virtual disk files. # 2. Create mirror pool based on the virtual disk files. # 3. Fill the filesystem with directories and files. # 4. Record all the files and directories checksum information. # 5. Damaged at most N-1 of the virtual disk files. # 6. Verify the data are correct to prove mirror can withstand N-1 devices # are failing. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2006-08-21) # # __stc_assertion_end # ################################################################################ verify_runnable "global" log_assert "Verify mirrored pool can withstand N-1 devices are failing or missing." log_onexit cleanup -typeset -i cnt=$(random 2 5) -setup_test_env $TESTPOOL mirror $cnt +for cnt in 3 2; do + typeset -i i=1 -typeset -i i=1 + setup_test_env $TESTPOOL mirror $cnt -# -# Inject data corruption errors for mirrored pool -# -while (( i < cnt )); do - damage_devs $TESTPOOL $i "label" - log_must is_data_valid $TESTPOOL - log_must clear_errors $TESTPOOL - - (( i +=1 )) -done + # + # Inject data corruption errors for mirrored pool + # + while (( i < cnt )); do + damage_devs $TESTPOOL $i "label" + log_must is_data_valid $TESTPOOL + log_must clear_errors $TESTPOOL + + (( i +=1 )) + done -# -# Inject bad devices errors for mirrored pool -# -i=1 -while (( i < cnt )); do - damage_devs $TESTPOOL $i - log_must is_data_valid $TESTPOOL - log_must recover_bad_missing_devs $TESTPOOL $i + # + # Inject bad devices errors for mirrored pool + # + i=1 + while (( i < cnt )); do + damage_devs $TESTPOOL $i + log_must is_data_valid $TESTPOOL + log_must recover_bad_missing_devs $TESTPOOL $i - (( i +=1 )) -done + (( i +=1 )) + done -# -# Inject missing device errors for mirrored pool -# -i=1 -while (( i < cnt )); do - remove_devs $TESTPOOL $i - log_must is_data_valid $TESTPOOL - log_must recover_bad_missing_devs $TESTPOOL $i + # + # Inject missing device errors for mirrored pool + # + i=1 + while (( i < cnt )); do + remove_devs $TESTPOOL $i + log_must is_data_valid $TESTPOOL + log_must recover_bad_missing_devs $TESTPOOL $i - (( i +=1 )) + (( i +=1 )) + done done log_pass "Mirrored pool can withstand N-1 devices failing as expected." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_004_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_004_neg.ksh (revision 292299) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/redundancy/redundancy_004_neg.ksh (revision 292300) @@ -1,72 +1,72 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)redundancy_004_neg.ksh 1.4 07/05/25 SMI" # . $STF_SUITE/tests/redundancy/redundancy.kshlib ################################################################################# # # __stc_assertion_start # # ID: redundancy_004_neg # # DESCRIPTION: # Striped pool have no data redundancy. Any device errors will # cause data corruption. # # STRATEGY: # 1. Create N virtual disk file. # 2. Create stripe pool based on the virtual disk files. # 3. Fill the filesystem with directories and files. # 4. Record all the files and directories checksum information. # 5. Damage one of the virtual disk file. # 6. Verify the data is error. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2006-08-17) # # __stc_assertion_end # ################################################################################ verify_runnable "global" log_assert "Verify striped pool have no data redundancy." log_onexit cleanup -typeset -i cnt=$(random 2 5) -setup_test_env $TESTPOOL "" $cnt - -damage_devs $TESTPOOL 1 "keep_label" -log_must $ZPOOL clear $TESTPOOL -log_mustnot is_healthy $TESTPOOL +for cnt in 2 3; do + setup_test_env $TESTPOOL "" $cnt + damage_devs $TESTPOOL 1 "keep_label" + log_must $ZPOOL clear $TESTPOOL + log_mustnot is_healthy $TESTPOOL +done log_pass "Striped pool has no data redundancy as expected."