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