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