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 https://opensource.org/licenses/CDDL-1.0. 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# 29# Copyright (c) 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33 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 51verify_runnable "both" 52 53function cleanup 54{ 55 for ds in $vol $fs1; do 56 datasetexists $ds && destroy_dataset $ds -f 57 done 58 59 snapexists $snap && destroy_dataset $snap 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# Testing invalid datasets 95for ds in $snap $vol "blah"; do 96 for opt in "" "-f"; do 97 log_mustnot eval "zfs unmount $opt $ds >/dev/null 2>&1" 98 done 99done 100 101# Testing invalid mountpoint 102dir=foodir.$$ 103file=foo.$$ 104fs1=$TESTPOOL/fs.$$ 105mkdir /tmp/$dir 106touch /tmp/$file 107log_must zfs create -o mountpoint=/tmp/$dir $fs1 108curpath=`dirname $0` 109cd /tmp 110for mpt in "./$dir" "./$file" "/tmp"; do 111 for opt in "" "-f"; do 112 log_mustnot eval "zfs unmount $opt $mpt >/dev/null 2>&1" 113 done 114done 115cd $curpath 116 117# Testing null argument and too many arguments 118for opt in "" "-f"; do 119 log_mustnot eval "zfs unmount $opt >/dev/null 2>&1" 120 log_mustnot eval "zfs unmount $opt $fs $fs1 >/dev/null 2>&1" 121done 122 123# Testing already unmounted filesystem 124log_must zfs unmount $fs1 125for opt in "" "-f"; do 126 log_mustnot eval "zfs unmount $opt $fs1 >/dev/null 2>&1" 127 log_mustnot eval "zfs unmount /tmp/$dir >/dev/null 2>&1" 128done 129 130# Testing legacy mounted filesystem 131log_must zfs set mountpoint=legacy $fs1 132if is_linux || is_freebsd; then 133 log_must mount -t zfs $fs1 /tmp/$dir 134else 135 log_must mount -F zfs $fs1 /tmp/$dir 136fi 137for opt in "" "-f"; do 138 log_mustnot eval "zfs unmount $opt $fs1 >/dev/null 2>&1" 139done 140umount /tmp/$dir 141 142log_pass "zfs unmount fails with bad parameters or scenarios as expected." 143