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 2009 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26 27. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib 28 29############################################################################### 30# 31# __stc_assertion_start 32# 33# ID: readonly_001_pos 34# 35# DESCRIPTION: 36# Setting readonly on a dataset, it should keep the dataset as readonly. 37# 38# STRATEGY: 39# 1. Create pool, then create filesystem and volume within it. 40# 2. Setting readonly to each dataset. 41# 3. Check the return value and make sure it is 0. 42# 4. Verify the stuff under mountpoint is readonly. 43# 44# TESTABILITY: explicit 45# 46# TEST_AUTOMATION_LEVEL: automated 47# 48# CODING_STATUS: COMPLETED (2009-04-21) 49# 50# __stc_assertion_end 51# 52################################################################################ 53 54verify_runnable "both" 55 56function cleanup 57{ 58 for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do 59 snapexists ${dataset}@$TESTSNAP && \ 60 log_must $ZFS destroy -R ${dataset}@$TESTSNAP 61 done 62} 63 64function initial_dataset # $1 dataset 65{ 66 typeset dataset=$1 67 68 typeset fstype=$(get_prop type $dataset) 69 70 if [[ $fstype == "filesystem" ]] ; then 71 typeset mtpt=$(get_prop mountpoint $dataset) 72 log_must $TOUCH $mtpt/$TESTFILE0 73 log_must $MKDIR -p $mtpt/$TESTDIR0 74 fi 75} 76 77 78function cleanup_dataset # $1 dataset 79{ 80 typeset dataset=$1 81 82 typeset fstype=$(get_prop type $dataset) 83 84 if [[ $fstype == "filesystem" ]] ; then 85 typeset mtpt=$(get_prop mountpoint $dataset) 86 log_must $RM -f $mtpt/$TESTFILE0 87 log_must $RM -rf $mtpt/$TESTDIR0 88 fi 89} 90 91function verify_readonly # $1 dataset, $2 on|off 92{ 93 typeset dataset=$1 94 typeset value=$2 95 96 if datasetnonexists $dataset ; then 97 log_note "$dataset not exist!" 98 return 1 99 fi 100 101 typeset fstype=$(get_prop type $dataset) 102 103 expect="log_must" 104 105 if [[ $2 == "on" ]] ; then 106 expect="log_mustnot" 107 fi 108 109 case $fstype in 110 filesystem) 111 typeset mtpt=$(get_prop mountpoint $dataset) 112 $expect $TOUCH $mtpt/$TESTFILE1 113 $expect $MKDIR -p $mtpt/$TESTDIR1 114 $expect $ECHO 'y' | $RM $mtpt/$TESTFILE0 115 $expect $RMDIR $mtpt/$TESTDIR0 116 117 if [[ $expect == "log_must" ]] ; then 118 log_must $ECHO 'y' | $RM $mtpt/$TESTFILE1 119 log_must $RMDIR $mtpt/$TESTDIR1 120 log_must $TOUCH $mtpt/$TESTFILE0 121 log_must $MKDIR -p $mtpt/$TESTDIR0 122 fi 123 ;; 124 volume) 125 $expect eval "$ECHO 'y' | $NEWFS /dev/zvol/$dataset > /dev/null 2>&1" 126 ;; 127 *) 128 ;; 129 esac 130 131 return 0 132} 133 134log_onexit cleanup 135 136log_assert "Setting a valid readonly property on a dataset succeeds." 137 138typeset all_datasets 139 140log_must $ZFS mount -a 141 142log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP 143log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE 144 145if is_global_zone ; then 146 log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP 147 log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1 148 all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCLONE $TESTPOOL/$TESTCLONE1" 149else 150 all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE" 151fi 152 153 154for dataset in $all_datasets; do 155 for value in on off; do 156 set_n_check_prop "off" "readonly" "$dataset" 157 initial_dataset $dataset 158 159 set_n_check_prop "$value" "readonly" "$dataset" 160 verify_readonly $dataset $value 161 162 set_n_check_prop "off" "readonly" "$dataset" 163 cleanup_dataset $dataset 164 done 165done 166 167log_pass "Setting a valid readonly property on a dataset succeeds." 168