xref: /freebsd/tests/sys/cddl/zfs/tests/reservation/reservation_001_pos.ksh (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
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 2008 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_001_pos
35#
36# DESCRIPTION:
37#
38# ZFS allows reservations to be set on filesystems and volumes, provided
39# the reservation is less than the space available in the pool.
40#
41# STRATEGY:
42# 1) Create a regular and sparse volume
43#   (filesystem already created by default_setup)
44# 2) Get the space available in the pool
45# 3) Set a reservation on the filesystem less than the space available.
46# 4) Verify that the 'reservation' property for the filesystem has
47#    the correct value.
48# 5) Reset the reservation to 'none'
49# 6) Repeat steps 2-5 for both volume types
50#
51# TESTABILITY: explicit
52#
53# TEST_AUTOMATION_LEVEL: automated
54#
55# CODING_STATUS: COMPLETED (2005-07-19)
56#
57# __stc_assertion_end
58#
59###############################################################################
60
61verify_runnable "both"
62
63log_assert "Verify that to set a reservation on a filesystem" \
64        " or volume must use value smaller than space" \
65	" available property of pool"
66
67space_avail=`get_prop available $TESTPOOL`
68
69if ! is_global_zone ; then
70	OBJ_LIST=""
71else
72	OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
73
74	(( vol_set_size = space_avail / 4 ))
75	vol_set_size=$(floor_volsize $vol_set_size)
76	(( sparse_vol_set_size = space_avail * 4 ))
77	sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
78
79	#
80	# Note that when creating a regular volume we are implicitly
81	# setting a reservation upon it (i.e. the size of the volume)
82	# which we reset back to zero initially.
83	#
84	log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
85	log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
86	if fs_prop_exist refreserv; then
87		log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
88	fi
89	log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
90fi
91
92
93for obj in $TESTPOOL/$TESTFS $OBJ_LIST; do
94
95        space_avail=`get_prop available $TESTPOOL`
96        resv_size_set=`expr $space_avail - $RESV_DELTA`
97
98	#
99	# For a regular (non-sparse) volume the upper limit
100	# for reservations is not determined by the space
101	# available in the pool but rather by the size of
102	# the volume itself.
103	#
104        [[ $obj == $TESTPOOL/$TESTVOL ]] && \
105                (( resv_size_set = vol_set_size - RESV_DELTA ))
106
107        log_must $ZFS set reservation=$resv_size_set $obj
108
109        resv_size_get=`get_prop reservation $obj`
110        if [[ $resv_size_set != $resv_size_get ]]; then
111                log_fail "Reservation not the expected value "\
112                        "($resv_size_set != $resv_size_get)"
113        fi
114
115        log_must zero_reservation $obj
116
117        new_space_avail=`get_prop available $obj`
118
119        #
120        # Due to the way space is consumed and released by metadata we
121        # can't do an exact check here, but we do do a basic sanity
122        # check.
123        #
124        log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
125done
126
127log_pass "Successfully set reservation on filesystem and volume"
128