xref: /freebsd/tools/test/stress2/misc/unionfs18.sh (revision a64729f5077d77e13b9497cb33ecb3c82e606ee8)
1#!/bin/sh
2
3#
4# Copyright (c) 2024 Peter Holm <pho@FreeBSD.org>
5#
6# SPDX-License-Identifier: BSD-2-Clause
7#
8
9# Simple unionfs(4) + tmpfs(4) test
10
11# "rmdir: d2: Directory not empty" seen.
12
13[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
14. ../default.cfg
15
16mp1=/mnt$mdstart
17mp2=/mnt$((mdstart + 1))
18mkdir -p $mp1 $mp2
19set -e
20for i in $mp1 $mp2; do
21	mount | grep -q "on $i " && umount -f $i
22done
23
24md1=$mdstart
25md2=$((md1 + 1))
26mp1=/mnt$md1
27mp2=/mnt$md2
28mkdir -p $mp1 $mp2
29for i in $mp1 $mp2; do
30	mount | grep -q "on $i " && umount -f $i
31done
32
33if [ $# -eq 0 ]; then
34	echo "tmpfs version"
35	mount -o size=4g -t tmpfs dummy $mp1
36	mount -o size=4g -t tmpfs dummy $mp2
37else
38	echo "UFS version"
39	for i in $md1 $md2; do
40		mdconfig -l | grep -q md$i && mdconfig -d -u $i
41	done
42	mdconfig -a -t swap -s 4g -u $md1
43	mdconfig -a -t swap -s 4g -u $md2
44	newfs $newfs_flags -n md$md1 > /dev/null
45	newfs $newfs_flags -n md$md2 > /dev/null
46	mount /dev/md$md1 $mp1
47	mount /dev/md$md2 $mp2
48fi
49
50mount -t unionfs -o noatime $mp1 $mp2
51set +e
52
53N=3	# Tree depth
54here=`pwd`
55cd $mp2
56mkdir dir; cd dir
57for j in `seq 1 $N`; do
58	mkdir d$j && cd d$j
59done
60for j in `seq $N 1`; do
61	cd .. && rmdir d$j
62done
63cd ..
64rmdir dir || { s=1; find dir -ls; }
65cd $here
66
67while mount | grep -Eq "on $mp2 .*unionfs"; do
68	umount $mp2 && break
69	sleep 5
70done
71umount $mp2
72umount $mp1
73exit $s
74