xref: /freebsd/contrib/netbsd-tests/fs/tmpfs/t_vnode_leak.sh (revision 8c4282b370bd66908b45b6a223226a9fc2b69d57)
157718be8SEnji Cooper# $NetBSD: t_vnode_leak.sh,v 1.6 2010/11/07 17:51:18 jmmv Exp $
257718be8SEnji Cooper#
357718be8SEnji Cooper# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
457718be8SEnji Cooper# All rights reserved.
557718be8SEnji Cooper#
657718be8SEnji Cooper# Redistribution and use in source and binary forms, with or without
757718be8SEnji Cooper# modification, are permitted provided that the following conditions
857718be8SEnji Cooper# are met:
957718be8SEnji Cooper# 1. Redistributions of source code must retain the above copyright
1057718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer.
1157718be8SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
1257718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
1357718be8SEnji Cooper#    documentation and/or other materials provided with the distribution.
1457718be8SEnji Cooper#
1557718be8SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1657718be8SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1757718be8SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1857718be8SEnji Cooper# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1957718be8SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2057718be8SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2157718be8SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2257718be8SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2357718be8SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2457718be8SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2557718be8SEnji Cooper# POSSIBILITY OF SUCH DAMAGE.
2657718be8SEnji Cooper#
2757718be8SEnji Cooper
2857718be8SEnji Cooperatf_test_case main cleanup
2957718be8SEnji Coopermain_head() {
3057718be8SEnji Cooper	atf_set "descr" "Verifies that vnodes are not leaked and that" \
3157718be8SEnji Cooper	                "their reclaim operation works as expected: i.e.," \
3257718be8SEnji Cooper	                "when all free vnodes are exhausted, unused ones" \
3357718be8SEnji Cooper	                "have to be recycled, which is what the reclaim" \
3457718be8SEnji Cooper	                "operation does."
3557718be8SEnji Cooper	atf_set "require.user" "root"
3657718be8SEnji Cooper}
3757718be8SEnji Coopermain_body() {
3857718be8SEnji Cooper	echo "Lowering kern.maxvnodes to 2000"
39*d3de0623SEnji Cooper	# Begin FreeBSD
40*d3de0623SEnji Cooper	if true; then
41*d3de0623SEnji Cooper		sysctl -n kern.maxvnodes > oldvnodes
42*d3de0623SEnji Cooper	else
43*d3de0623SEnji Cooper	# End FreeBSD
4457718be8SEnji Cooper	sysctl kern.maxvnodes | awk '{ print $3; }' >oldvnodes
45*d3de0623SEnji Cooper	# Begin FreeBSD
46*d3de0623SEnji Cooper	fi
47*d3de0623SEnji Cooper	# End FreeBSD
4857718be8SEnji Cooper	atf_check -s eq:0 -o ignore -e empty sysctl -w kern.maxvnodes=2000
4957718be8SEnji Cooper
5057718be8SEnji Cooper	test_mount -o -s$(((4000 + 2) * 4096))
5157718be8SEnji Cooper	echo "Creating 4000 directories"
5257718be8SEnji Cooper	for f in $(jot 4000); do
5357718be8SEnji Cooper		mkdir ${f}
5457718be8SEnji Cooper	done
5557718be8SEnji Cooper	test_unmount
5657718be8SEnji Cooper}
5757718be8SEnji Coopermain_cleanup() {
5857718be8SEnji Cooper	oldvnodes=$(cat oldvnodes)
5957718be8SEnji Cooper	echo "Restoring kern.maxvnodes to ${oldvnodes}"
6057718be8SEnji Cooper	sysctl -w kern.maxvnodes=${oldvnodes}
6157718be8SEnji Cooper}
6257718be8SEnji Cooper
6357718be8SEnji Cooperatf_init_test_cases() {
6457718be8SEnji Cooper	. $(atf_get_srcdir)/../h_funcs.subr
6557718be8SEnji Cooper	. $(atf_get_srcdir)/h_funcs.subr
6657718be8SEnji Cooper
6757718be8SEnji Cooper	atf_add_test_case main
6857718be8SEnji Cooper}
69