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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)reservation_004_pos.ksh	1.3	08/02/27 SMI"
28#
29
30. $STF_SUITE/include/libtest.kshlib
31. $STF_SUITE/tests/reservation/reservation.kshlib
32
33###############################################################################
34#
35# __stc_assertion_start
36#
37# ID: reservation_004_pos
38#
39# DESCRIPTION:
40#
41# When a dataset which has a reservation set on it is destroyed,
42# the space consumed or reserved by that dataset should be released
43# back into the pool.
44#
45# STRATEGY:
46# 1) Create a filesystem, regular and sparse volume
47# 2) Get the space used and available in the pool
48# 3) Set a reservation on the filesystem less than the space available.
49# 4) Verify that the 'reservation' property for the filesystem has
50# the correct value.
51# 5) Destroy the filesystem without resetting the reservation value.
52# 6) Verify that the space used and available totals for the pool have
53# changed by the expected amounts (within tolerances).
54# 7) Repeat steps 3-6 for a regular volume and sparse volume
55#
56# TESTABILITY: explicit
57#
58# TEST_AUTOMATION_LEVEL: automated
59#
60# CODING_STATUS: COMPLETED (2005-07-19)
61#
62# __stc_assertion_end
63#
64################################################################################
65
66verify_runnable "both"
67
68log_assert "Verify space released when a dataset with reservation is destroyed"
69
70log_must $ZFS create $TESTPOOL/$TESTFS2
71
72space_avail=`get_prop available $TESTPOOL`
73
74if ! is_global_zone ; then
75	OBJ_LIST="$TESTPOOL/$TESTFS2"
76else
77	OBJ_LIST="$TESTPOOL/$TESTFS2 \
78		$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
79
80        (( vol_set_size = space_avail / 4 ))
81	vol_set_size=$(floor_volsize $vol_set_size)
82	(( sparse_vol_set_size = space_avail * 4 ))
83	sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
84
85	log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
86	if fs_prop_exist refreserv; then
87                log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
88        fi
89	log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
90	log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
91fi
92
93# re-calculate space available.
94space_avail=`get_prop available $TESTPOOL`
95
96# Calculate a large but valid reservation value.
97resv_size_set=`expr $space_avail - $RESV_DELTA`
98
99for obj in $OBJ_LIST ; do
100
101	space_avail=`get_prop available $TESTPOOL`
102	space_used=`get_prop used $TESTPOOL`
103
104	#
105        # For regular (non-sparse) volumes the upper limit is determined
106        # not by the space available in the pool but rather by the size
107        # of the volume itself.
108        #
109        [[ $obj == $TESTPOOL/$TESTVOL ]] && \
110                (( resv_size_set = vol_set_size - RESV_DELTA ))
111
112	log_must $ZFS set reservation=$resv_size_set $obj
113
114	resv_size_get=`get_prop reservation $obj`
115	if [[ $resv_size_set != $resv_size_get ]]; then
116		log_fail "Reservation not the expected value " \
117		"($resv_size_set != $resv_size_get)"
118	fi
119
120	log_must $ZFS destroy -f $obj
121
122	new_space_avail=`get_prop available $TESTPOOL`
123	new_space_used=`get_prop used $TESTPOOL`
124
125	log_must within_limits $space_used $new_space_used $RESV_TOLERANCE
126	log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
127done
128
129log_pass "Space correctly released when dataset is destroyed"
130