]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/projectquota/projectquota_003_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / projectquota / projectquota_003_pos.ksh
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 #
31
32 . $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib
33
34 #
35 # DESCRIPTION:
36 #       Check the basic function project{obj}used
37 #
38 #
39 # STRATEGY:
40 #       1. Write data to fs with some project then check the project{obj}used
41 #
42
43 function cleanup
44 {
45         cleanup_projectquota
46 }
47
48 if ! lsattr -pd > /dev/null 2>&1; then
49         log_unsupported "Current e2fsprogs does not support set/show project ID"
50 fi
51
52 log_onexit cleanup
53
54 log_assert "Check the basic function of project{obj}used"
55
56 sync_pool
57 typeset project_used=$(get_value "projectused@$PRJID1" $QFS)
58 typeset file_size='10m'
59
60 if [[ $project_used != 0 ]]; then
61         log_fail "FAIL: projectused is $project_used, should be 0"
62 fi
63
64 mkmount_writable $QFS
65 log_must user_run $PUSER mkdir $PRJDIR
66 log_must chattr +P -p $PRJID1 $PRJDIR
67 log_must user_run $PUSER mkfile $file_size $PRJDIR/qf
68 sync_pool
69 project_used=$(get_value "projectused@$PRJID1" $QFS)
70 # get_value() reads the exact byte value which is slightly more than 10m
71 if [[ "$(($project_used/1024/1024))m" != "$file_size" ]]; then
72         log_note "project $PRJID1 used is $project_used"
73         log_fail "projectused for project $PRJID1 expected to be $file_size, " \
74             "not $project_used"
75 fi
76
77 log_must rm -rf $PRJDIR
78 typeset project_obj_used=$(get_value "projectobjused@$PRJID2" $QFS)
79 typeset file_count=100
80
81 if [[ $project_obj_used != 0 ]]; then
82         log_fail "FAIL: projectobjused is $project_obj_used, should be 0"
83 fi
84
85 log_must zfs set xattr=sa $QFS
86 log_must user_run $PUSER mkdir $PRJDIR
87 log_must chattr +P -p $PRJID2 $PRJDIR
88 # $PRJDIR has already used one object with the $PRJID2
89 log_must user_run $PUSER mkfiles $PRJDIR/qf_ $((file_count - 1))
90 sync_pool
91 project_obj_used=$(get_value "projectobjused@$PRJID2" $QFS)
92 if [[ $project_obj_used != $file_count ]]; then
93         log_note "project $PRJID2 used is $project_obj_used"
94         log_fail "projectobjused for project $PRJID2 expected to be " \
95             "$file_count, not $project_obj_used"
96 fi
97
98 log_pass "Check the basic function of project{obj}used pass as expect"