1# 2# CDDL HEADER START 3# 4# The contents of this file are subject to the terms of the 5# Common Development and Distribution License (the "License"). 6# You may not use this file except in compliance with the License. 7# 8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9# or http://www.opensolaris.org/os/licensing. 10# See the License for the specific language governing permissions 11# and limitations under the License. 12# 13# When distributing Covered Code, include this CDDL HEADER in each 14# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15# If applicable, add the following below this CDDL HEADER, with the 16# fields enclosed by brackets "[]" replaced with your own identifying 17# information: Portions Copyright [yyyy] [name of copyright owner] 18# 19# CDDL HEADER END 20# 21 22# 23# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24# Use is subject to license terms. 25# 26 27. $STF_SUITE/include/libtest.shlib 28. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.cfg 29 30function force_unmount #dev 31{ 32 typeset dev=$1 33 34 ismounted $dev 35 if (( $? == 0 )); then 36 log_must $ZFS $unmountforce $dev 37 fi 38 return 0 39} 40 41# Create pool and ( fs | container | vol ) with the given parameters, 42# it'll destroy prior exist one that has the same name. 43 44function setup_filesystem #disklist #pool #fs #mntpoint #type #vdev 45{ 46 typeset disklist=$1 47 typeset pool=$2 48 typeset fs=${3##/} 49 typeset mntpoint=$4 50 typeset type=$5 51 typeset vdev=$6 52 53 if [[ -z $pool || -z $fs || -z $mntpoint ]]; then 54 log_note "Missing parameter: (\"$pool\", \"$fs\", \"$mntpoint\")" 55 return 1 56 fi 57 58 if is_global_zone && [[ -z $disklist ]] ; then 59 log_note "Missing disklist." 60 return 1 61 fi 62 63 if [[ $vdev != "" && \ 64 $vdev != "mirror" && \ 65 $vdev != "raidz" ]] ; then 66 67 log_note "Wrong vdev: (\"$vdev\")" 68 return 1 69 fi 70 71 poolexists $pool || \ 72 create_pool $pool $vdev $disklist 73 74 datasetexists $pool/$fs && \ 75 log_must cleanup_filesystem $pool $fs 76 77 $RMDIR $mntpoint > /dev/null 2>&1 78 if [[ ! -d $mntpoint ]]; then 79 log_must $MKDIR -p $mntpoint 80 fi 81 82 case "$type" in 83 'ctr') log_must $ZFS create $pool/$fs 84 log_must $ZFS set mountpoint=$mntpoint $pool/$fs 85 ;; 86 'vol') log_must $ZFS create -V $VOLSIZE $pool/$fs 87 ;; 88 *) log_must $ZFS create $pool/$fs 89 log_must $ZFS set mountpoint=$mntpoint $pool/$fs 90 ;; 91 esac 92 93 return 0 94} 95 96# Destroy ( fs | container | vol ) with the given parameters. 97function cleanup_filesystem #pool #fs 98{ 99 typeset pool=$1 100 typeset fs=${2##/} 101 typeset mtpt="" 102 103 if [[ -z $pool || -z $fs ]]; then 104 log_note "Missing parameter: (\"$pool\", \"$fs\")" 105 return 1 106 fi 107 108 if datasetexists "$pool/$fs" ; then 109 mtpt=$(get_prop mountpoint "$pool/$fs") 110 log_must $ZFS destroy -r $pool/$fs 111 112 [[ -d $mtpt ]] && \ 113 log_must $RM -rf $mtpt 114 else 115 return 1 116 fi 117 118 return 0 119} 120 121# Make sure 'zfs mount' should display all ZFS filesystems currently mounted. 122# The results of 'zfs mount' and 'df -F zfs' should be identical. 123function verify_mount_display 124{ 125 typeset fs 126 127 for fs in $($ZFS $mountcmd | $AWK '{print $1}') ; do 128 log_must mounted $fs 129 done 130 return 0 131} 132