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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2016 by Delphix. All rights reserved.
30# Copyright 2019 RackTop Systems.
31#
32
33. $STF_SUITE/include/libtest.shlib
34. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
35
36#
37# DESCRIPTION:
38#	Invoke "zfs mount <filesystem>" with a filesystem
39#	which mountpoint be the identical or the top of an existing one,
40#	it will fail with a return code of 1
41#
42# STRATEGY:
43#	1. Prepare an existing mounted filesystem.
44#	2. Setup a new filesystem and make sure that it is unmounted.
45#       3. Mount the new filesystem using the various combinations
46#		- zfs set mountpoint=<identical path> <filesystem>
47#		- zfs set mountpoint=<top path> <filesystem>
48#       4. Verify that mount failed with return code of 1.
49#
50
51verify_runnable "both"
52
53function cleanup
54{
55	log_must force_unmount $TESTPOOL/$TESTFS
56
57	datasetexists $TESTPOOL/$TESTFS1 && \
58		cleanup_filesystem $TESTPOOL $TESTFS1
59
60	[[ -d $TESTDIR ]] && \
61		log_must rm -rf $TESTDIR
62	log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
63	log_must force_unmount $TESTPOOL/$TESTFS
64
65	return 0
66}
67
68typeset -i ret=0
69
70log_assert "Verify that 'zfs $mountcmd <filesystem>' " \
71	"which mountpoint be the identical or the top of an existing one " \
72	"will fail with return code 1."
73
74log_onexit cleanup
75
76unmounted $TESTPOOL/$TESTFS || \
77	log_must force_unmount $TESTPOOL/$TESTFS
78
79[[ -d $TESTDIR ]] && \
80	log_must rm -rf $TESTDIR
81
82typeset -i MAXDEPTH=3
83typeset -i depth=0
84typeset mtpt=$TESTDIR
85
86while (( depth < MAXDEPTH )); do
87	mtpt=$mtpt/$depth
88	(( depth = depth + 1))
89done
90
91log_must zfs set mountpoint=$mtpt $TESTPOOL/$TESTFS
92log_must zfs $mountcmd $TESTPOOL/$TESTFS
93
94mounted $TESTPOOL/$TESTFS || \
95	log_unresolved "Filesystem $TESTPOOL/$TESTFS is unmounted"
96
97log_must zfs create $TESTPOOL/$TESTFS1
98
99unmounted $TESTPOOL/$TESTFS1 || \
100	log_must force_unmount $TESTPOOL/$TESTFS1
101
102while [[ $mtpt != $TESTDIR ]] ; do
103	(( depth == MAXDEPTH )) && \
104		log_note "Verify that 'zfs $mountcmd <filesystem>' " \
105		"which mountpoint be the identical of an existing one " \
106		"will fail with return code 1."
107
108	log_must zfs set mountpoint=$mtpt $TESTPOOL/$TESTFS1
109	log_mustnot zfs $mountcmd $TESTPOOL/$TESTFS1
110
111	unmounted $TESTPOOL/$TESTFS1 || \
112		log_fail "Filesystem $TESTPOOL/$TESTFS1 is mounted."
113
114	mtpt=${mtpt%/*}
115
116	(( depth == MAXDEPTH )) && \
117		log_note "Verify that 'zfs $mountcmd <filesystem>' " \
118		"which mountpoint be the top of an existing one " \
119		"will fail with return code 1."
120	(( depth = depth - 1 ))
121done
122
123log_pass "'zfs $mountcmd <filesystem>' " \
124	"which mountpoint be the identical or the top of an existing one " \
125	"will fail with return code 1."
126