]>
Commit | Line | Data |
---|---|---|
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 | ||
51 | verify_runnable "both" | |
52 | ||
53 | function 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 | ||
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 | |
c1d9abf9 | 83 | log_must zfs mount $fs |
6bb24f4d BB |
84 | fi |
85 | ||
c1d9abf9 | 86 | log_must zfs snapshot $snap |
6bb24f4d | 87 | if is_global_zone; then |
c1d9abf9 | 88 | log_must zfs create -V 10m $vol |
6bb24f4d BB |
89 | else |
90 | vol="" | |
91 | fi | |
92 | ||
93 | # Testing bad options | |
94 | for arg in ${badargs[@]}; do | |
c1d9abf9 | 95 | log_mustnot eval "zfs unmount $arg $fs >/dev/null 2>&1" |
6bb24f4d BB |
96 | done |
97 | ||
767f65cf | 98 | # Testing invalid datasets |
6bb24f4d BB |
99 | for 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 |
103 | done | |
104 | ||
767f65cf | 105 | # Testing invalid mountpoint |
6bb24f4d BB |
106 | dir=foodir.$$ |
107 | file=foo.$$ | |
108 | fs1=$TESTPOOL/fs.$$ | |
c1d9abf9 JWK |
109 | mkdir /tmp/$dir |
110 | touch /tmp/$file | |
111 | log_must zfs create -o mountpoint=/tmp/$dir $fs1 | |
112 | curpath=`dirname $0` | |
6bb24f4d BB |
113 | cd /tmp |
114 | for 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 |
118 | done | |
119 | cd $curpath | |
120 | ||
767f65cf | 121 | # Testing null argument and too many arguments |
6bb24f4d | 122 | for 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 |
125 | done |
126 | ||
767f65cf | 127 | # Testing already unmounted filesystem |
c1d9abf9 | 128 | log_must zfs unmount $fs1 |
6bb24f4d | 129 | for 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 |
132 | done |
133 | ||
767f65cf | 134 | # Testing legacy mounted filesystem |
c1d9abf9 | 135 | log_must zfs set mountpoint=legacy $fs1 |
7839c4b5 | 136 | if is_linux || is_freebsd; then |
c1d9abf9 | 137 | log_must mount -t zfs $fs1 /tmp/$dir |
6bb24f4d | 138 | else |
c1d9abf9 | 139 | log_must mount -F zfs $fs1 /tmp/$dir |
6bb24f4d BB |
140 | fi |
141 | for opt in "" "-f"; do | |
c1d9abf9 | 142 | log_mustnot eval "zfs unmount $opt $fs1 >/dev/null 2>&1" |
6bb24f4d | 143 | done |
c1d9abf9 | 144 | umount /tmp/$dir |
6bb24f4d BB |
145 | |
146 | log_pass "zfs unmount fails with bad parameters or scenarios as expected." |