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# For a sparse volume changes to the volsize are not reflected in the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# reservation.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# STRATEGY:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 1) Create a regular and sparse volume
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 2) Get the space available in the pool
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 3) Set reservation with various sizes on the regular and sparse volumes
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 4) Verify that the 'reservation' property for the regular volume has
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# the correct value.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 5) Verify that the 'reservation' property for the sparse volume is set to
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 'none'
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_runnable "global"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset vol
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy for vol in $regvol $sparsevol; do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy datasetexists $vol && log_must zfs destroy $vol
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_onexit cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_assert "Verify that the volsize changes of sparse volumes are not " \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "reflected in the reservation."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_onexit cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Create a regular and sparse volume for testing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyregvol=$TESTPOOL/$TESTVOL
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedysparsevol=$TESTPOOL/$TESTVOL2
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must zfs create -V 64M $regvol
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must zfs create -s -V 64M $sparsevol
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i vsize=$(get_prop available $TESTPOOL)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i iterate=10
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i regreserv
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i sparsereserv
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i volblocksize=$(get_prop volblocksize $regvol)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i blknum=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i randomblknum
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy((blknum = vsize / volblocksize))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedywhile ((iterate > 1)); do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((randomblknum = 1 + RANDOM % blknum))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # Make sure volsize is a multiple of volume block size
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((vsize = randomblknum * volblocksize))
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs set volsize=$vsize $regvol
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs set volsize=$vsize $sparsevol
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy vsize=$(volsize_to_reservation $regvol $vsize)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy regreserv=$(get_prop refreservation $regvol)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy sparsereserv=$(get_prop reservation $sparsevol)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((sparsereserv == vsize)) && \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "volsize changes of sparse volume is reflected in " \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "reservation (expected $vsize, got $sparsereserv)."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((regreserv != vsize)) && \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "volsize changes of regular volume is not reflected " \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "in reservation (expected $vsize, got $regreserv)."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((iterate = iterate - 1))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_pass "The volsize changes of sparse volumes are not reflected in the " \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "reservation"