]> git.proxmox.com Git - mirror_zfs.git/blame - tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh
Update ZTS to work on FreeBSD
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zfs_set / readonly_001_pos.ksh
CommitLineData
6bb24f4d
BB
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#
c1d9abf9 29# Copyright (c) 2014, 2016 by Delphix. All rights reserved.
6bb24f4d
BB
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 && \
c1d9abf9 51 log_must zfs destroy -R ${dataset}@$TESTSNAP
6bb24f4d
BB
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)
c1d9abf9
JWK
63 log_must touch $mtpt/$TESTFILE0
64 log_must mkdir -p $mtpt/$TESTDIR0
6bb24f4d
BB
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)
c1d9abf9
JWK
77 log_must rm -f $mtpt/$TESTFILE0
78 log_must rm -rf $mtpt/$TESTDIR0
6bb24f4d
BB
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)
c1d9abf9
JWK
103 $expect touch $mtpt/$TESTFILE1
104 $expect mkdir -p $mtpt/$TESTDIR1
105 $expect eval "echo 'y' | rm $mtpt/$TESTFILE0"
106 $expect rmdir $mtpt/$TESTDIR0
6bb24f4d
BB
107
108 if [[ $expect == "log_must" ]] ; then
c1d9abf9
JWK
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
6bb24f4d
BB
113 fi
114 ;;
115 volume)
7839c4b5 116 $expect eval "new_fs \
6bb24f4d
BB
117 ${ZVOL_DEVDIR}/$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
c1d9abf9 132log_must zfs mount -a
6bb24f4d 133
c1d9abf9
JWK
134log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP
135log_must zfs clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
6bb24f4d
BB
136
137if is_global_zone ; then
c1d9abf9
JWK
138 log_must zfs snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
139 log_must zfs clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
6bb24f4d
BB
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."