xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/reservation/reservation_016_pos.sh (revision 1d32ba663e202c24a5a1f2e5aef83fffb447cb7f)
1f38cb554SJohn Wren Kennedy#!/usr/bin/bash -p
2f38cb554SJohn Wren Kennedy#
3f38cb554SJohn Wren Kennedy# CDDL HEADER START
4f38cb554SJohn Wren Kennedy#
5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the
6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License").
7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License.
8f38cb554SJohn Wren Kennedy#
9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions
12f38cb554SJohn Wren Kennedy# and limitations under the License.
13f38cb554SJohn Wren Kennedy#
14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19f38cb554SJohn Wren Kennedy#
20f38cb554SJohn Wren Kennedy# CDDL HEADER END
21f38cb554SJohn Wren Kennedy#
22f38cb554SJohn Wren Kennedy
23f38cb554SJohn Wren Kennedy#
24f38cb554SJohn Wren Kennedy# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25f38cb554SJohn Wren Kennedy# Use is subject to license terms.
26f38cb554SJohn Wren Kennedy#
27f38cb554SJohn Wren Kennedy
28f38cb554SJohn Wren Kennedy#
29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30f38cb554SJohn Wren Kennedy#
31f38cb554SJohn Wren Kennedy
32f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib
33f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/reservation/reservation.shlib
34f38cb554SJohn Wren Kennedy
35f38cb554SJohn Wren Kennedy#
36f38cb554SJohn Wren Kennedy# DESCRIPTION:
37f38cb554SJohn Wren Kennedy#
38f38cb554SJohn Wren Kennedy# In pool with a full filesystem and a regular volume (with implicit
39f38cb554SJohn Wren Kennedy# reservation) destroying the volume should allow more data to be written
40f38cb554SJohn Wren Kennedy# to the filesystem
41f38cb554SJohn Wren Kennedy#
42f38cb554SJohn Wren Kennedy#
43f38cb554SJohn Wren Kennedy# STRATEGY:
44f38cb554SJohn Wren Kennedy# 1) Create a regular (non-sparse) volume
45f38cb554SJohn Wren Kennedy# 2) Create a filesystem at the same level
46f38cb554SJohn Wren Kennedy# 3) Fill up the filesystem
47f38cb554SJohn Wren Kennedy# 4) Destroy the volume
48f38cb554SJohn Wren Kennedy# 5) Verify can write more data to the filesystem
49f38cb554SJohn Wren Kennedy#
50f38cb554SJohn Wren Kennedy
51f38cb554SJohn Wren Kennedyverify_runnable "global"
52f38cb554SJohn Wren Kennedy
53f38cb554SJohn Wren Kennedylog_assert "Destroying a regular volume with reservation allows more data to" \
54f38cb554SJohn Wren Kennedy    " be written to top level filesystem"
55f38cb554SJohn Wren Kennedy
56f38cb554SJohn Wren Kennedyfunction cleanup
57f38cb554SJohn Wren Kennedy{
58f38cb554SJohn Wren Kennedy	datasetexists $TESTPOOL/$TESTVOL && \
59*1d32ba66SJohn Wren Kennedy	    log_must zfs destroy $TESTPOOL/$TESTVOL
60f38cb554SJohn Wren Kennedy
61*1d32ba66SJohn Wren Kennedy	[[ -e $TESTDIR/$TESTFILE1 ]] && log_must rm -rf $TESTDIR/$TESTFILE1
62*1d32ba66SJohn Wren Kennedy	[[ -e $TESTDIR/$TESTFILE2 ]] && log_must rm -rf $TESTDIR/$TESTFILE2
63f38cb554SJohn Wren Kennedy}
64f38cb554SJohn Wren Kennedylog_onexit cleanup
65f38cb554SJohn Wren Kennedy
66f38cb554SJohn Wren Kennedyspace_avail=$(largest_volsize_from_pool $TESTPOOL)
67f38cb554SJohn Wren Kennedy
68f38cb554SJohn Wren Kennedy#
69f38cb554SJohn Wren Kennedy# To make sure this test doesn't take too long to execute on
70f38cb554SJohn Wren Kennedy# large pools, we calculate a volume size which will ensure we
71f38cb554SJohn Wren Kennedy# have RESV_FREE_SPACE left free in the pool.
72f38cb554SJohn Wren Kennedy#
73f38cb554SJohn Wren Kennedy((vol_set_size = space_avail - RESV_FREE_SPACE))
74f38cb554SJohn Wren Kennedyvol_set_size=$(floor_volsize $vol_set_size)
75f38cb554SJohn Wren Kennedy
76f38cb554SJohn Wren Kennedy# Creating a regular volume implicitly sets its reservation
77f38cb554SJohn Wren Kennedy# property to the same value.
78*1d32ba66SJohn Wren Kennedylog_must zfs create -V $vol_set_size $TESTPOOL/$TESTVOL
79f38cb554SJohn Wren Kennedy
80f38cb554SJohn Wren Kennedyspace_avail_still=$(get_prop available $TESTPOOL)
81f38cb554SJohn Wren Kennedyfill_size=$((space_avail_still + $RESV_TOLERANCE))
82f38cb554SJohn Wren Kennedywrite_count=$((fill_size / BLOCK_SIZE))
83f38cb554SJohn Wren Kennedy
84f38cb554SJohn Wren Kennedy# Now fill up the filesystem (which doesn't have a reservation set
85f38cb554SJohn Wren Kennedy# and thus will use up whatever free space is left in the pool).
86*1d32ba66SJohn Wren Kennedyfile_write -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE -c $write_count -d 0
87f38cb554SJohn Wren Kennedyret=$?
88f38cb554SJohn Wren Kennedyif (($ret != $ENOSPC)); then
89f38cb554SJohn Wren Kennedy	log_fail "Did not get ENOSPC as expected (got $ret)."
90f38cb554SJohn Wren Kennedyfi
91f38cb554SJohn Wren Kennedy
92*1d32ba66SJohn Wren Kennedylog_must zfs destroy -f $TESTPOOL/$TESTVOL
93f38cb554SJohn Wren Kennedy
94*1d32ba66SJohn Wren Kennedylog_must file_write -o create -f $TESTDIR/$TESTFILE2 -b pagesize \
95f38cb554SJohn Wren Kennedy    -c 1000 -d 0
96f38cb554SJohn Wren Kennedy
97f38cb554SJohn Wren Kennedylog_pass "Destroying volume with reservation allows more data to be written " \
98f38cb554SJohn Wren Kennedy    "to top level filesystem"
99