From owner-svn-src-user@freebsd.org Mon Mar 12 21:50:00 2018 Return-Path: Delivered-To: svn-src-user@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 71517F4E062 for ; Mon, 12 Mar 2018 21:50:00 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 23D0D76070; Mon, 12 Mar 2018 21:50:00 +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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1A5FA113EE; Mon, 12 Mar 2018 21:50:00 +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 w2CLnxAp043403; Mon, 12 Mar 2018 21:49:59 GMT (envelope-from pho@FreeBSD.org) Received: (from pho@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2CLnxwo043401; Mon, 12 Mar 2018 21:49:59 GMT (envelope-from pho@FreeBSD.org) Message-Id: <201803122149.w2CLnxwo043401@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org using -f From: Peter Holm Date: Mon, 12 Mar 2018 21:49:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r330816 - user/pho/stress2/misc X-SVN-Group: user X-SVN-Commit-Author: pho X-SVN-Commit-Paths: user/pho/stress2/misc X-SVN-Commit-Revision: 330816 X-SVN-Commit-Repository: base 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.25 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, 12 Mar 2018 21:50:00 -0000 Author: pho Date: Mon Mar 12 21:49:59 2018 New Revision: 330816 URL: https://svnweb.freebsd.org/changeset/base/330816 Log: Added two tests for triggering a "newbuf" deadlock. Sponsored by: Dell EMC Isilon Added: user/pho/stress2/misc/fdatasync.sh (contents, props changed) user/pho/stress2/misc/fdatasync2.sh (contents, props changed) Added: user/pho/stress2/misc/fdatasync.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/fdatasync.sh Mon Mar 12 21:49:59 2018 (r330816) @@ -0,0 +1,202 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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$ +# + +# fdatasync(2) fuzz. + +# Deadlock seen: +# https://people.freebsd.org/~pho/stress/log/fdatasync.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +dir=$RUNDIR +nfiles=500 +[ `df -i $dir | tail -1 | awk '{print $7}'` -lt $nfiles ] && exit 0 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > fdatasync.c +rm -f /tmp/fdatasync +mycc -o fdatasync -Wall -Wextra -O2 -g fdatasync.c -lpthread || exit 1 +rm -f fdatasync.c + +mkdir -p $dir && chmod 777 $dir + +cd $dir +jot $nfiles | xargs touch +jot $nfiles | xargs chmod 666 +cd $odir + +(cd /tmp; /tmp/fdatasync $dir) +e=$? + +rm -rf $dir/* /tmp/fdatasync +exit $e +EOF +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define RUNTIME 180 +#define THREADS 2 + +static int fd[900]; +static u_int32_t r[N]; +static char *args[2]; + +static unsigned long +makearg(void) +{ + unsigned long val; + + val = arc4random(); +#if defined(__LP64__) + val = (val << 32) | arc4random(); + val = val & 0x00007fffffffffffUL; +#endif + + return(val); +} + +static void * +test(void *arg __unused) +{ + FTS *fts; + FTSENT *p; + int ftsoptions, i, n; + + ftsoptions = FTS_PHYSICAL; + + for (;;) { + for (i = 0; i < N; i++) + r[i] = arc4random(); + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + i = n = 0; + while ((p = fts_read(fts)) != NULL) { + if (fd[i] > 0) + close(fd[i]); + if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) + if ((fd[i] = open(p->fts_path, O_WRONLY)) == + -1) + continue; + if (ftruncate(fd[i], 0) != 0) + err(1, "ftruncate"); + i++; + i = i % nitems(fd); + } + + if (fts_close(fts) == -1) + err(1, "fts_close()"); + sleep(1); + } + return(0); +} + +static void * +calls(void *arg __unused) +{ + off_t offset; + time_t start; + int fd2; + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + fd2 = makearg() % nitems(fd) + 3; + offset = makearg(); + if (lseek(fd2, offset - 1, SEEK_SET) != -1) { + if (write(fd2, "x", 1) != 1) + if (errno != EBADF && errno != ENOSPC && + errno != E2BIG && errno != ESTALE && + errno != EFBIG) + warn("write"); + } else + if (errno != EBADF) + warn("lseek"); + if (fdatasync(fd2) == -1) + if (errno != EBADF) + warn("x"); + + } + + return (0); +} + +int +main(int argc, char **argv) +{ + struct passwd *pw; + pthread_t rp, cp[THREADS]; + int e, i; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + args[0] = argv[1]; + args[1] = 0; + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "failed to resolve nobody"); + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) + errc(1, e, "pthread_create"); + usleep(1000); + for (i = 0; i < THREADS; i++) + if ((e = pthread_create(&cp[i], NULL, calls, NULL)) != 0) + errc(1, e, "pthread_create"); + for (i = 0; i < THREADS; i++) + pthread_join(cp[i], NULL); + + return (0); +} Added: user/pho/stress2/misc/fdatasync2.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/fdatasync2.sh Mon Mar 12 21:49:59 2018 (r330816) @@ -0,0 +1,201 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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$ +# + +# fdatasync(2) fuzz. Variation of fdatasync.sh. +# https://people.freebsd.org/~pho/stress/log/fdatasync2.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +dir=$RUNDIR +nfiles=10000 +[ `df -i $dir | tail -1 | awk '{print $7}'` -lt $nfiles ] && exit 0 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > fdatasync2.c +rm -f /tmp/fdatasync2 +mycc -o fdatasync2 -Wall -Wextra -O2 -g fdatasync2.c -lpthread || exit 1 +rm -f fdatasync2.c + +mkdir -p $dir && chmod 777 $dir + +cd $dir +jot $nfiles | xargs touch +jot $nfiles | xargs chmod 666 +cd $odir + +(cd /tmp; /tmp/fdatasync2 $dir) +e=$? + +rm -rf $dir/* /tmp/fdatasync2 +exit $e +EOF +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define RUNTIME 180 +#define THREADS 6 + +static int fd[900]; +static u_int32_t r[N]; +static char *args[2]; + +static unsigned long +makearg(void) +{ + unsigned long val; + + val = arc4random(); +#if defined(__LP64__) + val = (val << 32) | arc4random(); + val = val & 0x00007fffffffffffUL; +#endif + + return(val); +} + +static void * +test(void *arg __unused) +{ + FTS *fts; + FTSENT *p; + int ftsoptions, i, n; + + ftsoptions = FTS_PHYSICAL; + + for (;;) { + for (i = 0; i < N; i++) + r[i] = arc4random(); + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + i = n = 0; + while ((p = fts_read(fts)) != NULL) { + if (fd[i] > 0) + close(fd[i]); + if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) + if ((fd[i] = open(p->fts_path, O_WRONLY)) == + -1) + continue; + if (ftruncate(fd[i], 0) != 0) + err(1, "ftruncate"); + i++; + i = i % nitems(fd); + } + + if (fts_close(fts) == -1) + err(1, "fts_close()"); + sleep(1); + } + return(0); +} + +static void * +calls(void *arg __unused) +{ + off_t offset; + time_t start; + int fd2; + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + fd2 = makearg() % nitems(fd) + 3; + offset = makearg(); + if (lseek(fd2, offset - 1, SEEK_SET) != -1) { + if (write(fd2, "x", 1) != 1) + if (errno != EBADF && errno != ENOSPC && + errno != E2BIG && errno != ESTALE && + errno != EFBIG) + warn("write"); + } else + if (errno != EBADF) + warn("lseek"); + if (fdatasync(fd2) == -1) + if (errno != EBADF) + warn("x"); + + } + + return (0); +} + +int +main(int argc, char **argv) +{ + struct passwd *pw; + pthread_t rp, cp[THREADS]; + int e, i, threads; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + args[0] = argv[1]; + args[1] = 0; + threads = arc4random() % (THREADS -1 ) + 2; /* 2 - THREADS */ + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "failed to resolve nobody"); + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) + errc(1, e, "pthread_create"); + usleep(1000); + for (i = 0; i < threads; i++) + if ((e = pthread_create(&cp[i], NULL, calls, NULL)) != 0) + errc(1, e, "pthread_create"); + for (i = 0; i < threads; i++) + pthread_join(cp[i], NULL); + + return (0); +}