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