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#
24# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/include/libtest.kshlib
28. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
29
30###############################################################################
31#
32# __stc_assertion_start
33#
34# ID: ro_props_001_pos
35#
36# DESCRIPTION:
37# Verify that read-only properties are immutable.
38#
39# STRATEGY:
40# 1. Create pool, fs, vol, fs@snap & vol@snap.
41# 2. Get the original property value and set value to those properties.
42# 3. Check return value.
43# 4. Compare the current property value with the original one.
44#
45# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2005-07-04)
50#
51# __stc_assertion_end
52#
53################################################################################
54
55verify_runnable "both"
56
57set -A values filesystem volume snapshot -3 0 1 50K 10G 80G \
58	2005/06/17 30K 20x yes no \
59	on off default pool/fs@snap $TESTDIR
60set -A dataset $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
61	$TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS@$TESTSNAP \
62	$TESTPOOL/$TESTVOL@$TESTSNAP
63
64typeset ro_props="type"
65ro_props="$ro_props creation"
66ro_props="$ro_props compressratio"
67ro_props="$ro_props mounted"
68ro_props="$ro_props origin"
69# Uncomment these once the test ensures they can't be changed.
70#ro_props="$ro_props used"
71#ro_props="$ro_props available"
72#ro_props="$ro_props avail"
73#ro_props="$ro_props referenced"
74#ro_props="$ro_props refer"
75
76typeset snap_ro_props="volsize"
77snap_ro_props="$snap_ro_props recordsize"
78snap_ro_props="$snap_ro_props recsize"
79snap_ro_props="$snap_ro_props quota"
80snap_ro_props="$snap_ro_props reservation"
81snap_ro_props="$snap_ro_props reserv"
82snap_ro_props="$snap_ro_props mountpoint"
83snap_ro_props="$snap_ro_props sharenfs"
84snap_ro_props="$snap_ro_props checksum"
85snap_ro_props="$snap_ro_props compression"
86snap_ro_props="$snap_ro_props compress"
87snap_ro_props="$snap_ro_props atime"
88snap_ro_props="$snap_ro_props devices"
89snap_ro_props="$snap_ro_props exec"
90snap_ro_props="$snap_ro_props readonly"
91snap_ro_props="$snap_ro_props rdonly"
92snap_ro_props="$snap_ro_props setuid"
93
94$ZFS upgrade -v > /dev/null 2>&1
95if [[ $? -eq 0 ]]; then
96	snap_ro_props="$snap_ro_props version"
97fi
98
99function cleanup
100{
101	poolexists $TESTPOOL && log_must $ZPOOL history $TESTPOOL
102	datasetexists $TESTPOOL/$TESTVOL@$TESTSNAP && \
103		destroy_snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
104	datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \
105		destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP
106}
107
108log_assert "Verify that read-only properties are immutable."
109log_onexit cleanup
110
111# Create filesystem and volume's snapshot
112create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
113create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
114
115# Make sure any history logs have been synced.  They're asynchronously
116# pushed to the syncing context, and could influence the value of some
117# properties on $TESTPOOL, like 'used'.  Fetching it here forces the sync,
118# per spa_history.c:spa_history_get().
119log_must $ZPOOL history $TESTPOOL
120
121typeset -i i=0
122typeset -i j=0
123typeset cur_value=""
124typeset props=""
125
126while (( i < ${#dataset[@]} )); do
127	props=$ro_props
128
129	dst_type=$(get_prop type ${dataset[i]})
130	if [[ $dst_type == 'snapshot' ]]; then
131		props="$ro_props $snap_ro_props"
132	fi
133
134	for prop in $props; do
135		cur_value=$(get_prop $prop ${dataset[i]})
136
137		j=0
138		while (( j < ${#values[@]} )); do
139			#
140			# If the current property value is equal to values[j],
141			# just expect it failed. Otherwise, set it to dataset,
142			# expecting it failed and the property value is not
143			# equal to values[j].
144			#
145			if [[ $cur_value == ${values[j]} ]]; then
146				log_mustnot $ZFS set $prop=${values[j]} \
147					${dataset[i]}
148			else
149				set_n_check_prop ${values[j]} $prop \
150					${dataset[i]} false
151			fi
152			(( j += 1 ))
153		done
154	done
155	(( i += 1 ))
156done
157
158log_pass "Setting uneditable properties fail, as required."
159