]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos.ksh
Update ZTS to work on FreeBSD
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zfs_mount / zfs_mount_007_pos.ksh
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 original 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
57 log_must zfs mount $TESTPOOL/$TESTFS
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"
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
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
114 echo ${values[$ind]}
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)
126 log_must zfs unmount $fs
127 log_must zfs mount -o $reverse_opt $fs
128
129 cur_val=$(get_prop $property $fs)
130 (($? != 0)) && log_fail "get_prop $property $fs"
131
132 # In LZ, a user with all zone privileges can never with "devices"
133 if ! is_global_zone && [[ $property == devices ]] ; then
134 if [[ $cur_val != off || $orig_val != off ]]; then
135 log_fail "'devices' property shouldn't " \
136 "be enabled in LZ"
137 fi
138 elif [[ $orig_val == $cur_val ]]; then
139 log_fail "zfs mount -o $reverse_opt " \
140 "doesn't change property."
141 fi
142
143 # unmount & mount will revert property to the original value
144 log_must zfs unmount $fs
145 log_must zfs mount $fs
146
147 cur_val=$(get_prop $property $fs)
148 (($? != 0)) && log_fail "get_prop $property $fs"
149 if [[ $orig_val != $cur_val ]]; then
150 log_fail "zfs mount -o $reverse_opt " \
151 "change the property that is stored on disks"
152 fi
153 done
154
155 log_pass "Verify '-o' set filesystem property temporarily passed."