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