1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26
27#
28# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
29#
30
31. $STF_SUITE/include/libtest.shlib
32. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.cfg
33
34#
35# Find the storage device in /etc/vfstab
36#
37function find_vfstab_dev
38{
39	typeset vfstabdev
40	typeset vfstabdevs=""
41	typeset line
42
43	if is_illumos; then
44		vfstab="/etc/vfstab"
45		tmpfile="$TEST_BASE_DIR/vfstab.tmp"
46	else
47		vfstab="/etc/fstab"
48		tmpfile="$TEST_BASE_DIR/fstab.tmp"
49	fi
50
51	cat $vfstab | grep "^${DEV_DSKDIR}" >$tmpfile
52	while read -r line
53	do
54		vfstabdev=`echo "$line" | awk '{print $1}'`
55		vfstabdev=${vfstabdev%%:}
56		vfstabdevs="$vfstabdev $vfstabdevs"
57	done <$tmpfile
58
59	rm -f $tmpfile
60	echo $vfstabdevs
61}
62
63#
64# Find the storage device in /etc/mnttab
65#
66function find_mnttab_dev
67{
68	typeset mnttabdev
69	typeset mnttabdevs=""
70	typeset line
71
72	if is_freebsd; then
73		# FreeBSD doesn't have a mnttab file.
74		mount -p | awk -v dir="^${DEV_DSKDIR}" \
75		    '$1 ~ dir { print $1 }' | xargs
76		return 0
77	elif is_linux; then
78		typeset mnttab="/etc/mtab"
79		typeset tmpfile="$TEST_BASE_DIR/mtab.tmp"
80	else
81		typeset mnttab="/etc/mnttab"
82		typeset tmpfile="$TEST_BASE_DIR/mnttab.tmp"
83	fi
84
85	cat $mnttab | grep "^${DEV_DSKDIR}" >$tmpfile
86	while read -r line
87	do
88		mnttabdev=`echo "$line" | awk '{print $1}'`
89		mnttabdev=${mnttabdev%%:}
90		mnttabdevs="$mnttabdev $mnttabdevs"
91	done <$tmpfile
92
93	rm -f $tmpfile
94	echo $mnttabdevs
95}
96
97#
98# Save the system current dump device configuration
99#
100function save_dump_dev
101{
102
103	typeset dumpdev=""
104
105	if is_illumos; then
106		typeset fnd="Dump device"
107		dumpdev=`dumpadm | grep "$fnd" | cut -f2 -d : | \
108			awk '{print $1}'`
109	fi
110	echo $dumpdev
111}
112