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_unshare_002_pos 34# 35# DESCRIPTION: 36# Verify that 'zfs unshare [-a] <filesystem|mountpoint>' is aware of legacy share. 37# 38# STRATEGY: 39# 1. Set 'zfs set sharenfs=off' 40# 2. Use 'share' to share given filesystem 41# 3. Verify that 'zfs unshare <filesystem|mountpoint>' is aware of legacy share 42# 4. Verify that 'zfs unshare -a' is aware of legacy share. 43# 44# TESTABILITY: explicit 45# 46# TEST_AUTOMATION_LEVEL: automated 47# 48# CODING_STATUS: COMPLETED (2005-07-28) 49# 50# __stc_assertion_end 51# 52################################################################################ 53 54verify_runnable "global" 55 56function cleanup 57{ 58 typeset -i i=0 59 while (( i < ${#mntp_fs[*]} )); do 60 is_shared ${mntp_fs[i]} && \ 61 log_must $UNSHARE -F nfs ${mntp_fs[i]} 62 63 ((i = i + 2)) 64 done 65 66 if mounted $TESTPOOL/$TESTCLONE; then 67 log_must $ZFS unmount $TESTDIR2 68 fi 69 70 [[ -d $TESTDIR2 ]] && \ 71 log_must $RM -rf $TESTDIR2 72 73 if datasetexists "$TESTPOOL/$TESTCLONE"; then 74 log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE 75 fi 76 77 if snapexists "$TESTPOOL/$TESTFS2@snapshot"; then 78 log_must $ZFS destroy -f $TESTPOOL/$TESTFS2@snapshot 79 fi 80 81 if datasetexists "$TESTPOOL/$TESTFS2"; then 82 log_must $ZFS destroy -f $TESTPOOL/$TESTFS2 83 fi 84} 85 86# 87# Main test routine. 88# 89# Given a mountpoint and file system this routine will attempt 90# to verify 'zfs unshare' is aware of legacy share. 91# 92function test_legacy_unshare # <mntp> <filesystem> 93{ 94 typeset mntp=$1 95 typeset filesystem=$2 96 97 log_must $ZFS set sharenfs=off $filesystem 98 not_shared $mntp || \ 99 log_fail "'zfs set sharenfs=off' fails to make ZFS filesystem $filesystem unshared." 100 101 log_must $SHARE -F nfs $mntp 102 is_shared $mntp || \ 103 log_fail "'share' command fails to share ZFS file system." 104 # 105 # Verify 'zfs unshare <filesystem>' is aware of legacy share. 106 # 107 log_mustnot $ZFS unshare $filesystem 108 is_shared $mntp || \ 109 log_fail "'zfs unshare <filesystem>' fails to be aware" \ 110 "of legacy share." 111 112 # 113 # Verify 'zfs unshare <filesystem>' is aware of legacy share. 114 # 115 log_mustnot $ZFS unshare $mntp 116 is_shared $mntp || \ 117 log_fail "'zfs unshare <mountpoint>' fails to be aware" \ 118 "of legacy share." 119} 120 121 122set -A mntp_fs \ 123 "$TESTDIR" "$TESTPOOL/$TESTFS" \ 124 "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \ 125 "$TESTDIR2" "$TESTPOOL/$TESTCLONE" 126 127log_assert "Verify that 'zfs unshare [-a]' is aware of legacy share." 128log_onexit cleanup 129 130log_must $ZFS create $TESTPOOL/$TESTFS2 131log_must $ZFS snapshot $TESTPOOL/$TESTFS2@snapshot 132log_must $ZFS clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE 133log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE 134 135# 136# Invoke 'test_legacy_unshare' routine to verify. 137# 138typeset -i i=0 139while (( i < ${#mntp_fs[*]} )); do 140 test_legacy_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]} 141 142 ((i = i + 2)) 143done 144 145 146log_note "Verify '$ZFS unshare -a' is aware of legacy share." 147 148# 149# set the 'sharenfs' property to 'off' for each filesystem 150# 151i=0 152while (( i < ${#mntp_fs[*]} )); do 153 log_must $ZFS set sharenfs=off ${mntp_fs[((i + 1))]} 154 not_shared ${mntp_fs[i]} || \ 155 log_fail "'$ZFS set sharenfs=off' unshares file system failed." 156 157 ((i = i + 2)) 158done 159 160# 161# Share each of the file systems via legacy share. 162# 163i=0 164while (( i < ${#mntp_fs[*]} )); do 165 $SHARE -F nfs ${mntp_fs[i]} 166 is_shared ${mntp_fs[i]} || \ 167 log_fail "'$SHARE' shares ZFS filesystem failed." 168 169 ((i = i + 2)) 170done 171 172# 173# Verify that 'zfs unshare -a' is aware of legacy share 174# 175log_must $ZFS unshare -a 176 177# 178# verify ZFS filesystems are still shared 179# 180i=0 181while (( i < ${#mntp_fs[*]} )); do 182 is_shared ${mntp_fs[i]} || \ 183 log_fail "'$ZFS unshare -a' fails to be aware of legacy share." 184 185 ((i = i + 2)) 186done 187 188log_pass "'$ZFS unshare [-a]' succeeds to be aware of legacy share." 189 190