xref: /freebsd/tests/sys/cddl/zfs/tests/xattr/xattr_012_pos.ksh (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1#!/usr/local/bin/ksh93 -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# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23# Use is subject to license terms.
24
25. $STF_SUITE/include/libtest.kshlib
26. $STF_SUITE/tests/xattr/xattr_common.kshlib
27
28################################################################################
29#
30# __stc_assertion_start
31#
32# ID:  xattr_012_pos
33#
34# DESCRIPTION:
35# xattr file sizes count towards normal disk usage
36#
37# STRATEGY:
38#	1. Create a file, and check pool and filesystem usage
39#       2. Create a 200mb xattr in that file
40#	3. Check pool and filesystem usage, to ensure it reflects the size
41#	   of the xattr
42#
43# TESTABILITY: explicit
44#
45# TEST_AUTOMATION_LEVEL: automated
46#
47# CODING_STATUS: COMPLETED (2006-12-15)
48#
49# __stc_assertion_end
50#
51################################################################################
52
53function cleanup {
54	log_must $RM $TESTDIR/myfile.${TESTCASE_ID}
55}
56
57function get_pool_size	{
58	poolname=$1
59	psize=$( $ZPOOL list -H -o used $poolname )
60	if [[ $psize == *[mM] ]]
61	then
62		returnvalue=$($ECHO $psize | $SED -e 's/m//g' -e 's/M//g')
63		returnvalue=$(( returnvalue * 1024 ))
64	else
65		returnvalue=$($ECHO $psize | $SED -e 's/k//g' -e 's/K//g')
66	fi
67	print $returnvalue
68}
69
70log_assert "xattr file sizes count towards normal disk usage"
71log_onexit cleanup
72
73test_requires RUNAT
74
75log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID}
76
77POOL_SIZE=0
78NEW_POOL_SIZE=0
79
80if is_global_zone
81then
82	# get pool and filesystem sizes. Since we're starting with an empty
83	# pool, the usage should be small - a few k.
84	POOL_SIZE=$(get_pool_size $TESTPOOL)
85fi
86
87FS_SIZE=$( $ZFS get -p -H -o value used $TESTPOOL/$TESTFS )
88
89log_must $RUNAT $TESTDIR/myfile.${TESTCASE_ID} $MKFILE 200m xattr
90
91#Make sure the newly created file is counted into zpool usage
92log_must $SYNC
93
94# now check to see if our pool disk usage has increased
95if is_global_zone
96then
97	NEW_POOL_SIZE=$(get_pool_size $TESTPOOL)
98	if (( $NEW_POOL_SIZE <= $POOL_SIZE ))
99	then
100		log_fail "The new pool size $NEW_POOL_SIZE was less \
101                than or equal to the old pool size $POOL_SIZE."
102	fi
103
104fi
105
106# also make sure our filesystem usage has increased
107NEW_FS_SIZE=$( $ZFS get -p -H -o value used $TESTPOOL/$TESTFS )
108if (( $NEW_FS_SIZE <= $FS_SIZE ))
109then
110	log_fail "The new filesystem size $NEW_FS_SIZE was less \
111		than or equal to the old filesystem size $FS_SIZE."
112fi
113
114log_pass "xattr file sizes count towards normal disk usage"
115