xref: /freebsd/tests/sys/cddl/zfs/tests/reservation/reservation_003_pos.ksh (revision 7ab1a32cd43cbae61ad4dd435d6a482bbf61cb52)
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 2009 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_003_pos
35#
36# DESCRIPTION:
37#
38# Verify that it's possible to set a reservation on a filesystem,
39# or volume multiple times, without resetting the reservation
40# to none.
41#
42# STRATEGY:
43# 1) Create a regular volume and a sparse volume
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) Repeat 2-4 for different reservation values
49# 6) Repeat 3-5 for regular and sparse volume
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 it is possible to set reservations multiple times " \
64	"on a filesystem regular and sparse volume"
65
66
67#
68# Set a reservation $RESV_ITER times on a dataset and verify that
69# the reservation is correctly set each time.
70#
71function multiple_resv { #dataset
72	typeset -i i=0
73
74	dataset=$1
75
76	log_must zero_reservation $dataset
77	space_avail=`get_prop available $TESTPOOL`
78
79	(( resv_size = ( space_avail - RESV_DELTA ) / RESV_ITER ))
80
81	#
82        # For regular (non-sparse) volumes the upper limit is determined
83        # not by the space available in the pool but rather by the size
84        # of the volume itself.
85        #
86        [[ $obj == $TESTPOOL/$TESTVOL ]] && \
87                (( resv_size = ( vol_set_size - RESV_DELTA ) / RESV_ITER ))
88
89	resv_size_set=$resv_size
90
91	while (( $i < $RESV_ITER )); do
92
93		(( i = i + 1 ))
94
95		(( resv_size_set = resv_size * i ))
96
97		log_must $ZFS set reservation=$resv_size_set $dataset
98
99		resv_size_get=`get_prop reservation $dataset`
100		if [[ $resv_size_set != $resv_size_get ]]; then
101			log_fail "Reservation not the expected value " \
102				"($resv_size_set != $resv_size_get)"
103		fi
104	done
105
106	log_must zero_reservation $dataset
107}
108
109space_avail=`get_prop available $TESTPOOL`
110
111if ! is_global_zone ; then
112	OBJ_LIST=""
113else
114	OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
115
116	(( vol_set_size = space_avail / 4 ))
117	vol_set_size=$(floor_volsize $vol_set_size)
118	(( sparse_vol_set_size = space_avail * 4 ))
119	sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
120
121
122	log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
123	log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
124	log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
125fi
126
127for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
128	multiple_resv $obj
129done
130
131log_pass "Multiple reservations successfully set on filesystem" \
132	" and both volume types"
133