xref: /freebsd/tools/test/stress2/misc/nullfs31.sh (revision ef777be98543f7daae90bd123d4fc1ec4a54efc2)
1#!/bin/sh
2
3#
4# Copyright (c) 2025 Peter Holm <pho@FreeBSD.org>
5#
6# SPDX-License-Identifier: BSD-2-Clause
7#
8
9# Variation of nullfs25.sh, using cp(1) (copy_file_range())
10
11# Page fault in vn_copy_file_range() seen:
12# https://people.freebsd.org/~pho/stress/log/log0497.txt
13# Fixed by: 23210f538a00
14
15[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
16. ../default.cfg
17
18set -u
19mounts=4	# Number of parallel scripts
20: ${nullfs_srcdir:=$mntpoint}
21: ${nullfs_dstdir:=$mntpoint}
22prog=$(basename "$0" .sh)
23CONT=/tmp/$prog.continue
24
25mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint
26mdconfig -l | grep -q md$mdstart &&  mdconfig -d -u $mdstart
27mdconfig -a -t swap -s 1g -u $mdstart
28newfs $newfs_flags md$mdstart > /dev/null
29mount /dev/md$mdstart $mntpoint
30chmod 777 $mntpoint
31(cd $mntpoint; jot 500 | xargs touch)
32(cd ../testcases/swap; ./swap -t 5m -i 20 > /dev/null) &
33
34for i in `jot $mounts $mdstart`; do
35	[ ! -d ${nullfs_dstdir}$i ] && mkdir ${nullfs_dstdir}$i
36	mount | grep -q " ${nullfs_dstdir}$i " &&
37	    umount ${nullfs_dstdir}$i
38done
39
40# Start the parallel tests
41touch $CONT
42for i in `jot $mounts $mdstart`; do
43	while [ -f $CONT ]; do
44		cp /etc/group ${nullfs_dstdir}$i > \
45		    /dev/null 2>&1
46	done &
47	# The test: Parallel mount and unmount
48	start=`date +%s`
49	(
50		while [ $((`date +%s` - start))  -lt 300 ]; do
51			mount_nullfs $nullfs_srcdir ${nullfs_dstdir}$i > \
52			    /dev/null 2>&1
53			opt=$([ `jot -r 1 0 1` -eq 0 ] && echo "-f")
54			while mount | grep -q ${nullfs_dstdir}$i; do
55				umount $opt ${nullfs_dstdir}$i > \
56				    /dev/null 2>&1
57			done
58		done
59		rm -f $CONT
60	) &
61done
62while [ -f $CONT ] ; do sleep 1; done
63while pgrep -q swap; do pkill swap; done
64wait
65
66for i in `jot $mounts`; do
67	umount ${nullfs_dstdir}$i > /dev/null 2>&1
68done
69n=0
70while mount | grep $mntpoint | grep -q /dev/md; do
71	umount $mntpoint || sleep 1
72	[ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; }
73done
74mdconfig -d -u $mdstart
75exit 0
76