xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/projectquota/projectquota_003_pos.ksh (revision b531f6d16eb39863e7bbc34773fb7ef7a282a0a2)
1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2017 by Fan Yong. All rights reserved.
30# Copyright 2019 Joyent, Inc.
31#
32
33. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib
34
35#
36# DESCRIPTION:
37#	Check the basic function project{obj}used
38#
39#
40# STRATEGY:
41#	1. Write data to fs with some project then check the project{obj}used
42#
43
44function cleanup
45{
46	cleanup_projectquota
47}
48
49log_onexit cleanup
50
51log_assert "Check the basic function of project{obj}used"
52
53sync_pool
54typeset project_used=$(get_value "projectused@$PRJID1" $QFS)
55typeset file_size='10m'
56
57if [[ $project_used -ge 8192 ]]; then
58	log_fail "FAIL: projectused is $project_used, should be less than 8k"
59fi
60
61mkmount_writable $QFS
62log_must user_run $PUSER mkdir $PRJDIR
63# log_must chattr +P -p $PRJID1 $PRJDIR
64log_must zfs project -s -p $PRJID1 $PRJDIR
65log_must user_run $PUSER mkfile $file_size $PRJDIR/qf
66sync_pool
67project_used=$(get_value "projectused@$PRJID1" $QFS)
68# get_value() reads the exact byte value which is slightly more than 10m
69if [[ "$(($project_used/1024/1024))m" != "$file_size" ]]; then
70	log_note "project $PRJID1 used is $project_used"
71	log_fail "projectused for project $PRJID1 expected to be $file_size, " \
72	    "not $project_used"
73fi
74
75log_must rm -rf $PRJDIR
76typeset project_obj_used=$(get_value "projectobjused@$PRJID2" $QFS)
77typeset file_count=100
78
79if [[ $project_obj_used -ge 2 ]]; then
80	log_fail "FAIL: projectobjused is $project_obj_used, should be " \
81	"less than 2"
82fi
83
84log_must zfs set xattr=on $QFS
85log_must user_run $PUSER mkdir $PRJDIR
86# log_must chattr +P -p $PRJID2 $PRJDIR
87log_must zfs project -s -p $PRJID2 $PRJDIR
88# $PRJDIR has already used one object with the $PRJID2
89log_must user_run $PUSER mkfiles $PRJDIR/qf_ $((file_count - 1))
90sync_pool
91project_obj_used=$(get_value "projectobjused@$PRJID2" $QFS)
92exp_count=$((file_count + 1))
93if [[ $project_obj_used -gt $exp_count ]]; then
94	log_note "project $PRJID2 used is $project_obj_used"
95	log_fail "projectobjused for project $PRJID2 expected to be less than" \
96	    "$exp_count, not $project_obj_used"
97fi
98
99log_pass "Check the basic function of project{obj}used pass as expected"
100