7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zfs_mount / zfs_mount_all_001_pos.ksh
blob765e242796b84e0cd70c895d9294de58de5c5679
1 #!/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
35 # DESCRIPTION:
36 # Verify that 'zfs mount -a' succeeds as root.
38 # STRATEGY:
39 # 1. Create a group of pools with specified vdev.
40 # 2. Create zfs filesystems within the given pools.
41 # 3. Unmount all the filesystems.
42 # 4. Verify that 'zfs mount -a' command succeed,
43 # and all available ZFS filesystems are mounted.
44 # 5. Verify that 'zfs mount' is identical with 'df -F zfs'
47 verify_runnable "both"
49 set -A fs "$TESTFS" "$TESTFS1"
50 set -A ctr "" "$TESTCTR" "$TESTCTR/$TESTCTR1" "$TESTCTR1"
51 set -A vol "$TESTVOL" "$TESTVOL1"
53 function setup_all
55 typeset -i i=0
56 typeset -i j=0
57 typeset path
59 while (( i < ${#ctr[*]} )); do
61 path=${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL
62 if [[ -n ${ctr[i]} ]]; then
63 path=$path/${ctr[i]}
65 setup_filesystem "$DISKS" "$TESTPOOL" \
66 "${ctr[i]}" "$path" \
67 "ctr"
70 if is_global_zone ; then
71 j=0
72 while (( j < ${#vol[*]} )); do
73 setup_filesystem "$DISKS" "$TESTPOOL" \
74 "${ctr[i]}/${vol[j]}" \
75 "$path/${vol[j]}" \
76 "vol"
77 ((j = j + 1))
78 done
81 j=0
82 while (( j < ${#fs[*]} )); do
83 setup_filesystem "$DISKS" "$TESTPOOL" \
84 "${ctr[i]}/${fs[j]}" \
85 "$path/${fs[j]}"
86 ((j = j + 1))
87 done
89 ((i = i + 1))
90 done
92 return 0
95 function cleanup_all
97 typeset -i i=0
98 typeset -i j=0
99 typeset path
101 ((i = ${#ctr[*]} - 1))
103 while (( i >= 0 )); do
104 if is_global_zone ; then
106 while (( j < ${#vol[*]} )); do
107 cleanup_filesystem "$TESTPOOL" \
108 "${ctr[i]}/${vol[j]}"
109 ((j = j + 1))
110 done
114 while (( j < ${#fs[*]} )); do
115 cleanup_filesystem "$TESTPOOL" \
116 "${ctr[i]}/${fs[j]}"
117 ((j = j + 1))
118 done
120 [[ -n ${ctr[i]} ]] && \
121 cleanup_filesystem "$TESTPOOL" "${ctr[i]}"
123 ((i = i - 1))
124 done
126 [[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
127 rm -rf ${TEST_BASE_DIR%%/}/testroot$$
131 # This function takes a single true/false argument. If true it will verify that
132 # all file systems are mounted. If false it will verify that they are not
133 # mounted.
135 function verify_all
137 typeset -i i=0
138 typeset -i j=0
139 typeset path
140 typeset logfunc
142 if $1; then
143 logfunc=log_must
144 else
145 logfunc=log_mustnot
148 while (( i < ${#ctr[*]} )); do
150 path=$TESTPOOL
151 [[ -n ${ctr[i]} ]] && \
152 path=$path/${ctr[i]}
154 if is_global_zone ; then
156 while (( j < ${#vol[*]} )); do
157 log_mustnot mounted "$path/${vol[j]}"
158 ((j = j + 1))
159 done
163 while (( j < ${#fs[*]} )); do
164 $logfunc mounted "$path/${fs[j]}"
165 ((j = j + 1))
166 done
168 $logfunc mounted "$path"
170 ((i = i + 1))
171 done
173 return 0
177 log_assert "Verify that 'zfs $mountall' succeeds as root, " \
178 "and all available ZFS filesystems are mounted."
180 log_onexit cleanup_all
182 log_must setup_all
184 export __ZFS_POOL_RESTRICT="$TESTPOOL"
185 log_must zfs $unmountall
186 unset __ZFS_POOL_RESTRICT
188 verify_all false
190 export __ZFS_POOL_RESTRICT="$TESTPOOL"
191 log_must zfs $mountall
192 unset __ZFS_POOL_RESTRICT
194 verify_all true
196 log_note "Verify that 'zfs $mountcmd' will display " \
197 "all ZFS filesystems currently mounted."
199 verify_mount_display
201 log_pass "'zfs $mountall' succeeds as root, " \
202 "and all available ZFS filesystems are mounted."