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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/include/libtest.kshlib
28. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
29
30###############################################################################
31#
32# __stc_assertion_start
33#
34# ID: mountpoint_001_pos
35#
36# DESCRIPTION:
37# Setting valid mountpoint to filesystem, it is successful.
38# Whatever is set to volume, it is failed.
39# 'zfs set mountpoint=<path>|legacy|none <fs|ctr|vol>'
40#
41# STRATEGY:
42# 1. Setup a pool and create fs, ctr within it.
43# 2. Loop all the valid mountpoint value.
44# 3. Check the return value.
45#
46# TESTABILITY: explicit
47#
48# TEST_AUTOMATION_LEVEL: automated
49#
50# CODING_STATUS: COMPLETED (2005-07-04)
51#
52# __stc_assertion_end
53#
54################################################################################
55
56verify_runnable "both"
57
58if is_global_zone ; then
59	set -A dataset \
60		"$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL"
61else
62	set -A dataset "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR"
63fi
64
65set -A values "$TESTDIR2" "legacy" "none" "$TESTDIR_NOTEXISTING"
66
67function cleanup
68{
69	log_must $ZFS set mountpoint=$old_ctr_mpt $TESTPOOL/$TESTCTR
70	log_must $ZFS set mountpoint=$old_fs_mpt $TESTPOOL/$TESTFS
71	[[ -d $TESTDIR2 ]] && log_must $RM -r $TESTDIR2
72	[[ -d $TESTDIR_NOTEXISTING ]] && log_must $RM -r $TESTDIR_NOTEXISTING
73}
74
75log_assert "Setting a valid mountpoint to file system, it must be successful."
76log_onexit cleanup
77
78old_fs_mpt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
79[[ $? != 0 ]] && \
80	log_fail "Get the $TESTPOOL/$TESTFS mountpoint error."
81old_ctr_mpt=$(get_prop mountpoint $TESTPOOL/$TESTCTR)
82[[ $? != 0 ]] && \
83	log_fail "Get the $TESTPOOL/$TESTCTR mountpoint error."
84
85if [[ ! -d $TESTDIR2 ]]; then
86	log_must $MKDIR $TESTDIR2
87fi
88
89typeset -i i=0
90typeset -i j=0
91while (( i < ${#dataset[@]} )); do
92	j=0
93	while (( j < ${#values[@]} )); do
94		if [[ ${dataset[i]} == "$TESTPOOL/$TESTVOL" ]]; then
95			set_n_check_prop "${values[j]}" "mountpoint" \
96				"${dataset[i]}" "false"
97		else
98			set_n_check_prop "${values[j]}" "mountpoint" \
99				"${dataset[i]}"
100		fi
101		(( j += 1 ))
102	done
103	cleanup
104	(( i += 1 ))
105done
106
107log_pass "Setting mountpoint to filesystem pass."
108