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 https://opensource.org/licenses/CDDL-1.0.
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
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/zfs_set/zfs_set_common.kshlib
34
35#
36# DESCRIPTION:
37#	If ZFS is currently managing the file system but it is currently unmounted,
38#	and the mountpoint property is changed, the file system should be mounted
39#	if it is a valid mountpoint and canmount allows to mount, otherwise it
40#	should not be mounted.
41#
42# STRATEGY:
43# 1. Setup a pool and create fs, ctr within it.
44# 2. Unmount that dataset
45# 2. Change the mountpoint to the valid mountpoint value.
46# 3. Check the file system remains unmounted.
47#
48
49verify_runnable "both"
50
51export TESTDIR_NOTEXISTING=${TEST_BASE_DIR%%/}/testdir_notexisting$$
52
53set -A dataset "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR"
54
55set -A values "$TESTDIR2" "$TESTDIR_NOTEXISTING"
56
57function cleanup
58{
59	log_must zfs set mountpoint=$old_ctr_mpt $TESTPOOL/$TESTCTR
60	log_must zfs set mountpoint=$old_fs_mpt $TESTPOOL/$TESTFS
61	log_must zfs mount -a
62	[[ -d $TESTDIR2 ]] && log_must rm -r $TESTDIR2
63	[[ -d $TESTDIR_NOTEXISTING ]] && log_must rm -r $TESTDIR_NOTEXISTING
64}
65
66log_assert "Setting a valid mountpoint for an unmounted file system, \
67	it gets mounted."
68log_onexit cleanup
69
70old_fs_mpt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
71old_ctr_mpt=$(get_prop mountpoint $TESTPOOL/$TESTCTR)
72
73if [[ ! -d $TESTDIR2 ]]; then
74	log_must mkdir $TESTDIR2
75fi
76
77typeset -i i=0
78typeset -i j=0
79while (( i < ${#dataset[@]} )); do
80	j=0
81	if ismounted ${dataset[i]} ; then
82		log_must zfs unmount ${dataset[i]}
83	fi
84	log_mustnot ismounted ${dataset[i]}
85	while (( j < ${#values[@]} )); do
86		set_n_check_prop "${values[j]}" "mountpoint" \
87			"${dataset[i]}"
88		if [ "${dataset[i]}" = "$TESTPOOL/$TESTFS" ]; then
89			log_must ismounted ${dataset[i]}
90		else
91			log_mustnot ismounted ${dataset[i]}
92		fi
93		(( j += 1 ))
94	done
95	cleanup
96	(( i += 1 ))
97done
98
99log_pass "Setting a valid mountpoint for an unmounted file system, \
100	it remains unmounted."
101