]> git.proxmox.com Git - mirror_zfs.git/blame - tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh
Update ZTS to work on FreeBSD
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zfs_unmount / zfs_unmount_008_neg.ksh
CommitLineData
6bb24f4d
BB
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
c1d9abf9
JWK
28#
29# Copyright (c) 2016 by Delphix. All rights reserved.
30#
31
6bb24f4d
BB
32. $STF_SUITE/include/libtest.shlib
33
34#
35# DESCRIPTION:
36# Verify that zfs unmount should fail with bad parameters or scenarios:
37# 1. bad option;
38# 2. too many arguments;
39# 3. null arguments;
40# 4. invalid datasets;
41# 5. invalid mountpoint;
42# 6. already unmounted zfs filesystem;
43# 7. legacy mounted zfs filesystem
44#
45# STRATEGY:
46# 1. Make an array of bad parameters
47# 2. Use zfs unmount to unmount the filesystem
48# 3. Verify that zfs unmount returns error
49#
50
51verify_runnable "both"
52
53function cleanup
54{
55 for ds in $vol $fs1; do
56 if datasetexists $ds; then
c1d9abf9 57 log_must zfs destroy -f $ds
6bb24f4d
BB
58 fi
59 done
60
61 if snapexists $snap; then
c1d9abf9 62 log_must zfs destroy $snap
6bb24f4d
BB
63 fi
64
65 if [[ -e /tmp/$file ]]; then
c1d9abf9 66 rm -f /tmp/$file
6bb24f4d
BB
67 fi
68 if [[ -d /tmp/$dir ]]; then
c1d9abf9 69 rm -rf /tmp/$dir
6bb24f4d
BB
70 fi
71
72}
73
74log_assert "zfs unmount fails with bad parameters or scenarios"
75log_onexit cleanup
76
77fs=$TESTPOOL/$TESTFS
78vol=$TESTPOOL/vol.$$
79snap=$TESTPOOL/$TESTFS@snap.$$
80set -A badargs "A" "-A" "F" "-F" "-" "-x" "-?"
81
82if ! ismounted $fs; then
c1d9abf9 83 log_must zfs mount $fs
6bb24f4d
BB
84fi
85
c1d9abf9 86log_must zfs snapshot $snap
6bb24f4d 87if is_global_zone; then
c1d9abf9 88 log_must zfs create -V 10m $vol
6bb24f4d
BB
89else
90 vol=""
91fi
92
93# Testing bad options
94for arg in ${badargs[@]}; do
c1d9abf9 95 log_mustnot eval "zfs unmount $arg $fs >/dev/null 2>&1"
6bb24f4d
BB
96done
97
767f65cf 98# Testing invalid datasets
6bb24f4d
BB
99for ds in $snap $vol "blah"; do
100 for opt in "" "-f"; do
c1d9abf9 101 log_mustnot eval "zfs unmount $opt $ds >/dev/null 2>&1"
6bb24f4d
BB
102 done
103done
104
767f65cf 105# Testing invalid mountpoint
6bb24f4d
BB
106dir=foodir.$$
107file=foo.$$
108fs1=$TESTPOOL/fs.$$
c1d9abf9
JWK
109mkdir /tmp/$dir
110touch /tmp/$file
111log_must zfs create -o mountpoint=/tmp/$dir $fs1
112curpath=`dirname $0`
6bb24f4d
BB
113cd /tmp
114for mpt in "./$dir" "./$file" "/tmp"; do
115 for opt in "" "-f"; do
c1d9abf9 116 log_mustnot eval "zfs unmount $opt $mpt >/dev/null 2>&1"
6bb24f4d
BB
117 done
118done
119cd $curpath
120
767f65cf 121# Testing null argument and too many arguments
6bb24f4d 122for opt in "" "-f"; do
c1d9abf9
JWK
123 log_mustnot eval "zfs unmount $opt >/dev/null 2>&1"
124 log_mustnot eval "zfs unmount $opt $fs $fs1 >/dev/null 2>&1"
6bb24f4d
BB
125done
126
767f65cf 127# Testing already unmounted filesystem
c1d9abf9 128log_must zfs unmount $fs1
6bb24f4d 129for opt in "" "-f"; do
c1d9abf9
JWK
130 log_mustnot eval "zfs unmount $opt $fs1 >/dev/null 2>&1"
131 log_mustnot eval "zfs unmount /tmp/$dir >/dev/null 2>&1"
6bb24f4d
BB
132done
133
767f65cf 134# Testing legacy mounted filesystem
c1d9abf9 135log_must zfs set mountpoint=legacy $fs1
7839c4b5 136if is_linux || is_freebsd; then
c1d9abf9 137 log_must mount -t zfs $fs1 /tmp/$dir
6bb24f4d 138else
c1d9abf9 139 log_must mount -F zfs $fs1 /tmp/$dir
6bb24f4d
BB
140fi
141for opt in "" "-f"; do
c1d9abf9 142 log_mustnot eval "zfs unmount $opt $fs1 >/dev/null 2>&1"
6bb24f4d 143done
c1d9abf9 144umount /tmp/$dir
6bb24f4d
BB
145
146log_pass "zfs unmount fails with bad parameters or scenarios as expected."