xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_003_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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28. $STF_SUITE/include/libtest.shlib
29
30#
31# DESCRIPTION:
32# Invoking "zfs share <file system>" with a file system
33# whose sharenfs property is 'off' , will fail with a
34# return code of 1 and issue an error message.
35#
36# STRATEGY:
37# 1. Make sure that the ZFS file system is unshared.
38# 2. Mount the file system using the various combinations
39# - zfs set sharenfs=off <file system>
40# - zfs set sharenfs=none <file system>
41# 3. Verify that share failed with return code of 1.
42#
43
44verify_runnable "both"
45
46set -A fs \
47    "$TESTDIR" "$TESTPOOL/$TESTFS" \
48    "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1"
49
50function cleanup
51{
52	typeset -i i=0
53	while (( i < ${#fs[*]} )); do
54		log_must $ZFS inherit -r sharenfs ${fs[((i + 1))]}
55		log_must unshare_fs ${fs[i]}
56
57		((i = i + 2))
58	done
59}
60
61
62#
63# Main test routine.
64#
65# Given a mountpoint and file system this routine will attempt
66# to share a legacy mountpoint and then verify the share fails as
67# expected.
68#
69function test_legacy_share # mntp filesystem
70{
71	typeset mntp=$1
72	typeset filesystem=$2
73
74	not_shared $mntp || \
75	    log_fail "File system $filesystem is already shared."
76
77	if is_global_zone ; then
78		log_must $ZFS set sharenfs=off $filesystem
79		not_shared $mntp || \
80		    log_fail "File system $filesystem is still shared (set sharenfs)."
81	fi
82
83	$ZFS share $filesystem
84	ret=$?
85	(( ret == 1)) || \
86	    log_fail "'$ZFS share $filesystem' " \
87		"unexpected return code of $ret."
88
89	not_shared $mntp || \
90	    log_fail "file system $filesystem is shared (zfs share)."
91}
92
93log_assert "Verify that '$ZFS share' with a file system " \
94        "whose sharenfs property is 'off'  " \
95        "will fail with return code 1."
96log_onexit cleanup
97
98typeset -i i=0
99while (( i < ${#fs[*]} )); do
100	test_legacy_share ${fs[i]} ${fs[((i + 1))]}
101
102	((i = i + 2))
103done
104
105log_pass "Verify that '$ZFS share' with a file system " \
106        "whose sharenfs property is 'off' fails."
107