redundancy.kshlib revision 4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1c
#
# 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
# 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.
#
#
# Copyright (c) 2013, 2015 by Delphix. All rights reserved.
#
function cleanup
{
if poolexists $TESTPOOL; then
fi
typeset dir
if [[ -d $dir ]]; then
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
break
fi
done
}
#
# 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
[[ -f $recordfile ]] && log_must $RM -f $recordfile
typeset mntpnt
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
((i += 1))
done
if [[ ! -d $BASEDIR ]]; then
fi
if poolexists $pool ; then
fi
log_note "Filling up the filesystem ..."
typeset -i ret=0
typeset -i i=0
while $TRUE ; do
$FILE_WRITE -o create -f $file.$i \
-b $BLOCKSZ -c $NUM_WRITES
ret=$?
(( i = i + 1 ))
done
}
#
# 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)
return 0
else
typeset -i ret
ret=$?
typeset l_scan
typeset errnum
return $errnum
fi
}
#
# Check pool data is valid
#
# $1 pool
#
function is_data_valid
{
typeset pool=$1
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
typeset -i i=0
typeset vdevs
((i += 1))
done
}
#
# Synchronize all the data in pool
#
# $1 pool name
#
function sync_pool #pool
{
typeset pool=$1
# Flush all the pool data.
typeset -i ret
ret=$?
while ! is_pool_scrubbed $pool; do
if is_pool_resilvered $pool ; then
fi
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
while true; do
if ! is_pool_resilvered $pool ; then
else
break
fi
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 dev
if [[ -n $label ]]; then
done
else
done
fi
}
#
# Clear errors in the pool caused by data corruptions
#
# $1 pool name
#
function clear_errors
{
typeset pool=$1
if ! is_healthy $pool ; then
return 1
fi
if ! is_data_valid $pool ; then
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
}
#
# 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
if ! is_healthy $pool ; then
return 1
fi
if ! is_data_valid $pool ; then
return 1
fi
return 0
}