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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/include/libtest.kshlib
28. $STF_SUITE/tests/zvol/zvol_common.kshlib
29
30#################################################################################
31#
32# __stc_assertion_start
33#
34# ID: zvol_swap_006_pos
35#
36# DESCRIPTION:
37#	 A volume can be add as several segments, but overlapping are not
38#	 allowed.
39#
40# STRATEGY:
41#	1. Figure out three groups swaplow and swaplen.
42#	2. Verify different volume segments can be added correctly.
43#	3. Verify overlapping swap volume are not allowed.
44#
45# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2006-12-13)
50#
51# __stc_assertion_end
52#
53################################################################################
54
55verify_runnable "global"
56
57function cleanup
58{
59	typeset -i i=0
60
61	while ((count > 0)); do
62		log_must $SWAP -d $swapname ${swap_opt[$i]}
63
64		((i += 2))
65		((count -= 1))
66	done
67}
68
69log_assert "Verify volume can be add as several segments, but overlapping " \
70	"are not allowed."
71log_onexit cleanup
72
73test_requires SWAP
74
75typeset vol=$TESTPOOL/$TESTVOL
76typeset -i pageblocks volblocks
77((pageblocks = $($PAGESIZE) / 512))
78((volblocks = $(get_prop volsize $vol) / 512))
79
80log_note "Verify volume can be add as several segments."
81
82#
83#		swaplow			swaplen
84set -A swap_opt	$((pageblocks))	    \
85		$((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
86		$((volblocks / 3))  \
87		$((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
88		$((volblocks / 2))  \
89		$((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
90		$(((volblocks*2) / 3))  \
91		$((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) ))
92
93swapname=/dev/zvol/$vol
94typeset -i i=0 count=0
95
96if is_swap_inuse $swapname ; then
97	log_must $SWAP -d $swapname
98fi
99
100while ((i < ${#swap_opt[@]})); do
101	log_must $SWAP -a $swapname ${swap_opt[$i]} ${swap_opt[((i+1))]}
102
103	((i += 2))
104	((count += 1))
105done
106
107log_note "Verify overlapping swap volume are not allowed"
108i=0
109while ((i < ${#swap_opt[@]})); do
110	log_mustnot $SWAP -a $swapname ${swap_opt[$i]}
111
112	((i += 2))
113done
114
115log_pass "Verify volume can be added as several segments passed."
116