1#!/bin/ksh -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#
27
28#
29# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
34
35#
36# DESCRIPTION:
37# 'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' can create an
38#  alternate root pool or a new pool mounted at the specified mountpoint.
39#
40# STRATEGY:
41# 1. Create a pool with '-m' option
42# 2. Verify the pool is mounted at the specified mountpoint
43#
44
45verify_runnable "global"
46
47function cleanup
48{
49	poolexists $TESTPOOL && destroy_pool $TESTPOOL
50	rm -rf $TESTDIR $TESTDIR1
51}
52
53log_assert "'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' can create" \
54	"an alternate pool or a new pool mounted at the specified mountpoint."
55log_onexit cleanup
56
57set -A pooltype "" "mirror" "raidz" "raidz1" "raidz2" "draid" "draid2"
58
59#
60# cleanup the pools created in previous case if zpool_create_004_pos timedout
61#
62for pool in $TESTPOOL2 $TESTPOOL1 $TESTPOOL; do
63	poolexists $pool && destroy_pool $pool
64done
65
66#prepare raw file for file disk
67rm -rf $TESTDIR
68log_must mkdir -p $TESTDIR
69typeset -i i=1
70while (( i < 5 )); do
71	log_must truncate -s $FILESIZE $TESTDIR/file.$i
72
73	(( i = i + 1 ))
74done
75
76#Remove the directory with name as pool name if it exists
77rm -rf /$TESTPOOL
78file=$TESTDIR/file
79
80for opt in "-R $TESTDIR1" "-m $TESTDIR1" \
81	"-R $TESTDIR1 -m $TESTDIR1" "-m $TESTDIR1 -R $TESTDIR1"
82do
83	i=0
84	while (( i < ${#pooltype[*]} )); do
85		#Remove the testing pool and its mount directory
86		poolexists $TESTPOOL && \
87			log_must zpool destroy -f $TESTPOOL
88		[[ -d $TESTDIR1 ]] && rm -rf $TESTDIR1
89		log_must zpool create $opt $TESTPOOL ${pooltype[i]} \
90			$file.1 $file.2 $file.3 $file.4
91		! poolexists $TESTPOOL && \
92			log_fail "Creating pool with $opt fails."
93		mpt=`zfs mount | awk -v pat="^$TESTPOOL[^/]" '$0 ~ pat {print $2}'`
94		[ -z "$mpt" ] && \
95			log_fail "$TESTPOOL created with $opt is not mounted."
96		mpt_val=$(get_prop "mountpoint" $TESTPOOL)
97		[[ "$mpt" != "$mpt_val" ]] && \
98			log_fail "The value of mountpoint property is different\
99				from the output of zfs mount"
100		if [[ "$opt" == "-m $TESTDIR1" ]]; then
101			[[ ! -d $TESTDIR1 ]] && \
102				log_fail "$TESTDIR1 is not created automatically."
103			[[ "$mpt" != "$TESTDIR1" ]] && \
104				log_fail "$TESTPOOL is not mounted on $TESTDIR1."
105		elif [[ "$opt" == "-R $TESTDIR1" ]]; then
106			[[ ! -d $TESTDIR1/$TESTPOOL ]] && \
107				log_fail "$TESTDIR1/$TESTPOOL is not created automatically."
108			[[ "$mpt" != "$TESTDIR1/$TESTPOOL" ]] && \
109				log_fail "$TESTPOOL is not mounted on $TESTDIR1/$TESTPOOL."
110		else
111			[[ ! -d ${TESTDIR1}$TESTDIR1 ]] && \
112				log_fail "${TESTDIR1}$TESTDIR1 is not created automatically."
113			[[ "$mpt" != "${TESTDIR1}$TESTDIR1" ]] && \
114				log_fail "$TESTPOOL is not mounted on ${TESTDIR1}$TESTDIR1."
115		fi
116		[[ -d /$TESTPOOL ]] && \
117			log_fail "The default mountpoint /$TESTPOOL is created" \
118				"while with $opt option."
119
120		(( i = i + 1 ))
121	done
122done
123
124log_pass "'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' works as expected."
125