From owner-svn-src-user@FreeBSD.ORG Mon Oct 21 06:55:07 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B90AE33F; Mon, 21 Oct 2013 06:55:07 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 979602ED8; Mon, 21 Oct 2013 06:55:07 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9L6t7sA090768; Mon, 21 Oct 2013 06:55:07 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9L6t7PW090766; Mon, 21 Oct 2013 06:55:07 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201310210655.r9L6t7PW090766@svn.freebsd.org> From: Peter Holm Date: Mon, 21 Oct 2013 06:55:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256831 - user/pho/stress2/misc X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Oct 2013 06:55:07 -0000 Author: pho Date: Mon Oct 21 06:55:07 2013 New Revision: 256831 URL: http://svnweb.freebsd.org/changeset/base/256831 Log: Added test scenario for per-filesystem soft-updates lock. Sponsored by: EMC / Isilon storage division Added: user/pho/stress2/misc/pfl.sh (contents, props changed) Added: user/pho/stress2/misc/pfl.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/pfl.sh Mon Oct 21 06:55:07 2013 (r256831) @@ -0,0 +1,167 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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 + +# Test scenario for the change of a global SU lock to a per filesystem lock. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pfl.c +cc -o pfl -Wall -Wextra pfl.c || exit 1 +rm -f pfl.c +cd $here + +mp1=$mntpoint +mp2=${mntpoint}2 +[ -d $mp2 ] || mkdir -p $mp2 +md1=$mdstart +md2=$((mdstart + 1)) + +opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-j" || echo "-U") +mount | grep $mp1 | grep -q /dev/md && umount -f $mp1 +mdconfig -l | grep -q md$md1 && mdconfig -d -u $md1 +mdconfig -a -t swap -s 2g -u $md1 +bsdlabel -w md$md1 auto +newfs $opt md${md1}$part > /dev/null +mount /dev/md${md1}$part $mp1 +chmod 777 $mp1 + +mount | grep $mp2 | grep -q /dev/md && umount -f $mp2 +mdconfig -l | grep -q md$md2 && mdconfig -d -u $md2 +mdconfig -a -t swap -s 2g -u $md2 +bsdlabel -w md$md2 auto +newfs $opt md${md2}$part > /dev/null +mount /dev/md${md2}$part $mp2 +chmod 777 $mp2 + +su ${testuser} -c "cd $mp1; /tmp/pfl" & +su ${testuser} -c "cd $mp2; /tmp/pfl" & +wait; wait + +while mount | grep "$mp2 " | grep -q /dev/md; do + umount $mp2 || sleep 1 +done +mdconfig -d -u $md2 +while mount | grep "$mp1 " | grep -q /dev/md; do + umount $mp1 || sleep 1 +done +mdconfig -d -u $md1 +exit + +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 10 +static int size = 10000; + +void +test(void) +{ + int fd, i, j; + pid_t pid; + char file[128]; + + pid = getpid(); + sprintf(file,"d%05d", pid); + if (mkdir(file, 0740) == -1) + err(1, "mkdir(%s)", file); + chdir(file); + for (j = 0; j < size; j++) { + sprintf(file,"p%05d.%05d", pid, j); + if ((fd = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1) { + if (errno != EINTR) { + warn("mkdir(%s). %s:%d", file, __FILE__, __LINE__); + unlink("continue"); + break; + } + } + if (arc4random() % 100 < 10) + if (write(fd, "1", 1) != 1) + err(1, "write()"); + close(fd); + + } + sleep(3); + + for (i = --j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + + } + chdir(".."); + sprintf(file,"d%05d", pid); + if (rmdir(file) == -1) + err(3, "unlink(%s)", file); +} + +int +main(void) +{ + int fd, i, j, k; + + umask(0); + if ((fd = open("continue", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(fd); + for (i = 0; i < 1; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) { + for (k = 0; k < 50; k++) + test(); + exit(0); + } + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + + if (access("continue", R_OK) == -1) { + fprintf(stderr, "Loop #%d\n", i + 1); fflush(stderr); + break; + } + } + unlink("continue"); + + return (0); +}