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# $FreeBSD$
24
25#
26# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)reservation_017_pos.ksh	1.5	09/01/12 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33. $STF_SUITE/tests/reservation/reservation.kshlib
34
35###############################################################################
36#
37# __stc_assertion_start
38#
39# ID: reservation_017_pos
40#
41# DESCRIPTION:
42#
43# For a sparse volume changes to the volsize are not reflected in the reservation
44#
45# STRATEGY:
46# 1) Create a regular and sparse volume
47# 2) Get the space available in the pool
48# 3) Set reservation with various size on the regular and sparse volume
49# 4) Verify that the 'reservation' property for the regular volume has
50#    the correct value.
51# 5) Verify that the 'reservation' property for the sparse volume is set to 'none'
52#
53# TESTABILITY: explicit
54#
55# TEST_AUTOMATION_LEVEL: automated
56#
57# CODING_STATUS: COMPLETED (2006-08-17)
58#
59# __stc_assertion_end
60#
61###############################################################################
62
63verify_runnable "global"
64
65log_assert "Verify that the volsize changes of sparse volume are not reflected" \
66	"in the reservation"
67
68#Create a regular and sparse volume for testing.
69regvol=$TESTPOOL/$TESTVOL
70sparsevol=$TESTPOOL/$TESTVOL2
71log_must $ZFS create -V $VOLSIZE -o volblocksize=16k $regvol
72log_must $ZFS create -s -V $VOLSIZE -o volblocksize=16k $sparsevol
73
74typeset -l vsize=$(get_prop available $TESTPOOL)
75typeset -i iterate=10
76typeset -l regreserv
77typeset -l sparsereserv
78typeset -l vblksize1=$(get_prop volblocksize $regvol)
79typeset -l vblksize2=$(get_prop volblocksize $sparsevol)
80typeset -l blknum=0
81if [ "$vblksize1" != "$vblksize2" ]; then
82	log_must $ZFS set volblocksize=$vblksize1 $sparsevol
83fi
84(( blknum = vsize / vblksize1 ))
85
86typeset -i randomblknum
87while (( iterate > 1 )); do
88	(( randomblknum = 1 + $RANDOM % $blknum ))
89	#Make sure volsize is a multiple of volume block size
90	(( vsize = $randomblknum * $vblksize1 ))
91	log_must $ZFS set volsize=$vsize $regvol
92	log_must $ZFS set volsize=$vsize $sparsevol
93	regreserv=$(get_prop refreservation $regvol)
94	sparsereserv=$(get_prop refreservation $sparsevol)
95	reg_shouldreserv=$(zvol_volsize_to_reservation $vsize $vblksize1 1)
96
97	(( $sparsereserv == $vsize )) && \
98		log_fail "volsize changes of sparse volume is reflected in reservation."
99	(( $regreserv != $reg_shouldreserv )) && \
100		log_fail "volsize changes of regular volume isnot reflected in reservation."
101
102	(( iterate = iterate - 1 ))
103done
104
105log_pass "The volsize change of sparse volume is not reflected in reservation as expected."
106