xref: /freebsd/tests/sys/cddl/zfs/tests/reservation/reservation_015_pos.ksh (revision ac00d4d59b18a76c6148ca5d7439bb446d38da5c)
1*2fae26bdSAlan Somers#! /usr/local/bin/ksh93 -p
2*2fae26bdSAlan Somers#
3*2fae26bdSAlan Somers# CDDL HEADER START
4*2fae26bdSAlan Somers#
5*2fae26bdSAlan Somers# The contents of this file are subject to the terms of the
6*2fae26bdSAlan Somers# Common Development and Distribution License (the "License").
7*2fae26bdSAlan Somers# You may not use this file except in compliance with the License.
8*2fae26bdSAlan Somers#
9*2fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*2fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing.
11*2fae26bdSAlan Somers# See the License for the specific language governing permissions
12*2fae26bdSAlan Somers# and limitations under the License.
13*2fae26bdSAlan Somers#
14*2fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each
15*2fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*2fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the
17*2fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying
18*2fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner]
19*2fae26bdSAlan Somers#
20*2fae26bdSAlan Somers# CDDL HEADER END
21*2fae26bdSAlan Somers#
22*2fae26bdSAlan Somers
23*2fae26bdSAlan Somers#
24*2fae26bdSAlan Somers# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25*2fae26bdSAlan Somers# Use is subject to license terms.
26*2fae26bdSAlan Somers
27*2fae26bdSAlan Somers. $STF_SUITE/include/libtest.kshlib
28*2fae26bdSAlan Somers. $STF_SUITE/tests/reservation/reservation.kshlib
29*2fae26bdSAlan Somers
30*2fae26bdSAlan Somers###############################################################################
31*2fae26bdSAlan Somers#
32*2fae26bdSAlan Somers# __stc_assertion_start
33*2fae26bdSAlan Somers#
34*2fae26bdSAlan Somers# ID: reservation_015_pos
35*2fae26bdSAlan Somers#
36*2fae26bdSAlan Somers# DESCRIPTION:
37*2fae26bdSAlan Somers#
38*2fae26bdSAlan Somers# In pool with a full filesystem and a regular volume with an implicit
39*2fae26bdSAlan Somers# reservation, setting the reservation on the volume to 'none' should allow
40*2fae26bdSAlan Somers# more data to be written to the filesystem.
41*2fae26bdSAlan Somers#
42*2fae26bdSAlan Somers#
43*2fae26bdSAlan Somers# STRATEGY:
44*2fae26bdSAlan Somers# 1) Create a regular non-sparse volume (which implicitly sets the reservation
45*2fae26bdSAlan Somers#    property to a value equal to the volume size)
46*2fae26bdSAlan Somers# 2) Create a filesystem at the same level
47*2fae26bdSAlan Somers# 3) Fill up the filesystem
48*2fae26bdSAlan Somers# 4) Set the reservation on the volume to 'none'
49*2fae26bdSAlan Somers# 5) Verify can write more data to the filesystem
50*2fae26bdSAlan Somers#
51*2fae26bdSAlan Somers# TESTABILITY: explicit
52*2fae26bdSAlan Somers#
53*2fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated
54*2fae26bdSAlan Somers#
55*2fae26bdSAlan Somers# CODING_STATUS: COMPLETED (2005-07-19)
56*2fae26bdSAlan Somers#
57*2fae26bdSAlan Somers# __stc_assertion_end
58*2fae26bdSAlan Somers#
59*2fae26bdSAlan Somers################################################################################
60*2fae26bdSAlan Somers
61*2fae26bdSAlan Somersverify_runnable "global"
62*2fae26bdSAlan Somers
63*2fae26bdSAlan Somerslog_assert "Setting volume reservation to 'none' allows more data to" \
64*2fae26bdSAlan Somers	" be written to top level filesystem"
65*2fae26bdSAlan Somers
66*2fae26bdSAlan Somersspace_avail=`get_prop available $TESTPOOL`
67*2fae26bdSAlan Somers
68*2fae26bdSAlan Somers#
69*2fae26bdSAlan Somers# To make sure this test doesn't take too long to execute on
70*2fae26bdSAlan Somers# large pools, we calculate a volume size which when applied
71*2fae26bdSAlan Somers# to the volume will ensure we have RESV_FREE_SPACE
72*2fae26bdSAlan Somers# left free in the pool which we can quickly fill.
73*2fae26bdSAlan Somers#
74*2fae26bdSAlan Somers# For the volume itself, set a reservation to 95% of available
75*2fae26bdSAlan Somers# space to allow space for metadata.
76*2fae26bdSAlan Somers#
77*2fae26bdSAlan Somers(( resv_size_set = space_avail * 95 / 100 ))
78*2fae26bdSAlan Somersresv_size_set=$(floor_volsize $resv_size_set $BLOCK_SIZE)
79*2fae26bdSAlan Somers
80*2fae26bdSAlan Somerslog_must $ZFS create -b $BLOCK_SIZE -V $resv_size_set $TESTPOOL/$TESTVOL
81*2fae26bdSAlan Somers
82*2fae26bdSAlan Somers# Create a secondary filesystem to soak up what's left to get
83*2fae26bdSAlan Somers# to RESV_FREE_SPACE for the pool.
84*2fae26bdSAlan Somersspace_avail_still=`get_prop available $TESTPOOL`
85*2fae26bdSAlan Somers(( zfs_res = space_avail_still - RESV_FREE_SPACE ))
86*2fae26bdSAlan Somerslog_must $ZFS create -o refreservation=$zfs_res $TESTPOOL/$TESTFS2
87*2fae26bdSAlan Somers
88*2fae26bdSAlan Somersspace_avail_still=`get_prop available $TESTPOOL`
89*2fae26bdSAlan Somers
90*2fae26bdSAlan Somersfill_size=`expr $space_avail_still + $RESV_TOLERANCE`
91*2fae26bdSAlan Somerswrite_count=`expr $fill_size / $BLOCK_SIZE`
92*2fae26bdSAlan Somers
93*2fae26bdSAlan Somers# Now fill up the filesystem (which doesn't have a reservation set
94*2fae26bdSAlan Somers# and thus will use up whatever free space is left in the pool).
95*2fae26bdSAlan Somers$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \
96*2fae26bdSAlan Somers        -c $write_count -d 0
97*2fae26bdSAlan Somersret=$?
98*2fae26bdSAlan Somers
99*2fae26bdSAlan Somersif (( $ret != $ENOSPC )); then
100*2fae26bdSAlan Somers	log_fail "Did not get ENOSPC as expected (got $ret)."
101*2fae26bdSAlan Somersfi
102*2fae26bdSAlan Somers
103*2fae26bdSAlan Somerslog_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
104*2fae26bdSAlan Somers
105*2fae26bdSAlan Somerslog_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $BLOCK_SIZE \
106*2fae26bdSAlan Somers        -c 1000 -d 0
107*2fae26bdSAlan Somers
108*2fae26bdSAlan Somerslog_pass "Setting top level volume reservation to 'none' allows more " \
109*2fae26bdSAlan Somers	"data to be written to the top level filesystem"
110