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