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 50bsdlabel -w md$mdstart auto 51newfs md${mdstart}$part > /dev/null 2>&1 52mount /dev/md${mdstart}$part $mntpoint 53export RUNDIR=$mntpoint/stressX 54for i in `jot 25`; do 55 (cd /$mntpoint; /tmp/umountf3) & 56done 57sleep $((4 * 60)) 58echo "umount -f $mntpoint" 59umount -f $mntpoint 60while pkill umountf3; do :; done 61wait 62mdconfig -d -u $mdstart 63rm -f $D /tmp/umountf3 64exit 65EOF 66 67#include <sys/param.h> 68#include <sys/stat.h> 69#include <err.h> 70#include <fcntl.h> 71#include <stdio.h> 72#include <stdlib.h> 73#include <unistd.h> 74 75static unsigned long size = 1024 * 1024 * 2; 76 77int 78main(int argc, char **argv) 79{ 80 int buf[1024], index, to, n; 81 int fd; 82 char file[128]; 83 84 sprintf(file,"p%06d", getpid()); 85 if ((fd = open(file, O_CREAT | O_RDWR, 0666)) == -1) 86 err(1, "creat(%s)", file); 87 88 to = sizeof(buf); 89 for (;;) { 90 index = 0; 91 while (index < size) { 92 if (index + to > size) 93 to = size - index; 94 index += to; 95 if (write(fd, buf, to) != to) 96 err(1, "write(%s), %s:%d", file, __FILE__, __LINE__); 97 } 98 99 if (lseek(fd, 0, 0) == -1) 100 err(1, "lseek"); 101 index = 0; 102 while (index < size) { 103 if (index + to > size) 104 to = size - index; 105 if ((n = read(fd, buf, to)) != to) 106 err(1, "rw read(%d, %d, %d). %s.%d", n, to, index, __FILE__, __LINE__); 107 index += to; 108 } 109 if (lseek(fd, 0, 0) == -1) 110 err(1, "lseek"); 111 } 112 113 if (close(fd) == -1) 114 err(1, "close(%s), %s:%d", file, __FILE__, __LINE__); 115 if (unlink(file) == -1) 116 err(1, "unlink(%s), %s:%d", file, __FILE__, __LINE__); 117 return (0); 118} 119