xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh (revision b6805bf78d2bbbeeaea8909a05623587b42d58b3)
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. $STF_SUITE/include/libtest.shlib
28
29#
30# DESCRIPTION:
31# Creates a file system and verifies that it can be unmounted
32# using each of the various unmount options and sub-command
33# variants.
34#
35# STRATEGY:
36# 1. Create and mount a file system as necessary.
37# 2. Umount the file system using the various combinations.
38#	- With force option.
39#	- Without force option.
40#	- Using the unmount sub-command.
41#	- Using the umount sub-command.
42#
43
44verify_runnable "both"
45
46
47function cleanup
48{
49	mounted $TESTDIR2 && \
50		log_must $ZFS umount -f $TESTDIR2
51
52	datasetexists $TESTPOOL/$TESTFS2 && \
53		log_must $ZFS destroy $TESTPOOL/$TESTFS2
54
55	[[ -d $TESTDIR2 ]] && \
56		log_must $RM -rf $TESTDIR2
57}
58function do_unmount
59{
60	typeset cmd=$1
61	typeset opt=$2
62	typeset mnt=$3
63
64	[[ ! -d $TESTDIR2 ]] && \
65	    log_must $MKDIR $TESTDIR2
66
67	if ! datasetexists $TESTPOOL/$TESTFS2 ; then
68		log_must $ZFS create $TESTPOOL/$TESTFS2
69		log_must $ZFS set mountpoint=$TESTDIR2 \
70		    $TESTPOOL/$TESTFS2
71	fi
72
73	unmounted $TESTPOOL/$TESTFS2 && \
74		log_must $ZFS mount $TESTPOOL/$TESTFS2
75
76	log_must $ZFS $cmd $options $mnt
77
78	unmounted "$mnt" || \
79		log_fail "Unable to unmount $options $mnt"
80
81	log_note "Successfully unmounted $options $mnt"
82}
83
84log_onexit cleanup
85
86set -A cmd "umount" "unmount"
87set -A options "" "-f"
88set -A dev "$TESTPOOL/$TESTFS2" "$TESTDIR2"
89
90log_assert "Verify the u[n]mount [-f] sub-command."
91
92typeset -i i=0
93typeset -i j=0
94typeset -i k=0
95while [[ $i -lt ${#cmd[*]} ]]; do
96	j=0
97	while [[ $j -lt ${#options[*]} ]]; do
98		k=0
99		while [[ $k -lt ${#dev[*]} ]]; do
100			do_unmount "${cmd[i]}" "${options[j]}" \
101			    "${dev[k]}"
102
103			((k = k + 1))
104		done
105
106		((j = j + 1))
107	done
108
109	((i = i + 1))
110done
111
112log_pass "zfs u[n]mount [-f] completed successfully."
113