Skip to content

Commit deb6959

Browse files
Don BradyRageLtMan
authored andcommitted
'zfs share -a' should clean noauto exports
This is a follow on to PR openzfs#10688 where `zfs share -a` allows the sharing of canmount=noauto datasets if they are mounted. However, when a dataset with canmount=noauto is not mounted, the command should also purge any existing entries from the exports file. Otherwise, after a reboot, the nfs server attempts to export the underlying mountpath, not the dataset. This can lead to a hard hang for existing client mounts. Instead of just skipping the adding of an export if not mounted and canmount=noauto, have it also remove an existing export of the dataset so that, after a reboot, we don't export an unmounted dataset. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: George Wilson <[email protected]> Signed-off-by: Don Brady <[email protected]> Closes openzfs#10747
1 parent 8e89cfa commit deb6959

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

cmd/zfs/zfs_main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6634,8 +6634,11 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol,
66346634
*/
66356635
if (op == OP_MOUNT)
66366636
return (0);
6637-
if (op == OP_SHARE && !zfs_is_mounted(zhp, NULL))
6637+
if (op == OP_SHARE && !zfs_is_mounted(zhp, NULL)) {
6638+
/* also purge it from existing exports */
6639+
zfs_unshareall_bypath(zhp, mountpoint);
66386640
return (0);
6641+
}
66396642
}
66406643

66416644
/*

tests/runfiles/linux.run

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ tests = ['zfs_mount_006_pos', 'zfs_mount_008_pos', 'zfs_multi_mount']
5252
tags = ['functional', 'cli_root', 'zfs_mount']
5353

5454
[tests/functional/cli_root/zfs_share:Linux]
55-
tests = ['zfs_share_005_pos', 'zfs_share_007_neg', 'zfs_share_009_neg']
55+
tests = ['zfs_share_005_pos', 'zfs_share_007_neg', 'zfs_share_009_neg',
56+
'zfs_share_012_pos']
5657
tags = ['functional', 'cli_root', 'zfs_share']
5758

5859
[tests/functional/cli_root/zfs_sysfs:Linux]

tests/zfs-tests/tests/functional/cli_root/zfs_share/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dist_pkgdata_SCRIPTS = \
1313
zfs_share_009_neg.ksh \
1414
zfs_share_010_neg.ksh \
1515
zfs_share_011_pos.ksh \
16+
zfs_share_012_pos.ksh \
1617
zfs_share_concurrent_shares.ksh
1718

1819
dist_pkgdata_DATA = \
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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) 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+
44+
verify_runnable "both"
45+
46+
dataset="$TESTPOOL/$TESTFS"
47+
mountpt=$(get_prop mountpoint $dataset)
48+
49+
function 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+
64+
log_assert "Unmounted canmount=noauto export is removed during zfs share -a"
65+
log_onexit cleanup
66+
67+
log_must zfs set canmount=noauto $dataset
68+
zfs mount $dataset > /dev/null 2>&1
69+
log_must mounted $dataset
70+
log_must zfs set sharenfs=on $dataset
71+
log_must is_exported $mountpt
72+
73+
log_must cp /etc/exports.d/zfs.exports /etc/exports.d/zfs.exports.save
74+
log_must zfs umount $dataset
75+
log_must unmounted $dataset
76+
log_mustnot is_exported $mountpt
77+
78+
# simulate a reboot condition
79+
log_must mv /etc/exports.d/zfs.exports.save /etc/exports.d/zfs.exports
80+
81+
log_must is_exported $mountpt
82+
log_must zfs share -a
83+
log_mustnot is_exported $mountpt
84+
85+
log_pass "Unmounted canmount=noauto export is removed during zfs share -a"

0 commit comments

Comments
 (0)