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 https://opensource.org/licenses/CDDL-1.0.
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) 2020 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33
34#
35# DESCRIPTION: Unmounted canmount=noauto export is removed during zfs share -a
36#
37# STRATEGY:
38# 1. Share a dataset that also has canmount set to noauto
39# 2. Capture the zfs exports file when the dataset is mounted + shared
40# 3. Simulate a reboot by unmounting the dataset and restoring the exports file
41# 4. Verify that 'zfs share -a' removes the export since dataset is not mounted
42#
43
44verify_runnable "both"
45
46dataset="$TESTPOOL/$TESTFS"
47mountpt=$(get_prop mountpoint $dataset)
48
49function cleanup
50{
51	zfs set canmount=on $dataset
52	zfs set sharenfs=off $dataset
53	zfs mount -a
54
55	#
56	# unset __ZFS_POOL_EXCLUDE so that we include all file systems when
57	# rebuilding the exports file
58	#
59	unset __ZFS_POOL_EXCLUDE
60	rm /etc/exports.d/zfs.exports
61	zfs share -a
62}
63
64log_assert "Unmounted canmount=noauto export is removed during zfs share -a"
65log_onexit cleanup
66
67log_must zfs set canmount=noauto $dataset
68zfs mount $dataset > /dev/null 2>&1
69log_must mounted $dataset
70log_must zfs set sharenfs=on $dataset
71log_must is_exported $mountpt
72
73log_must cp /etc/exports.d/zfs.exports /etc/exports.d/zfs.exports.save
74log_must zfs umount $dataset
75log_must unmounted $dataset
76log_mustnot is_exported $mountpt
77
78# simulate a reboot condition
79log_must mv /etc/exports.d/zfs.exports.save /etc/exports.d/zfs.exports
80
81log_must is_exported $mountpt
82log_must zfs share -a
83log_mustnot is_exported $mountpt
84
85log_pass "Unmounted canmount=noauto export is removed during zfs share -a"
86