1eda14cbcSMatt Macy#!/bin/ksh -p
2eda14cbcSMatt Macy#
3eda14cbcSMatt Macy# CDDL HEADER START
4eda14cbcSMatt Macy#
5eda14cbcSMatt Macy# The contents of this file are subject to the terms of the
6eda14cbcSMatt Macy# Common Development and Distribution License (the "License").
7eda14cbcSMatt Macy# You may not use this file except in compliance with the License.
8eda14cbcSMatt Macy#
9eda14cbcSMatt Macy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*271171e0SMartin Matuska# or https://opensource.org/licenses/CDDL-1.0.
11eda14cbcSMatt Macy# See the License for the specific language governing permissions
12eda14cbcSMatt Macy# and limitations under the License.
13eda14cbcSMatt Macy#
14eda14cbcSMatt Macy# When distributing Covered Code, include this CDDL HEADER in each
15eda14cbcSMatt Macy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16eda14cbcSMatt Macy# If applicable, add the following below this CDDL HEADER, with the
17eda14cbcSMatt Macy# fields enclosed by brackets "[]" replaced with your own identifying
18eda14cbcSMatt Macy# information: Portions Copyright [yyyy] [name of copyright owner]
19eda14cbcSMatt Macy#
20eda14cbcSMatt Macy# CDDL HEADER END
21eda14cbcSMatt Macy#
22eda14cbcSMatt Macy
23eda14cbcSMatt Macy#
24eda14cbcSMatt Macy# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25eda14cbcSMatt Macy# Use is subject to license terms.
26eda14cbcSMatt Macy#
27eda14cbcSMatt Macy
28eda14cbcSMatt Macy#
29eda14cbcSMatt Macy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30eda14cbcSMatt Macy#
31eda14cbcSMatt Macy
32eda14cbcSMatt Macy. $STF_SUITE/include/libtest.shlib
33eda14cbcSMatt Macy. $STF_SUITE/tests/functional/reservation/reservation.shlib
34eda14cbcSMatt Macy
35eda14cbcSMatt Macy#
36eda14cbcSMatt Macy# DESCRIPTION:
37eda14cbcSMatt Macy#
38eda14cbcSMatt Macy# When a reservation property of a filesystem, regular volume
39eda14cbcSMatt Macy# or sparse volume is set to 'none' the space previously consumed by the
40eda14cbcSMatt Macy# reservation should be released back to the pool
41eda14cbcSMatt Macy#
42eda14cbcSMatt Macy# STRATEGY:
43eda14cbcSMatt Macy# 1) Create a filesystem, regular volume and sparse volume
44eda14cbcSMatt Macy# 2) Get the space used and available in the pool
45eda14cbcSMatt Macy# 3) Set a reservation on the filesystem less than the space available.
46eda14cbcSMatt Macy# 4) Verify that the 'reservation' property for the filesystem has
47eda14cbcSMatt Macy# the correct value.
48eda14cbcSMatt Macy# 5) Reset the reservation value back to zero (or 'none')
49eda14cbcSMatt Macy# 6) Verify that the space used and available totals for the pool have
50eda14cbcSMatt Macy# changed by the expected amounts (within tolerances).
51eda14cbcSMatt Macy# 7) Repeat steps 3-6 for a regular volume, sparse volume
52eda14cbcSMatt Macy#
53eda14cbcSMatt Macy
54eda14cbcSMatt Macyverify_runnable "both"
55eda14cbcSMatt Macy
56eda14cbcSMatt Macylog_assert "Verify space released when reservation on a dataset is set "\
57eda14cbcSMatt Macy	"to 'none'"
58eda14cbcSMatt Macy
59eda14cbcSMatt Macyfunction cleanup
60eda14cbcSMatt Macy{
61eda14cbcSMatt Macy	for obj in $OBJ_LIST; do
6281b22a98SMartin Matuska		datasetexists $obj && destroy_dataset $obj -f
63eda14cbcSMatt Macy	done
64eda14cbcSMatt Macy}
65eda14cbcSMatt Macy
66eda14cbcSMatt Macylog_onexit cleanup
67eda14cbcSMatt Macy
68eda14cbcSMatt Macyspace_avail=`get_prop available $TESTPOOL`
69eda14cbcSMatt Macy
70eda14cbcSMatt Macyif ! is_global_zone ; then
71eda14cbcSMatt Macy	OBJ_LIST=""
72eda14cbcSMatt Macyelse
73eda14cbcSMatt Macy	OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
74eda14cbcSMatt Macy	((vol_set_size = space_avail / 4))
75eda14cbcSMatt Macy	vol_set_size=$(floor_volsize $vol_set_size)
76eda14cbcSMatt Macy	((sparse_vol_set_size = space_avail * 4))
77eda14cbcSMatt Macy	sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
78eda14cbcSMatt Macy
79eda14cbcSMatt Macy
80eda14cbcSMatt Macy	log_must zfs create -V $vol_set_size $TESTPOOL/$TESTVOL
81eda14cbcSMatt Macy	log_must zfs set reservation=none $TESTPOOL/$TESTVOL
82eda14cbcSMatt Macy	log_must zfs create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
83eda14cbcSMatt Macyfi
84eda14cbcSMatt Macy
85eda14cbcSMatt Macyspace_avail=`get_prop available $TESTPOOL`
86eda14cbcSMatt Macyspace_used=`get_prop used $TESTPOOL`
87eda14cbcSMatt Macy
88eda14cbcSMatt Macy# Calculate a large but valid reservation value.
89eda14cbcSMatt Macyresv_size_set=`expr $space_avail - $RESV_DELTA`
90eda14cbcSMatt Macy
91eda14cbcSMatt Macyfor obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
92eda14cbcSMatt Macy
93eda14cbcSMatt Macy	#
94eda14cbcSMatt Macy	# For regular (non-sparse) volumes the upper limit is determined
95eda14cbcSMatt Macy	# not by the space available in the pool but rather by the size
96eda14cbcSMatt Macy	# of the volume itself.
97eda14cbcSMatt Macy	#
98eda14cbcSMatt Macy	[[ $obj == $TESTPOOL/$TESTVOL ]] && \
99eda14cbcSMatt Macy	    ((resv_size_set = vol_set_size - RESV_DELTA))
100eda14cbcSMatt Macy
101eda14cbcSMatt Macy	log_must zfs set reservation=$resv_size_set $obj
102eda14cbcSMatt Macy
103eda14cbcSMatt Macy	resv_size_get=`get_prop reservation $obj`
104eda14cbcSMatt Macy	if [[ $resv_size_set != $resv_size_get ]]; then
105eda14cbcSMatt Macy		log_fail "Reservation not the expected value "\
106eda14cbcSMatt Macy			"($resv_size_set != $resv_size_get)"
107eda14cbcSMatt Macy	fi
108eda14cbcSMatt Macy
109eda14cbcSMatt Macy	log_must zfs set reservation=none $obj
110eda14cbcSMatt Macy
111eda14cbcSMatt Macy	new_space_avail=`get_prop available $TESTPOOL`
112eda14cbcSMatt Macy	new_space_used=`get_prop used $TESTPOOL`
113eda14cbcSMatt Macy
114eda14cbcSMatt Macy	log_must within_limits $space_used $new_space_used $RESV_TOLERANCE
115eda14cbcSMatt Macy	log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
116eda14cbcSMatt Macydone
117eda14cbcSMatt Macy
118eda14cbcSMatt Macylog_pass "Space correctly released when dataset reservation set to 'none'"
119