7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / userquota / userquota_common.kshlib
blobc38308c4d18d2fcd6d99a7cb0b7d1c2f34a655c5
2 # CDDL HEADER START
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
19 # CDDL HEADER END
23 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24 # Use is subject to license terms.
28 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
31 . $STF_SUITE/include/libtest.shlib
32 . $STF_SUITE/tests/functional/userquota/userquota.cfg
35 # reset the userquota and groupquota and delete temporary files
37 function cleanup_quota
39         if datasetexists $QFS; then
40                 log_must zfs set userquota@$QUSER1=none $QFS
41                 log_must zfs set userquota@$QUSER2=none $QFS
42                 log_must zfs set groupquota@$QGROUP=none $QFS
43                 recovery_writable $QFS
44         fi
46         [[ -f $QFILE ]] && log_must rm -f $QFILE
47         [[ -f $OFILE ]] && log_must rm -f $OFILE
48         sync
50          return 0
54 # delete user and group that created during the test
56 function clean_user_group
58         for usr in $QUSER1 $QUSER2; do
59                 log_must del_user $usr
60         done
62         log_must del_group $QGROUP
64         return 0
68 #  make the $QFS's mountpoint writable for all users
70 function mkmount_writable
72         typeset fs=$1
73         typeset mntp=$(get_prop mountpoint $fs)
74         log_must chmod 0777 $mntp
78 # recovery the directory permission for $QFS
80 function recovery_writable
82         typeset fs=$1
83         typeset mntp=$(get_prop mountpoint $fs)
84         log_must chmod 0755 $mntp
88 # check the quota value of a specific FS
90 function check_quota
92         typeset fs=$2
93         typeset prop=$1
94         typeset expected=$3
95         typeset value=$(get_prop $prop $fs)
97         if (($value != $expected)); then
98                 return 1
99         fi
103 # zfs get prop, which return raw value not -p value.
105 function get_value # property dataset
107         typeset prop_val
108         typeset prop=$1
109         typeset dataset=$2
111         prop_val=$(zfs get -H -o value $prop $dataset 2>/dev/null)
112         if [[ $? -ne 0 ]]; then
113                 log_note "Unable to get $prop property for dataset " \
114                 "$dataset"
115                 return 1
116         fi
118         echo $prop_val
119         return 0