xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/canmount_004_pos.ksh (revision f985abb4a2473d3c04b086f7c9fab177e368ffef)
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 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
28. $STF_SUITE/include/libtest.shlib
29
30#
31# DESCRIPTION:
32# Verify canmount=noauto work fine when setting sharenfs or sharesmb.
33#
34# STRATEGY:
35# 1. Create a fs canmount=noauto.
36# 2. Set sharenfs or sharesmb.
37# 3. Verify the fs is umounted.
38#
39
40verify_runnable "global"
41
42# properties
43set -A sharenfs_prop "off" "on" "rw"
44set -A sharesmb_prop "off" "on"
45
46function cleanup
47{
48	log_must $ZFS destroy -rR $CS_FS
49}
50
51function assert_unmounted
52{
53	mnted=$(get_prop mounted $CS_FS)
54	if [[ "$mnted" == "yes" ]]; then
55		canmnt=$(get_prop canmount $CS_FS)
56		shnfs=$(get_prop sharenfs $CS_FS)
57		shsmb=$(get_prop sharesmb $CS_FS)
58		mntpt=$(get_prop mountpoint $CS_FS)
59		log_fail "$CS_FS should be unmounted" \
60		"[canmount=$canmnt,sharenfs=$shnfs,sharesmb=$shsmb,mountpoint=$mntpt]."
61	fi
62}
63
64log_assert "Verify canmount=noauto work fine when setting sharenfs or sharesmb."
65log_onexit cleanup
66
67CS_FS=$TESTPOOL/$TESTFS/cs_fs.$$
68oldmpt=$TESTDIR/old_cs_fs.$$
69newmpt=$TESTDIR/new_cs_fs.$$
70
71log_must $ZFS create -o canmount=noauto -o mountpoint=$oldmpt $CS_FS
72assert_unmounted
73
74for n in ${sharenfs_prop[@]}; do
75	log_must $ZFS set sharenfs="$n" $CS_FS
76	assert_unmounted
77	for s in ${sharesmb_prop[@]}; do
78		log_must $ZFS set sharesmb="$s" $CS_FS
79		assert_unmounted
80
81		mntpt=$(get_prop mountpoint $CS_FS)
82		if [[ "$mntpt" == "$oldmpt" ]]; then
83			log_must $ZFS set mountpoint="$newmpt" $CS_FS
84		else
85			log_must $ZFS set mountpoint="$oldmpt" $CS_FS
86		fi
87		assert_unmounted
88	done
89done
90
91log_pass "Verify canmount=noauto work fine when setting sharenfs or sharesmb."
92
93