]>
Commit | Line | Data |
---|---|---|
6bb24f4d BB |
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 | ||
c1d9abf9 JWK |
28 | # |
29 | # Copyright (c) 2016 by Delphix. All rights reserved. | |
30 | # | |
31 | ||
6bb24f4d BB |
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 | ||
54 | function cleanup | |
55 | { | |
56 | if ! ismounted $TESTPOOL/$TESTFS; then | |
c1d9abf9 | 57 | log_must zfs mount $TESTPOOL/$TESTFS |
6bb24f4d BB |
58 | fi |
59 | } | |
60 | ||
61 | log_assert "Verify '-o' will set filesystem property temporarily, " \ | |
62 | "without affecting the property that is stored on disk." | |
63 | log_onexit cleanup | |
64 | ||
65 | set -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 | # | |
73 | function 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" | |
95401cb6 BB |
79 | if is_linux; then |
80 | set -A values "noatime" "atime" \ | |
81 | "nodev" "dev" \ | |
82 | "noexec" "exec" \ | |
83 | "rw" "ro" \ | |
84 | "nosuid" "suid" | |
85 | else | |
86 | set -A values "noatime" "atime" \ | |
87 | "nodevices" "devices" \ | |
88 | "noexec" "exec" \ | |
89 | "rw" "ro" \ | |
90 | "nosetuid" "setuid" | |
91 | fi | |
6bb24f4d BB |
92 | |
93 | typeset -i i=0 | |
94 | while (( i < ${#properties[@]} )); do | |
95 | if [[ $prop == ${properties[$i]} ]]; then | |
96 | break | |
97 | fi | |
98 | ||
99 | (( i += 1 )) | |
100 | done | |
101 | if (( i >= ${#properties[@]} )); then | |
102 | log_fail "Incorrect option: $prop" | |
103 | fi | |
104 | ||
105 | typeset val | |
106 | typeset -i ind=0 | |
107 | val=$(get_prop $prop $fs) || log_fail "get_prop $prop $fs" | |
108 | if [[ $val == "on" ]]; then | |
109 | (( ind = i * 2 )) | |
110 | else | |
111 | (( ind = i * 2 + 1 )) | |
112 | fi | |
113 | ||
c1d9abf9 | 114 | echo ${values[$ind]} |
6bb24f4d BB |
115 | } |
116 | ||
117 | fs=$TESTPOOL/$TESTFS | |
118 | cleanup | |
119 | ||
120 | for property in ${properties[@]}; do | |
121 | orig_val=$(get_prop $property $fs) | |
122 | (($? != 0)) && log_fail "get_prop $property $fs" | |
123 | ||
124 | # Set filesystem property temporarily | |
125 | reverse_opt=$(get_reverse_option $fs $property) | |
c1d9abf9 | 126 | log_must zfs mount -o remount,$reverse_opt $fs |
6bb24f4d BB |
127 | |
128 | cur_val=$(get_prop $property $fs) | |
129 | (($? != 0)) && log_fail "get_prop $property $fs" | |
130 | ||
131 | # In LZ, a user with all zone privileges can never with "devices" | |
132 | if ! is_global_zone && [[ $property == devices ]] ; then | |
133 | if [[ $cur_val != off || $orig_val != off ]]; then | |
134 | log_fail "'devices' property shouldn't " \ | |
135 | "be enabled in LZ" | |
136 | fi | |
137 | elif [[ $orig_val == $cur_val ]]; then | |
138 | log_fail "zfs mount -o remount,$reverse_opt " \ | |
139 | "doesn't change property." | |
140 | fi | |
141 | ||
142 | # unmount & mount will revert property to the original value | |
c1d9abf9 JWK |
143 | log_must zfs unmount $fs |
144 | log_must zfs mount $fs | |
6bb24f4d BB |
145 | |
146 | cur_val=$(get_prop $property $fs) | |
147 | (($? != 0)) && log_fail "get_prop $property $fs" | |
148 | if [[ $orig_val != $cur_val ]]; then | |
149 | log_fail "zfs mount -o remount,$reverse_opt " \ | |
150 | "change the property that is stored on disks" | |
151 | fi | |
152 | done | |
153 | ||
154 | log_pass "Verify '-o' set filesystem property temporarily passed." |