Date: Sun, 4 Mar 2012 12:52:00 +0000 (UTC) From: Peter Holm <pho@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r232489 - projects/stress2/misc Message-ID: <201203041252.q24Cq0vW035226@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <pho@FreeBSD.org> +# 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 <err.h> +#include <errno.h> +#include <fcntl.h> +#include <sched.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <strings.h> +#include <sys/param.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/wait.h> +#include <time.h> +#include <unistd.h> + +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); +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203041252.q24Cq0vW035226>