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 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26 27. $STF_SUITE/include/libtest.kshlib 28 29############################################################################### 30# 31# __stc_assertion_start 32# 33# ID: zfs_unmount_008_neg 34# 35# DESCRIPTION: 36# Verify that zfs unmount should fail with bad parameters or scenarios: 37# 1. bad option; 38# 2. too many arguments; 39# 3. null arguments; 40# 4. invalid datasets; 41# 5. invalid mountpoint; 42# 6. already unmounted zfs filesystem; 43# 7. legacy mounted zfs filesystem 44# 45# STRATEGY: 46# 1. Make an array of bad parameters 47# 2. Use zfs unmount to unmount the filesystem 48# 3. Verify that zfs unmount returns error 49# 50# TESTABILITY: explicit 51# 52# TEST_AUTOMATION_LEVEL: automated 53# 54# CODING_STATUS: COMPLETED (2007-07-9) 55# 56# __stc_assertion_end 57# 58################################################################################ 59 60verify_runnable "both" 61 62function cleanup 63{ 64 for ds in $vol $fs1; do 65 if datasetexists $ds; then 66 log_must $ZFS destroy -f $ds 67 fi 68 done 69 70 if snapexists $snap; then 71 log_must $ZFS destroy $snap 72 fi 73 74 if [[ -e $TMPDIR/$file ]]; then 75 $RM -f $TMPDIR/$file 76 fi 77 if [[ -d $TMPDIR/$dir ]]; then 78 $RM -rf $TMPDIR/$dir 79 fi 80 81} 82 83log_assert "zfs unmount fails with bad parameters or scenarios" 84log_onexit cleanup 85 86fs=$TESTPOOL/$TESTFS 87vol=$TESTPOOL/vol.${TESTCASE_ID} 88snap=$TESTPOOL/$TESTFS@snap.${TESTCASE_ID} 89set -A badargs "A" "-A" "F" "-F" "-" "-x" "-?" 90 91if ! ismounted $fs; then 92 log_must $ZFS mount $fs 93fi 94 95log_must $ZFS snapshot $snap 96if is_global_zone; then 97 log_must $ZFS create -V 10m $vol 98else 99 vol="" 100fi 101 102# Testing bad options 103for arg in ${badargs[@]}; do 104 log_mustnot eval "$ZFS unmount $arg $fs >/dev/null 2>&1" 105done 106 107 108#Testing invalid datasets 109for ds in $snap $vol "blah"; do 110 for opt in "" "-f"; do 111 log_mustnot eval "$ZFS unmount $opt $ds >/dev/null 2>&1" 112 done 113done 114 115#Testing invalid mountpoint 116dir=foodir.${TESTCASE_ID} 117file=foo.${TESTCASE_ID} 118fs1=$TESTPOOL/fs.${TESTCASE_ID} 119$MKDIR $TMPDIR/$dir 120$TOUCH $TMPDIR/$file 121log_must $ZFS create -o mountpoint=$TMPDIR/$dir $fs1 122curpath=`$DIRNAME $0` 123cd $TMPDIR 124for mpt in "./$dir" "./$file"; do 125 for opt in "" "-f"; do 126 log_mustnot eval "$ZFS unmount $opt $mpt >/dev/null 2>&1" 127 done 128done 129cd $curpath 130 131#Testing null argument and too many arguments 132for opt in "" "-f"; do 133 log_mustnot eval "$ZFS unmount $opt >/dev/null 2>&1" 134 log_mustnot eval "$ZFS unmount $opt $fs $fs1 >/dev/null 2>&1" 135done 136 137#Testing already unmounted filesystem 138log_must $ZFS unmount $fs1 139for opt in "" "-f"; do 140 log_mustnot eval "$ZFS unmount $opt $fs1 >/dev/null 2>&1" 141 log_mustnot eval "$ZFS unmount $TMPDIR/$dir >/dev/null 2>&1" 142done 143 144#Testing legacy mounted filesystem 145log_must $ZFS set mountpoint=legacy $fs1 146log_must $MOUNT -t zfs $fs1 $TMPDIR/$dir 147for opt in "" "-f"; do 148 log_mustnot eval "$ZFS unmount $opt $fs1 >/dev/null 2>&1" 149done 150$UMOUNT $TMPDIR/$dir 151 152log_pass "zfs unmount fails with bad parameters or scenarios as expected." 153