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