1#!/bin/ksh -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
28#
29# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
34
35#
36# DESCRIPTION:
37#	A volume can be added as several segments, but overlapping segments
38#	are not 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
46verify_runnable "global"
47
48function cleanup
49{
50	typeset -i i=0
51
52	while ((count > 0)); do
53		log_must swap -d $swapname ${swap_opt[$i]}
54
55		((i += 2))
56		((count -= 1))
57	done
58}
59
60log_assert "Verify volume can be add as several segments, but overlapping " \
61	"are not allowed."
62log_onexit cleanup
63
64# swap -a won't allow the use of multiple segments of the same volume unless
65# libdiskmgmt is disabled with the environment variable below.
66typeset -x NOINUSE_CHECK=1
67
68typeset vol=$TESTPOOL/$TESTVOL
69typeset -i pageblocks volblocks
70((pageblocks = $(pagesize) / 512))
71((volblocks = $(get_prop volsize $vol) / 512))
72
73log_note "Verify volume can be add as several segments."
74
75#
76#		swaplow			swaplen
77set -A swap_opt	$((pageblocks))	    \
78		$((RANDOM % (50 * pageblocks) + 2 * pageblocks)) \
79		$((volblocks / 3))  \
80		$((RANDOM % (50 * pageblocks) + 2 * pageblocks)) \
81		$((volblocks / 2))  \
82		$((RANDOM % (50 * pageblocks) + 2 * pageblocks)) \
83		$(((volblocks*2) / 3))  \
84		$((RANDOM % (50 * pageblocks) + 2 * pageblocks))
85
86swapname=/dev/zvol/dsk/$vol
87typeset -i i=0 count=0
88
89if is_swap_inuse $swapname ; then
90	log_must swap -d $swapname
91fi
92
93while ((i < ${#swap_opt[@]})); do
94	log_must swap -a $swapname ${swap_opt[$i]} ${swap_opt[((i+1))]}
95
96	((i += 2))
97	((count += 1))
98done
99
100log_note "Verify overlapping swap volume are not allowed"
101i=0
102while ((i < ${#swap_opt[@]})); do
103	log_mustnot swap -a $swapname ${swap_opt[$i]}
104
105	((i += 2))
106done
107
108log_pass "Verify volume can be added as several segments passed."
109