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