xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_007_neg.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/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
33. $STF_SUITE/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib
34
35#
36# DESCRIPTION:
37#	Try each 'zfs unmount' with inapplicable scenarios to make sure
38#	it returns an error. include:
39#		* Multiple filesystem|mountpoint specified
40#		* '-a', but also with a specific filesystem|mountpoint.
41#
42# STRATEGY:
43#	1. Create an array of parameters
44#	2. For each parameter in the array, execute the sub-command
45#	3. Verify an error is returned.
46#
47
48verify_runnable "both"
49
50multifs="$TESTFS $TESTFS1"
51datasets=""
52
53for fs in $multifs ; do
54	datasets="$datasets $TESTPOOL/$fs"
55done
56
57set -A args "$unmountall $TESTPOOL/$TESTFS" \
58	"$unmountcmd $datasets"
59
60function setup_all
61{
62	typeset fs
63
64	for fs in $multifs ; do
65		setup_filesystem "$DISKS" "$TESTPOOL" \
66			"$fs" \
67			"${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL/$fs"
68	done
69	return 0
70}
71
72function cleanup_all
73{
74	typeset fs
75
76	cleanup_filesystem "$TESTPOOL" "$TESTFS1"
77	log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
78
79	[[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
80		rm -rf ${TEST_BASE_DIR%%/}/testroot$$
81
82	return 0
83}
84
85function verify_all
86{
87	typeset fs
88
89	for fs in $multifs ; do
90		log_must mounted $TESTPOOL/$fs
91	done
92	return 0
93}
94
95log_assert "Badly-formed 'zfs $unmountcmd' with inapplicable scenarios " \
96	"should return an error."
97log_onexit cleanup_all
98
99log_must setup_all
100
101typeset -i i=0
102while (( i < ${#args[*]} )); do
103	log_mustnot zfs ${args[i]}
104	((i = i + 1))
105done
106
107log_must verify_all
108
109log_pass "Badly formed 'zfs $unmountcmd' with inapplicable scenarios " \
110	"fail as expected."
111