xref: /titanic_51/usr/src/test/zfs-tests/tests/functional/userquota/userquota_common.kshlib (revision f38cb554a534c6df738be3f4d23327e69888e634)
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#
37function cleanup_quota
38{
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
45
46	[[ -f $QFILE ]] && log_must $RM -f $QFILE
47	[[ -f $OFILE ]] && log_must $RM -f $OFILE
48	$SYNC
49
50	 return 0
51}
52
53#
54# delete user and group that created during the test
55#
56function clean_user_group
57{
58	for usr in $QUSER1 $QUSER2; do
59		log_must del_user $usr
60	done
61
62	log_must del_group $QGROUP
63
64	return 0
65}
66
67#
68#  make the $QFS's mountpoint writable for all users
69#
70function mkmount_writable
71{
72	typeset fs=$1
73	typeset mntp=$(get_prop mountpoint $fs)
74	log_must $CHMOD 0777 $mntp
75}
76
77#
78# recovery the directory permission for $QFS
79#
80function recovery_writable
81{
82	typeset fs=$1
83	typeset mntp=$(get_prop mountpoint $fs)
84	log_must $CHMOD 0755 $mntp
85}
86
87#
88# check the quota value of a specific FS
89#
90function check_quota
91{
92	typeset fs=$2
93	typeset prop=$1
94	typeset expected=$3
95	typeset value=$(get_prop $prop $fs)
96
97	if (($value != $expected)); then
98		return 1
99	fi
100}
101
102#
103# zfs get prop, which return raw value not -p value.
104#
105function get_value # property dataset
106{
107        typeset prop_val
108        typeset prop=$1
109        typeset dataset=$2
110
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
117
118        $ECHO $prop_val
119        return 0
120}
121