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# $FreeBSD$
24
25#
26# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)reservation_008_pos.ksh	1.3	09/08/06 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33. $STF_SUITE/tests/reservation/reservation.kshlib
34
35###############################################################################
36#
37# __stc_assertion_start
38#
39# ID: reservation_008_pos
40#
41# DESCRIPTION:
42#
43# Setting a reservation reserves a defined minimum amount of space for
44# a dataset, and prevents other datasets using that space. Verify that
45# reducing the reservation on a filesystem allows other datasets in
46# the pool to use that space.
47#
48# STRATEGY:
49# 1) Create multiple filesystems
50# 2) Set reservations on all bar one of the filesystems
51# 3) Fill up the one non-reserved filesystem
52# 4) Reduce one of the reservations and verify can write more
53# data into the non-reserved filesystem
54#
55# TESTABILITY: explicit
56#
57# TEST_AUTOMATION_LEVEL: automated
58#
59# CODING_STATUS: COMPLETED (2005-07-04)
60#
61# __stc_assertion_end
62#
63################################################################################
64
65verify_runnable "both"
66
67log_assert "Verify reducing reservation allows other datasets to use space"
68
69log_must create_multiple_fs $RESV_NUM_FS $TESTPOOL/$TESTFS $TESTDIR
70
71space_avail=`get_prop available $TESTPOOL`
72space_used=`get_prop used $TESTPOOL`
73
74#
75# To make sure this test doesn't take too long to execute on
76# large pools, we calculate a reservation setting which when
77# applied to all bar one of the filesystems (RESV_NUM_FS-1) will
78# ensure we have RESV_FREE_SPACE left free in the pool, which we will
79# be able to quickly fill.
80#
81resv_space_avail=`expr $space_avail - $RESV_FREE_SPACE`
82num_resv_fs=`expr $RESV_NUM_FS - 1` # Number of FS to which resv will be applied
83resv_size_set=`expr $resv_space_avail / $num_resv_fs`
84
85#
86# We set the reservations now, rather than when we created the filesystems
87# to allow us to take into account space used by the filsystem metadata
88#
89# Note we don't set a reservation on the first filesystem we created,
90# hence num=1 rather than zero below.
91#
92typeset -i num=1
93while (( $num < $RESV_NUM_FS )); do
94	log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS$num
95	(( num = num + 1 ))
96done
97
98space_avail_still=`get_prop available $TESTPOOL`
99
100fill_size=`expr $space_avail_still + $RESV_TOLERANCE`
101write_count=`expr $fill_size / $BLOCK_SIZE`
102
103# Now fill up the first filesystem (which doesn't have a reservation set
104# and thus will use up whatever free space is left in the pool).
105num=0
106log_note "Writing to $TESTDIR$num/$TESTFILE1"
107
108$FILE_WRITE -o create -f $TESTDIR$num/$TESTFILE1 -b $BLOCK_SIZE \
109        -c $write_count -d 0
110ret=$?
111if (( $ret != $ENOSPC )); then
112	log_fail "Did not get ENOSPC as expected (got $ret)."
113fi
114
115# Remove the reservation on one of the other filesystems and verify
116# can write more data to the original non-reservation filesystem.
117num=1
118log_must $ZFS set reservation=none $TESTPOOL/${TESTFS}$num
119num=0
120log_must $FILE_WRITE -o create -f ${TESTDIR}$num/$TESTFILE2 -b $BLOCK_SIZE \
121        -c 1000 -d 0
122
123log_pass "reducing reservation allows other datasets to use space"
124