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_002_pos
35#
36# DESCRIPTION:
37# 	If ZFS is currently managing the file system but it is currently unmoutned,
38#	and the mountpoint property is changed, the file system remains unmounted.
39#
40# STRATEGY:
41# 1. Setup a pool and create fs, ctr within it.
42# 2. Unmount that dataset
43# 2. Change the mountpoint to the valid mountpoint value.
44# 3. Check the file system remains unmounted.
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
58set -A dataset "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR"
59
60set -A values "$TESTDIR2" "$TESTDIR_NOTEXISTING"
61
62function cleanup
63{
64	log_must $ZFS set mountpoint=$old_ctr_mpt $TESTPOOL/$TESTCTR
65	log_must $ZFS set mountpoint=$old_fs_mpt $TESTPOOL/$TESTFS
66	log_must $ZFS mount -a
67	[[ -d $TESTDIR2 ]] && log_must $RM -r $TESTDIR2
68	[[ -d $TESTDIR_NOTEXISTING ]] && log_must $RM -r $TESTDIR_NOTEXISTING
69}
70
71log_assert "Setting a valid mountpoint for an unmounted file system, \
72	it remains unmounted."
73log_onexit cleanup
74
75old_fs_mpt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
76[[ $? != 0 ]] && \
77	log_fail "Unable to get the mountpoint property for $TESTPOOL/$TESTFS"
78old_ctr_mpt=$(get_prop mountpoint $TESTPOOL/$TESTCTR)
79[[ $? != 0 ]] && \
80	log_fail "Unable to get the mountpoint property for $TESTPOOL/$TESTCTR"
81
82if [[ ! -d $TESTDIR2 ]]; then
83	log_must $MKDIR $TESTDIR2
84fi
85
86typeset -i i=0
87typeset -i j=0
88while (( i < ${#dataset[@]} )); do
89	j=0
90	if ismounted ${dataset[i]} ; then
91		log_must $ZFS unmount ${dataset[i]}
92	fi
93	log_mustnot ismounted ${dataset[i]}
94	while (( j < ${#values[@]} )); do
95		set_n_check_prop "${values[j]}" "mountpoint" \
96			"${dataset[i]}"
97		log_mustnot ismounted ${dataset[i]}
98		(( j += 1 ))
99	done
100	cleanup
101	(( i += 1 ))
102done
103
104log_pass "Setting a valid mountpoint for an unmounted file system, \
105	it remains unmounted."
106