aboutsummaryrefslogtreecommitdiff
path: root/tools/test/stress2/misc/suj10.sh
blob: dae7e36c35617092c1fdfdf82392f80b9a933fef (plain) (blame)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/sh

#
# Copyright (c) 2011 Peter Holm <pho@FreeBSD.org>
# All rights reserved.
#
# 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.
#

[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1

# Page fault in softdep_revert_mkdir+0x4d seen and

# fsck updates "clean" FS:
# *** /tmp/dumpfs.1       2010-12-24 19:18:44.000000000 +0100
# --- /tmp/dumpfs.2       2010-12-24 19:18:46.000000000 +0100
# ***************
# *** 5,11 ****
#   frag  8       shift   3       fsbtodb 2
#   minfree       8%      optim   time    symlinklen 120
#   maxbsize 16384        maxbpg  2048    maxcontig 8     contigsumsize 8
# ! nbfree        62794   ndir    2       nifree  141307  nffree  25
#   bpg   11761   fpg     94088   ipg     23552   unrefs  0
#   nindir        2048    inopb   64      maxfilesize     140806241583103
#   sbsize        2048    cgsize  16384   csaddr  3000    cssize  2048
# --- 5,11 ----
#   frag  8       shift   3       fsbtodb 2
#   minfree       8%      optim   time    symlinklen 120
#   maxbsize 16384        maxbpg  2048    maxcontig 8     contigsumsize 8
# ! nbfree        62794   ndir    30      nifree  141307  nffree  25
#   bpg   11761   fpg     94088   ipg     23552   unrefs  0
#   nindir        2048    inopb   64      maxfilesize     140806241583103
#   sbsize        2048    cgsize  16384   csaddr  3000    cssize  2048

. ../default.cfg

here=`pwd`
cd /tmp
sed '1,/^EOF/d' < $here/$0 > suj10.c
mycc -o suj10 -Wall -Wextra -O2 suj10.c || exit 1
rm -f suj10.c
cd $here

mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint
mdconfig -l | grep -q md$mdstart &&  mdconfig -d -u $mdstart
mdconfig -a -t swap -s 1g -u $mdstart
newfs -j md$mdstart > /dev/null
mount /dev/md$mdstart $mntpoint
chmod 777 $mntpoint

su $testuser -c "cd $mntpoint; /tmp/suj10"

while mount | grep "$mntpoint " | grep -q /dev/md; do
	umount $mntpoint || sleep 1
done
dumpfs /dev/md$mdstart | grep -vE "UFS2|last.*time" > /tmp/dumpfs.1
sleep 1
fsck -t ufs -y -v /dev/md$mdstart > /tmp/fsck.log 2>&1
dumpfs /dev/md$mdstart | grep -vE "UFS2|last.*time" > /tmp/dumpfs.2
diff -c /tmp/dumpfs.1 /tmp/dumpfs.2 || { s=1; cat /tmp/fsck.log; } && s=0
mdconfig -d -u $mdstart
rm -f /tmp/fsck.log /tmp/dumpfs.? /tmp/suj10
exit $s
EOF
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define PARALLEL 10
/*
static int size = 14100;
Causes:
    Fatal trap 12: page fault while in kernel mode
    Stopped at softdep_revert_mkdir+0x4d: movl 0x28(%ebx),%eax
*/
static int size = 13000;

static void
test(void)
{
	pid_t pid;
	int fd, i, j;
	char file[128];

	for (;;) {
		if (access("rendezvous", R_OK) == 0)
			break;
		sched_yield();
	}
	pid = getpid();
	sprintf(file,"d%05d", pid);
	if (mkdir(file, 0740) == -1)
		err(1, "mkdir(%s)", file);
	chdir(file);
	for (j = 0; j < size; j++) {
		sprintf(file,"p%05d.%05d", pid, j);
		if ((fd = mkdir(file, 0740)) == -1) {
			if (errno != EINTR) {
				warn("mkdir(%s). %s:%d", file, __FILE__, __LINE__);
				unlink("continue");
				break;
			}
		}

	}
	sleep(3);

	for (i = --j; i >= 0; i--) {
		sprintf(file,"p%05d.%05d", pid, i);
		if (rmdir(file) == -1)
			err(3, "unlink(%s)", file);

	}
	chdir("..");
	sprintf(file,"d%05d", pid);
	if (rmdir(file) == -1)
		err(3, "unlink(%s)", file);
}

int
main(void)
{
	int fd, i, j;

	umask(0);
	if ((fd = open("continue", O_CREAT, 0644)) == -1)
		err(1, "open()");
	close(fd);
	for (i = 0; i < 1; i++) {
		for (j = 0; j < PARALLEL; j++) {
			if (fork() == 0) {
				test();
				exit(0);
			}
		}

		if ((fd = open("rendezvous", O_CREAT, 0644)) == -1)
			err(1, "open()");
		close(fd);

		for (j = 0; j < PARALLEL; j++)
			wait(NULL);

		unlink("rendezvous");
		if (access("continue", R_OK) == -1) {
			fprintf(stderr, "Loop #%d\n", i + 1); fflush(stderr);
			break;
		}
	}
	unlink("continue");

	return (0);
}