12fae26bdSAlan Somers#! /usr/local/bin/ksh93 -p
22fae26bdSAlan Somers#
32fae26bdSAlan Somers# CDDL HEADER START
42fae26bdSAlan Somers#
52fae26bdSAlan Somers# The contents of this file are subject to the terms of the
62fae26bdSAlan Somers# Common Development and Distribution License (the "License").
72fae26bdSAlan Somers# You may not use this file except in compliance with the License.
82fae26bdSAlan Somers#
92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing.
112fae26bdSAlan Somers# See the License for the specific language governing permissions
122fae26bdSAlan Somers# and limitations under the License.
132fae26bdSAlan Somers#
142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each
152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the
172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying
182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner]
192fae26bdSAlan Somers#
202fae26bdSAlan Somers# CDDL HEADER END
212fae26bdSAlan Somers#
222fae26bdSAlan Somers
232fae26bdSAlan Somers#
242fae26bdSAlan Somers# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
252fae26bdSAlan Somers# Use is subject to license terms.
262fae26bdSAlan Somers
272fae26bdSAlan Somers. $STF_SUITE/include/libtest.kshlib
282fae26bdSAlan Somers. $STF_SUITE/tests/reservation/reservation.kshlib
292fae26bdSAlan Somers
302fae26bdSAlan Somers###############################################################################
312fae26bdSAlan Somers#
322fae26bdSAlan Somers# __stc_assertion_start
332fae26bdSAlan Somers#
342fae26bdSAlan Somers# ID: reservation_014_pos
352fae26bdSAlan Somers#
362fae26bdSAlan Somers# DESCRIPTION:
372fae26bdSAlan Somers#
382fae26bdSAlan Somers# A reservation cannot exceed the quota on a dataset
392fae26bdSAlan Somers#
402fae26bdSAlan Somers# STRATEGY:
412fae26bdSAlan Somers# 1) Create a filesystem and volume
422fae26bdSAlan Somers# 2) Set a quota on the filesystem
432fae26bdSAlan Somers# 3) Attempt to set a reservation larger than the quota. Verify
442fae26bdSAlan Somers# that the attempt fails.
452fae26bdSAlan Somers# 4) Repeat 2-3 for volume
462fae26bdSAlan Somers#
472fae26bdSAlan Somers# TESTABILITY: explicit
482fae26bdSAlan Somers#
492fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated
502fae26bdSAlan Somers#
512fae26bdSAlan Somers# CODING_STATUS: COMPLETED (2005-07-04)
522fae26bdSAlan Somers#
532fae26bdSAlan Somers# __stc_assertion_end
542fae26bdSAlan Somers#
552fae26bdSAlan Somers################################################################################
562fae26bdSAlan Somers
572fae26bdSAlan Somersverify_runnable "both"
582fae26bdSAlan Somers
592fae26bdSAlan Somerslog_assert "Verify cannot set reservation larger than quota"
602fae26bdSAlan Somers
612fae26bdSAlan Somersspace_avail=`get_prop available $TESTPOOL`
622fae26bdSAlan Somers
632fae26bdSAlan Somersif ! is_global_zone ; then
642fae26bdSAlan Somers	OBJ_LIST=""
652fae26bdSAlan Somerselse
662fae26bdSAlan Somers	OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
672fae26bdSAlan Somers
682fae26bdSAlan Somers        (( vol_set_size = space_avail / 4 ))
692fae26bdSAlan Somers	vol_set_size=$(floor_volsize $vol_set_size)
702fae26bdSAlan Somers	(( sparse_vol_set_size = space_avail * 4 ))
712fae26bdSAlan Somers	sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
722fae26bdSAlan Somers
732fae26bdSAlan Somers
742fae26bdSAlan Somers	log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
752fae26bdSAlan Somers	log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
762fae26bdSAlan Somersfi
772fae26bdSAlan Somers
782fae26bdSAlan Somersfor obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
792fae26bdSAlan Somers
802fae26bdSAlan Somers        space_avail=`get_prop available $TESTPOOL`
812fae26bdSAlan Somers        (( quota_set_size = space_avail / 3 ))
822fae26bdSAlan Somers
832fae26bdSAlan Somers	#
842fae26bdSAlan Somers	# A regular (non-sparse) volume's size is effectively
852fae26bdSAlan Somers	# its quota so only need to explicitly set quotas for
862fae26bdSAlan Somers	# filesystems and datasets.
872fae26bdSAlan Somers	#
882fae26bdSAlan Somers	# A volumes size is effectively its quota. The maximum
892fae26bdSAlan Somers	# reservation value that can be set on a volume is
902fae26bdSAlan Somers	# determined by the size of the volume or the amount of
912fae26bdSAlan Somers	# space in the pool, whichever is smaller.
922fae26bdSAlan Somers	#
932fae26bdSAlan Somers	if [[ $obj == $TESTPOOL/$TESTFS ]]; then
942fae26bdSAlan Somers                log_must $ZFS set quota=$quota_set_size $obj
952fae26bdSAlan Somers		(( resv_set_size = quota_set_size + RESV_SIZE ))
962fae26bdSAlan Somers
972fae26bdSAlan Somers	elif [[ $obj == $TESTPOOL/$TESTVOL2 ]] ; then
982fae26bdSAlan Somers
992fae26bdSAlan Somers		(( resv_set_size = sparse_vol_set_size + RESV_SIZE ))
1002fae26bdSAlan Somers
1012fae26bdSAlan Somers	elif [[ $obj == $TESTPOOL/$TESTVOL ]] ; then
1022fae26bdSAlan Somers
1032fae26bdSAlan Somers		(( resv_set_size = vol_set_size + RESV_SIZE ))
1042fae26bdSAlan Somers	fi
1052fae26bdSAlan Somers
1062fae26bdSAlan Somers	orig_quota=`get_prop quota $obj`
1072fae26bdSAlan Somers
1082fae26bdSAlan Somers        log_mustnot $ZFS set reservation=$resv_set_size $obj
1092fae26bdSAlan Somers	new_quota=`get_prop quota $obj`
1102fae26bdSAlan Somers
1112fae26bdSAlan Somers	if [[ $orig_quota != $new_quota ]]; then
1122fae26bdSAlan Somers		log_fail "Quota value changed from $orig_quota " \
1132fae26bdSAlan Somers				"to $new_quota"
1142fae26bdSAlan Somers	fi
1152fae26bdSAlan Somers
1162fae26bdSAlan Somers	if [[ $obj == $TESTPOOL/$TESTFS ]]; then
1172fae26bdSAlan Somers        	log_must $ZFS set quota=none $obj
1182fae26bdSAlan Somers	fi
1192fae26bdSAlan Somersdone
1202fae26bdSAlan Somers
1212fae26bdSAlan Somerslog_pass "As expected cannot set reservation larger than quota"
122