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/tests/cli_root/zfs_mount/zfs_mount.kshlib 28 29################################################################################# 30# 31# __stc_assertion_start 32# 33# ID: zfs_mount_007_pos 34# 35# DESCRIPTION: 36# The following options can be set on a temporary basis using the -o option 37# without affecting the on-disk property. The original on-disk value will be 38# restored when the file system is unmounted and mounted. 39# 40# PROPERTY MOUNT OPTION 41# atime atime/noatime 42# exec exec/noexec 43# readonly ro/rw 44# setuid setuid/nosetuid 45# 46# STRATEGY: 47# 1. Create filesystem and get origianl property value. 48# 2. Using 'zfs mount -o' to set filesystem property. 49# 3. Verify the property was set temporarily. 50# 4. Verify it will not affect the property that is stored on disk. 51# 52# TESTABILITY: explicit 53# 54# TEST_AUTOMATION_LEVEL: automated 55# 56# CODING_STATUS: COMPLETED (2006-08-02) 57# 58# __stc_assertion_end 59# 60################################################################################ 61 62function cleanup 63{ 64 if ! ismounted $TESTPOOL/$TESTFS; then 65 log_must $ZFS mount $TESTPOOL/$TESTFS 66 fi 67} 68 69log_assert "Verify '-o' will set filesystem property temporarily, " \ 70 "without affecting the property that is stored on disk." 71log_onexit cleanup 72 73set -A properties "atime" "exec" "readonly" "setuid" 74 75# 76# Get the specified filesystem property reverse mount option. 77# 78# $1 filesystem 79# $2 property 80# 81function get_reverse_option 82{ 83 typeset fs=$1 84 typeset prop=$2 85 86 # Define property value: "reverse if value=on" "reverse if value=off" 87 set -A values "noatime" "atime" \ 88 "noexec" "exec" \ 89 "rw" "ro" \ 90 "nosetuid" "setuid" 91 92 typeset -i i=0 93 while (( i < ${#properties[@]} )); do 94 if [[ $prop == ${properties[$i]} ]]; then 95 break 96 fi 97 98 (( i += 1 )) 99 done 100 if (( i >= ${#properties[@]} )); then 101 log_fail "Incorrect option: $prop" 102 fi 103 104 typeset val 105 typeset -i ind=0 106 val=$(get_prop $prop $fs) || log_fail "get_prop $prop $fs" 107 if [[ $val == "on" ]]; then 108 (( ind = i * 2 )) 109 else 110 (( ind = i * 2 + 1 )) 111 fi 112 113 $ECHO ${values[$ind]} 114} 115 116fs=$TESTPOOL/$TESTFS 117cleanup 118 119for property in ${properties[@]}; do 120 orig_val=$(get_prop $property $fs) 121 (($? != 0)) && log_fail "get_prop $property $fs" 122 123 # Set filesystem property temporarily 124 reverse_opt=$(get_reverse_option $fs $property) 125 log_must $ZFS mount -o update,$reverse_opt $fs 126 127 cur_val=$(get_prop $property $fs) 128 (($? != 0)) && log_fail "get_prop $property $fs" 129 130 if [[ $orig_val == $cur_val ]]; then 131 log_fail "zfs mount -o update,$reverse_opt " \ 132 "doesn't change property." 133 fi 134 135 # unmount & mount will revert property to the original value 136 log_must $ZFS unmount $fs 137 log_must $ZFS mount $fs 138 139 cur_val=$(get_prop $property $fs) 140 (($? != 0)) && log_fail "get_prop $property $fs" 141 if [[ $orig_val != $cur_val ]]; then 142 log_fail "zfs mount -o update,$reverse_opt " \ 143 "change the property that is stored on disks" 144 fi 145done 146 147log_pass "Verify '-o' set filesystem property temporarily passed." 148