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# 29# Copyright (c) 2014 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib 33 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 45verify_runnable "both" 46 47function cleanup 48{ 49 for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do 50 snapexists ${dataset}@$TESTSNAP && \ 51 log_must $ZFS destroy -R ${dataset}@$TESTSNAP 52 done 53} 54 55function initial_dataset # $1 dataset 56{ 57 typeset dataset=$1 58 59 typeset fstype=$(get_prop type $dataset) 60 61 if [[ $fstype == "filesystem" ]] ; then 62 typeset mtpt=$(get_prop mountpoint $dataset) 63 log_must $TOUCH $mtpt/$TESTFILE0 64 log_must $MKDIR -p $mtpt/$TESTDIR0 65 fi 66} 67 68 69function cleanup_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 $RM -f $mtpt/$TESTFILE0 78 log_must $RM -rf $mtpt/$TESTDIR0 79 fi 80} 81 82function verify_readonly # $1 dataset, $2 on|off 83{ 84 typeset dataset=$1 85 typeset value=$2 86 87 if datasetnonexists $dataset ; then 88 log_note "$dataset does not exist!" 89 return 1 90 fi 91 92 typeset fstype=$(get_prop type $dataset) 93 94 expect="log_must" 95 96 if [[ $2 == "on" ]] ; then 97 expect="log_mustnot" 98 fi 99 100 case $fstype in 101 filesystem) 102 typeset mtpt=$(get_prop mountpoint $dataset) 103 $expect $TOUCH $mtpt/$TESTFILE1 104 $expect $MKDIR -p $mtpt/$TESTDIR1 105 $expect eval "$ECHO 'y' | $RM $mtpt/$TESTFILE0" 106 $expect $RMDIR $mtpt/$TESTDIR0 107 108 if [[ $expect == "log_must" ]] ; then 109 log_must eval "$ECHO 'y' | $RM $mtpt/$TESTFILE1" 110 log_must $RMDIR $mtpt/$TESTDIR1 111 log_must $TOUCH $mtpt/$TESTFILE0 112 log_must $MKDIR -p $mtpt/$TESTDIR0 113 fi 114 ;; 115 volume) 116 $expect eval "$ECHO 'y' | $NEWFS \ 117 /dev/zvol/dsk/$dataset > /dev/null 2>&1" 118 ;; 119 *) 120 ;; 121 esac 122 123 return 0 124} 125 126log_onexit cleanup 127 128log_assert "Setting a valid readonly property on a dataset succeeds." 129 130typeset all_datasets 131 132log_must $ZFS mount -a 133 134log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP 135log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE 136 137if is_global_zone ; then 138 log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP 139 log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1 140 all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL " 141 all_datasets+="$TESTPOOL/$TESTCLONE $TESTPOOL/$TESTCLONE1" 142else 143 all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE" 144fi 145 146 147for dataset in $all_datasets; do 148 for value in on off; do 149 set_n_check_prop "off" "readonly" "$dataset" 150 initial_dataset $dataset 151 152 set_n_check_prop "$value" "readonly" "$dataset" 153 verify_readonly $dataset $value 154 155 set_n_check_prop "off" "readonly" "$dataset" 156 cleanup_dataset $dataset 157 done 158done 159 160log_pass "Setting a valid readonly property on a dataset succeeds." 161