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