f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#!/bin/ksh -p
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/include/libtest.shlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# DESCRIPTION:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# xattr file sizes count towards normal disk usage
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# STRATEGY:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 1. Create a file, and check pool and filesystem usage
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 2. Create a 200mb xattr in that file
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 3. Check pool and filesystem usage, to ensure it reflects the size
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# of the xattr
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction cleanup {
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must rm $TESTDIR/myfile.$$
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction get_pool_size {
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy poolname=$1
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy psize=$(zpool list -H -o allocated $poolname)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $psize == *[mM] ]]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy returnvalue=$(echo $psize | sed -e 's/m//g' -e 's/M//g')
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy returnvalue=$((returnvalue * 1024))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy else
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy returnvalue=$(echo $psize | sed -e 's/k//g' -e 's/K//g')
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy echo $returnvalue
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_assert "xattr file sizes count towards normal disk usage"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_onexit cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must touch $TESTDIR/myfile.$$
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren KennedyPOOL_SIZE=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren KennedyNEW_POOL_SIZE=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedythen
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # get pool and filesystem sizes. Since we're starting with an empty
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # pool, the usage should be small - a few k.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy POOL_SIZE=$(get_pool_size $TESTPOOL)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren KennedyFS_SIZE=$(zfs get -p -H -o value used $TESTPOOL/$TESTFS)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must runat $TESTDIR/myfile.$$ mkfile 200m xattr
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#Make sure the newly created file is counted into zpool usage
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must sync
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# now check to see if our pool disk usage has increased
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedythen
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy NEW_POOL_SIZE=$(get_pool_size $TESTPOOL)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy (($NEW_POOL_SIZE <= $POOL_SIZE)) && \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "The new pool size $NEW_POOL_SIZE was less \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy than or equal to the old pool size $POOL_SIZE."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# also make sure our filesystem usage has increased
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren KennedyNEW_FS_SIZE=$(zfs get -p -H -o value used $TESTPOOL/$TESTFS)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy(($NEW_FS_SIZE <= $FS_SIZE)) && \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "The new filesystem size $NEW_FS_SIZE was less \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy than or equal to the old filesystem size $FS_SIZE."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_pass "xattr file sizes count towards normal disk usage"