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