xref: /dragonfly/test/stress/stress2/misc/umountf3.sh (revision 86d7f5d3)
1*86d7f5d3SJohn Marino#!/bin/sh
2*86d7f5d3SJohn Marino
3*86d7f5d3SJohn Marino#
4*86d7f5d3SJohn Marino# Copyright (c) 2008 Peter Holm <pho@FreeBSD.org>
5*86d7f5d3SJohn Marino# All rights reserved.
6*86d7f5d3SJohn Marino#
7*86d7f5d3SJohn Marino# Redistribution and use in source and binary forms, with or without
8*86d7f5d3SJohn Marino# modification, are permitted provided that the following conditions
9*86d7f5d3SJohn Marino# are met:
10*86d7f5d3SJohn Marino# 1. Redistributions of source code must retain the above copyright
11*86d7f5d3SJohn Marino#    notice, this list of conditions and the following disclaimer.
12*86d7f5d3SJohn Marino# 2. Redistributions in binary form must reproduce the above copyright
13*86d7f5d3SJohn Marino#    notice, this list of conditions and the following disclaimer in the
14*86d7f5d3SJohn Marino#    documentation and/or other materials provided with the distribution.
15*86d7f5d3SJohn Marino#
16*86d7f5d3SJohn Marino# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*86d7f5d3SJohn Marino# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*86d7f5d3SJohn Marino# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*86d7f5d3SJohn Marino# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*86d7f5d3SJohn Marino# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*86d7f5d3SJohn Marino# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*86d7f5d3SJohn Marino# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*86d7f5d3SJohn Marino# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*86d7f5d3SJohn Marino# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*86d7f5d3SJohn Marino# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*86d7f5d3SJohn Marino# SUCH DAMAGE.
27*86d7f5d3SJohn Marino#
28*86d7f5d3SJohn Marino# $FreeBSD$
29*86d7f5d3SJohn Marino#
30*86d7f5d3SJohn Marino
31*86d7f5d3SJohn Marino# Demonstrate livelock with "umount -f" seen both with UFS and MSDOS
32*86d7f5d3SJohn Marino
33*86d7f5d3SJohn Marino[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
34*86d7f5d3SJohn Marino
35*86d7f5d3SJohn Marino. ../default.cfg
36*86d7f5d3SJohn Marino
37*86d7f5d3SJohn MarinoD=$diskimage
38*86d7f5d3SJohn Marinodede $D 1m 1k || exit 1
39*86d7f5d3SJohn Marino
40*86d7f5d3SJohn Marinoodir=`pwd`
41*86d7f5d3SJohn Marino
42*86d7f5d3SJohn Marinocd /tmp
43*86d7f5d3SJohn Marinosed '1,/^EOF/d' < $odir/$0 > umountf3.c
44*86d7f5d3SJohn Marinocc -o umountf3 -Wall umountf3.c
45*86d7f5d3SJohn Marinorm -f umountf3.c
46*86d7f5d3SJohn Marinocd $odir
47*86d7f5d3SJohn Marino
48*86d7f5d3SJohn Marino
49*86d7f5d3SJohn Marinomount | grep "$mntpoint" | grep md${mdstart} > /dev/null && umount $mntpoint
50*86d7f5d3SJohn Marinomdconfig -l | grep md${mdstart} > /dev/null &&  mdconfig -d -u ${mdstart}
51*86d7f5d3SJohn Marino
52*86d7f5d3SJohn Marinomdconfig -a -t vnode -f $D -u ${mdstart}
53*86d7f5d3SJohn Marinobsdlabel -w md${mdstart} auto
54*86d7f5d3SJohn Marinonewfs md${mdstart}${part} > /dev/null 2>&1
55*86d7f5d3SJohn Marinomount /dev/md${mdstart}${part} $mntpoint
56*86d7f5d3SJohn Marino#newfs_msdos -F 32 -b 8192 /dev/md${mdstart}a
57*86d7f5d3SJohn Marino#mount -t msdosfs /dev/md${mdstart}a $mntpoint
58*86d7f5d3SJohn Marinoexport RUNDIR=$mntpoint/stressX
59*86d7f5d3SJohn Marinofor i in `jot 25`; do
60*86d7f5d3SJohn Marino	(cd /$mntpoint; /tmp/umountf3) &
61*86d7f5d3SJohn Marinodone
62*86d7f5d3SJohn Marinosleep $((4 * 60))
63*86d7f5d3SJohn Marinoecho "umount -f $mntpoint"
64*86d7f5d3SJohn Marinoumount -f $mntpoint
65*86d7f5d3SJohn Marinomdconfig -d -u $mdstart
66*86d7f5d3SJohn Marinorm -f $D /tmp/umountf3
67*86d7f5d3SJohn Marinoexit
68*86d7f5d3SJohn MarinoEOF
69*86d7f5d3SJohn Marino
70*86d7f5d3SJohn Marino#include <stdio.h>
71*86d7f5d3SJohn Marino#include <stdlib.h>
72*86d7f5d3SJohn Marino#include <unistd.h>
73*86d7f5d3SJohn Marino#include <fcntl.h>
74*86d7f5d3SJohn Marino#include <sys/stat.h>
75*86d7f5d3SJohn Marino#include <sys/param.h>
76*86d7f5d3SJohn Marino#include <err.h>
77*86d7f5d3SJohn Marino
78*86d7f5d3SJohn Marinostatic unsigned long size = 1024 * 1024 * 2;
79*86d7f5d3SJohn Marino
80*86d7f5d3SJohn Marinoint
81*86d7f5d3SJohn Marinomain(int argc, char **argv)
82*86d7f5d3SJohn Marino{
83*86d7f5d3SJohn Marino	int buf[1024], index, to, n;
84*86d7f5d3SJohn Marino	int fd;
85*86d7f5d3SJohn Marino	char file[128];
86*86d7f5d3SJohn Marino
87*86d7f5d3SJohn Marino
88*86d7f5d3SJohn Marino	sprintf(file,"p%06d", getpid());
89*86d7f5d3SJohn Marino	if ((fd = open(file, O_CREAT | O_RDWR, 0666)) == -1)
90*86d7f5d3SJohn Marino		err(1, "creat(%s)", file);
91*86d7f5d3SJohn Marino
92*86d7f5d3SJohn Marino	to = sizeof(buf);
93*86d7f5d3SJohn Marino	for (;;) {
94*86d7f5d3SJohn Marino		index = 0;
95*86d7f5d3SJohn Marino		while (index < size) {
96*86d7f5d3SJohn Marino			if (index + to > size)
97*86d7f5d3SJohn Marino				to = size - index;
98*86d7f5d3SJohn Marino			index += to;
99*86d7f5d3SJohn Marino			if (write(fd, buf, to) != to)
100*86d7f5d3SJohn Marino				err(1, "write(%s), %s:%d", file, __FILE__, __LINE__);
101*86d7f5d3SJohn Marino		}
102*86d7f5d3SJohn Marino
103*86d7f5d3SJohn Marino		if (lseek(fd, 0, 0) == -1)
104*86d7f5d3SJohn Marino			err(1, "lseek");
105*86d7f5d3SJohn Marino		index = 0;
106*86d7f5d3SJohn Marino		while (index < size) {
107*86d7f5d3SJohn Marino			if (index + to > size)
108*86d7f5d3SJohn Marino				to = size - index;
109*86d7f5d3SJohn Marino			if ((n = read(fd, buf, to)) != to)
110*86d7f5d3SJohn Marino				err(1, "rw read(%d, %d, %d). %s.%d", n, to, index,  __FILE__, __LINE__);
111*86d7f5d3SJohn Marino			index += to;
112*86d7f5d3SJohn Marino		}
113*86d7f5d3SJohn Marino		if (lseek(fd, 0, 0) == -1)
114*86d7f5d3SJohn Marino			err(1, "lseek");
115*86d7f5d3SJohn Marino	}
116*86d7f5d3SJohn Marino
117*86d7f5d3SJohn Marino	if (close(fd) == -1)
118*86d7f5d3SJohn Marino		err(1, "close(%s), %s:%d", file, __FILE__, __LINE__);
119*86d7f5d3SJohn Marino	if (unlink(file) == -1)
120*86d7f5d3SJohn Marino		err(1, "unlink(%s), %s:%d", file, __FILE__, __LINE__);
121*86d7f5d3SJohn Marino	return (0);
122*86d7f5d3SJohn Marino}
123