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
292fae26bdSAlan Somers#################################################################################
302fae26bdSAlan Somers#
312fae26bdSAlan Somers# __stc_assertion_start
322fae26bdSAlan Somers#
332fae26bdSAlan Somers# ID: refreserv_004_pos
342fae26bdSAlan Somers#
352fae26bdSAlan Somers# DESCRIPTION:
362fae26bdSAlan Somers#	Verify refreservation is limited by available space.
372fae26bdSAlan Somers#
382fae26bdSAlan Somers# STRATEGY:
392fae26bdSAlan Somers#	1. Setting quota and refreservation on parent filesystem.
402fae26bdSAlan Somers#	2. Get available space on sub-filesystem.
412fae26bdSAlan Somers#	3. Verify refreservation is limited by available on it.
422fae26bdSAlan Somers#
432fae26bdSAlan Somers# TESTABILITY: explicit
442fae26bdSAlan Somers#
452fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated
462fae26bdSAlan Somers#
472fae26bdSAlan Somers# CODING_STATUS: COMPLETED (2007-11-05)
482fae26bdSAlan Somers#
492fae26bdSAlan Somers# __stc_assertion_end
502fae26bdSAlan Somers#
512fae26bdSAlan Somers################################################################################
522fae26bdSAlan Somers
532fae26bdSAlan Somersverify_runnable "both"
542fae26bdSAlan Somers
552fae26bdSAlan Somersfunction cleanup
562fae26bdSAlan Somers{
572fae26bdSAlan Somers	if is_global_zone ; then
582fae26bdSAlan Somers		log_must $ZFS set refreservation=none $TESTPOOL
592fae26bdSAlan Somers	fi
602fae26bdSAlan Somers	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
612fae26bdSAlan Somers	log_must $ZFS create $TESTPOOL/$TESTFS
622fae26bdSAlan Somers	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
632fae26bdSAlan Somers}
642fae26bdSAlan Somers
652fae26bdSAlan Somerslog_assert "Verify refreservation is limited by available space."
662fae26bdSAlan Somerslog_onexit cleanup
672fae26bdSAlan Somers
682fae26bdSAlan Somerspool=$TESTPOOL ; fs=$pool/$TESTFS ; subfs=$fs/subfs
692fae26bdSAlan Somerslog_must $ZFS create $subfs
702fae26bdSAlan Somers
712fae26bdSAlan Somerstypeset datasets
722fae26bdSAlan Somersif is_global_zone; then
732fae26bdSAlan Somers        datasets="$pool $fs"
742fae26bdSAlan Somerselse
752fae26bdSAlan Somers        datasets="$fs"
762fae26bdSAlan Somersfi
772fae26bdSAlan Somers
782fae26bdSAlan Somersfor ds in $datasets; do
792fae26bdSAlan Somers	log_must $ZFS set quota=25M $ds
802fae26bdSAlan Somers	log_must $ZFS set refreservation=15M $ds
812fae26bdSAlan Somers
822fae26bdSAlan Somers	typeset  avail
832fae26bdSAlan Somers	avail=5M
842fae26bdSAlan Somers	log_must $ZFS set refreservation=$avail $subfs
852fae26bdSAlan Somers	typeset mntpnt
862fae26bdSAlan Somers	mntpnt=$(get_prop mountpoint $subfs)
872fae26bdSAlan Somers	log_must $MKFILE $avail $mntpnt/$TESTFILE
882fae26bdSAlan Somers
892fae26bdSAlan Somers	typeset  exceed
902fae26bdSAlan Somers	exceed=15M
912fae26bdSAlan Somers	log_mustnot $ZFS set refreservation=$exceed $subfs
922fae26bdSAlan Somers	log_mustnot $MKFILE $exceed $mntpnt/$TESTFILE
932fae26bdSAlan Somers
942fae26bdSAlan Somers	log_must $ZFS set quota=none $ds
952fae26bdSAlan Somersdone
962fae26bdSAlan Somers
972fae26bdSAlan Somerslog_pass "Verify refreservation is limited by available space."
98