xref: /freebsd/tests/sys/cddl/zfs/tests/reservation/reservation_015_pos.ksh (revision 63f537551380d2dab29fa402ad1269feae17e594)
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# ident	"@(#)reservation_015_pos.ksh	1.4	09/08/06 SMI"
28#
29
30. $STF_SUITE/include/libtest.kshlib
31. $STF_SUITE/tests/reservation/reservation.kshlib
32
33###############################################################################
34#
35# __stc_assertion_start
36#
37# ID: reservation_015_pos
38#
39# DESCRIPTION:
40#
41# In pool with a full filesystem and a regular volume with an implicit
42# reservation, setting the reservation on the volume to 'none' should allow
43# more data to be written to the filesystem.
44#
45#
46# STRATEGY:
47# 1) Create a regular non-sparse volume (which implicitly sets the reservation
48#    property to a value equal to the volume size)
49# 2) Create a filesystem at the same level
50# 3) Fill up the filesystem
51# 4) Set the reservation on the volume to 'none'
52# 5) Verify can write more data to the filesystem
53#
54# TESTABILITY: explicit
55#
56# TEST_AUTOMATION_LEVEL: automated
57#
58# CODING_STATUS: COMPLETED (2005-07-19)
59#
60# __stc_assertion_end
61#
62################################################################################
63
64verify_runnable "global"
65
66log_assert "Setting volume reservation to 'none' allows more data to" \
67	" be written to top level filesystem"
68
69space_avail=`get_prop available $TESTPOOL`
70
71#
72# To make sure this test doesn't take too long to execute on
73# large pools, we calculate a volume size which when applied
74# to the volume will ensure we have RESV_FREE_SPACE
75# left free in the pool which we can quickly fill.
76#
77# For the volume itself, set a reservation to 95% of available
78# space to allow space for metadata.
79#
80(( resv_size_set = space_avail * 95 / 100 ))
81resv_size_set=$(floor_volsize $resv_size_set $BLOCK_SIZE)
82
83log_must $ZFS create -b $BLOCK_SIZE -V $resv_size_set $TESTPOOL/$TESTVOL
84
85# Create a secondary filesystem to soak up what's left to get
86# to RESV_FREE_SPACE for the pool.
87space_avail_still=`get_prop available $TESTPOOL`
88(( zfs_res = space_avail_still - RESV_FREE_SPACE ))
89log_must $ZFS create -o refreservation=$zfs_res $TESTPOOL/$TESTFS2
90
91space_avail_still=`get_prop available $TESTPOOL`
92
93fill_size=`expr $space_avail_still + $RESV_TOLERANCE`
94write_count=`expr $fill_size / $BLOCK_SIZE`
95
96# Now fill up the filesystem (which doesn't have a reservation set
97# and thus will use up whatever free space is left in the pool).
98$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \
99        -c $write_count -d 0
100ret=$?
101
102if (( $ret != $ENOSPC )); then
103	log_fail "Did not get ENOSPC as expected (got $ret)."
104fi
105
106log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
107
108log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $BLOCK_SIZE \
109        -c 1000 -d 0
110
111log_pass "Setting top level volume reservation to 'none' allows more " \
112	"data to be written to the top level filesystem"
113