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# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_unmount_008_neg.ksh	1.1	07/10/09 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33
34###############################################################################
35#
36# __stc_assertion_start
37#
38# ID: zfs_unmount_008_neg
39#
40# DESCRIPTION:
41# Verify that zfs unmount should fail with bad parameters or scenarios:
42#	1. bad option;
43#	2. too many arguments;
44#	3. null arguments;
45#	4. invalid datasets;
46#	5. invalid mountpoint;
47#	6. already unmounted zfs filesystem;
48#	7. legacy mounted zfs filesystem
49#
50# STRATEGY:
51# 1. Make an array of bad parameters
52# 2. Use zfs unmount to unmount the filesystem
53# 3. Verify that zfs unmount returns error
54#
55# TESTABILITY: explicit
56#
57# TEST_AUTOMATION_LEVEL: automated
58#
59# CODING_STATUS: COMPLETED (2007-07-9)
60#
61# __stc_assertion_end
62#
63################################################################################
64
65verify_runnable "both"
66
67function cleanup
68{
69	for ds in $vol $fs1; do
70		if datasetexists $ds; then
71			log_must $ZFS destroy -f $ds
72		fi
73	done
74
75	if snapexists $snap; then
76		log_must $ZFS destroy $snap
77	fi
78
79	if [[ -e $TMPDIR/$file ]]; then
80		$RM -f $TMPDIR/$file
81	fi
82	if [[ -d $TMPDIR/$dir ]]; then
83		$RM -rf $TMPDIR/$dir
84	fi
85
86}
87
88log_assert "zfs unmount fails with bad parameters or scenarios"
89log_onexit cleanup
90
91fs=$TESTPOOL/$TESTFS
92vol=$TESTPOOL/vol.${TESTCASE_ID}
93snap=$TESTPOOL/$TESTFS@snap.${TESTCASE_ID}
94set -A badargs "A" "-A" "F" "-F" "-" "-x" "-?"
95
96if ! ismounted $fs; then
97	log_must $ZFS mount $fs
98fi
99
100log_must $ZFS snapshot $snap
101if is_global_zone; then
102	log_must $ZFS create -V 10m $vol
103else
104	vol=""
105fi
106
107# Testing bad options
108for arg in ${badargs[@]}; do
109	log_mustnot eval "$ZFS unmount $arg $fs >/dev/null 2>&1"
110done
111
112
113#Testing invalid datasets
114for ds in $snap $vol "blah"; do
115	for opt in "" "-f"; do
116		log_mustnot eval "$ZFS unmount $opt $ds >/dev/null 2>&1"
117	done
118done
119
120#Testing invalid mountpoint
121dir=foodir.${TESTCASE_ID}
122file=foo.${TESTCASE_ID}
123fs1=$TESTPOOL/fs.${TESTCASE_ID}
124$MKDIR $TMPDIR/$dir
125$TOUCH $TMPDIR/$file
126log_must $ZFS create -o mountpoint=$TMPDIR/$dir $fs1
127curpath=`$DIRNAME $0`
128cd $TMPDIR
129for mpt in "./$dir" "./$file"; do
130	for opt in "" "-f"; do
131		log_mustnot eval "$ZFS unmount $opt $mpt >/dev/null 2>&1"
132	done
133done
134cd $curpath
135
136#Testing null argument and too many arguments
137for opt in "" "-f"; do
138	log_mustnot eval "$ZFS unmount $opt >/dev/null 2>&1"
139	log_mustnot eval "$ZFS unmount $opt $fs $fs1 >/dev/null 2>&1"
140done
141
142#Testing already unmounted filesystem
143log_must $ZFS unmount $fs1
144for opt in "" "-f"; do
145	log_mustnot eval "$ZFS unmount $opt $fs1 >/dev/null 2>&1"
146	log_mustnot eval "$ZFS unmount $TMPDIR/$dir >/dev/null 2>&1"
147done
148
149#Testing legacy mounted filesystem
150log_must $ZFS set mountpoint=legacy $fs1
151log_must $MOUNT -t zfs $fs1 $TMPDIR/$dir
152for opt in "" "-f"; do
153	log_mustnot eval "$ZFS unmount $opt $fs1 >/dev/null 2>&1"
154done
155$UMOUNT $TMPDIR/$dir
156
157log_pass "zfs unmount fails with bad parameters or scenarios as expected."
158