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