]>
git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/userquota/userspace_003_pos.ksh
671e144b092a530c2039cecb32fde9b381a66ca2
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) 2016 by Jinshan Xiong. All rights reserved.
32 .
$STF_SUITE/include
/libtest.shlib
33 .
$STF_SUITE/tests
/functional
/userquota
/userquota_common.kshlib
37 # Check the user used object accounting in zfs userspace
41 # 1. create a bunch of files by specific users
42 # 2. use zfs userspace to check the used objects
43 # 3. change the owner of test files and verify object count
44 # 4. delete files and verify object count
49 if datasetexists
$snapfs; then
50 log_must zfs destroy
$snapfs
53 log_must
rm -f ${QFILE}_
*
54 log_must cleanup_quota
57 function user_object_count
61 typeset cnt
=$
(zfs userspace
-oname,objused
$fs |
62 awk /$user/'{print $2}')
68 log_assert
"Check the zfs userspace object used"
71 log_must zfs
set xattr
=sa
$QFS
73 ((user1_cnt
= RANDOM
% 100 + 1))
74 ((user2_cnt
= RANDOM
% 100 + 1))
76 log_must user_run
$QUSER1 mkfiles
${QFILE}_1
$user1_cnt
77 log_must user_run
$QUSER2 mkfiles
${QFILE}_2
$user2_cnt
80 typeset snapfs
=$QFS@snap
82 log_must zfs snapshot
$snapfs
84 log_must
eval "zfs userspace $QFS >/dev/null 2>&1"
85 log_must
eval "zfs userspace $snapfs >/dev/null 2>&1"
87 for fs
in "$QFS" "$snapfs"; do
88 log_note
"check the user used objects in zfs userspace $fs"
89 [[ $
(user_object_count
$fs $QUSER1) -eq $user1_cnt ]] ||
90 log_fail
"expected $user1_cnt"
91 [[ $
(user_object_count
$fs $QUSER2) -eq $user2_cnt ]] ||
92 log_fail
"expected $user2_cnt"
95 log_note
"change the owner of files"
96 log_must chown
$QUSER2 ${QFILE}_1
*
99 [[ $
(user_object_count
$QFS $QUSER1) -eq 0 ]] ||
100 log_fail
"expected 0 files for $QUSER1"
102 [[ $
(user_object_count
$snapfs $QUSER1) -eq $user1_cnt ]] ||
103 log_fail
"expected $user_cnt files for $QUSER1 in snapfs"
105 [[ $
(user_object_count
$QFS $QUSER2) -eq $
((user1_cnt
+user2_cnt
)) ]] ||
106 log_fail
"expected $((user1_cnt+user2_cnt)) files for $QUSER2"
108 log_note
"file removal"
109 log_must
rm ${QFILE}_
*
112 [[ $
(user_object_count
$QFS $QUSER2) -eq 0 ]] ||
113 log_fail
"expected 0 files for $QUSER2"
116 log_pass
"Check the zfs userspace object used"