1# vim: filetype=sh
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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)zpool_add.kshlib	1.3	07/03/14 SMI"
28#
29
30. $STF_SUITE/include/libtest.kshlib
31
32#
33# check if the <pool> contains <vdev> ...
34#
35# $1 pool
36# $2..n <vdev> ...
37#
38# Return 0 if <vdev> are contained in the <pool>; 1 if not used; 2 if pool
39# name is missing
40#
41function iscontained
42{
43	typeset pool=$1
44	typeset vdev
45
46        if [[ -z $pool ]]; then
47                log_note "Missing pool name."
48                return 2
49        fi
50
51	shift
52
53	for vdev in $@; do
54
55# remove /dev/ in vdev if there is
56		vdev=${vdev#/dev/}
57
58		$ZPOOL status "$pool" | $AWK '$1 == vdevname {exit 1}' \
59			vdevname=$vdev >/dev/null 2>&1
60		(( $? != 1 )) && \
61			return 1
62	done
63
64	return 0;
65
66}
67
68#
69# Common cleanup routine for partitions used in testing
70#
71function partition_cleanup
72{
73	log_note "Cleaning up partitions..."
74	if [[ -n $DISK ]]; then
75		partition_disk $SIZE $DISK 7
76	else
77		typeset disk=""
78		for disk in $DISK0 $DISK1; do
79			partition_disk $SIZE $disk 7
80		done
81	fi
82}
83