5767 fix several problems with zfs test suite
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zfs_set / readonly_001_pos.ksh
blobfd8a9e4daf84fb951c56ec184851deb6a0608a50
1 #!/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2014 by Delphix. All rights reserved.
32 . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
35 # DESCRIPTION:
36 # Setting readonly on a dataset, it should keep the dataset as readonly.
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.
45 verify_runnable "both"
47 function cleanup
49 for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do
50 snapexists ${dataset}@$TESTSNAP && \
51 log_must $ZFS destroy -R ${dataset}@$TESTSNAP
52 done
55 function initial_dataset # $1 dataset
57 typeset dataset=$1
59 typeset fstype=$(get_prop type $dataset)
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
69 function cleanup_dataset # $1 dataset
71 typeset dataset=$1
73 typeset fstype=$(get_prop type $dataset)
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
82 function verify_readonly # $1 dataset, $2 on|off
84 typeset dataset=$1
85 typeset value=$2
87 if datasetnonexists $dataset ; then
88 log_note "$dataset does not exist!"
89 return 1
92 typeset fstype=$(get_prop type $dataset)
94 expect="log_must"
96 if [[ $2 == "on" ]] ; then
97 expect="log_mustnot"
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
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
115 volume)
116 $expect eval "$ECHO 'y' | $NEWFS \
117 /dev/zvol/dsk/$dataset > /dev/null 2>&1"
121 esac
123 return 0
126 log_onexit cleanup
128 log_assert "Setting a valid readonly property on a dataset succeeds."
130 typeset all_datasets
132 log_must $ZFS mount -a
134 log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
135 log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
137 if 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"
142 else
143 all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE"
147 for dataset in $all_datasets; do
148 for value in on off; do
149 set_n_check_prop "off" "readonly" "$dataset"
150 initial_dataset $dataset
152 set_n_check_prop "$value" "readonly" "$dataset"
153 verify_readonly $dataset $value
155 set_n_check_prop "off" "readonly" "$dataset"
156 cleanup_dataset $dataset
157 done
158 done
160 log_pass "Setting a valid readonly property on a dataset succeeds."