Path: blob/main/tools/test/stress2/misc/alternativeFlushPath.sh
39536 views
#!/bin/sh12#3# Copyright (c) 2008 Peter Holm <[email protected]>4# All rights reserved.5#6# Redistribution and use in source and binary forms, with or without7# modification, are permitted provided that the following conditions8# are met:9# 1. Redistributions of source code must retain the above copyright10# notice, this list of conditions and the following disclaimer.11# 2. Redistributions in binary form must reproduce the above copyright12# notice, this list of conditions and the following disclaimer in the13# documentation and/or other materials provided with the distribution.14#15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25# SUCH DAMAGE.26#2728# Alternate buffer flush path test (Not verified).29# Regression test for r169006.30# Apply this patch to amplify the problem:31#32# diff -r1.520 vfs_bio.c33# 894c89434# < if (bo->bo_dirty.bv_cnt > dirtybufthresh + 10) {35# ---36# > if (bo->bo_dirty.bv_cnt > dirtybufthresh /*+ 10*/) {3738. ../default.cfg3940odir=`pwd`41dir=$RUNDIR/alternativeFlushPath4243[ -d $dir ] && find $dir -type f | xargs rm44rm -rf $dir45mkdir -p $dir46cd $dir47sed '1,/^EOF/d' < $odir/$0 > $dir/alternativeFlushPath.c48mycc -o /tmp/alternativeFlushPath -Wall -Wextra alternativeFlushPath.c ||49exit 150rm -f alternativeFlushPath.c5152for j in `jot 10`; do53/tmp/alternativeFlushPath &54done55wait56sysctl vfs.altbufferflushes5758cd $odir59rm -rf /tmp/alternativeFlushPath $dir6061exit6263EOF64#include <stdio.h>65#include <unistd.h>66#include <stdlib.h>67#include <fcntl.h>68#include <sys/signal.h>69#include <sys/types.h>70#include <sys/time.h>71#include <sys/resource.h>72#include <err.h>7374#define MAXNOFILE 500000 /* To limit runtime */7576static volatile sig_atomic_t more;7778static void79handler(int i __unused) {80more = 0;81}8283void84test(void)85{86int i, j;87char name[80];88pid_t mypid;89int *fd;90struct rlimit rlp;9192if (getrlimit(RLIMIT_NOFILE, &rlp) == -1)93err(1, "getrlimit(RLIMIT_NOFILE)");94if (rlp.rlim_cur > MAXNOFILE)95rlp.rlim_cur = MAXNOFILE;96rlp.rlim_cur /= 10;97mypid = getpid();98fd = malloc(rlp.rlim_cur * sizeof(int));99100for (i = 0, j = 0; i < rlp.rlim_cur && more == 1; i++, j++) {101sprintf(name, "f%05d.%05d", mypid, i);102if ((fd[i] = open(name, O_CREAT|O_WRONLY, 0666)) == -1) {103warn("open(%s)", name);104more = 0;105break;106}107}108for (i = 0; i < j; i++) {109sprintf(name, "f%05d.%05d", mypid, i);110if (unlink(name) == -1)111warn("unlink(%s)", name);112}113for (i = 0; i < j; i++) {114if (close(fd[i]) == -1)115warn("close(%d)", i);116}117free(fd);118}119120int121main()122{123more = 1;124signal(SIGALRM, handler);125alarm(20 * 60);126while (more == 1)127test();128129return(0);130}131132133