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 unshare <filesystem|mountpoint>' unshares a given shared 33# filesystem. 34# 35# STRATEGY: 36# 1. Share filesystems 37# 2. Invoke 'zfs unshare <filesystem|mountpoint>' to unshare zfs file system 38# 3. Verify that the file system is unshared 39# 4. Verify that unsharing an unshared file system fails 40# 5. Verify that "zfs unshare -a" succeeds to unshare all zfs file systems. 41# 42 43verify_runnable "global" 44 45function cleanup 46{ 47 typeset -i i=0 48 while (( i < ${#mntp_fs[*]} )); do 49 log_must $ZFS set sharenfs=off ${mntp_fs[((i+1))]} 50 51 ((i = i + 2)) 52 done 53 54 if mounted $TESTPOOL/$TESTCLONE; then 55 log_must $ZFS unmount $TESTDIR2 56 fi 57 58 [[ -d $TESTDIR2 ]] && \ 59 log_must $RM -rf $TESTDIR2 60 61 if datasetexists "$TESTPOOL/$TESTCLONE"; then 62 log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE 63 fi 64 65 if snapexists "$TESTPOOL/$TESTFS2@snapshot"; then 66 log_must $ZFS destroy -f $TESTPOOL/$TESTFS2@snapshot 67 fi 68 69 if datasetexists "$TESTPOOL/$TESTFS2"; then 70 log_must $ZFS destroy -f $TESTPOOL/$TESTFS2 71 fi 72} 73 74# 75# Main test routine. 76# 77# Given a mountpoint and file system this routine will attempt 78# unshare the filesystem via <filesystem|mountpoint> argument 79# and then verify it has been unshared. 80# 81function test_unshare # <mntp> <filesystem> 82{ 83 typeset mntp=$1 84 typeset filesystem=$2 85 typeset prop_value 86 87 prop_value=$(get_prop "sharenfs" $filesystem) 88 89 if [[ $prop_value == "off" ]]; then 90 not_shared $mntp || 91 log_must $UNSHARE -F nfs $mntp 92 log_must $ZFS set sharenfs=on $filesystem 93 is_shared $mntp || \ 94 log_fail "'$ZFS set sharenfs=on' fails to make" \ 95 "file system $filesystem shared." 96 fi 97 98 is_shared $mntp || log_must $ZFS share $filesystem 99 100 # 101 # Verify 'zfs unshare <filesystem>' works as well. 102 # 103 log_must $ZFS unshare $filesystem 104 not_shared $mntp || log_fail "'zfs unshare <filesystem>' fails" 105 106 log_must $ZFS share $filesystem 107 108 log_must $ZFS unshare $mntp 109 not_shared $mntp || log_fail "'zfs unshare <mountpoint>' fails" 110 111 log_note "Unsharing an unshared file system fails." 112 log_mustnot $ZFS unshare $filesystem 113 log_mustnot $ZFS unshare $mntp 114} 115 116set -A mntp_fs \ 117 "$TESTDIR" "$TESTPOOL/$TESTFS" \ 118 "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \ 119 "$TESTDIR2" "$TESTPOOL/$TESTCLONE" 120 121log_assert "Verify that 'zfs unshare [-a] <filesystem|mountpoint>' succeeds as root." 122log_onexit cleanup 123 124log_must $ZFS create $TESTPOOL/$TESTFS2 125log_must $ZFS snapshot $TESTPOOL/$TESTFS2@snapshot 126log_must $ZFS clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE 127log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE 128 129# 130# Invoke 'test_unshare' routine to test 'zfs unshare <filesystem|mountpoint>'. 131# 132typeset -i i=0 133while (( i < ${#mntp_fs[*]} )); do 134 test_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]} 135 136 ((i = i + 2)) 137done 138 139log_note "Verify '$ZFS unshare -a' succeds as root." 140 141i=0 142typeset sharenfs_val 143while (( i < ${#mntp_fs[*]} )); do 144 sharenfs_val=$(get_prop "sharenfs" ${mntp_fs[((i+1))]}) 145 if [[ $sharenfs_val == "on" ]]; then 146 not_shared ${mntp_fs[i]} && \ 147 log_must $ZFS share ${mntp_fs[((i+1))]} 148 else 149 log_must $ZFS set sharenfs=on ${mntp_fs[((i+1))]} 150 is_shared ${mntp_fs[i]} || \ 151 log_fail "'$ZFS set sharenfs=on' fails to share filesystem." 152 fi 153 154 ((i = i + 2)) 155done 156 157# 158# test 'zfs unshare -a ' 159# 160log_must $ZFS unshare -a 161 162# 163# verify all shared filesystems become unshared 164# 165i=0 166while (( i < ${#mntp_fs[*]} )); do 167 not_shared ${mntp_fs[i]} || \ 168 log_fail "'$ZFS unshare -a' fails to unshare all shared zfs filesystems." 169 170 ((i = i + 2)) 171done 172 173log_pass "'$ZFS unshare [-a] <filesystem|mountpoint>' succeeds as root." 174