xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh (revision b6805bf78d2bbbeeaea8909a05623587b42d58b3)
1#!/bin/ksh -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
28. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
29
30#
31# DESCRIPTION:
32#	'zfs mount -O' allow the file system to be mounted over an existing
33#	mount point, making the underlying file system inaccessible.
34#
35# STRATEGY:
36#	1. Create two filesystem fs & fs1, and create two test files for them.
37#	2. Unmount fs1 and set mountpoint property is identical to fs.
38#	3. Verify 'zfs mount -O' will make the underlying filesystem fs
39#	   inaccessible.
40#
41
42function cleanup
43{
44	! ismounted $fs && log_must $ZFS mount $fs
45
46	if datasetexists $fs1; then
47		log_must $ZFS destroy $fs1
48	fi
49
50	if [[ -f $testfile ]]; then
51		log_must $RM -f $testfile
52	fi
53}
54
55log_assert "Verify 'zfs mount -O' will override existing mount point."
56log_onexit cleanup
57
58fs=$TESTPOOL/$TESTFS; fs1=$TESTPOOL/$TESTFS1
59
60cleanup
61
62# Get the original mountpoint of $fs and $fs1
63mntpnt=$(get_prop mountpoint $fs)
64log_must $ZFS create $fs1
65mntpnt1=$(get_prop mountpoint $fs1)
66
67testfile=$mntpnt/$TESTFILE0; testfile1=$mntpnt1/$TESTFILE1
68log_must $MKFILE 1M $testfile $testfile1
69
70log_must $ZFS unmount $fs1
71log_must $ZFS set mountpoint=$mntpnt $fs1
72log_mustnot $ZFS mount $fs1
73log_must $ZFS mount -O $fs1
74
75# Create new file in override mountpoint
76log_must $MKFILE 1M $mntpnt/$TESTFILE2
77
78# Verify the underlying file system inaccessible
79log_mustnot $LS $testfile
80log_must $LS $mntpnt/$TESTFILE1 $mntpnt/$TESTFILE2
81
82# Verify $TESTFILE2 was created in $fs1, rather then $fs
83log_must $ZFS unmount $fs1
84log_must $ZFS set mountpoint=$mntpnt1 $fs1
85log_must $ZFS mount $fs1
86log_must $LS $testfile1 $mntpnt1/$TESTFILE2
87
88# Verify $TESTFILE2 was not created in $fs, and $fs is accessable again.
89log_mustnot $LS $mntpnt/$TESTFILE2
90log_must $LS $testfile
91
92log_pass "Verify 'zfs mount -O' override mount point passed."
93