1#!/usr/local/bin/ksh93 -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 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#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_mount_008_pos
34#
35# DESCRIPTION:
36#	'zfs mount -O' allow the file system to be mounted over an existing
37#	mount point, making the underlying file system inaccessible.
38#
39# STRATEGY:
40#	1. Create two filesystem fs & fs1, and create two test files for them.
41#	2. Unmount fs1 and set mountpoint property is identical to fs.
42#	3. Verify 'zfs mount -O' will make the underlying filesystem fs
43#	   inaccessible.
44#
45# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2006-08-02)
50#
51# __stc_assertion_end
52#
53################################################################################
54
55function cleanup
56{
57	! ismounted $fs && log_must $ZFS mount $fs
58
59	if datasetexists $fs1; then
60		log_must $ZFS destroy $fs1
61	fi
62
63	if [[ -f $testfile ]]; then
64		log_must $RM -f $testfile
65	fi
66}
67
68log_assert "Verify 'zfs mount -O' will override existing mount point."
69log_onexit cleanup
70
71fs=$TESTPOOL/$TESTFS; fs1=$TESTPOOL/$TESTFS1
72
73cleanup
74
75# Get the original mountpoint of $fs and $fs1
76mntpnt=$(get_prop mountpoint $fs)
77log_must $ZFS create $fs1
78mntpnt1=$(get_prop mountpoint $fs1)
79
80testfile=$mntpnt/$TESTFILE0; testfile1=$mntpnt1/$TESTFILE1
81log_must $MKFILE 1M $testfile $testfile1
82
83log_must $ZFS unmount $fs1
84log_must $ZFS set mountpoint=$mntpnt $fs1
85log_must $ZFS mount $fs1
86
87# Create new file in override mountpoint
88log_must $MKFILE 1M $mntpnt/$TESTFILE2
89
90# Verify the underlying file system inaccessible
91log_mustnot $LS $testfile
92log_must $LS $mntpnt/$TESTFILE1 $mntpnt/$TESTFILE2
93
94# Verify $TESTFILE2 was created in $fs1, rather then $fs
95log_must $ZFS unmount $fs1
96log_must $ZFS set mountpoint=$mntpnt1 $fs1
97log_must $ZFS mount $fs1
98log_must $LS $testfile1 $mntpnt1/$TESTFILE2
99
100# Verify $TESTFILE2 was not created in $fs, and $fs is accessible again.
101log_mustnot $LS $mntpnt/$TESTFILE2
102log_must $LS $testfile
103
104log_pass "Verify 'zfs mount -O' override mount point passed."
105