xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/projectquota/projectquota_common.kshlib (revision 09fbbb7d1b5a956a9b81304070dcff318a4a158e)
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) 2017 by Fan Yong. All rights reserved.
29#
30
31. $STF_SUITE/include/libtest.shlib
32. $STF_SUITE/tests/functional/projectquota/projectquota.cfg
33
34#
35# reset the projectquota and delete temporary files
36#
37function cleanup_projectquota
38{
39	if datasetexists $QFS; then
40		typeset mntp=$(get_prop mountpoint $QFS)
41
42		log_must zfs set projectquota@$PRJID1=none $QFS
43		log_must zfs set projectobjquota@$PRJID1=none $QFS
44		log_must zfs set projectquota@$PRJID2=none $QFS
45		log_must zfs set projectobjquota@$PRJID2=none $QFS
46		log_must chmod 0755 $mntp
47	fi
48
49	[[ -f $PRJFILE ]] && log_must rm -f $PRJFILE
50	[[ -d $PRJDIR ]] && log_must rm -rf $PRJDIR
51	[[ -d $PRJDIR1 ]] && log_must rm -rf $PRJDIR1
52	[[ -d $PRJDIR2 ]] && log_must rm -rf $PRJDIR2
53	[[ -d $PRJDIR3 ]] && log_must rm -rf $PRJDIR3
54	sync_all_pools
55
56	return 0
57}
58
59function mkmount_writable
60{
61	typeset fs=$1
62	typeset mntp=$(get_prop mountpoint $fs)
63	log_must chmod 0777 $mntp
64}
65
66function check_quota
67{
68	typeset fs=$2
69	typeset prop=$1
70	typeset expected=$3
71	typeset value=$(get_prop $prop $fs)
72
73	if (($value != $expected)); then
74		return 1
75	fi
76}
77
78function get_value
79{
80	typeset prop_val
81	typeset prop=$1
82	typeset dataset=$2
83
84	prop_val=$(zfs get -H -p -o value $prop $dataset 2>/dev/null)
85	if [[ $? -ne 0 ]]; then
86		log_note "Unable to get $prop property for dataset $dataset"
87		return 1
88	fi
89
90	echo $prop_val
91}
92
93function project_obj_count
94{
95	typeset fs=$1
96	typeset prj=$2
97	typeset cnt=$(zfs projectspace -oname,objused $fs |
98	    awk /$prj/'{print $2}')
99	[[ "$cnt" == "-" ]] && cnt=0 || true
100	echo $cnt
101}
102