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# Verify that 'zfs set sharenfs' and 'zfs share' shares a given dataset. 33# 34# STRATEGY: 35# 1. Invoke 'zfs set sharenfs'. 36# 2. Verify that the file system is shared. 37# 3. Invoke 'zfs share'. 38# 4. Verify that the file system is shared. 39# 5. Verify that a shared filesystem cannot be shared again. 40# 6. Verify that share -a succeeds. 41# 42 43verify_runnable "global" 44 45set -A fs \ 46 "$TESTDIR" "$TESTPOOL/$TESTFS" \ 47 "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \ 48 "$TESTDIR2" "$TESTPOOL/$TESTFS-clone" 49 50function cleanup 51{ 52 typeset -i i=0 53 while (( i < ${#fs[*]} )); do 54 log_must $ZFS set sharenfs=off ${fs[((i+1))]} 55 unshare_fs ${fs[i]} 56 57 ((i = i + 2)) 58 done 59 60 if mounted $TESTPOOL/$TESTFS-clone; then 61 log_must $ZFS unmount $TESTDIR2 62 fi 63 64 datasetexists $TESTPOOL/$TESTFS-clone && \ 65 log_must $ZFS destroy -f $TESTPOOL/$TESTFS-clone 66 67 if snapexists "$TESTPOOL/$TESTFS@snapshot"; then 68 log_must $ZFS destroy -f $TESTPOOL/$TESTFS@snapshot 69 fi 70} 71 72 73# 74# Main test routine. 75# 76# Given a mountpoint and file system this routine will attempt 77# share the mountpoint and then verify it has been shared. 78# 79function test_share # mntp filesystem 80{ 81 typeset mntp=$1 82 typeset filesystem=$2 83 84 not_shared $mntp || \ 85 log_fail "File system $filesystem is already shared." 86 87 log_must $ZFS set sharenfs=on $filesystem 88 is_shared $mntp || \ 89 log_fail "File system $filesystem is not shared (set sharenfs)." 90 91 # 92 # Verify 'zfs share' works as well. 93 # 94 log_must $ZFS unshare $filesystem 95 is_shared $mntp && \ 96 log_fail "File system $filesystem is still shared." 97 98 log_must $ZFS share $filesystem 99 is_shared $mntp || \ 100 log_fail "file system $filesystem is not shared (zfs share)." 101 102 log_note "Sharing a shared file system fails." 103 log_mustnot $ZFS share $filesystem 104} 105 106log_assert "Verify that 'zfs share' succeeds as root." 107log_onexit cleanup 108 109log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot 110log_must $ZFS clone $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS-clone 111log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTFS-clone 112 113typeset -i i=0 114while (( i < ${#fs[*]} )); do 115 test_share ${fs[i]} ${fs[((i + 1))]} 116 117 ((i = i + 2)) 118done 119 120log_note "Verify 'zfs share -a' succeeds." 121 122# 123# Unshare each of the file systems. 124# 125i=0 126while (( i < ${#fs[*]} )); do 127 unshare_fs ${fs[i]} 128 129 ((i = i + 2)) 130done 131 132# 133# Try a zfs share -a and verify all file systems are shared. 134# 135log_must $ZFS share -a 136 137i=0 138while (( i < ${#fs[*]} )); do 139 is_shared ${fs[i]} || \ 140 log_fail "File system ${fs[i]} is not shared (share -a)" 141 142 ((i = i + 2)) 143done 144 145log_pass "'$ZFS share [ -a ] <filesystem>' succeeds as root." 146