]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_001_pos.ksh
Merge llvm-project main llvmorg-14-init-10223-g401b76fdf2b3
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / tests / zfs-tests / tests / functional / cli_root / zfs_set / canmount_001_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 . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
34
35 #
36 # DESCRIPTION:
37 # Setting valid canmount to filesystem, it is successful.
38 # Whatever is set to volume or snapshot, it is failed.
39 # 'zfs set canmount=on|off <fs>'
40 #
41 # STRATEGY:
42 # 1. Setup a pool and create fs, volume, snapshot clone within it.
43 # 2. Loop all the valid mountpoint value.
44 # 3. Check the return value.
45 #
46
47 verify_runnable "both"
48
49 set -A dataset_pos \
50         "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE"
51
52 if is_global_zone ; then
53         set -A dataset_neg \
54                 "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \
55                 "$TESTPOOL/$TESTVOL@$TESTSNAP"  "$TESTPOOL/$TESTCLONE1"
56 else
57         set -A dataset_neg \
58                 "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP"
59 fi
60
61
62 set -A values "on" "off"
63
64 function cleanup
65 {
66         snapexists $TESTPOOL/$TESTFS@$TESTSNAP && \
67                 destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP -R
68
69         snapexists $TESTPOOL/$TESTVOL@$TESTSNAP && \
70                 destroy_dataset $TESTPOOL/$TESTVOL@$TESTSNAP -R
71
72         [[ -n $old_ctr_canmount ]] && \
73                 log_must zfs set canmount=$old_ctr_canmount $TESTPOOL/$TESTCTR
74         [[ -n $old_fs_canmount ]] && \
75                 log_must zfs set canmount=$old_fs_canmount $TESTPOOL/$TESTFS
76
77         zfs unmount -a > /dev/null 2>&1
78         log_must zfs mount -a
79 }
80
81 log_assert "Setting a valid property of canmount to file system, it must be successful."
82 log_onexit cleanup
83
84 typeset old_fs_canmount="" old_ctr_canmount=""
85
86 old_fs_canmount=$(get_prop canmount $TESTPOOL/$TESTFS)
87 [[ $? != 0 ]] && \
88         log_fail "Get the $TESTPOOL/$TESTFS canmount error."
89 old_ctr_canmount=$(get_prop canmount $TESTPOOL/$TESTCTR)
90 [[ $? != 0 ]] && \
91         log_fail "Get the $TESTPOOL/$TESTCTR canmount error."
92
93 log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP
94 log_must zfs snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
95 log_must zfs clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
96 log_must zfs clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
97
98 for dataset in "${dataset_pos[@]}" ; do
99         for value in "${values[@]}" ; do
100                 set_n_check_prop "$value" "canmount" "$dataset"
101                 if [[ $value == "off" ]]; then
102                         log_mustnot ismounted $dataset
103                         log_mustnot zfs mount $dataset
104                         log_mustnot ismounted $dataset
105                 else
106                         if ! ismounted $dataset ; then
107                                 log_must zfs mount $dataset
108                         fi
109                         log_must ismounted $dataset
110                 fi
111         done
112 done
113
114 for dataset in "${dataset_neg[@]}" ; do
115         for value in "${values[@]}" ; do
116                 set_n_check_prop "$value" "canmount" \
117                         "$dataset" "false"
118                 log_mustnot ismounted $dataset
119         done
120 done
121
122 log_pass "Setting canmount to filesystem pass."