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# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)reservation_007_pos.ksh	1.2	07/01/09 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33. $STF_SUITE/tests/reservation/reservation.kshlib
34
35###############################################################################
36#
37# __stc_assertion_start
38#
39# ID: reservation_007_pos
40#
41# DESCRIPTION:
42#
43# Setting a reservation on dataset should have no effect on any other
44# dataset at the same level in the hierarchy beyond using up available
45# space in the pool.
46#
47# STRATEGY:
48# 1) Create a filesystem
49# 2) Set a reservation on the filesystem
50# 3) Create another filesystem at the same level
51# 4) Set a reservation on the second filesystem
52# 5) Destroy both the filesystems
53# 6) Verify space accounted for correctly
54#
55# TESTABILITY: explicit
56#
57# TEST_AUTOMATION_LEVEL: automated
58#
59# CODING_STATUS: COMPLETED (2005-07-04)
60#
61# __stc_assertion_end
62#
63################################################################################
64
65verify_runnable "both"
66
67log_assert "Verify reservations on data sets doesn't affect other data sets at" \
68	" same level except for consuming space from common pool"
69
70space_avail=`get_prop available $TESTPOOL`
71space_used=`get_prop used $TESTPOOL`
72
73resv_size_set=`expr $space_avail / 3`
74
75#
76# Function which creates two datasets, sets reservations on them,
77# then destroys them and ensures that space is correctly accounted
78# for.
79#
80# Any special arguments for create are passed in via the args
81# parameter.
82#
83function create_resv_destroy { # args1 dataset1 args2 dataset2
84
85	args1=$1
86        dataset1=$2
87        args2=$3
88        dataset2=$4
89
90	log_must $ZFS create $args1 $dataset1
91
92	log_must $ZFS set reservation=$RESV_SIZE $dataset1
93
94	avail_aft_dset1=`get_prop available $TESTPOOL`
95	used_aft_dset1=`get_prop used $TESTPOOL`
96
97	log_must $ZFS create $args2 $dataset2
98
99	log_must $ZFS set reservation=$RESV_SIZE $dataset2
100
101
102	# After destroying the second dataset the space used and
103	# available totals should revert back to the values they
104	# had after creating the first dataset.
105	#
106	log_must $ZFS destroy -f $dataset2
107
108	avail_dest_dset2=`get_prop available $TESTPOOL`
109	used_dest_dset2=`get_prop used $TESTPOOL`
110
111	log_must within_limits $avail_aft_dset1 $avail_dest_dset2 $RESV_TOLERANCE
112	log_must within_limits $used_aft_dset1 $used_dest_dset2 $RESV_TOLERANCE
113
114
115	# After destroying the first dataset the space used and
116	# space available totals should revert back to the values
117	# they had when the pool was first created.
118	log_must $ZFS destroy -f $dataset1
119
120	avail_dest_dset1=`get_prop available $TESTPOOL`
121	used_dest_dset1=`get_prop used $TESTPOOL`
122
123	log_must within_limits $avail_dest_dset1 $space_avail $RESV_TOLERANCE
124	log_must within_limits $used_dest_dset1 $space_used $RESV_TOLERANCE
125}
126
127create_resv_destroy "" $TESTPOOL/$TESTFS1 ""  $TESTPOOL/$TESTFS2
128create_resv_destroy "" $TESTPOOL/$TESTFS2 "" $TESTPOOL/$TESTFS1
129
130log_pass "Verify reservations on data sets doesn't affect other data sets at" \
131	" same level except for consuming space from common pool"
132