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 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/include/libtest.kshlib
28
29#
30# Given a pool vdevs list, create the pool,verify the created pool,
31# and destroy the pool
32# $1, pool name
33# $2, pool type, mirror, raidz, or none
34# $3, vdevs list
35#
36function create_pool_test
37{
38	typeset pool=$1
39	typeset keywd=$2
40	typeset vdevs
41	eval set -A diskarray $3
42
43        for vdevs in "${diskarray[@]}";do
44        	create_pool $pool $keywd $vdevs
45                log_must poolexists $pool
46		destroy_pool $pool
47        done
48}
49
50#
51# Create a ufs file system and make a vdev file on it
52#
53# $1, disk name to create ufs file system
54# $2, file name
55#
56function create_blockfile
57{
58	typeset disk=$1
59	typeset file=$2
60	typeset dir=`$DIRNAME $file`
61
62	if [[ -d $dir ]]; then
63		ismounted $dir ufs && log_must $UMOUNT -f $dir
64	else
65		log_must $MKDIR -p $dir
66	fi
67
68	log_must $NEWFS $disk
69	log_must $MOUNT $disk $dir
70	log_must create_vdevs $file
71}
72
73#
74# Umount the ufs filesystem and remove the mountpoint
75# $1, the mount point
76#
77function clean_blockfile
78{
79	typeset dirs=$1
80
81	for dir in $dirs; do
82		if [[ -d $dir ]]; then
83			if ismounted $dir ufs; then
84				log_must $UMOUNT -f $dir
85			fi
86			log_must $RM -rf $dir
87		fi
88	done
89}
90
91#
92# Find the storage device in /etc/vfstab
93#
94function find_fstab_dev
95{
96	typeset fstab="/etc/fstab"
97	typeset tmpfile="$TMPDIR/fstab.tmp"
98	typeset fstabdev
99	typeset fstabdevs=""
100	typeset line
101
102	$CAT $fstab | $GREP "^/dev" >$tmpfile
103	while read -r line
104	do
105		fstabdev=`$ECHO "$line" | $AWK '{print $1}'`
106		fstabdev=${fstabdev%%:}
107		fstabdevs="$fstabdev $fstabdevs"
108	done <$tmpfile
109
110	$RM -f $tmpfile
111	$ECHO $fstabdevs
112}
113