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