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