xref: /freebsd/tools/test/stress2/misc/symlink5.sh (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# Copyright (c) 2021 Peter Holm <pho@FreeBSD.org>
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27# SUCH DAMAGE.
28#
29
30# Variation of symlink.sh using a larger swap backed FS.
31
32# "panic: refcount 0xfffff8093d7ed268 wraparound" seen in WiP kernel code.
33# https://people.freebsd.org/~pho/stress/log/log0024.txt
34
35[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
36
37. ../default.cfg
38dbt=`sysctl -n vfs.dirtybufthresh`
39[ $dbt -lt 1000 ] && echo "Note: vfs.dirtybufthresh = $dbt"
40
41D=$diskimage
42
43odir=`pwd`
44dir=$mntpoint
45
46cd /tmp
47sed '1,/^EOF/d' < $odir/$0 > symlink.c
48mycc -o symlink -Wall -Wextra symlink.c || exit 1
49rm -f symlink.c
50cd $odir
51
52mount | grep -q "on $mntpoint " && umount $mntpoint
53mdconfig -l | grep md$mdstart > /dev/null &&  mdconfig -d -u $mdstart
54
55mdconfig -a -t swap -s 1g -u $mdstart
56
57tst() {
58	local i j k
59
60	cd $dir
61	df -ik $mntpoint
62	i=`df -ik $mntpoint | tail -1 | awk '{printf "%d\n", ($7 - 500)/2}'`
63	[ $i -gt 20000 ] && i=20000
64
65	for k in `jot 3`; do
66		for j in `jot 2`; do
67			/tmp/symlink $i &
68		done
69		for j in `jot 2`; do
70			wait
71		done
72	done
73	df -ik $mntpoint | tail -1
74	cd $odir
75}
76
77s=0
78for i in "" "-U"; do
79	t1=`date +%s`
80	echo "newfs $i /dev/md$mdstart"
81	newfs $i /dev/md$mdstart > /dev/null 2>&1
82	mount /dev/md$mdstart $mntpoint
83
84	tst; s=$?
85
86	umount -f $mntpoint
87	t2=$((`date +%s` - t1))
88	    echo "$t2 seconds elapsed for newfs option \"$i\""
89	[ $t2 -gt 1000 ] && s=111
90done
91rm -f /tmp/symlink
92mdconfig -d -u $mdstart
93exit $s
94EOF
95#include <sys/param.h>
96#include <sys/mount.h>
97#include <sys/sysctl.h>
98#include <sys/stat.h>
99
100#include <err.h>
101#include <errno.h>
102#include <fcntl.h>
103#include <stdio.h>
104#include <stdlib.h>
105#include <unistd.h>
106
107int
108main(int argc __unused, char **argv)
109{
110	pid_t pid;
111	int64_t size;
112	int i, j;
113	char file[128];
114
115	size = atol(argv[1]);
116
117	pid = getpid();
118	for (j = 0; j < size; j++) {
119		sprintf(file,"p%05d.%05d", pid, j);
120		if (symlink("/mnt/not/there", file) == -1) {
121			if (errno != EINTR) {
122				warn("symlink(%s)", file);
123				printf("break out at %d, errno %d\n", j, errno);
124				break;
125			}
126		}
127	}
128
129	for (i = --j; i >= 0; i--) {
130		sprintf(file,"p%05d.%05d", pid, i);
131		if (unlink(file) == -1)
132			err(3, "unlink(%s)", file);
133
134	}
135
136	return (0);
137}
138