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 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27# Copyright (c) 2016 by Delphix. All rights reserved. 28# 29 30. $STF_SUITE/include/libtest.shlib 31. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib 32 33# 34# DESCRIPTION: 35# Verify that read-only properties are immutable. 36# Note that we can only check properties that have no possibility of 37# changing while we are running (which excludes e.g. "available"). 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 46verify_runnable "both" 47 48set -A values filesystem volume snapshot -3 0 1 50K 10G 80G \ 49 2005/06/17 30K 20x yes no \ 50 on off default pool/fs@snap $TESTDIR 51set -A dataset $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ 52 $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS@$TESTSNAP \ 53 $TESTPOOL/$TESTVOL@$TESTSNAP 54typeset ro_props="type used creation referenced refer compressratio \ 55 mounted origin" 56typeset snap_ro_props="volsize recordsize recsize quota reservation reserv mountpoint \ 57 sharenfs checksum compression compress atime devices exec readonly rdonly \ 58 setuid zoned" 59 60zfs upgrade -v > /dev/null 2>&1 61if [[ $? -eq 0 ]]; then 62 snap_ro_props="$snap_ro_props version" 63fi 64 65function cleanup 66{ 67 datasetexists $TESTPOOL/$TESTVOL@$TESTSNAP && \ 68 destroy_snapshot $TESTPOOL/$TESTVOL@$TESTSNAP 69 datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \ 70 destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP 71} 72 73log_assert "Verify that read-only properties are immutable." 74log_onexit cleanup 75 76# Create filesystem and volume's snapshot 77create_snapshot $TESTPOOL/$TESTFS $TESTSNAP 78create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP 79 80typeset -i i=0 81typeset -i j=0 82typeset cur_value="" 83typeset props="" 84 85while (( i < ${#dataset[@]} )); do 86 props=$ro_props 87 88 dst_type=$(get_prop type ${dataset[i]}) 89 if [[ $dst_type == 'snapshot' ]]; then 90 props="$ro_props $snap_ro_props" 91 fi 92 93 for prop in $props; do 94 cur_value=$(get_prop $prop ${dataset[i]}) 95 96 j=0 97 while (( j < ${#values[@]} )); do 98 # 99 # If the current property value is equal to values[j], 100 # just expect it failed. Otherwise, set it to dataset, 101 # expecting it failed and the property value is not 102 # equal to values[j]. 103 # 104 if [[ $cur_value == ${values[j]} ]]; then 105 log_mustnot zfs set $prop=${values[j]} \ 106 ${dataset[i]} 107 else 108 set_n_check_prop ${values[j]} $prop \ 109 ${dataset[i]} false 110 fi 111 (( j += 1 )) 112 done 113 done 114 (( i += 1 )) 115done 116 117log_pass "Setting uneditable properties should failed. It passed." 118