1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
#!/bin/sh
#
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2023 Peter Holm <pho@FreeBSD.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Regression test for D37997: ffs_syncvnode(): avoid a LoR for SU
# https://people.freebsd.org/~pho/stress/log/log0402.txt
# Fixed by 6e1eabadcb1d - main - ffs_syncvnode(): avoid a LoR for SU
# Test scenario based on report by jkim
. ../default.cfg
[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1
dir=/tmp
odir=`pwd`
prog=$(basename "$0" .sh)
cd $dir
sed '1,/^EOF/d' < $odir/$0 > $dir/$prog.c
mycc -o $prog -Wall -Wextra -O0 -g $prog.c -lpthread || exit 1
rm -f $prog.c
cd $odir
set -eu
mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart
mdconfig -a -t swap -s 1g -u $mdstart
newfs -U md$mdstart > /dev/null
mount /dev/md$mdstart $mntpoint
set +e
cd $odir
../testcases/swap/swap -t 1m -i 20 -l 100 > /dev/null &
sleep .5
cd $mntpoint
mkdir -p d1/d2/d3/d4/d5
for i in `jot 8`; do
$dir/$prog $i &
done
cd $odir
wait
for i in `jot 6`; do
mount | grep -q "on $mntpoint " || break
umount $mntpoint && break || sleep 10
[ $i -eq 6 ] &&
{ echo FATAL; fstat -mf $mntpoint; exit 1; }
done
mdconfig -d -u $mdstart
rm -rf $dir/$prog
exit 0
EOF
#include <sys/types.h>
#include <sys/stat.h>
#include <err.h>
#include <fcntl.h>
#include <pthread.h>
#include <pthread_np.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define RUNTIME 60
static time_t start;
static volatile int fd, n;
static char buf[4096];
static void *
t1(void *data __unused)
{
char *path = "d1/d2/d3/d4/d5";
char d1[1024], d2[1024], file[1024];
pthread_set_name_np(pthread_self(), __func__);
snprintf(d1, sizeof(d1), "%s/dir.%d", path, getpid());
snprintf(d2, sizeof(d2), "%s/new.%d", path, getpid());
snprintf(file, sizeof(file), "%s/../file.%d", path, getpid());
while (time(NULL) - start < RUNTIME) {
if (mkdir(d1, 0740) == -1)
err(1, "mkdir(%s)", d1);
if (rename(d1, d2) == -1)
err(1, "rename(%s, %s)", d1, d2);
if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) == -1)
err(1, "open%s()", file);
if (write(fd, buf, sizeof(buf)) != sizeof(buf))
err(1, "write()");
close(fd);
if (rename(d2, d1) == -1)
err(1, "rename(%s, %s)", d2, d1);
if (rmdir(d1) == -1)
err(1, "rmdir(%s)", d1);
}
return (NULL);
}
static void *
t2(void *data __unused)
{
pthread_set_name_np(pthread_self(), __func__);
while (time(NULL) - start < RUNTIME) {
fsync(fd);
usleep(arc4random() % 500);
}
return (NULL);
}
int
main(int argc __unused, char *argv[])
{
pthread_t tid[2];
int r;
n = atoi(argv[1]);
start = time(NULL);
if ((r = pthread_create(&tid[0], NULL, t1, NULL)) != 0)
errc(1, r, "pthread_create");
if ((r = pthread_create(&tid[1], NULL, t2, NULL)) != 0)
errc(1, r, "pthread_create");
if ((r = pthread_join(tid[0], NULL)) != 0)
errc(1, r, "pthread_join");
if ((r = pthread_join(tid[1], NULL)) != 0)
errc(1, r, "pthread_join");
return (0);
}
|