f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#!/usr/bin/bash -p
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/include/libtest.shlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/tests/functional/reservation/reservation.shlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# DESCRIPTION:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Setting a reservation reserves a defined minimum amount of space for
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# a dataset, and prevents other datasets using that space. Verify that
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# reducing the reservation on a filesystem allows other datasets in
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# the pool to use that space.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# STRATEGY:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 1) Create multiple filesystems
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 2) Set reservations on all bar one of the filesystems
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 3) Fill up the one non-reserved filesystem
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 4) Reduce one of the reservations and verify can write more
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# data into the non-reserved filesystem
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_runnable "both"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_assert "Verify reducing reservation allows other datasets to use space"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i loop=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while (($loop < $RESV_NUM_FS)); do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy datasetexists $TESTPOOL/${TESTFS}$loop && \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs destroy -f $TESTPOOL/${TESTFS}$loop
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy [[ -d ${TESTDIR}$loop ]] && log_must rm -r ${TESTDIR}$loop
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((loop = loop + 1))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_onexit cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must create_multiple_fs $RESV_NUM_FS $TESTPOOL/$TESTFS $TESTDIR
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyspace_avail=`get_prop available $TESTPOOL`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyspace_used=`get_prop used $TESTPOOL`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# To make sure this test doesn't take too long to execute on
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# large pools, we calculate a reservation setting which when
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# applied to all bar one of the filesystems (RESV_NUM_FS-1) will
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# ensure we have RESV_FREE_SPACE left free in the pool, which we will
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# be able to quickly fill.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyresv_space_avail=`expr $space_avail - $RESV_FREE_SPACE`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedynum_resv_fs=`expr $RESV_NUM_FS - 1` # Number of FS to which resv will be applied
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyresv_size_set=`expr $resv_space_avail / $num_resv_fs`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# We set the reservations now, rather than when we created the filesystems
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# to allow us to take into account space used by the filsystem metadata
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Note we don't set a reservation on the first filesystem we created,
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# hence num=1 rather than zero below.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i num=1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedywhile (($num < $RESV_NUM_FS)); do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs set reservation=$resv_size_set $TESTPOOL/$TESTFS$num
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((num = num + 1))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyspace_avail_still=`get_prop available $TESTPOOL`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfill_size=`expr $space_avail_still + $RESV_TOLERANCE`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedywrite_count=`expr $fill_size / $BLOCK_SIZE`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Now fill up the first filesystem (which doesn't have a reservation set
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and thus will use up whatever free space is left in the pool).
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedynum=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_note "Writing to $TESTDIR$num/$TESTFILE1"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyfile_write -o create -f $TESTDIR$num/$TESTFILE1 -b $BLOCK_SIZE \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy -c $write_count -d 0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyret=$?
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif (($ret != $ENOSPC)); then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "Did not get ENOSPC as expected (got $ret)."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Remove the reservation on one of the other filesystems and verify
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# can write more data to the original non-reservation filesystem.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedynum=1
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must zfs set reservation=none $TESTPOOL/${TESTFS}$num
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedynum=0
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must file_write -o create -f ${TESTDIR}$num/$TESTFILE2 -b pagesize \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy -c 1000 -d 0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_pass "reducing reservation allows other datasets to use space"