f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/tests/functional/redundancy/redundancy.cfg
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ -d $dir ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Get random number between min and max number.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $1 Minimal value
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $2 Maximal value
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i min=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i max=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while true; do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Record the directories construction and checksum all the files which reside
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# within the specified pool
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $1 The specified pool
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $2 The file which save the record.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy [[ -z $pool ]] && log_fail "No specified pool."
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy [[ -f $recordfile ]] && log_must rm -f $recordfile
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must eval "du -a $mntpnt > $recordfile 2>&1"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # When the data was damaged, checksum is failing and return 1
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy find $mntpnt -type f -exec cksum {} + >> $recordfile 2>&1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Create test pool and fill with files and directories.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $3 virtual devices number
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i i=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ ! -d $BASEDIR ]]; then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zpool create -m $TESTDIR $pool $keyword $vdevs
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i i=0
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy while true ; do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy (($ret != 28 )) && log_note "file_write return value($ret) is unexpected."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Check pool status is healthy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset healthy_output="pool '$pool' is healthy"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy typeset real_output=$(zpool status -x $pool)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ "$real_output" == "$healthy_output" ]]; then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy l_scan=$(zpool status -x $pool | grep "scan:")
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Check pool data is valid
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy if ! diff $PRE_RECORD_FILE $PST_RECORD_FILE > /dev/null 2>&1; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Get the specified count devices name
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $2 devices count
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i cnt=$2
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy typeset all_devs=$(zpool iostat -v $pool | awk '{print $1}'| \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy egrep -v "^pool$|^capacity$|^mirror$|^raidz1$|^raidz2$|---" | \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i i=0
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy typeset dev=$(echo $all_devs | awk '{print $1}')
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Synchronize all the data in pool
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "$pool should not be resilver completed."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Create and replace the same name virtual device files
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $2-n virtual device files
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zpool replace -f $pool $vdev $vdev
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while true; do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Damage the pool's virtual device files.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $2 Failing devices count
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $3 damage vdevs method, if not null, we keep
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# the label for the vdevs
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i cnt=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ -n $label ]]; then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy dd if=/dev/zero of=$dev seek=512 bs=1024 \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy dd if=/dev/zero of=$dev bs=1024 count=$bs_count \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Clear errors in the pool caused by data corruptions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Remove the specified pool's virtual device files
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $2 Missing devices count
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i cnt=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Recover the bad or missing device files in the pool
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $2 Missing devices count
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i cnt=$2