From owner-svn-src-user@freebsd.org Fri Apr 28 12:07:24 2017 Return-Path: Delivered-To: svn-src-user@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F0745D547F5 for ; Fri, 28 Apr 2017 12:07:24 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CB48D194F; Fri, 28 Apr 2017 12:07:24 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3SC7N2Z034172; Fri, 28 Apr 2017 12:07:23 GMT (envelope-from pho@FreeBSD.org) Received: (from pho@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3SC7NG1034170; Fri, 28 Apr 2017 12:07:23 GMT (envelope-from pho@FreeBSD.org) Message-Id: <201704281207.v3SC7NG1034170@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org using -f From: Peter Holm Date: Fri, 28 Apr 2017 12:07:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r317549 - 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.23 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: Fri, 28 Apr 2017 12:07:25 -0000 Author: pho Date: Fri Apr 28 12:07:23 2017 New Revision: 317549 URL: https://svnweb.freebsd.org/changeset/base/317549 Log: Added two new nullfs test scenarios. Sponsored by: Dell EMC Isilon Added: user/pho/stress2/misc/nullfs21.sh (contents, props changed) user/pho/stress2/misc/nullfs22.sh (contents, props changed) Added: user/pho/stress2/misc/nullfs21.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/nullfs21.sh Fri Apr 28 12:07:23 2017 (r317549) @@ -0,0 +1,73 @@ +#!/bin/sh + +# +# Copyright (c) 2016 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 + +# mv removes the file. This is OK on FreeBSD. +# This is handled on Linux with "mount --bind". + +. ../default.cfg + +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 512m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs -n -b 4096 -f 512 -i 1024 md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint + +mp2=${mntpoint}2 +[ -d $mp2 ] || mkdir -p $mp2 +mount | grep -wq $mp2 && umount $mp2 +mount -t nullfs $mntpoint $mp2 + +touch $mntpoint/file + +# mv's rename(2) fails as this is a "cross mount" -> +# rm dst; cp src dst; rm src + +mv $mp2/file $mountpoint/file +[ -f $mntpoint/file ] || + { ls -ali $mntpoint $mp2; status=0; } +# { echo FAIL; ls -ali $mntpoint $mp2; status=1; } + +while mount | grep $mp2 | grep -q nullfs; do + umount $mp2 || sleep 1 +done +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + n=$((n + 1)) + [ $n -gt 30 ] && { echo FAIL; status=2; } +done +mdconfig -d -u $mdstart +exit $status Added: user/pho/stress2/misc/nullfs22.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/nullfs22.sh Fri Apr 28 12:07:23 2017 (r317549) @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright (c) 2016 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$ +# + +# fcntl(2) locking scenario, using UFS and a nullfs mount. +# No problems seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > nullfs22.c +mycc -o nullfs22 -Wall -Wextra -O0 -g nullfs22.c || exit 1 +rm -f nullfs22.c + +mp2=${mntpoint}2 +[ -d $mp2 ] || mkdir -p $mp2 +mount | grep -q "on $mp2 " && umount $mp2 +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 512m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs -n md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +mount -t nullfs $mntpoint $mp2 + +/tmp/nullfs22 $mntpoint $mp2 +status=$? + +while mount | grep -q "on $mp2 "; do + umount $mp2 +done +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/nullfs22 +exit $status +EOF +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 1024 +#define N (512) +#define PARALLEL 4 + +#define DONE 1 +#define SYNC 0 + +int fd; +volatile u_int *share; +char name1[80], name2[80]; + +static void +ahandler(int s __unused) +{ + fprintf(stderr, "In alarm handler\n"); + unlink(name1); + _exit(1); +} + +void +add(int n, int increment) +{ + struct flock fl; + off_t pos; + long val, oval; + int r; + + pos = n * sizeof(val); + memset(&fl, 0, sizeof(fl)); + fl.l_start = pos; + fl.l_len = sizeof(val); + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + + while (fcntl(fd, F_SETLKW, &fl) < 0) { + if (errno != EAGAIN) + err(1, "F_SETLKW (child)"); + usleep(100); + } + + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + oval = 999999; + while ((r = read(fd, &val, sizeof(val)) != sizeof(val))) { + if (r == -1 && errno != EAGAIN) + err(1, "read"); + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + } + oval = val; + val = val + increment; +#if defined(DEBUG) + fprintf(stderr, "add(%d, %d) @ pos %ld: %ld = %ld + %d\n", + n, increment, (long)pos, val, oval, increment); +#endif + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + while ((r = write(fd, &val, sizeof(val)) != sizeof(val))) { + if (r == -1 && errno != EAGAIN) + err(1, "write"); + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + } + + fl.l_type = F_UNLCK; + if (fcntl(fd, F_SETLK, &fl) < 0) + err(1, "F_UNLCK"); + +} + +void +count(int val) +{ + int i, j; + char help[80], *name; + + if (val == 1) + name = name1; + else + name = name2; + snprintf(help, sizeof(help), "%s %d %s", __func__, val, name); + setproctitle("%s", help); + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != 2 * PARALLEL) + ; + + /* Need to re-open after a fork() */ + close(fd); + if ((fd = open(name, O_RDWR)) == -1) + err(1, "open(%s)", name); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < N; j++) + add(j, val); + } + + atomic_add_int(&share[DONE], 1); + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + off_t len; + size_t mlen; + long val, sum; + int i, s, stat; + + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + + mlen = PAGE_SIZE; + if ((share = mmap(NULL, mlen, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + snprintf(name1, sizeof(name1), "%s/work", argv[1]); + snprintf(name2, sizeof(name2), "%s/work", argv[2]); + signal(SIGALRM, ahandler); + alarm(300); + if ((fd = open(name1, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) + err(1, "open(%s)", name1); + len = N * sizeof(val); + if (ftruncate(fd, len) == -1) + err(1, "ftruncate"); + + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + count(1); + } + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + count(-1); + } + + while (share[DONE] != 2 * PARALLEL) + usleep(10000); + + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + sum = 0; + for (i = 0; i < N; i++) { + if (read(fd, &val, sizeof(val)) != sizeof(val)) + err(1, "Final read"); + if (val != 0) + fprintf(stderr, "index %d: %ld\n", i, val); + sum += val; + } + if (sum != 0) + fprintf(stderr, "FAIL\n"); + unlink(name1); + + s = 0; + for (i = 0; i < PARALLEL; i++) { + wait(&stat); + s += WEXITSTATUS(stat); + wait(&stat); + s += WEXITSTATUS(stat); + } + + close(fd); + + return (sum != 0 || s != 0); +}