1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2017 by Delphix. All rights reserved.
19#
20
21. $STF_SUITE/include/libtest.shlib
22. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
23
24# DESCRIPTION:
25#       Verify that if 'zfs mount -a' fails to mount one filesystem,
26#       the command fails with a non-zero error code, but all other
27#       filesystems are mounted.
28#
29# STRATEGY:
30#       1. Create zfs filesystems
31#       2. Unmount a leaf filesystem
32#       3. Create a file in the above filesystem's mountpoint
33#       4. Verify that 'zfs mount -a' succeeds if overlay=on and
34#          fails to mount the above if overlay=off
35#       5. Verify that all other filesystems were mounted
36#
37
38verify_runnable "both"
39
40typeset -a filesystems
41typeset path=${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL
42typeset fscount=10
43
44function setup_all
45{
46	# Create $fscount filesystems at the top level of $path
47	for ((i=0; i<$fscount; i++)); do
48		setup_filesystem "$DISKS" "$TESTPOOL" $i "$path/$i" ctr
49	done
50
51	zfs list -r $TESTPOOL
52
53	return 0
54}
55
56function cleanup_all
57{
58	export __ZFS_POOL_RESTRICT="$TESTPOOL"
59	log_must zfs $unmountall
60	unset __ZFS_POOL_RESTRICT
61
62	[[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
63		rm -rf ${TEST_BASE_DIR%%/}/testroot$$
64}
65
66log_onexit cleanup_all
67
68log_must setup_all
69
70#
71# Unmount all of the above so that we can create the stray file
72# in one of the mountpoint directories.
73#
74export __ZFS_POOL_RESTRICT="$TESTPOOL"
75log_must zfs $unmountall
76unset __ZFS_POOL_RESTRICT
77
78# All of our filesystems should be unmounted at this point
79for ((i=0; i<$fscount; i++)); do
80	log_mustnot mounted "$TESTPOOL/$i"
81done
82
83# Create a stray file in one filesystem's mountpoint
84touch $path/0/strayfile
85
86export __ZFS_POOL_RESTRICT="$TESTPOOL"
87
88# Verify that zfs mount -a succeeds with overlay=on (default)
89log_must zfs $mountall
90log_must mounted "$TESTPOOL/0"
91log_must zfs $unmountall
92
93# Verify that zfs mount -a succeeds with overlay=off
94log_must zfs set overlay=off "$TESTPOOL/0"
95log_mustnot zfs $mountall
96log_mustnot mounted "$TESTPOOL/0"
97
98unset __ZFS_POOL_RESTRICT
99
100# All other filesystems should be mounted
101for ((i=1; i<$fscount; i++)); do
102	log_must mounted "$TESTPOOL/$i"
103done
104
105log_pass "'zfs $mountall' behaves as expected."
106