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