1#!/usr/local/bin/ksh93 -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. $STF_SUITE/include/libtest.kshlib
27. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib
28
29################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zpool_create_005_pos
34#
35# DESCRIPTION:
36# 'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' can create an
37#  alternate root pool or a new pool mounted at the specified mountpoint.
38#
39# STRATEGY:
40# 1. Create a pool with '-m' option
41# 2. Verify the pool is mounted at the specified mountpoint
42#
43# TESTABILITY: explicit
44#
45# TEST_AUTOMATION_LEVEL: automated
46#
47# CODING_STATUS: COMPLETED (2006-08-04)
48#
49# __stc_assertion_end
50#
51################################################################################
52
53verify_runnable "global"
54
55function cleanup
56{
57	poolexists $TESTPOOL && \
58		log_must $ZPOOL destroy -f $TESTPOOL
59
60	for dir in $TMPDIR/zpool_create_005_pos $TESTDIR1; do
61		[[ -d $dir ]] && $RM -rf $dir
62	done
63}
64
65log_assert "'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' can create" \
66	"an alternate pool or a new pool mounted at the specified mountpoint."
67log_onexit cleanup
68
69set -A pooltype "" "mirror" "raidz" "raidz1" "raidz2"
70
71#prepare raw file for file disk
72TDIR=$TMPDIR/zpool_create_005_pos
73FBASE=$TDIR/file
74log_must $MKDIR $TDIR
75log_must create_vdevs $FBASE.0 $FBASE.1 $FBASE.2 $FBASE.3
76#Remove the directory with name as pool name if it exists
77[[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL
78
79for opt in "-R $TESTDIR1" "-m $TESTDIR1" \
80	"-R $TESTDIR1 -m $TESTDIR1" "-m $TESTDIR1 -R $TESTDIR1"
81do
82	i=0
83	while (( i < ${#pooltype[*]} )); do
84		#Remove the testing pool and its mount directory
85		poolexists $TESTPOOL && \
86			log_must $ZPOOL destroy -f $TESTPOOL
87		[[ -d $TESTDIR1 ]] && $RM -rf $TESTDIR1
88		log_must $ZPOOL create $opt $TESTPOOL ${pooltype[i]} \
89			$FBASE.1 $FBASE.2 $FBASE.3
90		mpt=`$ZFS mount | $EGREP "^$TESTPOOL[^/]" | $AWK '{print $2}'`
91		(( ${#mpt} == 0 )) && \
92			log_fail "$TESTPOOL created with $opt is not mounted."
93		mpt_val=$(get_prop "mountpoint" $TESTPOOL)
94		[[ "$mpt" != "$mpt_val" ]] && \
95			log_fail "The value of mountpoint property is different\
96				from the output of zfs mount"
97		if [[ "$opt" == "-R $TESTDIR1" ]]; then
98			expected_mpt=${TESTDIR1}/${TESTPOOL}
99		elif [[ "$opt" == "-m $TESTDIR1" ]]; then
100			expected_mpt=${TESTDIR1}
101		else
102			expected_mpt=${TESTDIR1}${TESTDIR1}
103		fi
104		[[ ! -d $expected_mpt ]] && \
105			log_fail "$expected_mpt is not created auotmatically."
106		[[ "$mpt" != "$expected_mpt" ]] && \
107			log_fail "$expected_mpt is mounted on ${mpt} instead of $expected_mpt."
108
109		[[ -d /$TESTPOOL ]] && \
110			log_fail "The default mountpoint /$TESTPOOL is created" \
111				"while with $opt option."
112
113		(( i = i + 1 ))
114	done
115done
116
117log_pass "'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' works as expected."
118