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