]> granicus.if.org Git - zfs/blob - tests/zfs-tests/tests/functional/projectquota/projectspace_003_pos.ksh
Project Quota on ZFS
[zfs] / tests / zfs-tests / tests / functional / projectquota / projectspace_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 project used object accounting in zfs projectspace
37 #
38 #
39 # STRATEGY:
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
44 #
45
46 function cleanup
47 {
48         if datasetexists $snapfs; then
49                 log_must zfs destroy $snapfs
50         fi
51
52         log_must cleanup_projectquota
53 }
54
55 if ! lsattr -pd > /dev/null 2>&1; then
56         log_unsupported "Current e2fsprogs does not support set/show project ID"
57 fi
58
59 log_onexit cleanup
60
61 log_assert "Check the zfs projectspace object used"
62
63 mkmount_writable $QFS
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
69
70 ((prj_cnt1 = RANDOM % 100 + 2))
71 ((prj_cnt2 = RANDOM % 100 + 2))
72
73 log_must user_run $PUSER mkfiles $PRJDIR1/qf $((prj_cnt1 - 1))
74 log_must user_run $PUSER mkfiles $PRJDIR2/qf $((prj_cnt2 - 1))
75 sync_pool
76
77 typeset snapfs=$QFS@snap
78
79 log_must zfs snapshot $snapfs
80
81 log_must eval "zfs projectspace $QFS >/dev/null 2>&1"
82 log_must eval "zfs projectspace $snapfs >/dev/null 2>&1"
83
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"
92 done
93
94 log_note "change the project of files"
95 log_must chattr -p $PRJID2 $PRJDIR1/qf*
96 sync_pool
97
98 prjused=$(project_obj_count $QFS $PRJID1)
99 [[ $prjused -eq 1 ]] ||
100         log_fail "expected 1 for project $PRJID1, got $prjused"
101
102 prjused=$(project_obj_count $snapfs $PRJID1)
103 [[ $prjused -eq $prj_cnt1 ]] ||
104         log_fail "expected $prj_cnt1 for $PRJID1 in snapfs, got $prjused"
105
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"
109
110 log_note "file removal"
111 log_must rm -rf $PRJDIR1
112 sync_pool
113
114 prjused=$(project_obj_count $QFS $PRJID1)
115 [[ $prjused -eq 0 ]] || log_fail "expected 0 for $PRJID1, got $prjused"
116
117 cleanup
118 log_pass "Check the zfs projectspace object used"