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