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#
92b33eab9463d6c4878cfe65febf2ff232689649John Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/tests/functional/reservation/reservation.cfg
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Function to set the reservation property of a dataset to
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 'none' and verify that it is correctly set using both the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# "normal" 'zfs get reservation' and the '-p' option which
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# gives a numerical value.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction zero_reservation
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset resv_val
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy dataset=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs set reservation=none $dataset
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy resv_val=`zfs get -H reservation $dataset | awk '{print $3}'`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $? -ne 0 ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "Unable to get reservation prop on $dataset"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy elif [[ $resv_val != "none" ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "Reservation not 'none' ($resv_val) as expected"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy resv_val=`zfs get -pH reservation $dataset | awk '{print $3}'`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $? -ne 0 ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "Unable to get reservation prop on $dataset"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy elif [[ $resv_val -ne 0 ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "Reservation not 0 ($resv_val) as expected"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy return 0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Utility function to see if two values are within a certain specified
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# limit of each other. Used primarily to check that a dataset's parent
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# is correctly accounting for space used/available. Need this function as
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# currently there is some slop in the way space is accounted (i.e. can't
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# do a direct comparison).
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction within_limits
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -l valA=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -l valB=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -l delta=$3
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if ((valA <= valB)); then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if (((valB - valA) <= delta)); then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy return 0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy elif ((valB <= valA)); then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if (((valA - valB) <= delta)); then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy return 0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy return 1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Function to create and mount multiple filesystems. The filesystem
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# will be named according to the name specified with a suffix value
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# taken from the loop counter.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction create_multiple_fs # num_fs base_fs_name base_mnt_name
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i iter=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i count=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset FS_NAME=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset MNT_NAME=$3
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while (($iter < $count)); do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs create ${FS_NAME}$iter
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs set mountpoint=${MNT_NAME}$iter ${FS_NAME}$iter
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((iter = iter + 1))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# This function compute the largest volume size which is multiple of volume
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# block size (default 8K) and not greater than the largest expected volsize.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $1 The largest expected volume size.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# $2 The volume block size
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction floor_volsize #<largest_volsize> [volblksize]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -l largest_volsize=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -l volblksize=${2:-8192}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if ((largest_volsize < volblksize)); then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "The largest_volsize must be greater than volblksize."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -l real_volsize
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -l n
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((n = largest_volsize / volblksize))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((largest_volsize = volblksize * n))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy print $largest_volsize
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# This function is a copy of a function by the same name in libzfs_dataset.c
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Its purpose is to reserve additional space for volume metadata so volumes
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# don't unexpectedly run out of room.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Note: This function can be used to do an estimate for a volume that has not
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# yet been created. In this case, $vol is not a volume, but rather a pool in
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# which a volume is going to be created. In this case, use default properties.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction volsize_to_reservation
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset vol=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i volsize=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
92b33eab9463d6c4878cfe65febf2ff232689649John Wren Kennedy typeset -i DN_MAX_INDBLKSHIFT=17
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i SPA_BLKPTRSHIFT=7
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i SPA_DVAS_PER_BP=3
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i DNODES_PER_LEVEL_SHIFT=$((DN_MAX_INDBLKSHIFT - \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy SPA_BLKPTRSHIFT))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i DNODES_PER_LEVEL=$((1 << $DNODES_PER_LEVEL_SHIFT))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if ds_is_volume $vol; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i ncopies=$(get_prop copies $vol)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i volblocksize=$(get_prop volblocksize $vol)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy else
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i ncopies=1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i volblocksize=8192
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i nblocks=$((volsize / volblocksize))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i numdb=7
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while ((nblocks > 1)); do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((nblocks += DNODES_PER_LEVEL - 1))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((nblocks /= DNODES_PER_LEVEL))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((numdb += nblocks))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((numdb *= SPA_DVAS_PER_BP < ncopies + 1 ? SPA_DVAS_PER_BP : \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ncopies + 1))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((volsize *= ncopies))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((numdb *= 1 << DN_MAX_INDBLKSHIFT))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((volsize += numdb))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy echo $volsize
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# This function takes a pool name as an argument, and returns the largest (give
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or take some slop) -V value that can be used to create a volume in that pool.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# This is necessary because during volume creation, a reservation is created
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# that will be larger than the value specified with -V, and potentially larger
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# than the available space in the pool. See volsize_to_reservation().
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction largest_volsize_from_pool
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset pool=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i poolsize=$(get_prop available $pool)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i volsize=$poolsize
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i nvolsize
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while :; do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # knock 50M off the volsize each time through
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((volsize -= 50 * 1024 * 1024))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy nvolsize=$(volsize_to_reservation $pool $volsize)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy nvolsize=$(floor_volsize $nvolsize)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((nvolsize < poolsize)) && break
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy echo $volsize
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}