7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zfs_set / canmount_002_pos.ksh
blob7cbcf7903e33fd2ffb759faead6ceaf22303eb73
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 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
36 # DESCRIPTION:
37 # Setting valid canmount to filesystem, it is successful.
38 # Whatever is set to volume or snapshot, it is failed.
39 # 'zfs set canmount=noauto <fs>'
41 # STRATEGY:
42 # 1. Setup a pool and create fs, volume, snapshot clone within it.
43 # 2. Set canmount=noauto for each dataset and check the retuen value
44 # and check if it still can be mounted by mount -a.
45 # 3. mount each dataset(except volume) to see if it can be mounted.
48 verify_runnable "both"
50 set -A dataset_pos \
51 "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE"
53 if is_global_zone ; then
54 set -A dataset_neg \
55 "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \
56 "$TESTPOOL/$TESTVOL@$TESTSNAP" "$TESTPOOL/$TESTCLONE1"
57 else
58 set -A dataset_neg \
59 "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP"
62 function cleanup
64 i=0
65 while (( i < ${#dataset_pos[*]} )); do
66 ds=${dataset_pos[i]}
67 if datasetexists $ds; then
68 log_must zfs set mountpoint=${old_mnt[i]} $ds
69 log_must zfs set canmount=${old_canmount[i]} $ds
71 (( i = i + 1 ))
72 done
74 ds=$TESTPOOL/$TESTCLONE
75 if datasetexists $ds; then
76 mntp=$(get_prop mountpoint $ds)
77 log_must zfs destroy $ds
78 if [[ -d $mntp ]]; then
79 rm -fr $mntp
83 if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then
84 log_must zfs destroy -R $TESTPOOL/$TESTFS@$TESTSNAP
86 if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then
87 log_must zfs destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP
90 zfs unmount -a > /dev/null 2>&1
91 log_must zfs mount -a
93 if [[ -d $tmpmnt ]]; then
94 rm -fr $tmpmnt
98 log_assert "Setting canmount=noauto to file system, it must be successful."
99 log_onexit cleanup
101 set -A old_mnt
102 set -A old_canmount
103 typeset tmpmnt=/tmpmount$$
104 typeset ds
106 log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP
107 log_must zfs snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
108 log_must zfs clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
109 log_must zfs clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
111 typeset -i i=0
112 while (( i < ${#dataset_pos[*]} )); do
113 ds=${dataset_pos[i]}
114 old_mnt[i]=$(get_prop mountpoint $ds)
115 old_canmount[i]=$(get_prop canmount $ds)
116 (( i = i + 1 ))
117 done
120 while (( i < ${#dataset_pos[*]} )) ; do
121 dataset=${dataset_pos[i]}
122 set_n_check_prop "noauto" "canmount" "$dataset"
123 log_must zfs set mountpoint=$tmpmnt $dataset
124 if ismounted $dataset; then
125 zfs unmount -a > /dev/null 2>&1
126 log_must mounted $dataset
127 log_must zfs unmount $dataset
128 log_must unmounted $dataset
129 log_must zfs mount -a
130 log_must unmounted $dataset
131 else
132 log_must zfs mount -a
133 log_must unmounted $dataset
134 zfs unmount -a > /dev/null 2>&1
135 log_must unmounted $dataset
138 log_must zfs mount $dataset
139 log_must mounted $dataset
140 log_must zfs set canmount="${old_canmount[i]}" $dataset
141 log_must zfs set mountpoint="${old_mnt[i]}" $dataset
142 (( i = i + 1 ))
143 done
145 for dataset in "${dataset_neg[@]}" ; do
146 set_n_check_prop "noauto" "canmount" "$dataset" "false"
147 log_mustnot ismounted $dataset
148 done
150 log_pass "Setting canmount=noauto to filesystem pass."