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