From owner-svn-src-projects@FreeBSD.ORG Sun Mar 4 12:52:00 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id D2BE8106566B; Sun, 4 Mar 2012 12:52:00 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C22818FC0A; Sun, 4 Mar 2012 12:52:00 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q24Cq099035227; Sun, 4 Mar 2012 12:52:00 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q24Cq0vW035226; Sun, 4 Mar 2012 12:52:00 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201203041252.q24Cq0vW035226@svn.freebsd.org> From: Peter Holm Date: Sun, 4 Mar 2012 12:52:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r232489 - projects/stress2/misc X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Mar 2012 12:52:00 -0000 Author: pho Date: Sun Mar 4 12:52:00 2012 New Revision: 232489 URL: http://svn.freebsd.org/changeset/base/232489 Log: Scenario for rename(2) and umount returning "Device busy" added. Added: projects/stress2/misc/rename7.sh (contents, props changed) Added: projects/stress2/misc/rename7.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/stress2/misc/rename7.sh Sun Mar 4 12:52:00 2012 (r232489) @@ -0,0 +1,160 @@ +#!/bin/sh + +# +# Copyright (c) 2012 Peter Holm +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# After a few runs this will happen: +# $ umount /mnt +# umount: unmount of /mnt failed: Device busy +# $ umount -f /mnt +# $ + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename7.c +cc -o rename7 -Wall -Wextra -O2 rename7.c +rm -f rename7.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs -U md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +su ${testuser} -c "cd $mntpoint; /tmp/rename7" + +for i in `jot 10`; do + mount | grep -q md${mdstart}$part && \ + umount $mntpoint && mdconfig -d -u $mdstart && break +done +if mount | grep -q md${mdstart}$part; then + echo "Test failed" + exit 1 +fi +rm -d /tmp/rename7 +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char *logfile = "test.log"; +int need_reopen = 1; +pid_t wpid, spid; + +void +handler(int s __unused) +{ + need_reopen = 1; +} + +void +cleanup() +{ + kill(wpid, SIGINT); + kill(spid, SIGINT); +} + +void +r1(void) +{ + int i; + struct stat sb1, sb2; + + for (i = 0; i < 800000; i++) { + rename(logfile, "r1"); + if (stat("r1", &sb1) == 0 && stat("r2", &sb2) == 0 && + bcmp(&sb1, &sb2, sizeof(sb1)) == 0) { + fprintf(stderr, "Bummer\n"); + system("ls -ail"); + } + } +} + +void +r2(void) +{ + int i; + struct stat sb1, sb2; + +// _exit(0); /* No problems with only r1 running */ + for (i = 0; i < 800000; i++) { + rename(logfile, "r2"); + if (stat("r1", &sb1) == 0 && stat("r2", &sb2) == 0 && + bcmp(&sb1, &sb2, sizeof(sb1)) == 0) { + fprintf(stderr, "Bummer\n"); + system("ls -ail"); + } + } +} +int +main(void) +{ + pid_t wpid, spid; + int fd, i; + + if ((wpid = fork()) == 0) + r1(); + if ((spid = fork()) == 0) + r2(); + + setproctitle("main"); + atexit(cleanup); + + for (i = 0; i < 800000; i++) { + if ((fd = open(logfile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) + warn("creat(%s)", logfile); + close(fd); + } + + + kill(wpid, SIGINT); + kill(spid, SIGINT); + wait(NULL); + wait(NULL); + + return (0); +}