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.
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.
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]
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
28 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
31 . $STF_SUITE/include/libtest.shlib
32 . $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.cfg
35 # Compare the value of copies property with specified value
36 # $1, the dataset name
37 # $2, the expected copies value
45 val_actual=$(get_prop copies $ds)
46 if [[ $val_actual != $val_expect ]]; then
47 log_fail "Expected value ($val_expect) != actual value " \
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
59 typeset charged_spc=$1
61 typeset -i expected_cfactor=$2
63 typeset -i fsize=${FILESIZE%[m|M]}
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."
74 # test ncopies on volume
75 # $1 test type zfs|ufs|ext2
77 # $3 mntp for ufs|ext2 test
84 vol=$TESTPOOL/$TESTVOL1
85 vol_b_path=$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL1
86 vol_r_path=$ZVOL_RDEVDIR/$TESTPOOL/$TESTVOL1
88 log_must zfs create -V $VOLSIZE -o copies=$copies $vol
89 log_must zfs set refreservation=none $vol
95 log_unsupported "ext2 test not implemented for freebsd"
97 log_must eval "new_fs $vol_r_path >/dev/null 2>&1"
98 log_must mount -o rw $vol_b_path $mntp
102 log_unsupported "ufs test not implemented for linux"
104 log_must eval "new_fs $vol_r_path >/dev/null 2>&1"
105 log_must mount $vol_b_path $mntp
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
118 log_must zpool create $TESTPOOL1 $vol_b_path
120 log_must zfs create $TESTPOOL1/$TESTFS1
123 log_unsupported "$type test not implemented"
127 ((nfilesize = copies * ${FILESIZE%m}))
128 pre_used=$(get_prop used $vol)
129 ((target_size = pre_used + nfilesize))
131 if [[ $type == "zfs" ]]; then
132 log_must mkfile $FILESIZE /$TESTPOOL1/$TESTFS1/$FILE
134 log_must mkfile $FILESIZE $mntp/$FILE
137 post_used=$(get_prop used $vol)
139 while ((post_used < target_size && retries++ < 42)); do
141 post_used=$(get_prop used $vol)
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}"
151 if [[ $type == "zfs" ]]; then
152 log_must zpool destroy $TESTPOOL1
154 log_must umount $mntp
157 log_must zfs destroy $vol