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 https://opensource.org/licenses/CDDL-1.0.
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
26#
27# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
28#
29
30#
31# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
32#
33
34. $STF_SUITE/include/libtest.shlib
35. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
36
37#
38# DESCRIPTION:
39# xattr file sizes count towards normal disk usage
40#
41# STRATEGY:
42#	1. Create a file, and check pool and filesystem usage
43#       2. Create a 200mb xattr in that file
44#	3. Check pool and filesystem usage, to ensure it reflects the size
45#	   of the xattr
46#
47
48function cleanup {
49	log_must rm $TESTDIR/myfile.$$
50	if is_freebsd; then
51		log_must rm /tmp/xattr.$$
52	fi
53}
54
55log_assert "xattr file sizes count towards normal disk usage"
56log_onexit cleanup
57
58log_must touch $TESTDIR/myfile.$$
59
60POOL_SIZE=0
61NEW_POOL_SIZE=0
62
63if is_global_zone
64then
65	# get pool and filesystem sizes. Since we're starting with an empty
66	# pool, the usage should be small - a few k.
67	POOL_SIZE=$(get_pool_prop allocated $TESTPOOL)
68fi
69
70FS_SIZE=$(get_prop used $TESTPOOL/$TESTFS)
71
72if is_freebsd; then
73	# FreeBSD setextattr has awful scaling with respect to input size.
74	# It reallocs after every 1024 bytes. For now we'll just break up
75	# the 200MB into 10 20MB attributes, but this test could be revisited
76	# if someone cared about large extattrs and improves setextattr -i.
77	log_must mkfile 20m /tmp/xattr.$$
78	for i in {0..10}; do
79		log_must eval "set_xattr_stdin xattr$i $TESTDIR/myfile.$$ \
80		    < /tmp/xattr.$$"
81	done
82elif is_linux; then
83	# Linux setxattr() syscalls limits individual xattrs to 64k.  Create
84	# 100 files, with 128 xattrs each of size 16k.  100*128*16k=200m
85	log_must xattrtest -k -f 100 -x 128 -s 16384 -p $TESTDIR
86else
87	log_must runat $TESTDIR/myfile.$$ mkfile 200m xattr
88fi
89
90#Make sure the newly created file is counted into zpool usage
91sync_pool
92
93# now check to see if our pool disk usage has increased
94if is_global_zone
95then
96	NEW_POOL_SIZE=$(get_pool_prop allocated $TESTPOOL)
97	(($NEW_POOL_SIZE <= $POOL_SIZE)) && \
98	    log_fail "The new pool size $NEW_POOL_SIZE was less \
99            than or equal to the old pool size $POOL_SIZE."
100
101fi
102
103# also make sure our filesystem usage has increased
104NEW_FS_SIZE=$(get_prop used $TESTPOOL/$TESTFS)
105(($NEW_FS_SIZE <= $FS_SIZE)) && \
106    log_fail "The new filesystem size $NEW_FS_SIZE was less \
107    than or equal to the old filesystem size $FS_SIZE."
108
109log_pass "xattr file sizes count towards normal disk usage"
110