]> git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh
New upstream version 0.7.2
[mirror_zfs-debian.git] / tests / zfs-tests / tests / functional / cli_root / zfs_unmount / zfs_unmount_008_neg.ksh
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 # 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
51 verify_runnable "both"
52
53 function cleanup
54 {
55 for ds in $vol $fs1; do
56 if datasetexists $ds; then
57 log_must zfs destroy -f $ds
58 fi
59 done
60
61 if snapexists $snap; then
62 log_must zfs destroy $snap
63 fi
64
65 if [[ -e /tmp/$file ]]; then
66 rm -f /tmp/$file
67 fi
68 if [[ -d /tmp/$dir ]]; then
69 rm -rf /tmp/$dir
70 fi
71
72 }
73
74 log_assert "zfs unmount fails with bad parameters or scenarios"
75 log_onexit cleanup
76
77 fs=$TESTPOOL/$TESTFS
78 vol=$TESTPOOL/vol.$$
79 snap=$TESTPOOL/$TESTFS@snap.$$
80 set -A badargs "A" "-A" "F" "-F" "-" "-x" "-?"
81
82 if ! ismounted $fs; then
83 log_must zfs mount $fs
84 fi
85
86 log_must zfs snapshot $snap
87 if is_global_zone; then
88 log_must zfs create -V 10m $vol
89 else
90 vol=""
91 fi
92
93 # Testing bad options
94 for arg in ${badargs[@]}; do
95 log_mustnot eval "zfs unmount $arg $fs >/dev/null 2>&1"
96 done
97
98
99 #Testing invalid datasets
100 for ds in $snap $vol "blah"; do
101 for opt in "" "-f"; do
102 log_mustnot eval "zfs unmount $opt $ds >/dev/null 2>&1"
103 done
104 done
105
106 #Testing invalid mountpoint
107 dir=foodir.$$
108 file=foo.$$
109 fs1=$TESTPOOL/fs.$$
110 mkdir /tmp/$dir
111 touch /tmp/$file
112 log_must zfs create -o mountpoint=/tmp/$dir $fs1
113 curpath=`dirname $0`
114 cd /tmp
115 for mpt in "./$dir" "./$file" "/tmp"; do
116 for opt in "" "-f"; do
117 log_mustnot eval "zfs unmount $opt $mpt >/dev/null 2>&1"
118 done
119 done
120 cd $curpath
121
122 #Testing null argument and too many arguments
123 for opt in "" "-f"; do
124 log_mustnot eval "zfs unmount $opt >/dev/null 2>&1"
125 log_mustnot eval "zfs unmount $opt $fs $fs1 >/dev/null 2>&1"
126 done
127
128 #Testing already unmounted filesystem
129 log_must zfs unmount $fs1
130 for opt in "" "-f"; do
131 log_mustnot eval "zfs unmount $opt $fs1 >/dev/null 2>&1"
132 log_mustnot eval "zfs unmount /tmp/$dir >/dev/null 2>&1"
133 done
134
135 #Testing legacy mounted filesystem
136 log_must zfs set mountpoint=legacy $fs1
137 if is_linux; then
138 log_must mount -t zfs $fs1 /tmp/$dir
139 else
140 log_must mount -F zfs $fs1 /tmp/$dir
141 fi
142 for opt in "" "-f"; do
143 log_mustnot eval "zfs unmount $opt $fs1 >/dev/null 2>&1"
144 done
145 umount /tmp/$dir
146
147 log_pass "zfs unmount fails with bad parameters or scenarios as expected."