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_003_pos
35#
36# DESCRIPTION:
37# While canmount=noauto and  the dataset is mounted,
38# zfs must not attempt to unmount it.
39#
40# STRATEGY:
41# 1. Setup a pool and create fs, volume, snapshot clone within it.
42# 2. Set canmount=noauto for each dataset and check the return value
43#    and check if it still can not be unmounted when the dataset is mounted
44#
45# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2008-09-05)
50#
51# __stc_assertion_end
52#
53################################################################################
54
55verify_runnable "both"
56
57# check if the testing box support noauto option or not.
58$ZFS get 2>&1 | $GREP -w canmount | $GREP -w noauto >/dev/null 2>&1
59if (( $? != 0 )); then
60	log_unsupported "canmount=noauto is not supported."
61fi
62
63set -A dataset_pos "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCLONE"
64
65function cleanup
66{
67	i=0
68	cd $pwd
69	while (( i < ${#dataset_pos[*]} )); do
70		ds=${dataset_pos[i]}
71		if datasetexists $ds; then
72			log_must $ZFS set mountpoint=${old_mnt[i]} $ds
73			log_must $ZFS set canmount=${old_canmount[i]} $ds
74		fi
75		(( i = i + 1 ))
76	done
77
78	ds=$TESTPOOL/$TESTCLONE
79	if datasetexists $ds; then
80		mntp=$(get_prop mountpoint $ds)
81		log_must $ZFS destroy $ds
82		if [[ -d $mntp ]]; then
83			log_must $RM -fr $mntp
84		fi
85	fi
86
87	if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then
88		log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP
89	fi
90
91	unmount_all_safe > /dev/null 2>&1
92	log_must $ZFS mount -a
93}
94
95log_assert "While canmount=noauto and  the dataset is mounted,"\
96		" zfs must not attempt to unmount it"
97log_onexit cleanup
98
99set -A old_mnt
100set -A old_canmount
101typeset ds
102typeset pwd=$PWD
103
104log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
105log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
106
107typeset -i i=0
108while (( i < ${#dataset_pos[*]} )); do
109	ds=${dataset_pos[i]}
110	old_mnt[i]=$(get_prop mountpoint $ds)
111	old_canmount[i]=$(get_prop canmount $ds)
112	(( i = i + 1 ))
113done
114
115i=0
116while (( i < ${#dataset_pos[*]} )) ; do
117	dataset=${dataset_pos[i]}
118	if  ismounted $dataset; then
119		log_must cd ${old_mnt[i]}
120		set_n_check_prop "noauto" "canmount" "$dataset"
121		log_must mounted $dataset
122	fi
123	(( i = i + 1 ))
124done
125
126log_pass "Setting canmount=noauto to filesystem while dataset busy pass."
127