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