Date: Wed, 6 Apr 2011 12:05:09 +0000 (UTC) From: Peter Holm <pho@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r220383 - projects/stress2/misc Message-ID: <201104061205.p36C59t5087708@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pho Date: Wed Apr 6 12:05:09 2011 New Revision: 220383 URL: http://svn.freebsd.org/changeset/base/220383 Log: Add the scenarios used to show the premature "out of space" problem for Soft Updates, fixed in R220374. Added: projects/stress2/misc/linger.sh (contents, props changed) projects/stress2/misc/linger2.sh (contents, props changed) Added: projects/stress2/misc/linger.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/stress2/misc/linger.sh Wed Apr 6 12:05:09 2011 (r220383) @@ -0,0 +1,166 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 + +# Demonstrate premature "out of inodes" problem with SU + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > linger.c +cc -o linger -Wall -O2 linger.c +rm -f linger.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 1g -u $mdstart +bsdlabel -w md$mdstart auto +[ $# -eq 1 ] && opt="$1" +[ $# -eq 0 ] && opt=-U # No argument == -U +echo "newfs $opt md${mdstart}$part" +newfs $opt md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +if ! su ${testuser} -c "cd $mntpoint; /tmp/linger $size"; then + min=2 + [ -r $mntpoint/.sujournal ] && min=3 + r=`df -hi $mntpoint | head -1` + echo " $r" + for i in `jot 10`; do + r=`df -hi $mntpoint | tail -1` + echo "`date '+%T'` $r" + [ `echo $r | awk '{print $6}'` = $min ] && break + sleep 10 + done + ls -lR $mntpoint +fi + +while mount | grep "$mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/linger +exit +EOF +#include <err.h> +#include <errno.h> +#include <fcntl.h> +#include <sched.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/mount.h> +#include <sys/param.h> +#include <sys/stat.h> +#include <sys/wait.h> +#include <unistd.h> + +#define PARALLEL 10 +static int size = 14130; /* 6 free inodes */ + +int +test(void) +{ + int error = 0, fd, i, j; + pid_t pid; + char file[128]; + + for (;;) { + if (access("rendezvous", R_OK) == 0) + break; + sched_yield(); + } + pid = getpid(); + for (j = 0; j < size; j++) { + sprintf(file,"p%05d.%05d", pid, j); + if ((fd = creat(file, 0660)) == -1) { + if (errno != EINTR) { + warn("creat(%s). %s:%d", file, __FILE__, __LINE__); + unlink("continue"); + error = 1; + break; + } + } + if (fd != -1 && close(fd) == -1) + err(2, "close(%d)", j); + + } + sleep(3); + + if (error == 0) + j--; + for (i = j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + + } + return (0); +} + +int +main(void) +{ + int error = 0, fd, i, j, status; + + umask(0); + if ((fd = open("continue", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(fd); + for (i = 0; i < 100; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) { + test(); + exit(0); + } + } + + if ((fd = open("rendezvous", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(fd); + + for (j = 0; j < PARALLEL; j++) { + wait(&status); + error += status; + } + + unlink("rendezvous"); + if (access("continue", R_OK) == -1) { + fprintf(stderr, "Loop #%d\n", i + 1); + break; + } + } + unlink("continue"); + + return (error != 0); +} Added: projects/stress2/misc/linger2.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/stress2/misc/linger2.sh Wed Apr 6 12:05:09 2011 (r220383) @@ -0,0 +1,176 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 + +# Variation of linger.sh, with emphasis on blocks. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > linger2.c +cc -o linger2 -Wall -O2 linger2.c +rm -f linger2.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 1g -u $mdstart +bsdlabel -w md$mdstart auto +[ $# -eq 1 ] && opt="$1" +[ $# -eq 0 ] && opt=-U # The default is "-U" +echo "newfs $opt md${mdstart}$part" +newfs $opt md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +min=24 +[ -r $mntpoint/.sujournal ] && { size=88; min=8232; } +if ! su ${testuser} -c "cd $mntpoint; /tmp/linger2 $size"; then + ls -lR $mntpoint + r=`df -i $mntpoint | head -1` + echo " $r" + for i in `jot 10`; do + r=`df -ik $mntpoint | tail -1` + echo "`date '+%T'` $r" + [ `echo $r | awk '{print $3}'` -le $min ] && break + sleep 10 + done +fi + +while mount | grep "$mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/linger2 +exit +EOF +#include <err.h> +#include <errno.h> +#include <fcntl.h> +#include <sched.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/param.h> +#include <sys/stat.h> +#include <sys/wait.h> +#include <unistd.h> + +#define PARALLEL 10 +static int size = 89; + +int +test(void) +{ + int error = 0, fd, i, j; + pid_t pid; + char file[128]; + char *buf; + + for (;;) { + if (access("rendezvous", R_OK) == 0) + break; + sched_yield(); + } + pid = getpid(); + buf = malloc(1024 * 1024); + for (j = 0; j < size; j++) { + sprintf(file,"p%05d.%05d", pid, j); + if ((fd = creat(file, 0660)) == -1) { + if (errno != EINTR) { + warn("creat(%s). %s:%d", file, __FILE__, __LINE__); + unlink("continue"); + error = 1; + break; + } + } + if (write(fd, buf, 1024 * 1024) != 1024 * 1024) { + warn("write()"); + unlink("continue"); + error = 1; + break; + } + if (fd != -1 && close(fd) == -1) + err(2, "close(%d)", j); + + } + sleep(3); + + if (error == 0) + j--; + for (i = j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + warn("unlink(%s)", file); + + } + return (error); +} + +int +main(int argc, char **argv) +{ + int error = 0, fd, i, j, status; + + if (argc == 2) + size = atoi(argv[1]); + + umask(0); + if ((fd = open("continue", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(fd); + for (i = 0; i < 200; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + exit(test()); + } + + if ((fd = open("rendezvous", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(fd); + + for (j = 0; j < PARALLEL; j++) { + wait(&status); + error += status; + } + + unlink("rendezvous"); + if (access("continue", R_OK) == -1) { + fprintf(stderr, "Loop #%d\n", i + 1); + break; + } +// sleep(60); /* Debug */ + } + unlink("continue"); + + return (error != 0); +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104061205.p36C59t5087708>