xref: /freebsd/tools/test/stress2/misc/umountf3.sh (revision a18b956b73cee784e5c422d20fd0e4dabebd7eee)
1#!/bin/sh
2
3#
4# Copyright (c) 2008 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# Demonstrate livelock with "umount -f" seen both with UFS and MSDOS
30
31[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
32
33. ../default.cfg
34
35D=$diskimage
36dd if=/dev/zero of=$D bs=1m count=1k status=none || exit 1
37
38odir=`pwd`
39
40cd /tmp
41sed '1,/^EOF/d' < $odir/$0 > umountf3.c
42mycc -o umountf3 -Wall umountf3.c
43rm -f umountf3.c
44cd $odir
45
46mount | grep "$mntpoint" | grep md$mdstart > /dev/null && umount $mntpoint
47mdconfig -l | grep md$mdstart > /dev/null &&  mdconfig -d -u $mdstart
48
49mdconfig -a -t vnode -f $D -u $mdstart
50newfs md$mdstart > /dev/null 2>&1
51mount /dev/md$mdstart $mntpoint
52export RUNDIR=$mntpoint/stressX
53for i in `jot 25`; do
54	(cd /$mntpoint; /tmp/umountf3) &
55done
56sleep $((4 * 60))
57echo "umount -f $mntpoint"
58umount -f $mntpoint
59while pkill umountf3; do :; done
60wait
61mdconfig -d -u $mdstart
62rm -f $D /tmp/umountf3
63exit
64EOF
65
66#include <sys/param.h>
67#include <sys/stat.h>
68#include <err.h>
69#include <fcntl.h>
70#include <stdio.h>
71#include <stdlib.h>
72#include <unistd.h>
73
74static unsigned long size = 1024 * 1024 * 2;
75
76int
77main(int argc, char **argv)
78{
79	int buf[1024], index, to, n;
80	int fd;
81	char file[128];
82
83	sprintf(file,"p%06d", getpid());
84	if ((fd = open(file, O_CREAT | O_RDWR, 0666)) == -1)
85		err(1, "creat(%s)", file);
86
87	to = sizeof(buf);
88	for (;;) {
89		index = 0;
90		while (index < size) {
91			if (index + to > size)
92				to = size - index;
93			index += to;
94			if (write(fd, buf, to) != to)
95				err(1, "write(%s), %s:%d", file, __FILE__, __LINE__);
96		}
97
98		if (lseek(fd, 0, 0) == -1)
99			err(1, "lseek");
100		index = 0;
101		while (index < size) {
102			if (index + to > size)
103				to = size - index;
104			if ((n = read(fd, buf, to)) != to)
105				err(1, "rw read(%d, %d, %d). %s.%d", n, to, index,  __FILE__, __LINE__);
106			index += to;
107		}
108		if (lseek(fd, 0, 0) == -1)
109			err(1, "lseek");
110	}
111
112	if (close(fd) == -1)
113		err(1, "close(%s), %s:%d", file, __FILE__, __LINE__);
114	if (unlink(file) == -1)
115		err(1, "unlink(%s), %s:%d", file, __FILE__, __LINE__);
116	return (0);
117}
118