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# $FreeBSD$
24
25#
26# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)canmount_001_pos.ksh	1.5	09/08/06 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
34
35###############################################################################
36#
37# __stc_assertion_start
38#
39# ID: canmount_001_pos
40#
41# DESCRIPTION:
42# Setting valid canmount to filesystem, it is successful.
43# Whatever is set to volume or snapshot, it is failed.
44# 'zfs set canmount=on|off <fs>'
45#
46# STRATEGY:
47# 1. Setup a pool and create fs, volume, snapshot clone within it.
48# 2. Loop all the valid mountpoint value.
49# 3. Check the return value.
50#
51# TESTABILITY: explicit
52#
53# TEST_AUTOMATION_LEVEL: automated
54#
55# CODING_STATUS: COMPLETED (2006-08-30)
56#
57# __stc_assertion_end
58#
59################################################################################
60
61verify_runnable "both"
62
63set -A dataset_pos \
64	"$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE"
65
66if is_global_zone ; then
67	set -A dataset_neg \
68		"$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \
69		"$TESTPOOL/$TESTVOL@$TESTSNAP"  "$TESTPOOL/$TESTCLONE1"
70else
71	set -A dataset_neg \
72		"$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP"
73fi
74
75
76set -A values "on" "off"
77
78function cleanup
79{
80	if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then
81		log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP
82	fi
83	if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then
84		log_must $ZFS destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP
85	fi
86
87	[[ -n $old_ctr_canmount ]] && \
88		log_must $ZFS set canmount=$old_ctr_canmount $TESTPOOL/$TESTCTR
89	[[ -n $old_fs_canmount ]] && \
90		log_must $ZFS set canmount=$old_fs_canmount $TESTPOOL/$TESTFS
91
92	unmount_all_safe > /dev/null 2>&1
93	log_must $ZFS mount -a
94}
95
96log_assert "Setting a valid property of canmount to file system, it must be successful."
97log_onexit cleanup
98
99typeset old_fs_canmount="" old_ctr_canmount=""
100
101old_fs_canmount=$(get_prop canmount $TESTPOOL/$TESTFS)
102[[ $? != 0 ]] && \
103	log_fail "Get the $TESTPOOL/$TESTFS canmount error."
104old_ctr_canmount=$(get_prop canmount $TESTPOOL/$TESTCTR)
105[[ $? != 0 ]] && \
106	log_fail "Get the $TESTPOOL/$TESTCTR canmount error."
107
108log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
109log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
110log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
111log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
112
113for dataset in "${dataset_pos[@]}" ; do
114	for value in "${values[@]}" ; do
115		set_n_check_prop "$value" "canmount" "$dataset"
116		if [[ $value == "off" ]]; then
117			log_mustnot ismounted $dataset
118			log_mustnot $ZFS mount $dataset
119			log_mustnot ismounted $dataset
120		else
121			if ! ismounted $dataset ; then
122				log_must $ZFS mount $dataset
123			fi
124			log_must ismounted $dataset
125		fi
126	done
127done
128
129for dataset in "${dataset_neg[@]}" ; do
130	for value in "${values[@]}" ; do
131		set_n_check_prop "$value" "canmount" \
132			"$dataset" "false"
133		log_mustnot ismounted $dataset
134	done
135done
136
137log_pass "Setting canmount to filesystem pass."
138