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