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 2009 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: canmount_001_pos
35#
36# DESCRIPTION:
37# Setting valid canmount to filesystem, it is successful.
38# Whatever is set to volume or snapshot, it is failed.
39# 'zfs set canmount=on|off <fs>'
40#
41# STRATEGY:
42# 1. Setup a pool and create fs, volume, snapshot clone 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 (2006-08-30)
51#
52# __stc_assertion_end
53#
54################################################################################
55
56verify_runnable "both"
57
58set -A dataset_pos \
59	"$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE"
60
61if is_global_zone ; then
62	set -A dataset_neg \
63		"$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \
64		"$TESTPOOL/$TESTVOL@$TESTSNAP"  "$TESTPOOL/$TESTCLONE1"
65else
66	set -A dataset_neg \
67		"$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP"
68fi
69
70
71set -A values "on" "off"
72
73function cleanup
74{
75	if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then
76		log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP
77	fi
78	if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then
79		log_must $ZFS destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP
80	fi
81
82	[[ -n $old_ctr_canmount ]] && \
83		log_must $ZFS set canmount=$old_ctr_canmount $TESTPOOL/$TESTCTR
84	[[ -n $old_fs_canmount ]] && \
85		log_must $ZFS set canmount=$old_fs_canmount $TESTPOOL/$TESTFS
86
87	unmount_all_safe > /dev/null 2>&1
88	log_must $ZFS mount -a
89}
90
91log_assert "Setting a valid property of canmount to file system, it must be successful."
92log_onexit cleanup
93
94typeset old_fs_canmount="" old_ctr_canmount=""
95
96old_fs_canmount=$(get_prop canmount $TESTPOOL/$TESTFS)
97[[ $? != 0 ]] && \
98	log_fail "Get the $TESTPOOL/$TESTFS canmount error."
99old_ctr_canmount=$(get_prop canmount $TESTPOOL/$TESTCTR)
100[[ $? != 0 ]] && \
101	log_fail "Get the $TESTPOOL/$TESTCTR canmount error."
102
103log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
104log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
105log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
106log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
107
108for dataset in "${dataset_pos[@]}" ; do
109	for value in "${values[@]}" ; do
110		set_n_check_prop "$value" "canmount" "$dataset"
111		if [[ $value == "off" ]]; then
112			log_mustnot ismounted $dataset
113			log_mustnot $ZFS mount $dataset
114			log_mustnot ismounted $dataset
115		else
116			if ! ismounted $dataset ; then
117				log_must $ZFS mount $dataset
118			fi
119			log_must ismounted $dataset
120		fi
121	done
122done
123
124for dataset in "${dataset_neg[@]}" ; do
125	for value in "${values[@]}" ; do
126		set_n_check_prop "$value" "canmount" \
127			"$dataset" "false"
128		log_mustnot ismounted $dataset
129	done
130done
131
132log_pass "Setting canmount to filesystem pass."
133