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