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.
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.
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]
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2017 by Fan Yong. All rights reserved.
32 . $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib
36 # Check the project used object accounting in zfs projectspace
40 # 1. create a bunch of files by specific project
41 # 2. use zfs projectspace to check the used objects
42 # 3. change the project ID of test files and verify object count
43 # 4. delete files and verify object count
48 if datasetexists $snapfs; then
49 log_must zfs destroy $snapfs
52 log_must cleanup_projectquota
55 if ! lsattr -pd > /dev/null 2>&1; then
56 log_unsupported "Current e2fsprogs does not support set/show project ID"
61 log_assert "Check the zfs projectspace object used"
64 log_must zfs set xattr=sa $QFS
65 log_must user_run $PUSER mkdir $PRJDIR1
66 log_must user_run $PUSER mkdir $PRJDIR2
67 log_must chattr +P -p $PRJID1 $PRJDIR1
68 log_must chattr +P -p $PRJID2 $PRJDIR2
70 ((prj_cnt1 = RANDOM % 100 + 2))
71 ((prj_cnt2 = RANDOM % 100 + 2))
73 log_must user_run $PUSER mkfiles $PRJDIR1/qf $((prj_cnt1 - 1))
74 log_must user_run $PUSER mkfiles $PRJDIR2/qf $((prj_cnt2 - 1))
77 typeset snapfs=$QFS@snap
79 log_must zfs snapshot $snapfs
81 log_must eval "zfs projectspace $QFS >/dev/null 2>&1"
82 log_must eval "zfs projectspace $snapfs >/dev/null 2>&1"
84 for fs in "$QFS" "$snapfs"; do
85 log_note "check the project used objects in zfs projectspace $fs"
86 prjused=$(project_obj_count $fs $PRJID1)
87 [[ $prjused -eq $prj_cnt1 ]] ||
88 log_fail "($PRJID1) expected $prj_cnt1, got $prjused"
89 prjused=$(project_obj_count $fs $PRJID2)
90 [[ $prjused -eq $prj_cnt2 ]] ||
91 log_fail "($PRJID2) expected $prj_cnt2, got $prjused"
94 log_note "change the project of files"
95 log_must chattr -p $PRJID2 $PRJDIR1/qf*
98 prjused=$(project_obj_count $QFS $PRJID1)
99 [[ $prjused -eq 1 ]] ||
100 log_fail "expected 1 for project $PRJID1, got $prjused"
102 prjused=$(project_obj_count $snapfs $PRJID1)
103 [[ $prjused -eq $prj_cnt1 ]] ||
104 log_fail "expected $prj_cnt1 for $PRJID1 in snapfs, got $prjused"
106 prjused=$(project_obj_count $QFS $PRJID2)
107 [[ $prjused -eq $((prj_cnt1 + prj_cnt2 - 1)) ]] ||
108 log_fail "($PRJID2) expected $((prj_cnt1 + prj_cnt2 - 1)), got $prjused"
110 log_note "file removal"
111 log_must rm -rf $PRJDIR1
114 prjused=$(project_obj_count $QFS $PRJID1)
115 [[ $prjused -eq 0 ]] || log_fail "expected 0 for $PRJID1, got $prjused"
118 log_pass "Check the zfs projectspace object used"