diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index c6a29095e..2878f03a3 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -6627,7 +6627,15 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol, zfs_get_name(zhp)); return (1); } else if (canmount == ZFS_CANMOUNT_NOAUTO && !explicit) { - return (0); + /* + * When performing a 'zfs mount -a', we skip any mounts for + * datasets that have 'noauto' set. Sharing a dataset with + * 'noauto' set is only allowed if it's mounted. + */ + if (op == OP_MOUNT) + return (0); + if (op == OP_SHARE && !zfs_is_mounted(zhp, NULL)) + return (0); } /* diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh index 3b8b88e36..1aeee44e0 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh @@ -41,8 +41,10 @@ # STRATEGY: # 1. Setup a pool and create fs, volume, snapshot clone within it. # 2. Set canmount=noauto for each dataset and check the return value -# and check if it still can be mounted by mount -a. +# and check if it still can be mounted by mount -a or shared by +# share -a # 3. mount each dataset(except volume) to see if it can be mounted. +# 4. verify that a mounted dataset can be shared by share -a. # verify_runnable "both" @@ -100,6 +102,7 @@ log_onexit cleanup set -A old_mnt set -A old_canmount +set -A old_sharenfs typeset tmpmnt=/tmpmount$$ typeset ds @@ -113,6 +116,7 @@ while (( i < ${#dataset_pos[*]} )); do ds=${dataset_pos[i]} old_mnt[i]=$(get_prop mountpoint $ds) old_canmount[i]=$(get_prop canmount $ds) + old_sharenfs[i]=$(get_prop sharenfs $ds) (( i = i + 1 )) done @@ -121,6 +125,7 @@ while (( i < ${#dataset_pos[*]} )) ; do dataset=${dataset_pos[i]} set_n_check_prop "noauto" "canmount" "$dataset" log_must zfs set mountpoint=$tmpmnt $dataset + log_must zfs set sharenfs=on $dataset if ismounted $dataset; then zfs unmount -a > /dev/null 2>&1 log_must mounted $dataset @@ -128,6 +133,8 @@ while (( i < ${#dataset_pos[*]} )) ; do log_must unmounted $dataset log_must zfs mount -a log_must unmounted $dataset + log_must zfs share -a + log_mustnot is_exported $tmpmnt else log_must zfs mount -a log_must unmounted $dataset @@ -137,6 +144,10 @@ while (( i < ${#dataset_pos[*]} )) ; do log_must zfs mount $dataset log_must mounted $dataset + log_must zfs share -a + log_must is_exported $tmpmnt + + log_must zfs set sharenfs="${old_sharenfs[i]}" $dataset log_must zfs set canmount="${old_canmount[i]}" $dataset log_must zfs set mountpoint="${old_mnt[i]}" $dataset (( i = i + 1 ))