Skip to content

Commit 53c9d1d

Browse files
authored
'zfs share -a' should handle 'canmount=noauto'
The 'zfs share -a' currently skips any filesystems which have 'canmount=noauto' set. This behavior is unexpected since the one would expect 'zfs share -a' to share any mounted filesystem that has the 'sharenfs' property already set. This changes the behavior of 'zfs share -a' to allow the sharing of 'canmount=noauto' datasets if they are mounted. Reviewed-by: Matt Ahrens <[email protected]> Reviewed-by: Don Brady <[email protected]> Reviewed-by: Prakash Surya <[email protected]> Signed-off-by: George Wilson <[email protected]> External-issue: DLPX-71313 Closes #10688
1 parent 6f763d4 commit 53c9d1d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

cmd/zfs/zfs_main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6627,7 +6627,15 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol,
66276627
zfs_get_name(zhp));
66286628
return (1);
66296629
} else if (canmount == ZFS_CANMOUNT_NOAUTO && !explicit) {
6630-
return (0);
6630+
/*
6631+
* When performing a 'zfs mount -a', we skip any mounts for
6632+
* datasets that have 'noauto' set. Sharing a dataset with
6633+
* 'noauto' set is only allowed if it's mounted.
6634+
*/
6635+
if (op == OP_MOUNT)
6636+
return (0);
6637+
if (op == OP_SHARE && !zfs_is_mounted(zhp, NULL))
6638+
return (0);
66316639
}
66326640

66336641
/*

tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@
4141
# STRATEGY:
4242
# 1. Setup a pool and create fs, volume, snapshot clone within it.
4343
# 2. Set canmount=noauto for each dataset and check the return value
44-
# and check if it still can be mounted by mount -a.
44+
# and check if it still can be mounted by mount -a or shared by
45+
# share -a
4546
# 3. mount each dataset(except volume) to see if it can be mounted.
47+
# 4. verify that a mounted dataset can be shared by share -a.
4648
#
4749

4850
verify_runnable "both"
@@ -100,6 +102,7 @@ log_onexit cleanup
100102

101103
set -A old_mnt
102104
set -A old_canmount
105+
set -A old_sharenfs
103106
typeset tmpmnt=/tmpmount$$
104107
typeset ds
105108

@@ -113,6 +116,7 @@ while (( i < ${#dataset_pos[*]} )); do
113116
ds=${dataset_pos[i]}
114117
old_mnt[i]=$(get_prop mountpoint $ds)
115118
old_canmount[i]=$(get_prop canmount $ds)
119+
old_sharenfs[i]=$(get_prop sharenfs $ds)
116120
(( i = i + 1 ))
117121
done
118122

@@ -121,13 +125,16 @@ while (( i < ${#dataset_pos[*]} )) ; do
121125
dataset=${dataset_pos[i]}
122126
set_n_check_prop "noauto" "canmount" "$dataset"
123127
log_must zfs set mountpoint=$tmpmnt $dataset
128+
log_must zfs set sharenfs=on $dataset
124129
if ismounted $dataset; then
125130
zfs unmount -a > /dev/null 2>&1
126131
log_must mounted $dataset
127132
log_must zfs unmount $dataset
128133
log_must unmounted $dataset
129134
log_must zfs mount -a
130135
log_must unmounted $dataset
136+
log_must zfs share -a
137+
log_mustnot is_exported $tmpmnt
131138
else
132139
log_must zfs mount -a
133140
log_must unmounted $dataset
@@ -137,6 +144,10 @@ while (( i < ${#dataset_pos[*]} )) ; do
137144

138145
log_must zfs mount $dataset
139146
log_must mounted $dataset
147+
log_must zfs share -a
148+
log_must is_exported $tmpmnt
149+
150+
log_must zfs set sharenfs="${old_sharenfs[i]}" $dataset
140151
log_must zfs set canmount="${old_canmount[i]}" $dataset
141152
log_must zfs set mountpoint="${old_mnt[i]}" $dataset
142153
(( i = i + 1 ))

0 commit comments

Comments
 (0)