1#!/usr/local/bin/ksh93 -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# ident	"@(#)zfs_mount_006_pos.ksh	1.2	07/01/09 SMI"
28#
29
30. $STF_SUITE/include/libtest.kshlib
31. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib
32
33#################################################################################
34#
35# __stc_assertion_start
36#
37# ID: zfs_mount_006_pos
38#
39# DESCRIPTION:
40#	Invoke "zfs mount <filesystem>" with a filesystem
41#	which mountpoint be the identical or the top of an existing one,
42#	it will fail with a return code of 1
43#
44# STRATEGY:
45#	1. Prepare an existing mounted filesystem.
46#	2. Setup a new filesystem and make sure that it is unmounted.
47#       3. Mount the new filesystem using the various combinations
48#		- zfs set mountpoint=<identical path> <filesystem>
49#		- zfs set mountpoint=<top path> <filesystem>
50#       4. Verify that mount failed with return code of 1.
51#
52# TESTABILITY: explicit
53#
54# TEST_AUTOMATION_LEVEL: automated
55#
56# CODING_STATUS: COMPLETED (2005-07-11)
57#
58# __stc_assertion_end
59#
60################################################################################
61
62verify_runnable "both"
63
64function cleanup
65{
66	log_must force_unmount $TESTPOOL/$TESTFS
67
68	datasetexists $TESTPOOL/$TESTFS1 && \
69		cleanup_filesystem $TESTPOOL $TESTFS1
70
71	[[ -d $TESTDIR ]] && \
72		log_must $RM -rf $TESTDIR
73	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
74	log_must force_unmount $TESTPOOL/$TESTFS
75
76	return 0
77}
78
79typeset -i ret=0
80
81log_assert "Verify that '$ZFS $mountcmd <filesystem>' " \
82	"which mountpoint be the identical or the top of an existing one " \
83	"will fail with return code 1."
84
85log_onexit cleanup
86
87unmounted $TESTPOOL/$TESTFS || \
88	log_must force_unmount $TESTPOOL/$TESTFS
89
90[[ -d $TESTDIR ]] && \
91	log_must $RM -rf $TESTDIR
92
93typeset -i MAXDEPTH=3
94typeset -i depth=0
95typeset mtpt=$TESTDIR
96
97while (( depth < MAXDEPTH )); do
98	mtpt=$mtpt/$depth
99	(( depth = depth + 1))
100done
101
102log_must $ZFS set mountpoint=$mtpt $TESTPOOL/$TESTFS
103log_must $ZFS $mountcmd $TESTPOOL/$TESTFS
104
105mounted $TESTPOOL/$TESTFS || \
106	log_unresolved "Filesystem $TESTPOOL/$TESTFS is unmounted"
107
108log_must $ZFS create $TESTPOOL/$TESTFS1
109
110unmounted $TESTPOOL/$TESTFS1 || \
111	log_must force_unmount $TESTPOOL/$TESTFS1
112
113while [[ -n $mtpt ]] ; do
114	(( depth == MAXDEPTH )) && \
115		log_note "Verify that '$ZFS $mountcmd <filesystem>' " \
116		"which mountpoint be the identical of an existing one " \
117		"will fail with return code 1."
118
119	log_must $ZFS set mountpoint=$mtpt $TESTPOOL/$TESTFS1
120	log_mustnot $ZFS $mountcmd $TESTPOOL/$TESTFS1
121
122	unmounted $TESTPOOL/$TESTFS1 || \
123		log_fail "Filesystem $TESTPOOL/$TESTFS1 is mounted."
124
125	mtpt=${mtpt%/*}
126
127	(( depth == MAXDEPTH )) && \
128		log_note "Verify that '$ZFS $mountcmd <filesystem>' " \
129		"which mountpoint be the top of an existing one " \
130		"will fail with return code 1."
131	(( depth = depth - 1 ))
132done
133
134log_pass "'$ZFS $mountcmd <filesystem>' " \
135	"which mountpoint be the identical or the top of an existing one " \
136	"will fail with return code 1."
137