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