1# vim: filetype=sh 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# $FreeBSD$ 24 25# 26# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)zfs_mount.kshlib 1.3 09/06/22 SMI" 30# 31 32. $STF_SUITE/include/libtest.kshlib 33 34function force_unmount #dev 35{ 36 typeset dev=$1 37 38 ismounted $dev 39 if (( $? == 0 )); then 40 log_must $ZFS $unmountforce $dev 41 fi 42 return 0 43} 44 45# Create pool and ( fs | container | vol ) with the given parameters, 46# it'll destroy prior exist one that has the same name. 47 48function setup_filesystem #disklist #pool #fs #mntpoint #type #vdev 49{ 50 typeset disklist=$1 51 typeset pool=$2 52 typeset fs=${3##/} 53 typeset mntpoint=$4 54 typeset type=$5 55 typeset vdev=$6 56 57 if [[ -z $pool || -z $fs || -z $mntpoint ]]; then 58 log_note "Missing parameter: (\"$pool\", \"$fs\", \"$mntpoint\")" 59 return 1 60 fi 61 62 if is_global_zone && [[ -z $disklist ]] ; then 63 log_note "Missing disklist." 64 return 1 65 fi 66 67 if [[ $vdev != "" && \ 68 $vdev != "mirror" && \ 69 $vdev != "raidz" ]] ; then 70 71 log_note "Wrong vdev: (\"$vdev\")" 72 return 1 73 fi 74 75 poolexists $pool || \ 76 create_pool $pool $vdev $disklist 77 78 datasetexists $pool/$fs && \ 79 log_must cleanup_filesystem $pool $fs 80 81 $RMDIR $mntpoint > /dev/null 2>&1 82 if [[ ! -d $mntpoint ]]; then 83 log_must $MKDIR -p $mntpoint 84 fi 85 86 case "$type" in 87 'ctr') log_must $ZFS create $pool/$fs 88 log_must $ZFS set mountpoint=$mntpoint $pool/$fs 89 ;; 90 'vol') log_must $ZFS create -V $VOLSIZE $pool/$fs 91 ;; 92 *) log_must $ZFS create $pool/$fs 93 log_must $ZFS set mountpoint=$mntpoint $pool/$fs 94 ;; 95 esac 96 97 return 0 98} 99 100# Destroy ( fs | container | vol ) with the given parameters. 101function cleanup_filesystem #pool #fs 102{ 103 typeset pool=$1 104 typeset fs=${2##/} 105 typeset mtpt="" 106 107 if [[ -z $pool || -z $fs ]]; then 108 log_note "Missing parameter: (\"$pool\", \"$fs\")" 109 return 1 110 fi 111 112 if datasetexists "$pool/$fs" ; then 113 mtpt=$(get_prop mountpoint "$pool/$fs") 114 log_must $ZFS destroy -r $pool/$fs 115 116 [[ -d $mtpt ]] && \ 117 log_must $RM -rf $mtpt 118 else 119 return 1 120 fi 121 122 return 0 123} 124 125# Make sure 'zfs mount' should display all ZFS filesystems currently mounted. 126# The results of 'zfs mount' and 'df -F zfs' should be identical. 127function verify_mount_display 128{ 129 typeset fs 130 131 for fs in $($ZFS $mountcmd | $AWK '{print $1}') ; do 132 log_must mounted $fs 133 done 134 return 0 135} 136