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