1f67950bNasf-Fan#
2f67950bNasf-Fan# CDDL HEADER START
3f67950bNasf-Fan#
4f67950bNasf-Fan# The contents of this file are subject to the terms of the
5f67950bNasf-Fan# Common Development and Distribution License (the "License").
6f67950bNasf-Fan# You may not use this file except in compliance with the License.
7f67950bNasf-Fan#
8f67950bNasf-Fan# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9f67950bNasf-Fan# or http://www.opensolaris.org/os/licensing.
10f67950bNasf-Fan# See the License for the specific language governing permissions
11f67950bNasf-Fan# and limitations under the License.
12f67950bNasf-Fan#
13f67950bNasf-Fan# When distributing Covered Code, include this CDDL HEADER in each
14f67950bNasf-Fan# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15f67950bNasf-Fan# If applicable, add the following below this CDDL HEADER, with the
16f67950bNasf-Fan# fields enclosed by brackets "[]" replaced with your own identifying
17f67950bNasf-Fan# information: Portions Copyright [yyyy] [name of copyright owner]
18f67950bNasf-Fan#
19f67950bNasf-Fan# CDDL HEADER END
20f67950bNasf-Fan#
21f67950bNasf-Fan
22f67950bNasf-Fan#
23f67950bNasf-Fan# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24f67950bNasf-Fan# Use is subject to license terms.
25f67950bNasf-Fan#
26f67950bNasf-Fan
27f67950bNasf-Fan#
28f67950bNasf-Fan# Copyright (c) 2017 by Fan Yong. All rights reserved.
29f67950bNasf-Fan#
30f67950bNasf-Fan
31f67950bNasf-Fan. $STF_SUITE/include/libtest.shlib
32f67950bNasf-Fan. $STF_SUITE/tests/functional/projectquota/projectquota.cfg
33f67950bNasf-Fan
34f67950bNasf-Fan#
35f67950bNasf-Fan# reset the projectquota and delete temporary files
36f67950bNasf-Fan#
37f67950bNasf-Fanfunction cleanup_projectquota
38f67950bNasf-Fan{
39f67950bNasf-Fan	if datasetexists $QFS; then
40f67950bNasf-Fan		typeset mntp=$(get_prop mountpoint $QFS)
41f67950bNasf-Fan
42f67950bNasf-Fan		log_must zfs set projectquota@$PRJID1=none $QFS
43f67950bNasf-Fan		log_must zfs set projectobjquota@$PRJID1=none $QFS
44f67950bNasf-Fan		log_must zfs set projectquota@$PRJID2=none $QFS
45f67950bNasf-Fan		log_must zfs set projectobjquota@$PRJID2=none $QFS
46f67950bNasf-Fan		log_must chmod 0755 $mntp
47f67950bNasf-Fan	fi
48f67950bNasf-Fan
49f67950bNasf-Fan	[[ -f $PRJFILE ]] && log_must rm -f $PRJFILE
50f67950bNasf-Fan	[[ -d $PRJDIR ]] && log_must rm -rf $PRJDIR
51f67950bNasf-Fan	[[ -d $PRJDIR1 ]] && log_must rm -rf $PRJDIR1
52f67950bNasf-Fan	[[ -d $PRJDIR2 ]] && log_must rm -rf $PRJDIR2
53f67950bNasf-Fan	[[ -d $PRJDIR3 ]] && log_must rm -rf $PRJDIR3
54f67950bNasf-Fan	sync
55f67950bNasf-Fan
56f67950bNasf-Fan	return 0
57f67950bNasf-Fan}
58f67950bNasf-Fan
59f67950bNasf-Fanfunction mkmount_writable
60f67950bNasf-Fan{
61f67950bNasf-Fan	typeset fs=$1
62f67950bNasf-Fan	typeset mntp=$(get_prop mountpoint $fs)
63f67950bNasf-Fan	log_must chmod 0777 $mntp
64f67950bNasf-Fan}
65f67950bNasf-Fan
66f67950bNasf-Fanfunction check_quota
67f67950bNasf-Fan{
68f67950bNasf-Fan	typeset fs=$2
69f67950bNasf-Fan	typeset prop=$1
70f67950bNasf-Fan	typeset expected=$3
71f67950bNasf-Fan	typeset value=$(get_prop $prop $fs)
72f67950bNasf-Fan
73f67950bNasf-Fan	if (($value != $expected)); then
74f67950bNasf-Fan		return 1
75f67950bNasf-Fan	fi
76f67950bNasf-Fan}
77f67950bNasf-Fan
78f67950bNasf-Fanfunction get_value
79f67950bNasf-Fan{
80f67950bNasf-Fan	typeset prop_val
81f67950bNasf-Fan	typeset prop=$1
82f67950bNasf-Fan	typeset dataset=$2
83f67950bNasf-Fan
84f67950bNasf-Fan	prop_val=$(zfs get -H -p -o value $prop $dataset 2>/dev/null)
85f67950bNasf-Fan	if [[ $? -ne 0 ]]; then
86f67950bNasf-Fan		log_note "Unable to get $prop property for dataset $dataset"
87f67950bNasf-Fan		return 1
88f67950bNasf-Fan	fi
89f67950bNasf-Fan
90f67950bNasf-Fan	echo $prop_val
91f67950bNasf-Fan}
92f67950bNasf-Fan
93f67950bNasf-Fanfunction project_obj_count
94f67950bNasf-Fan{
95f67950bNasf-Fan	typeset fs=$1
96f67950bNasf-Fan	typeset prj=$2
97f67950bNasf-Fan	typeset cnt=$(zfs projectspace -oname,objused $fs |
98f67950bNasf-Fan	    awk /$prj/'{print $2}')
99f67950bNasf-Fan	[[ "$cnt" == "-" ]] && cnt=0 || true
100f67950bNasf-Fan	echo $cnt
101f67950bNasf-Fan}
102