1#!/usr/local/bin/ksh93 -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 2009 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26 27. $STF_SUITE/include/libtest.kshlib 28. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib 29 30############################################################################### 31# 32# __stc_assertion_start 33# 34# ID: canmount_002_pos 35# 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>' 40# 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. 46# 47# TESTABILITY: explicit 48# 49# TEST_AUTOMATION_LEVEL: automated 50# 51# CODING_STATUS: COMPLETED (2008-03-05) 52# 53# __stc_assertion_end 54# 55################################################################################ 56 57verify_runnable "both" 58 59# check if the testing box support noauto option or not. 60$ZFS get 2>&1 | $GREP -w canmount | $GREP -w noauto >/dev/null 2>&1 61if (( $? != 0 )); then 62 log_unsupported "canmount=noauto is not supported." 63fi 64 65set -A dataset_pos \ 66 "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE" 67 68if is_global_zone ; then 69 set -A dataset_neg \ 70 "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \ 71 "$TESTPOOL/$TESTVOL@$TESTSNAP" "$TESTPOOL/$TESTCLONE1" 72else 73 set -A dataset_neg \ 74 "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP" 75fi 76 77function cleanup 78{ 79 i=0 80 while (( i < ${#dataset_pos[*]} )); do 81 ds=${dataset_pos[i]} 82 if datasetexists $ds; then 83 log_must $ZFS set mountpoint=${old_mnt[i]} $ds 84 log_must $ZFS set canmount=${old_canmount[i]} $ds 85 fi 86 (( i = i + 1 )) 87 done 88 89 ds=$TESTPOOL/$TESTCLONE 90 if datasetexists $ds; then 91 mntp=$(get_prop mountpoint $ds) 92 log_must $ZFS destroy $ds 93 if [[ -d $mntp ]]; then 94 $RM -fr $mntp 95 fi 96 fi 97 98 if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then 99 log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP 100 fi 101 if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then 102 log_must $ZFS destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP 103 fi 104 105 $ZFS unmount -a > /dev/null 2>&1 106 log_must $ZFS mount -a 107 108 if [[ -d $tmpmnt ]]; then 109 $RM -fr $tmpmnt 110 fi 111} 112 113log_assert "Setting canmount=noauto to file system, it must be successful." 114log_onexit cleanup 115 116set -A old_mnt 117set -A old_canmount 118typeset tmpmnt=/tmpmount${TESTCASE_ID} 119typeset ds 120 121log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP 122log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP 123log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE 124log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1 125 126typeset -i i=0 127while (( i < ${#dataset_pos[*]} )); do 128 ds=${dataset_pos[i]} 129 old_mnt[i]=$(get_prop mountpoint $ds) 130 old_canmount[i]=$(get_prop canmount $ds) 131 (( i = i + 1 )) 132done 133 134i=0 135while (( i < ${#dataset_pos[*]} )) ; do 136 dataset=${dataset_pos[i]} 137 set_n_check_prop "noauto" "canmount" "$dataset" 138 log_must $ZFS set mountpoint=$tmpmnt $dataset 139 if ismounted $dataset; then 140 $ZFS unmount -a > /dev/null 2>&1 141 log_must mounted $dataset 142 log_must $ZFS unmount $dataset 143 log_must unmounted $dataset 144 log_must $ZFS mount -a 145 log_must unmounted $dataset 146 else 147 log_must $ZFS mount -a 148 log_must unmounted $dataset 149 $ZFS unmount -a > /dev/null 2>&1 150 log_must unmounted $dataset 151 fi 152 153 log_must $ZFS mount $dataset 154 log_must mounted $dataset 155 log_must $ZFS set canmount="${old_canmount[i]}" $dataset 156 log_must $ZFS set mountpoint="${old_mnt[i]}" $dataset 157 (( i = i + 1 )) 158done 159 160for dataset in "${dataset_neg[@]}" ; do 161 set_n_check_prop "noauto" "canmount" "$dataset" "false" 162 log_mustnot ismounted $dataset 163done 164 165log_pass "Setting canmount=noauto to filesystem pass." 166