1#!/bin/ksh -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 https://opensource.org/licenses/CDDL-1.0.
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
28#
29# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/refreserv/refreserv.cfg
34
35#
36# DESCRIPTION:
37#	Setting full size as refreservation, verify no snapshot can be created.
38#
39# STRATEGY:
40#	1. Setting full size as refreservation on pool
41#	2. Verify no snapshot can be created on this pool
42#	3. Setting full size as refreservation on filesystem
43#	4. Verify no snapshot can be created on it and its subfs
44#
45
46verify_runnable "both"
47
48function cleanup
49{
50	if is_global_zone ; then
51		log_must zfs set refreservation=none $TESTPOOL
52
53		datasetexists $TESTPOOL@snap && destroy_dataset $TESTPOOL@snap -f
54	fi
55	destroy_dataset $TESTPOOL/$TESTFS -rf
56	log_must zfs create $TESTPOOL/$TESTFS
57	log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
58}
59
60# This function iteratively increases refreserv to its highest possible
61# value. Simply setting refreserv == quota can allow enough writes to
62# complete that the test fails.
63function max_refreserv
64{
65	typeset ds=$1
66	typeset -i incsize=131072
67	typeset -i rr=$(get_prop available $ds)
68
69	log_must zfs set refreserv=$rr $ds
70	while :; do
71		if zfs set refreserv=$((rr + incsize)) $ds >/dev/null 2>&1; then
72			((rr += incsize))
73			continue
74		else
75			((incsize /= 2))
76			((incsize == 0)) && break
77		fi
78	done
79}
80
81
82log_assert "Setting full size as refreservation, verify no snapshot " \
83	"can be created."
84log_onexit cleanup
85
86log_must zfs create $TESTPOOL/$TESTFS/subfs
87
88typeset datasets
89if is_global_zone; then
90	datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs"
91else
92	datasets="$TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs"
93fi
94
95for ds in $datasets; do
96	#
97	# Verify refreservation on dataset
98	#
99	log_must zfs set quota=25M $ds
100	max_refreserv $ds
101	log_mustnot zfs snapshot $ds@snap
102	if datasetexists $ds@snap ; then
103		log_fail "ERROR: $ds@snap should not exists."
104	fi
105
106	log_must zfs set quota=none $ds
107	log_must zfs set refreservation=none $ds
108done
109
110log_pass "Setting full size as refreservation, verify no snapshot " \
111	"can be created."
112