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