]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_set / canmount_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) 2012, 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 # While canmount=noauto and  the dataset is mounted,
38 # zfs must not attempt to unmount it.
39 #
40 # STRATEGY:
41 # 1. Setup a pool and create fs, volume, snapshot clone within it.
42 # 2. Set canmount=noauto for each dataset and check the return value
43 #    and check if it still can not be unmounted when the dataset is mounted
44 #
45
46 verify_runnable "both"
47
48 set -A dataset_pos "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCLONE"
49
50 function cleanup
51 {
52         i=0
53         cd $pwd
54         while (( i < ${#dataset_pos[*]} )); do
55                 ds=${dataset_pos[i]}
56                 if datasetexists $ds; then
57                         log_must zfs set mountpoint=${old_mnt[i]} $ds
58                         log_must zfs set canmount=${old_canmount[i]} $ds
59                 fi
60                 (( i = i + 1 ))
61         done
62
63         ds=$TESTPOOL/$TESTCLONE
64         if datasetexists $ds; then
65                 mntp=$(get_prop mountpoint $ds)
66                 log_must zfs destroy $ds
67                 if [[ -d $mntp ]]; then
68                         log_must rm -fr $mntp
69                 fi
70         fi
71
72         if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then
73                 log_must zfs destroy -R $TESTPOOL/$TESTFS@$TESTSNAP
74         fi
75
76         zfs unmount -a > /dev/null 2>&1
77         log_must zfs mount -a
78 }
79
80 log_assert "While canmount=noauto and  the dataset is mounted,"\
81                 " zfs must not attempt to unmount it"
82 log_onexit cleanup
83
84 set -A old_mnt
85 set -A old_canmount
86 typeset ds
87 typeset pwd=$PWD
88
89 log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP
90 log_must zfs clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
91
92 typeset -i i=0
93 while (( i < ${#dataset_pos[*]} )); do
94         ds=${dataset_pos[i]}
95         old_mnt[i]=$(get_prop mountpoint $ds)
96         old_canmount[i]=$(get_prop canmount $ds)
97         (( i = i + 1 ))
98 done
99
100 i=0
101 while (( i < ${#dataset_pos[*]} )) ; do
102         dataset=${dataset_pos[i]}
103         if  ismounted $dataset; then
104                 log_must cd ${old_mnt[i]}
105                 set_n_check_prop "noauto" "canmount" "$dataset"
106                 log_must mounted $dataset
107         fi
108         (( i = i + 1 ))
109 done
110
111 log_pass "Setting canmount=noauto to filesystem while dataset busy pass."