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. $STF_SUITE/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib 30 31# 32# DESCRIPTION: 33# If invoke "zfs unmount" with a specific filesystem|mountpoint 34# that have been mounted, but it's currently in use, 35# it will fail with a return code of 1 36# and issue an error message. 37# But unmount forcefully will bypass this restriction and 38# unmount that given filesystem successfully. 39# 40# STRATEGY: 41# 1. Make sure that the ZFS filesystem is mounted. 42# 2. Change directory to that given mountpoint. 43# 3. Unmount the file system using the various combinations. 44# - Without force option. (FAILED) 45# - With force option. (PASS) 46# 4. Unmount the mountpoint using the various combinations. 47# - Without force option. (FAILED) 48# - With force option. (PASS) 49# 5. Verify the above expected results of the filesystem|mountpoint. 50# 51 52verify_runnable "both" 53 54 55set -A cmd "umount" "unmount" 56set -A options "" "-f" 57set -A dev "$TESTPOOL/$TESTFS" "$TESTDIR" 58 59function do_unmount_multiple #options #expect 60{ 61 typeset opt=$1 62 typeset -i expect=${2-0} 63 64 typeset -i i=0 65 typeset -i j=0 66 67 while (( i < ${#cmd[*]} )); do 68 j=0 69 while (( j < ${#dev[*]} )); do 70 mounted ${dev[j]} || \ 71 log_must $ZFS $mountcmd ${dev[0]} 72 73 cd $TESTDIR || \ 74 log_unresolved "Unable change dir to $TESTDIR" 75 76 do_unmount "${cmd[i]}" "$opt" \ 77 "${dev[j]}" $expect 78 79 cleanup 80 81 ((j = j + 1)) 82 done 83 84 ((i = i + 1)) 85 done 86} 87 88log_assert "Verify that '$ZFS $unmountcmd <filesystem|mountpoint>' " \ 89 "with a filesystem which mountpoint is currently in use " \ 90 "will fail with return code 1, and forcefully will succeeds as root." 91 92log_onexit cleanup 93 94cwd=$PWD 95 96typeset -i i=0 97 98while (( i < ${#options[*]} )); do 99 if [[ ${options[i]} == "-f" ]]; then 100 do_unmount_multiple "${options[i]}" 101 else 102 do_unmount_multiple "${options[i]}" 1 103 fi 104 ((i = i + 1)) 105done 106 107log_pass "'$ZFS $unmountcmd <filesystem|mountpoint>' " \ 108 "with a filesystem which mountpoint is currently in use " \ 109 "will fail with return code 1, and forcefully will succeeds as root." 110