xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh (revision 4585130b259133a26efae68275dbe56b08366deb)
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#
29# Copyright (c) 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
33
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
46function cleanup
47{
48	! ismounted $fs && log_must zfs mount $fs
49
50	if datasetexists $fs1; then
51		log_must zfs destroy $fs1
52	fi
53
54	if [[ -f $testfile ]]; then
55		log_must rm -f $testfile
56	fi
57}
58
59log_assert "Verify 'zfs mount -O' will override existing mount point."
60log_onexit cleanup
61
62fs=$TESTPOOL/$TESTFS; fs1=$TESTPOOL/$TESTFS1
63
64cleanup
65
66# Get the original mountpoint of $fs and $fs1
67mntpnt=$(get_prop mountpoint $fs)
68log_must zfs create $fs1
69mntpnt1=$(get_prop mountpoint $fs1)
70
71testfile=$mntpnt/$TESTFILE0; testfile1=$mntpnt1/$TESTFILE1
72log_must mkfile 1M $testfile $testfile1
73
74log_must zfs unmount $fs1
75log_must zfs set mountpoint=$mntpnt $fs1
76log_mustnot zfs mount $fs1
77log_must zfs mount -O $fs1
78
79# Create new file in override mountpoint
80log_must mkfile 1M $mntpnt/$TESTFILE2
81
82# Verify the underlying file system inaccessible
83log_mustnot ls $testfile
84log_must ls $mntpnt/$TESTFILE1 $mntpnt/$TESTFILE2
85
86# Verify $TESTFILE2 was created in $fs1, rather then $fs
87log_must zfs unmount $fs1
88log_must zfs set mountpoint=$mntpnt1 $fs1
89log_must zfs mount $fs1
90log_must ls $testfile1 $mntpnt1/$TESTFILE2
91
92# Verify $TESTFILE2 was not created in $fs, and $fs is accessable again.
93log_mustnot ls $mntpnt/$TESTFILE2
94log_must ls $testfile
95
96log_pass "Verify 'zfs mount -O' override mount point passed."
97