1# 2# CDDL HEADER START 3# 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. 7# 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. 12# 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] 18# 19# CDDL HEADER END 20# 21 22# 23# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24# Use is subject to license terms. 25# 26 27# 28# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 29# 30 31. $STF_SUITE/include/libtest.shlib 32. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.cfg 33 34# 35# Compare the value of copies property with specified value 36# $1, the dataset name 37# $2, the expected copies value 38# 39function cmp_prop 40{ 41 typeset ds=$1 42 typeset val_expect=$2 43 typeset val_actual 44 45 val_actual=$(get_prop copies $ds) 46 if [[ $val_actual != $val_expect ]]; then 47 log_fail "Expected value ($val_expect) != actual value " \ 48 "($val_actual)" 49 fi 50} 51 52# 53# Check the used space is charged correctly 54# $1, the number of used space 55# $2, the expected common factor between the used space and the file space 56# 57function check_used 58{ 59 typeset charged_spc=$1 60 typeset -i used 61 typeset -i expected_cfactor=$2 62 typeset -i cfactor 63 typeset -i fsize=${FILESIZE%[m|M]} 64 65 ((used = $charged_spc / 1024 / 1024)) 66 ((cfactor = used / fsize)) 67 if ((cfactor != expected_cfactor)); then 68 log_fail "The space is not charged correctly while setting" \ 69 "copies as $expected_cfactor." 70 fi 71} 72 73# 74# test ncopies on volume 75# $1 test type zfs|ufs|ext2 76# $2 copies 77# $3 mntp for ufs|ext2 test 78function do_vol_test 79{ 80 typeset type=$1 81 typeset copies=$2 82 typeset mntp=$3 83 84 vol=$TESTPOOL/$TESTVOL1 85 vol_b_path=$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL1 86 vol_r_path=$ZVOL_RDEVDIR/$TESTPOOL/$TESTVOL1 87 88 log_must zfs create -V $VOLSIZE -o copies=$copies $vol 89 log_must zfs set refreservation=none $vol 90 block_device_wait $vol_r_path 91 92 case "$type" in 93 "ext2") 94 if is_freebsd; then 95 log_unsupported "ext2 test not implemented for freebsd" 96 fi 97 log_must eval "new_fs $vol_r_path >/dev/null 2>&1" 98 log_must mount -o rw $vol_b_path $mntp 99 ;; 100 "ufs") 101 if is_linux; then 102 log_unsupported "ufs test not implemented for linux" 103 fi 104 log_must eval "new_fs $vol_r_path >/dev/null 2>&1" 105 log_must mount $vol_b_path $mntp 106 ;; 107 "zfs") 108 if is_freebsd; then 109 # Pool creation on zvols is forbidden by default. 110 # Save and restore the current setting. 111 typeset _saved=$(get_tunable VOL_RECURSIVE) 112 log_must set_tunable64 VOL_RECURSIVE 1 # Allow 113 zpool create $TESTPOOL1 $vol_b_path 114 typeset _zpool_create_result=$? 115 log_must set_tunable64 VOL_RECURSIVE $_saved # Restore 116 log_must test $_zpool_create_result = 0 117 else 118 log_must zpool create $TESTPOOL1 $vol_b_path 119 fi 120 log_must zfs create $TESTPOOL1/$TESTFS1 121 ;; 122 *) 123 log_unsupported "$type test not implemented" 124 ;; 125 esac 126 127 ((nfilesize = copies * ${FILESIZE%m})) 128 pre_used=$(get_prop used $vol) 129 ((target_size = pre_used + nfilesize)) 130 131 if [[ $type == "zfs" ]]; then 132 log_must mkfile $FILESIZE /$TESTPOOL1/$TESTFS1/$FILE 133 else 134 log_must mkfile $FILESIZE $mntp/$FILE 135 fi 136 137 post_used=$(get_prop used $vol) 138 ((retries = 0)) 139 while ((post_used < target_size && retries++ < 42)); do 140 sleep 1 141 post_used=$(get_prop used $vol) 142 done 143 144 ((used = post_used - pre_used)) 145 if ((used < nfilesize)); then 146 log_fail "The space is not charged correctly while setting" \ 147 "copies as $copies ($used < $nfilesize)" \ 148 "pre=${pre_used} post=${post_used}" 149 fi 150 151 if [[ $type == "zfs" ]]; then 152 log_must zpool destroy $TESTPOOL1 153 else 154 log_must umount $mntp 155 fi 156 157 log_must zfs destroy $vol 158} 159