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# $FreeBSD$ 24 25# 26# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)canmount_003_pos.ksh 1.2 09/08/06 SMI" 30# 31 32. $STF_SUITE/include/libtest.kshlib 33. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib 34 35############################################################################### 36# 37# __stc_assertion_start 38# 39# ID: canmount_003_pos 40# 41# DESCRIPTION: 42# While canmount=noauto and the dataset is mounted, 43# zfs must not attempt to unmount it. 44# 45# STRATEGY: 46# 1. Setup a pool and create fs, volume, snapshot clone within it. 47# 2. Set canmount=noauto for each dataset and check the return value 48# and check if it still can not be unmounted when the dataset is mounted 49# 50# TESTABILITY: explicit 51# 52# TEST_AUTOMATION_LEVEL: automated 53# 54# CODING_STATUS: COMPLETED (2008-09-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 "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCLONE" 69 70function cleanup 71{ 72 i=0 73 cd $pwd 74 while (( i < ${#dataset_pos[*]} )); do 75 ds=${dataset_pos[i]} 76 if datasetexists $ds; then 77 log_must $ZFS set mountpoint=${old_mnt[i]} $ds 78 log_must $ZFS set canmount=${old_canmount[i]} $ds 79 fi 80 (( i = i + 1 )) 81 done 82 83 ds=$TESTPOOL/$TESTCLONE 84 if datasetexists $ds; then 85 mntp=$(get_prop mountpoint $ds) 86 log_must $ZFS destroy $ds 87 if [[ -d $mntp ]]; then 88 log_must $RM -fr $mntp 89 fi 90 fi 91 92 if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then 93 log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP 94 fi 95 96 unmount_all_safe > /dev/null 2>&1 97 log_must $ZFS mount -a 98} 99 100log_assert "While canmount=noauto and the dataset is mounted,"\ 101 " zfs must not attempt to unmount it" 102log_onexit cleanup 103 104set -A old_mnt 105set -A old_canmount 106typeset ds 107typeset pwd=$PWD 108 109log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP 110log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE 111 112typeset -i i=0 113while (( i < ${#dataset_pos[*]} )); do 114 ds=${dataset_pos[i]} 115 old_mnt[i]=$(get_prop mountpoint $ds) 116 old_canmount[i]=$(get_prop canmount $ds) 117 (( i = i + 1 )) 118done 119 120i=0 121while (( i < ${#dataset_pos[*]} )) ; do 122 dataset=${dataset_pos[i]} 123 if ismounted $dataset; then 124 log_must cd ${old_mnt[i]} 125 set_n_check_prop "noauto" "canmount" "$dataset" 126 log_must mounted $dataset 127 fi 128 (( i = i + 1 )) 129done 130 131log_pass "Setting canmount=noauto to filesystem while dataset busy pass." 132