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