1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/include/libtest.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: refreserv_002_pos
34#
35# DESCRIPTION:
36#	Setting full size as refreservation, verify no snapshot can be created.
37#
38# STRATEGY:
39#	1. Setting full size as refreservation on pool
40#	2. Verify no snapshot can be created on this pool
41#	3. Setting full size as refreservation on filesystem
42#	4. Verify no snapshot can be created on it and its subfs
43#
44# TESTABILITY: explicit
45#
46# TEST_AUTOMATION_LEVEL: automated
47#
48# CODING_STATUS: COMPLETED (2007-11-05)
49#
50# __stc_assertion_end
51#
52################################################################################
53
54verify_runnable "both"
55
56function cleanup
57{
58	if is_global_zone ; then
59		log_must $ZFS set refreservation=none $TESTPOOL
60
61		if datasetexists $TESTPOOL@snap ; then
62			log_must $ZFS destroy -f $TESTPOOL@snap
63		fi
64	fi
65	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
66	log_must $ZFS create $TESTPOOL/$TESTFS
67	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
68}
69
70# This function iteratively increases refreserv to its highest possible
71# value. Simply setting refreserv == quota can allow enough writes to
72# complete that the test fails.
73function max_refreserv
74{
75	typeset ds=$1
76	typeset -i incsize=131072
77	typeset -i rr=$(get_prop available $ds)
78
79	log_must $ZFS set refreserv=$rr $ds
80	while :; do
81		$ZFS set refreserv=$((rr + incsize)) $ds >/dev/null 2>&1
82		if [[ $? == 0 ]]; then
83			((rr += incsize))
84			continue
85		else
86			((incsize /= 2))
87			((incsize == 0)) && break
88		fi
89	done
90}
91
92
93log_assert "Setting full size as refreservation, verify no snapshot " \
94	"can be created."
95log_onexit cleanup
96
97log_must $ZFS create $TESTPOOL/$TESTFS/subfs
98
99typeset datasets
100if is_global_zone; then
101	datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs"
102else
103	datasets="$TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs"
104fi
105
106for ds in $datasets; do
107	#
108	# Verify refreservation on dataset
109	#
110	log_must $ZFS set quota=25M $ds
111	max_refreserv $ds
112	log_mustnot $ZFS snapshot $ds@snap
113	if datasetexists $ds@snap ; then
114		log_fail "ERROR: $ds@snap should not exists."
115	fi
116
117	log_must $ZFS set quota=none $ds
118	log_must $ZFS set refreservation=none $ds
119done
120
121log_pass "Setting full size as refreservation, verify no snapshot " \
122	"can be created."
123