xref: /freebsd/tools/test/stress2/misc/suj10.sh (revision 1603881667360c015f6685131f2f25474fa67a72)
1#!/bin/sh
2
3#
4# Copyright (c) 2011 Peter Holm <pho@FreeBSD.org>
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28
29[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
30
31# Page fault in softdep_revert_mkdir+0x4d seen and
32
33# fsck updates "clean" FS:
34# *** /tmp/dumpfs.1       2010-12-24 19:18:44.000000000 +0100
35# --- /tmp/dumpfs.2       2010-12-24 19:18:46.000000000 +0100
36# ***************
37# *** 5,11 ****
38#   frag  8       shift   3       fsbtodb 2
39#   minfree       8%      optim   time    symlinklen 120
40#   maxbsize 16384        maxbpg  2048    maxcontig 8     contigsumsize 8
41# ! nbfree        62794   ndir    2       nifree  141307  nffree  25
42#   bpg   11761   fpg     94088   ipg     23552   unrefs  0
43#   nindir        2048    inopb   64      maxfilesize     140806241583103
44#   sbsize        2048    cgsize  16384   csaddr  3000    cssize  2048
45# --- 5,11 ----
46#   frag  8       shift   3       fsbtodb 2
47#   minfree       8%      optim   time    symlinklen 120
48#   maxbsize 16384        maxbpg  2048    maxcontig 8     contigsumsize 8
49# ! nbfree        62794   ndir    30      nifree  141307  nffree  25
50#   bpg   11761   fpg     94088   ipg     23552   unrefs  0
51#   nindir        2048    inopb   64      maxfilesize     140806241583103
52#   sbsize        2048    cgsize  16384   csaddr  3000    cssize  2048
53
54. ../default.cfg
55
56here=`pwd`
57cd /tmp
58sed '1,/^EOF/d' < $here/$0 > suj10.c
59mycc -o suj10 -Wall -Wextra -O2 suj10.c || exit 1
60rm -f suj10.c
61cd $here
62
63mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint
64mdconfig -l | grep -q md$mdstart &&  mdconfig -d -u $mdstart
65mdconfig -a -t swap -s 1g -u $mdstart
66newfs -j md$mdstart > /dev/null
67mount /dev/md$mdstart $mntpoint
68chmod 777 $mntpoint
69
70su $testuser -c "cd $mntpoint; /tmp/suj10"
71
72while mount | grep "$mntpoint " | grep -q /dev/md; do
73	umount $mntpoint || sleep 1
74done
75dumpfs /dev/md$mdstart | grep -vE "UFS2|last.*time" > /tmp/dumpfs.1
76sleep 1
77fsck -t ufs -y -v /dev/md$mdstart > /tmp/fsck.log 2>&1
78dumpfs /dev/md$mdstart | grep -vE "UFS2|last.*time" > /tmp/dumpfs.2
79diff -c /tmp/dumpfs.1 /tmp/dumpfs.2 || { s=1; cat /tmp/fsck.log; } && s=0
80mdconfig -d -u $mdstart
81rm -f /tmp/fsck.log /tmp/dumpfs.? /tmp/suj10
82exit $s
83EOF
84#include <sys/param.h>
85#include <sys/mount.h>
86#include <sys/stat.h>
87#include <sys/wait.h>
88#include <err.h>
89#include <errno.h>
90#include <fcntl.h>
91#include <sched.h>
92#include <stdio.h>
93#include <stdlib.h>
94#include <unistd.h>
95
96#define PARALLEL 10
97/*
98static int size = 14100;
99Causes:
100    Fatal trap 12: page fault while in kernel mode
101    Stopped at softdep_revert_mkdir+0x4d: movl 0x28(%ebx),%eax
102*/
103static int size = 13000;
104
105static void
106test(void)
107{
108	pid_t pid;
109	int fd, i, j;
110	char file[128];
111
112	for (;;) {
113		if (access("rendezvous", R_OK) == 0)
114			break;
115		sched_yield();
116	}
117	pid = getpid();
118	sprintf(file,"d%05d", pid);
119	if (mkdir(file, 0740) == -1)
120		err(1, "mkdir(%s)", file);
121	chdir(file);
122	for (j = 0; j < size; j++) {
123		sprintf(file,"p%05d.%05d", pid, j);
124		if ((fd = mkdir(file, 0740)) == -1) {
125			if (errno != EINTR) {
126				warn("mkdir(%s). %s:%d", file, __FILE__, __LINE__);
127				unlink("continue");
128				break;
129			}
130		}
131
132	}
133	sleep(3);
134
135	for (i = --j; i >= 0; i--) {
136		sprintf(file,"p%05d.%05d", pid, i);
137		if (rmdir(file) == -1)
138			err(3, "unlink(%s)", file);
139
140	}
141	chdir("..");
142	sprintf(file,"d%05d", pid);
143	if (rmdir(file) == -1)
144		err(3, "unlink(%s)", file);
145}
146
147int
148main(void)
149{
150	int fd, i, j;
151
152	umask(0);
153	if ((fd = open("continue", O_CREAT, 0644)) == -1)
154		err(1, "open()");
155	close(fd);
156	for (i = 0; i < 1; i++) {
157		for (j = 0; j < PARALLEL; j++) {
158			if (fork() == 0) {
159				test();
160				exit(0);
161			}
162		}
163
164		if ((fd = open("rendezvous", O_CREAT, 0644)) == -1)
165			err(1, "open()");
166		close(fd);
167
168		for (j = 0; j < PARALLEL; j++)
169			wait(NULL);
170
171		unlink("rendezvous");
172		if (access("continue", R_OK) == -1) {
173			fprintf(stderr, "Loop #%d\n", i + 1); fflush(stderr);
174			break;
175		}
176	}
177	unlink("continue");
178
179	return (0);
180}
181