]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib
Add support for user/group dnode accounting & quota
[mirror_zfs.git] / tests / zfs-tests / tests / functional / userquota / userquota_common.kshlib
1 #
2 # CDDL HEADER START
3 #
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.
7 #
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.
12 #
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]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26
27 #
28 # Copyright (c) 2013 by Delphix. All rights reserved.
29 #
30
31 . $STF_SUITE/include/libtest.shlib
32 . $STF_SUITE/tests/functional/userquota/userquota.cfg
33
34 #
35 # reset the userquota and groupquota and delete temporary files
36 #
37 function cleanup_quota
38 {
39 if datasetexists $QFS; then
40 log_must $ZFS set userquota@$QUSER1=none $QFS
41 log_must $ZFS set userobjquota@$QUSER1=none $QFS
42 log_must $ZFS set userquota@$QUSER2=none $QFS
43 log_must $ZFS set userobjquota@$QUSER2=none $QFS
44 log_must $ZFS set groupquota@$QGROUP=none $QFS
45 log_must $ZFS set groupobjquota@$QGROUP=none $QFS
46 recovery_writable $QFS
47 fi
48
49 [[ -f $QFILE ]] && log_must $RM -f $QFILE
50 [[ -f $OFILE ]] && log_must $RM -f $OFILE
51 $SYNC
52
53 return 0
54 }
55
56 #
57 # delete user and group that created during the test
58 #
59 function clean_user_group
60 {
61 for usr in $QUSER1 $QUSER2; do
62 log_must del_user $usr
63 done
64
65 log_must del_group $QGROUP
66
67 return 0
68 }
69
70 #
71 # make the $QFS's mountpoint writable for all users
72 #
73 function mkmount_writable
74 {
75 typeset fs=$1
76 typeset mntp=$(get_prop mountpoint $fs)
77 log_must $CHMOD 0777 $mntp
78 }
79
80 #
81 # recovery the directory permission for $QFS
82 #
83 function recovery_writable
84 {
85 typeset fs=$1
86 typeset mntp=$(get_prop mountpoint $fs)
87 log_must $CHMOD 0755 $mntp
88 }
89
90 #
91 # check the quota value of a specific FS
92 #
93 function check_quota
94 {
95 typeset fs=$2
96 typeset prop=$1
97 typeset expected=$3
98 typeset value=$(get_prop $prop $fs)
99
100 if (($value != $expected)); then
101 return 1
102 fi
103 }
104
105 #
106 # zfs get prop, which return raw value not -p value.
107 #
108 function get_value # property dataset
109 {
110 typeset prop_val
111 typeset prop=$1
112 typeset dataset=$2
113
114 prop_val=$($ZFS get -H -o value $prop $dataset 2>/dev/null)
115 if [[ $? -ne 0 ]]; then
116 log_note "Unable to get $prop property for dataset " \
117 "$dataset"
118 return 1
119 fi
120
121 $ECHO $prop_val
122 return 0
123 }