]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_003_pos.ksh
libarchive: import changes from upstream
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / tests / zfs-tests / tests / functional / cli_root / zfs_set / mountpoint_003_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 2009 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/include/libtest.shlib
33
34 #
35 # DESCRIPTION:
36 #       Verify FSType-specific option works well with legacy mount.
37 #
38 # STRATEGY:
39 #       1. Set up FSType-specific options and expected keywords array.
40 #       2. Create a test ZFS file system and set mountpoint=legacy.
41 #       3. Mount ZFS test filesystem with specific options.
42 #       4. Verify the filesystem was mounted with specific option.
43 #       5. Loop check all the options.
44 #
45
46 verify_runnable "both"
47
48 function cleanup
49 {
50         ismounted $tmpmnt && log_must umount $tmpmnt
51         [[ -d $tmpmnt ]] && log_must rm -rf $tmpmnt
52         [[ -n $oldmpt ]] && log_must zfs set mountpoint=$oldmpt $testfs
53         ! ismounted $oldmpt && log_must zfs mount $testfs
54 }
55
56 log_assert "With legacy mount, FSType-specific option works well."
57 log_onexit cleanup
58
59 #
60 #  /mnt on pool/fs read/write/setuid/devices/noexec/xattr/atime/dev=2d9009e
61 #
62 #       FSType-                         FSType-
63 #       specific        Keyword         specific        Keyword
64 #       option                          option
65 #
66 if is_linux; then
67         set -A args \
68         "nodev"         "dev"   \
69         "noexec"        "exec"  \
70         "ro"            "rw"    \
71         "nosuid"        "suid"  \
72         "xattr"         "noxattr"       \
73         "atime"         "noatime"
74
75         # Only older kernels support non-blocking mandatory locks
76         if [[ $(linux_version) -lt $(linux_version "4.4") ]]; then
77                 args+=("mand" "nomand")
78         fi
79 elif is_freebsd; then
80         # 'xattr' and 'devices' are not supported on FreeBSD
81         # Perhaps more options need to be added.
82         set -A args \
83         "noexec"        "exec"  \
84         "ro"            "rw"    \
85         "nosuid"        "suid"  \
86         "atime"         "noatime"
87 else
88         set -A args \
89         "devices"       "/devices/"     "nodevices"     "/nodevices/"   \
90         "exec"          "/exec/"        "noexec"        "/noexec/"      \
91         "nbmand"        "/nbmand/"      "nonbmand"      "/nonbmand/"    \
92         "ro"            "read only"     "rw"            "read/write"    \
93         "setuid"        "/setuid/"      "nosetuid"      "/nosetuid/"    \
94         "xattr"         "/xattr/"       "noxattr"       "/noxattr/"     \
95         "atime"         "/atime/"       "noatime"       "/noatime/"
96 fi
97
98 tmpmnt=/tmpmnt.$$
99 [[ -d $tmpmnt ]] && rm -rf $tmpmnt
100 testfs=$TESTPOOL/$TESTFS
101 log_must mkdir $tmpmnt
102 oldmpt=$(get_prop mountpoint $testfs)
103 log_must zfs set mountpoint=legacy $testfs
104
105 typeset i=0
106 while ((i < ${#args[@]})); do
107         if is_linux || is_freebsd; then
108                 log_must mount -t zfs -o ${args[$i]} $testfs $tmpmnt
109                 
110                 msg=$(mount | grep "$tmpmnt ")
111
112                 echo $msg | grep "${args[((i))]}" > /dev/null 2>&1
113                 if (($? != 0)) ; then
114                         echo $msg | grep "${args[((i-1))]}" > /dev/null 2>&1
115                         if (($? == 0)) ; then
116                                 log_fail "Expected option: ${args[((i))]} \n" \
117                                          "Real option: $msg"
118                         fi
119                 fi
120
121                 log_must umount $tmpmnt
122                 ((i += 1))
123         else
124                 log_must mount -F zfs -o ${args[$i]} $testfs $tmpmnt
125
126                 msg=$(mount | grep "^$tmpmnt ")
127
128                 # In LZ, a user with all zone privileges can never "devices"
129                 if ! is_global_zone && [[ ${args[$i]} == devices ]] ; then
130                         args[((i+1))]="/nodevices/"
131                 fi
132
133                 echo $msg | grep "${args[((i+1))]}" > /dev/null 2>&1
134                 if (($? != 0)) ; then
135                         log_fail "Expected option: ${args[((i+1))]} \n" \
136                                  "Real option: $msg"
137                 fi
138
139
140                 log_must umount $tmpmnt
141                 ((i += 2))
142         fi
143 done
144
145 log_pass "With legacy mount, FSType-specific option works well passed."