xref: /freebsd/tools/test/stress2/misc/nlink2.sh (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
125a1b1f3SPeter Holm#!/bin/sh
225a1b1f3SPeter Holm
325a1b1f3SPeter Holm#
4*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause
525a1b1f3SPeter Holm#
625a1b1f3SPeter Holm# Copyright (c) 2022 Peter Holm <pho@FreeBSD.org>
725a1b1f3SPeter Holm#
825a1b1f3SPeter Holm# Redistribution and use in source and binary forms, with or without
925a1b1f3SPeter Holm# modification, are permitted provided that the following conditions
1025a1b1f3SPeter Holm# are met:
1125a1b1f3SPeter Holm# 1. Redistributions of source code must retain the above copyright
1225a1b1f3SPeter Holm#    notice, this list of conditions and the following disclaimer.
1325a1b1f3SPeter Holm# 2. Redistributions in binary form must reproduce the above copyright
1425a1b1f3SPeter Holm#    notice, this list of conditions and the following disclaimer in the
1525a1b1f3SPeter Holm#    documentation and/or other materials provided with the distribution.
1625a1b1f3SPeter Holm#
1725a1b1f3SPeter Holm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1825a1b1f3SPeter Holm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1925a1b1f3SPeter Holm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2025a1b1f3SPeter Holm# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2125a1b1f3SPeter Holm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2225a1b1f3SPeter Holm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2325a1b1f3SPeter Holm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2425a1b1f3SPeter Holm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2525a1b1f3SPeter Holm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2625a1b1f3SPeter Holm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2725a1b1f3SPeter Holm# SUCH DAMAGE.
2825a1b1f3SPeter Holm#
2925a1b1f3SPeter Holm
3025a1b1f3SPeter Holm# Simple test to demonstrate EMLINK issue on a SU file system.
3125a1b1f3SPeter Holm
3225a1b1f3SPeter Holm# mkdir: /mnt10/a994: Too many links
3325a1b1f3SPeter Holm
3425a1b1f3SPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
3525a1b1f3SPeter Holm. ../default.cfg
3625a1b1f3SPeter Holm
3725a1b1f3SPeter Holmecho "$newfs_flags" | grep -q U || exit 0
3825a1b1f3SPeter Holmlog=/tmp/nlink2.sh.log
3925a1b1f3SPeter Holmmd=$mdstart
4025a1b1f3SPeter Holmmp=/mnt$md
4125a1b1f3SPeter Holmmkdir -p $mp
4225a1b1f3SPeter Holmset -e
4325a1b1f3SPeter Holmmount | grep -q "on $mp " && umount -f $mp
4425a1b1f3SPeter Holmmdconfig -l | grep -q md$md && mdconfig -d -u $md
4525a1b1f3SPeter Holm
4625a1b1f3SPeter Holmmdconfig -a -t swap -s 1g -u $md
4725a1b1f3SPeter Holmnewfs $newfs_flags -n md$md > /dev/null
4825a1b1f3SPeter Holmmount /dev/md$md $mp
4925a1b1f3SPeter Holmset +e
5025a1b1f3SPeter Holm
5125a1b1f3SPeter Holmstart=`date +%s`
5225a1b1f3SPeter Holmfor i in `jot 1000`; do
5325a1b1f3SPeter Holm	jot 1000 | xargs -P0 -I% mkdir $mp/a% || { s=1; break; }
5425a1b1f3SPeter Holm	jot 1000 | xargs -P0 -I% rmdir $mp/a%
5525a1b1f3SPeter Holm	t=$((`date +%s` - start))
5625a1b1f3SPeter Holm	if [ $t -ge 300 ]; then
5725a1b1f3SPeter Holm		echo "Warn: Timed out in loop #$i after $t seconds"
5825a1b1f3SPeter Holm		break
5925a1b1f3SPeter Holm	fi
6025a1b1f3SPeter Holmdone
6125a1b1f3SPeter Holmif [ $s ]; then
6225a1b1f3SPeter Holm	echo "Failed in loop #$i"
6325a1b1f3SPeter Holm	df -i $mp
6425a1b1f3SPeter Holmfi
6525a1b1f3SPeter Holm
6625a1b1f3SPeter Holmumount $mp
6725a1b1f3SPeter Holmfsck_ffs -fy /dev/md$md > $log 2>&1
6825a1b1f3SPeter Holmgrep -Eq "WAS MODIFIED" $log && { s=$((s + 2)); cat $log; }
6925a1b1f3SPeter Holmmdconfig -d -u $md
7025a1b1f3SPeter Holmrm -f $log
7125a1b1f3SPeter Holmexit $s
72