zfs_copies.kshlib revision 1d32ba663e202c24a5a1f2e5aef83fffb447cb7f
#
# 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 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.cfg
#
# Compare the value of copies property with specified value
# $1, the dataset name
# $2, the expected copies value
#
function cmp_prop
{
typeset ds=$1
typeset val_expect=$2
typeset val_actual
val_actual=$(get_prop copies $ds)
if [[ $val_actual != $val_expect ]]; then
log_fail "Expected value ($val_expect) != actual value " \
"($val_actual)"
fi
}
#
# Get the value of property used via zfs list
# $1, the dataset name
#
function get_used_prop
{
typeset ds=$1
typeset used
used=`zfs list -H -o used $ds`
used=${used%[m|M]}
if [[ $used == *K ]]; then
used=0
fi
echo $used
}
#
# Check the used space is charged correctly
# $1, the number of used space
# $2, the expected common factor between the used space and the file space
#
function check_used
{
typeset charged_spc=$1
typeset -i used
typeset -i expected_cfactor=$2
typeset -i cfactor
typeset -i fsize=${FILESIZE%[m|M]}
((used = ${charged_spc%[m|M]}))
((cfactor = used / fsize))
if ((cfactor != expected_cfactor)); then
log_fail "The space is not charged correctly while setting" \
"copies as $expected_cfactor."
fi
}
#
# test ncopies on volume
# $1 test type zfs|ufs, default zfs
# $2 copies
# $3 mntp for ufs test
function do_vol_test
{
typeset type=$1
typeset copy=$2
typeset mntp=$3
vol=$TESTPOOL/$TESTVOL1
vol_b_path=/dev/zvol/dsk/$TESTPOOL/$TESTVOL1
vol_r_path=/dev/zvol/rdsk/$TESTPOOL/$TESTVOL1
log_must zfs create -V $VOLSIZE -o copies=$copy $vol
log_must zfs set refreservation=none $vol
if [[ $type == "ufs" ]]; then
log_must echo y | newfs $vol_r_path >/dev/null 2>&1
log_must mount -F ufs -o rw $vol_b_path $mntp
else
log_must zpool create $TESTPOOL1 $vol_b_path
log_must zfs create $TESTPOOL1/$TESTFS1
fi
((nfilesize = copy * ${FILESIZE%m}))
pre_used=$(get_used_prop $vol)
((target_size = pre_used + nfilesize))
if [[ $type == "ufs" ]]; then
log_must mkfile $FILESIZE $mntp/$FILE
else
log_must mkfile $FILESIZE /$TESTPOOL1/$TESTFS1/$FILE
fi
post_used=$(get_used_prop $vol)
while ((post_used < target_size)) ; do
sleep 1
post_used=$(get_used_prop $vol)
done
((used = post_used - pre_used))
if ((used < nfilesize)); then
log_fail "The space is not charged correctly while setting" \
"copies as $copy"
fi
if [[ $type == "ufs" ]]; then
umount $mntp
else
log_must zpool destroy $TESTPOOL1
fi
log_must zfs destroy $vol
}