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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)reservation_010_pos.ksh	1.2	07/01/09 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_010_pos
38#
39# DESCRIPTION:
40#
41# In pool with a full filesystem and a filesystem with a reservation
42# destroying another filesystem should allow more data to be written to
43# the full filesystem
44#
45#
46# STRATEGY:
47# 1) Create a filesystem as dataset
48# 2) Create a filesystem at the same level
49# 3) Set a reservation on the dataset filesystem
50# 4) Fill up the second filesystem
51# 5) Destroy the dataset filesystem
52# 6) Verify can write more data to the full filesystem
53#
54# TESTABILITY: explicit
55#
56# TEST_AUTOMATION_LEVEL: automated
57#
58# CODING_STATUS: COMPLETED (2005-07-04)
59#
60# __stc_assertion_end
61#
62################################################################################
63
64verify_runnable "both"
65
66log_assert "Destroying top level filesystem with reservation allows more data to" \
67	" be written to another top level filesystem"
68
69log_must $ZFS create $TESTPOOL/$TESTFS1
70
71space_avail=`get_prop available $TESTPOOL`
72
73#
74# To make sure this test doesn't take too long to execute on
75# large pools, we calculate a reservation setting which when
76# applied to the dataset filesystem  will ensure we have
77# RESV_FREE_SPACE left free in the pool.
78#
79(( resv_size_set = space_avail - RESV_FREE_SPACE ))
80
81log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS1
82
83space_avail_still=`get_prop available $TESTPOOL`
84
85fill_size=`expr $space_avail_still + $RESV_TOLERANCE`
86write_count=`expr $fill_size / $BLOCK_SIZE`
87
88# Now fill up the filesystem (which doesn't have a reservation set
89# and thus will use up whatever free space is left in the pool).
90$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \
91        -c $write_count -d 0
92ret=$?
93if (( $ret != $ENOSPC )); then
94	log_fail "Did not get ENOSPC as expected (got $ret)."
95fi
96
97log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
98
99log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $BLOCK_SIZE \
100        -c 1000 -d 0
101
102log_pass "Destroying top level filesystem with reservation allows more data to" \
103	" be written to another top level filesystem"
104