xref: /freebsd/tools/test/stress2/misc/unionfs10.sh (revision a565cc81c04e94330115a742ee86378a91f9ee4c)
1*a565cc81SJason A. Harmening#!/bin/sh
2*a565cc81SJason A. Harmening
3*a565cc81SJason A. Harmening#
4*a565cc81SJason A. Harmening# Copyright (c) 2022 Jason Harmening <jah@FreeBSD.org>
5*a565cc81SJason A. Harmening# All rights reserved.
6*a565cc81SJason A. Harmening#
7*a565cc81SJason A. Harmening# Redistribution and use in source and binary forms, with or without
8*a565cc81SJason A. Harmening# modification, are permitted provided that the following conditions
9*a565cc81SJason A. Harmening# are met:
10*a565cc81SJason A. Harmening# 1. Redistributions of source code must retain the above copyright
11*a565cc81SJason A. Harmening#    notice, this list of conditions and the following disclaimer.
12*a565cc81SJason A. Harmening# 2. Redistributions in binary form must reproduce the above copyright
13*a565cc81SJason A. Harmening#    notice, this list of conditions and the following disclaimer in the
14*a565cc81SJason A. Harmening#    documentation and/or other materials provided with the distribution.
15*a565cc81SJason A. Harmening#
16*a565cc81SJason A. Harmening# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*a565cc81SJason A. Harmening# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*a565cc81SJason A. Harmening# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*a565cc81SJason A. Harmening# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*a565cc81SJason A. Harmening# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*a565cc81SJason A. Harmening# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*a565cc81SJason A. Harmening# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*a565cc81SJason A. Harmening# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*a565cc81SJason A. Harmening# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*a565cc81SJason A. Harmening# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*a565cc81SJason A. Harmening# SUCH DAMAGE.
27*a565cc81SJason A. Harmening#
28*a565cc81SJason A. Harmening
29*a565cc81SJason A. Harmening[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
30*a565cc81SJason A. Harmening
31*a565cc81SJason A. Harmening# Regression test:
32*a565cc81SJason A. Harmening
33*a565cc81SJason A. Harmening# There is an issue, namely, when the lower file is already
34*a565cc81SJason A. Harmening# opened r/w, but its nullfs alias is executed. This situation obviously
35*a565cc81SJason A. Harmening# shall result in ETXTBUSY, but it currently does not.
36*a565cc81SJason A. Harmening
37*a565cc81SJason A. Harmening# Based on nullfs10.sh by pho@, original test scenario by kib@
38*a565cc81SJason A. Harmening
39*a565cc81SJason A. Harmening. ../default.cfg
40*a565cc81SJason A. Harmening
41*a565cc81SJason A. Harmeningmd1=$mdstart
42*a565cc81SJason A. Harmeningmd2=$((md1 + 1))
43*a565cc81SJason A. Harmeningmp1=/mnt$md1
44*a565cc81SJason A. Harmeningmp2=/mnt$md2
45*a565cc81SJason A. Harmeningmkdir -p $mp1 $mp2
46*a565cc81SJason A. Harmeningset -e
47*a565cc81SJason A. Harmeningfor i in $mp1 $mp2; do
48*a565cc81SJason A. Harmening	mount | grep -q "on $i " && umount -f $i
49*a565cc81SJason A. Harmeningdone
50*a565cc81SJason A. Harmeningfor i in $md1 $md2; do
51*a565cc81SJason A. Harmening	mdconfig -l | grep -q md$i && mdconfig -d -u $i
52*a565cc81SJason A. Harmeningdone
53*a565cc81SJason A. Harmening
54*a565cc81SJason A. Harmeningmdconfig -a -t swap -s 4g -u $md1
55*a565cc81SJason A. Harmeningmdconfig -a -t swap -s 4g -u $md2
56*a565cc81SJason A. Harmeningnewfs $newfs_flags -n md$md1 > /dev/null
57*a565cc81SJason A. Harmeningnewfs $newfs_flags -n md$md2 > /dev/null
58*a565cc81SJason A. Harmeningmount /dev/md$md1 $mp1
59*a565cc81SJason A. Harmeningmount /dev/md$md2 $mp2
60*a565cc81SJason A. Harmening
61*a565cc81SJason A. Harmeningmount -t unionfs -o noatime $mp1 $mp2
62*a565cc81SJason A. Harmeningset +e
63*a565cc81SJason A. Harmening
64*a565cc81SJason A. Harmeningmount | grep -E "$mp1|$mp2"
65*a565cc81SJason A. Harmening
66*a565cc81SJason A. Harmeningchmod 777 $mp1
67*a565cc81SJason A. Harmeningchmod 777 $mp2
68*a565cc81SJason A. Harmening
69*a565cc81SJason A. Harmeningcp /bin/ls $mp1
70*a565cc81SJason A. Harmeningchmod +w $mp1/ls
71*a565cc81SJason A. Harmeningsleep 2 >> $mp1/ls &
72*a565cc81SJason A. Harmeningsleep .5
73*a565cc81SJason A. Harmening
74*a565cc81SJason A. Harmening# This line should cause a "$mp2/ls: Text file busy" error
75*a565cc81SJason A. Harmening$mp2/ls -l /bin/ls $mp1 $mp2 && echo FAIL || echo OK
76*a565cc81SJason A. Harmeningkill $!
77*a565cc81SJason A. Harmeningwait
78*a565cc81SJason A. Harmening
79*a565cc81SJason A. Harmeningwhile mount | grep -q "$mp2 "; do
80*a565cc81SJason A. Harmening	umount $mp2 || sleep 1
81*a565cc81SJason A. Harmeningdone
82*a565cc81SJason A. Harmening
83*a565cc81SJason A. Harmeningwhile mount | grep -q "$mp1 "; do
84*a565cc81SJason A. Harmening	umount $mp1 || sleep 1
85*a565cc81SJason A. Harmeningdone
86*a565cc81SJason A. Harmeningmdconfig -d -u $md2
87*a565cc81SJason A. Harmeningmdconfig -d -u $md1
88