4 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 # Copyright (c) 2020 Peter Holm <pho@FreeBSD.org>
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Hunt for "panic: ufsdirhash_dirtrunc: bad offset"
31 # by making the directory inode grow into the indirect blocks.
33 # Truncate directories larger than 12 * block_size bytes
34 # default is 12 * 32768 = 393216, 384k
39 [ `id -u` -ne 0 ] && echo "Must be root!" && exit 1
44 sed '1,/^EOF/d' < $odir/$0 > $dir/indir.c
45 sed -i '' -e "s#MNTPOINT#$mntpoint#g" $dir/indir.c
46 mycc -o indir -Wall -Wextra -O0 -g indir.c || exit 1
51 mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
52 [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart
53 mdconfig -a -t swap -s 1g -u $mdstart
54 newfs -j -n -b 16384 -f 2048 -i 2048 md$mdstart > /dev/null
55 mount /dev/md$mdstart $mntpoint
56 ifree=`df -i $mntpoint | tail -1 | awk '{print $7 - 50}'`
60 dtrace -w -n '*ufsdirhash_dirtrunc:entry {@rw[execname,probefunc] = \
66 /tmp/indir $mntpoint $ifree
74 mount | grep -q "on $mntpoint " || break
75 umount $mntpoint && break || sleep 10
77 { echo FATAL; fstat -mf $mntpoint; exit 1; }
79 mdconfig -d -u $mdstart
82 while pgrep -q dtrace; do sleep 1; done
83 kldstat | grep -q dtraceall &&
84 kldunload dtraceall.ko
88 #include <sys/param.h>
96 #include <stdatomic.h>
106 #define RUNTIME (10 * 60)
114 char dir[128], file[128], new[128];
118 snprintf(dir, sizeof(dir), "%s/d%d", path, idx);
119 if (mkdir(dir, 0755) == -1) {
121 err(1, "mkdir(%s)", dir);
123 if (chdir(dir) == -1)
124 err(1, "chdir(%s)", dir);
127 for (j = 0; j < files; j++) {
128 sprintf(file,"p%05d.%05ld", pid, j);
129 if ((fd = creat(file, 0660)) == -1)
130 err(1, "creat(%s). %s:%d", file, __FILE__, __LINE__);
131 if (fd != -1 && close(fd) == -1)
132 err(2, "close(%ld)", j);
135 for (j = 0; j < files; j++) {
136 sprintf(file,"p%05d.%05ld", pid, j);
137 sprintf(new,"p%05d.%05ld.old", pid, j);
138 if (rename(file, new) == -1)
139 err(1, "rename(%s, %s)", file, new);
142 for (j = 0; j < files; j++) {
143 sprintf(file,"p%05d.%05ld", pid, j);
144 sprintf(new,"p%05d.%05ld.old", pid, j);
145 if (rename(new, file) == -1)
146 err(1, "rename(%s, %s)", new, file);
149 for (j = 0; j < files; j++) {
150 sprintf(file,"p%05d.%05ld", pid, j);
151 if (unlink(file) == -1)
152 warn("unlink(%s)", file);
155 if (chdir("..") == -1)
162 main(int argc, char *argv[])
164 pid_t pids[PARALLEL];
169 fprintf(stderr, "Usage %s <path> <files>\n", argv[0]);
173 files = atol(argv[2]) / PARALLEL;
174 fprintf(stderr, "Using %ld inodes per dir. %d threads. %ld inodes in total\n",
175 files, PARALLEL, files * PARALLEL);
178 while ((time(NULL) - start) < RUNTIME && e == 0) {
179 fprintf(stderr, "Loop #%d\n", ++n);
180 for (i = 0; i < PARALLEL; i++) {
181 if ((pids[i] = fork()) == 0)
186 for (i = 0; i < PARALLEL; i++) {
187 if (waitpid(pids[i], &status, 0) == -1)
188 err(1, "waitpid(%d)", pids[i]);
190 if (WIFSIGNALED(status))
192 "pid %d exit signal %d\n",
193 pids[i], WTERMSIG(status));
195 e += status == 0 ? 0 : 1;
197 // system("(cd MNTPOINT; umount MNTPOINT) > /dev/null 2>&1");