xref: /freebsd/tools/test/stress2/misc/nullfs28.sh (revision a466cc55373fc3cf86837f09da729535b57e69a1)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# Copyright (c) 2022 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# Scenario: mount -t nullfs /mnt /mnt
31
32# Seen:
33# [root@mercat1 /home/pho]# ps -lUroot | grep -v grep | grep -E "find|umount"
34#   0 23496  3144  0  52  0  12856  2544 ufs      D+    0   0:00.00 find /mnt -type f -maxdepth 2 -ls
35#   0 23497  3126  6  52  0  12812  2512 mount dr D+    0   0:00.00 umount /mnt
36# [root@mercat1 /home/pho]#
37
38# Test suggestion by Jason Harmening:
39
40[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
41
42. ../default.cfg
43
44nullfs_srcdir=$mntpoint
45nullfs_dstdir=$mntpoint
46runtime=300
47
48set -e
49mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint
50mdconfig -l | grep -q md$mdstart &&  mdconfig -d -u $mdstart
51mdconfig -a -t swap -s 2g -u $mdstart || exit 1
52newfs $newfs_flags md$mdstart > /dev/null
53mount /dev/md$mdstart $mntpoint
54chmod 777 $mntpoint
55set +e
56
57start=`date '+%s'`
58while [ `date '+%s'` -lt $((start + $runtime)) ]; do
59	find $nullfs_dstdir -type f -maxdepth 2 -ls > \
60	    /dev/null 2>&1
61done &
62
63(cd ../testcases/swap; ./swap -t ${runtime}s -i 20) &
64start=`date '+%s'`
65while [ `date '+%s'` -lt $((start + $runtime)) ]; do
66	mount_nullfs $nullfs_srcdir $nullfs_dstdir
67	opt=$([ `jot -r 1 0 1` -eq 0 ] && echo "-f")
68	while mount | grep nullfs | grep -q ${nullfs_dstdir}; do
69		umount $opt $nullfs_dstdir
70	done
71done > /dev/null 2>&1
72pkill swap
73wait
74n=0
75while mount | grep $mntpoint | grep -q /dev/md; do
76	umount $mntpoint || sleep 1
77	n=$((n + 1))
78	[ $n -gt 30 ] && { echo FAIL; status=2; }
79done
80mdconfig -d -u $mdstart
81exit 0
82