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_002_pos.ksh	1.2	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_002_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=noauto <fs>'
45#
46# STRATEGY:
47# 1. Setup a pool and create fs, volume, snapshot clone within it.
48# 2. Set canmount=noauto for each dataset and check the retuen value
49#    and check if it still can be mounted by mount -a.
50# 3. mount each dataset(except volume) to see if it can be mounted.
51#
52# TESTABILITY: explicit
53#
54# TEST_AUTOMATION_LEVEL: automated
55#
56# CODING_STATUS: COMPLETED (2008-03-05)
57#
58# __stc_assertion_end
59#
60################################################################################
61
62verify_runnable "both"
63
64# check if the testing box support noauto option or not.
65$ZFS get 2>&1 | $GREP -w canmount | $GREP -w noauto >/dev/null 2>&1
66if (( $? != 0 )); then
67	log_unsupported "canmount=noauto is not supported."
68fi
69
70set -A dataset_pos \
71	"$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE"
72
73if is_global_zone ; then
74	set -A dataset_neg \
75		"$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \
76		"$TESTPOOL/$TESTVOL@$TESTSNAP"  "$TESTPOOL/$TESTCLONE1"
77else
78	set -A dataset_neg \
79		"$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP"
80fi
81
82function cleanup
83{
84	i=0
85	while (( i < ${#dataset_pos[*]} )); do
86		ds=${dataset_pos[i]}
87		if datasetexists $ds; then
88			log_must $ZFS set mountpoint=${old_mnt[i]} $ds
89			log_must $ZFS set canmount=${old_canmount[i]} $ds
90		fi
91		(( i = i + 1 ))
92	done
93
94	ds=$TESTPOOL/$TESTCLONE
95	if datasetexists $ds; then
96		mntp=$(get_prop mountpoint $ds)
97		log_must $ZFS destroy $ds
98		if [[ -d $mntp ]]; then
99			$RM -fr $mntp
100		fi
101	fi
102
103	if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then
104		log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP
105	fi
106	if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then
107		log_must $ZFS destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP
108	fi
109
110	$ZFS unmount -a > /dev/null 2>&1
111	log_must $ZFS mount -a
112
113	if [[ -d $tmpmnt ]]; then
114		$RM -fr $tmpmnt
115	fi
116}
117
118log_assert "Setting canmount=noauto to file system, it must be successful."
119log_onexit cleanup
120
121set -A old_mnt
122set -A old_canmount
123typeset tmpmnt=/tmpmount${TESTCASE_ID}
124typeset ds
125
126log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
127log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
128log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
129log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
130
131typeset -i i=0
132while (( i < ${#dataset_pos[*]} )); do
133	ds=${dataset_pos[i]}
134	old_mnt[i]=$(get_prop mountpoint $ds)
135	old_canmount[i]=$(get_prop canmount $ds)
136	(( i = i + 1 ))
137done
138
139i=0
140while (( i < ${#dataset_pos[*]} )) ; do
141	dataset=${dataset_pos[i]}
142	set_n_check_prop "noauto" "canmount" "$dataset"
143	log_must $ZFS set mountpoint=$tmpmnt $dataset
144	if  ismounted $dataset; then
145		$ZFS unmount -a > /dev/null 2>&1
146		log_must mounted $dataset
147		log_must $ZFS unmount $dataset
148		log_must unmounted $dataset
149		log_must $ZFS mount -a
150		log_must unmounted $dataset
151	else
152		log_must $ZFS mount -a
153		log_must unmounted $dataset
154		$ZFS unmount -a > /dev/null 2>&1
155		log_must unmounted $dataset
156	fi
157
158	log_must $ZFS mount $dataset
159	log_must mounted $dataset
160	log_must $ZFS set canmount="${old_canmount[i]}" $dataset
161	log_must $ZFS set mountpoint="${old_mnt[i]}" $dataset
162	(( i = i + 1 ))
163done
164
165for dataset in "${dataset_neg[@]}" ; do
166	set_n_check_prop "noauto" "canmount" "$dataset" "false"
167	log_mustnot ismounted $dataset
168done
169
170log_pass "Setting canmount=noauto to filesystem pass."
171