]> git.proxmox.com Git - mirror_zfs-debian.git/blame - tests/zfs-tests/tests/functional/userquota/groupspace_003_pos.ksh
New upstream version 0.7.4
[mirror_zfs-debian.git] / tests / zfs-tests / tests / functional / userquota / groupspace_003_pos.ksh
CommitLineData
cae5b340
AX
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) 2013 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
41d74433 33. $STF_SUITE/include/math.shlib
cae5b340
AX
34. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
35
36#
37# DESCRIPTION:
38# Check the user used and groupspace object counts in zfs groupspace
39#
40#
41# STRATEGY:
42# 1. set zfs groupquota to a fs
43# 2. create objects for different users in the same group
44# 3. use zfs groupspace to check the object count
45#
46
47function cleanup
48{
49 if datasetexists $snapfs; then
50 log_must zfs destroy $snapfs
51 fi
52
53 log_must rm -f ${QFILE}_*
54 log_must cleanup_quota
55}
56
57function group_object_count
58{
59 typeset fs=$1
41d74433
AX
60 typeset group=$2
61 typeset -i groupspacecnt=$(zfs groupspace -oname,objused $fs |
62 awk /$group/'{print $2}')
63 typeset -i zfsgetcnt=$(zfs get -H -ovalue groupobjused@$group $fs)
64
65 # 'zfs groupspace' and 'zfs get groupobjused@' should be equal
66 verify_eq "$groupspacecnt" "$zfsgetcnt" "groupobjused@$group"
67
68 echo $groupspacecnt
cae5b340
AX
69}
70
71log_onexit cleanup
72
73log_assert "Check the zfs groupspace object used"
74
75mkmount_writable $QFS
76log_must zfs set xattr=sa $QFS
77
78((user1_cnt = RANDOM % 100 + 1))
79((user2_cnt = RANDOM % 100 + 1))
80log_must user_run $QUSER1 mkfiles ${QFILE}_1 $user1_cnt
81log_must user_run $QUSER2 mkfiles ${QFILE}_2 $user2_cnt
82((grp_cnt = user1_cnt + user2_cnt))
83sync_pool
84
85typeset snapfs=$QFS@snap
86
87log_must zfs snapshot $snapfs
88
89log_must eval "zfs groupspace $QFS >/dev/null 2>&1"
90log_must eval "zfs groupspace $snapfs >/dev/null 2>&1"
91
92for fs in "$QFS" "$snapfs"; do
93 log_note "check the object count in zfs groupspace $fs"
94 [[ $(group_object_count $fs $QGROUP) -eq $grp_cnt ]] ||
95 log_fail "expected $grp_cnt"
96done
97
98log_note "file removal"
99log_must rm ${QFILE}_*
100sync_pool
101
102[[ $(group_object_count $QFS $QGROUP) -eq 0 ]] ||
103 log_fail "expected 0 files for $QGROUP"
104
105[[ $(group_object_count $snapfs $QGROUP) -eq $grp_cnt ]] ||
106 log_fail "expected $grp_cnt files for $QGROUP"
107
108cleanup
109log_pass "Check the zfs groupspace object used pass as expect"