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