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 https://opensource.org/licenses/CDDL-1.0. 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 2009 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28# 29# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib 34 35# 36# DESCRIPTION: 37# While canmount=noauto and the dataset is mounted, 38# zfs must not attempt to unmount it. 39# 40# STRATEGY: 41# 1. Setup a pool and create fs, volume, snapshot clone within it. 42# 2. Set canmount=noauto for each dataset and check the return value 43# and check if it still can not be unmounted when the dataset is mounted 44# 45 46verify_runnable "both" 47 48set -A dataset_pos "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCLONE" 49 50function cleanup 51{ 52 i=0 53 cd $pwd 54 while (( i < ${#dataset_pos[*]} )); do 55 ds=${dataset_pos[i]} 56 if datasetexists $ds; then 57 log_must zfs set mountpoint=${old_mnt[i]} $ds 58 log_must zfs set canmount=${old_canmount[i]} $ds 59 fi 60 (( i = i + 1 )) 61 done 62 63 ds=$TESTPOOL/$TESTCLONE 64 if datasetexists $ds; then 65 mntp=$(get_prop mountpoint $ds) 66 destroy_dataset $ds 67 if [[ -d $mntp ]]; then 68 log_must rm -fr $mntp 69 fi 70 fi 71 72 snapexists $TESTPOOL/$TESTFS@$TESTSNAP && \ 73 destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP -R 74 75 zfs unmount -a > /dev/null 2>&1 76 log_must zfs mount -a 77} 78 79log_assert "While canmount=noauto and the dataset is mounted,"\ 80 " zfs must not attempt to unmount it" 81log_onexit cleanup 82 83set -A old_mnt 84set -A old_canmount 85typeset ds 86typeset pwd=$PWD 87 88log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP 89log_must zfs clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE 90 91typeset -i i=0 92while (( i < ${#dataset_pos[*]} )); do 93 ds=${dataset_pos[i]} 94 old_mnt[i]=$(get_prop mountpoint $ds) 95 old_canmount[i]=$(get_prop canmount $ds) 96 (( i = i + 1 )) 97done 98 99i=0 100while (( i < ${#dataset_pos[*]} )); do 101 dataset=${dataset_pos[i]} 102 if ismounted $dataset; then 103 log_must cd ${old_mnt[i]} 104 set_n_check_prop "noauto" "canmount" "$dataset" 105 log_must mounted $dataset 106 fi 107 (( i = i + 1 )) 108done 109 110log_pass "Setting canmount=noauto to filesystem while dataset busy pass." 111