diff options
author | David Teigland <teigland@redhat.com> | 2010-04-06 13:59:09 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2010-04-06 13:59:09 -0500 |
commit | 2cd320665a8f5920e5d09b59744239169d1be78d (patch) | |
tree | 611c8830841edade179332848f713ed433729ecf /fs | |
parent | 9f2d0e1f6615d44c1e7a5ca9b65f6c23d2ac1368 (diff) | |
download | dct-stuff-2cd320665a8f5920e5d09b59744239169d1be78d.tar.gz dct-stuff-2cd320665a8f5920e5d09b59744239169d1be78d.tar.xz dct-stuff-2cd320665a8f5920e5d09b59744239169d1be78d.zip |
add new dlm and fs tests
Signed-off-by: David Teigland <teigland@redhat.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/alternate.c | 137 | ||||
-rw-r--r-- | fs/lock_load.c | 329 | ||||
-rwxr-xr-x | fs/make_panic | 162 |
3 files changed, 628 insertions, 0 deletions
diff --git a/fs/alternate.c b/fs/alternate.c new file mode 100644 index 0000000..942f3b9 --- /dev/null +++ b/fs/alternate.c @@ -0,0 +1,137 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright 2001 Sistina Software, Inc. +** +** This is free software released under the GNU General Public License. +** There is no warranty for this software. See the file COPYING for +** details. +** +******************************************************************************* +******************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> + +#define die(fmt, args...) \ +{ \ + fprintf(stderr, "%s: ", prog_name); \ + fprintf(stderr, fmt, ##args); \ + exit(EXIT_FAILURE); \ +} + +#define do_lseek(fd, off) \ +{ \ + if (lseek((fd), (off), SEEK_SET) != (off)) \ + die("bad seek: %s on line %d of file %s\n", \ + strerror(errno),__LINE__, __FILE__); \ +} + +#define do_read(fd, buff, len) \ +{ \ + if (read((fd), (buff), (len)) != (len)) \ + die("bad read: %s on line %d of file %s\n", \ + strerror(errno), __LINE__, __FILE__); \ +} + +#define do_write(fd, buff, len) \ +{ \ + if (write((fd), (buff), (len)) != (len)) \ + die("bad write: %s on line %d of file %s\n", \ + strerror(errno), __LINE__, __FILE__); \ +} + +#define BLOCK_SIZE (512) + +char *prog_name; + +unsigned int wait; +unsigned int delay = 0; + +int main(int argc, char *argv[]) +{ + int cont = 1; + int optchar; + int fd; + char *filename; + char buf[BLOCK_SIZE]; + unsigned long long offset; + unsigned long long num, last_num = 0; + unsigned int id, clients; + unsigned long long skip = 0; + unsigned int iterations = 0; + unsigned int delay = 0; + + prog_name = argv[0]; + + while (cont) { + optchar = getopt(argc, argv, "i:s:"); + switch (optchar) { + case 'i': + iterations = atoi(optarg); + break; + case 's': + delay = atoi(optarg); + break; + case 'h': + die("[-i iterations] [-s usleep] filename offset id clients\n"); + case EOF: + cont = 0; + break; + } + } + + if (argc - optind < 4) + die("[-i iterations] [-s usleep] filename offset id clients\n"); + + filename = argv[optind]; + offset = atoll(argv[optind + 1]); + id = atoi(argv[optind + 2]); + clients = atoi(argv[optind + 3]); + + fd = open(filename, O_RDWR | O_CREAT, 0644); + if (fd < 0) + die("can't open file %s: %s\n", argv[1], strerror(errno)); + + for (;;) { + do_lseek(fd, offset); + + do_read(fd, buf, BLOCK_SIZE); + + num = atoll(buf); + if (num % clients == id) { + num++; + sprintf(buf, "%llu\n", num); + printf("%llu %llu\n", num, skip); + + if (last_num && last_num + clients != num) + die("bad\n"); + + do_lseek(fd, offset); + + do_write(fd, buf, BLOCK_SIZE); + + if (iterations && num >= iterations) + break; + + last_num = num; + skip = 0; + } else { + skip++; + } + + if (delay) + usleep(delay); + } + + close(fd); + + exit(EXIT_SUCCESS); +} + diff --git a/fs/lock_load.c b/fs/lock_load.c new file mode 100644 index 0000000..79c449f --- /dev/null +++ b/fs/lock_load.c @@ -0,0 +1,329 @@ +/* + * Copyright (c) 2009 David Teigland + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License V2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <errno.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/file.h> +#include <fcntl.h> +#include <unistd.h> + +#define die(fmt, args...) \ +{ \ + fprintf(stderr, "%s: ", prog_name); \ + fprintf(stderr, fmt, ##args); \ + exit(EXIT_FAILURE); \ +} + +#define MAX_FILES 1000 +int fda[MAX_FILES]; +unsigned int inodea[MAX_FILES]; + +int do_create; +int use_flock; +int use_plock; +int filecount; +int iterations; +int our_pid; +char *prog_name; +int blocking; +int delay = 10; /* milliseconds */ + +void read_flock(int fd) +{ + int error; + int mode = LOCK_SH; + + if (!blocking) + mode |= LOCK_NB; + + error = flock(fd, mode); + if (error < 0) { + printf("%d read lock failed %d errno %d\n", + our_pid, error, errno); + } +} + +void write_flock(int fd) +{ + int error; + int mode = LOCK_EX; + + if (!blocking) + mode |= LOCK_NB; + + error = flock(fd, mode); + if (error < 0) { + printf("%d write lock failed %d errno %d\n", + our_pid, error, errno); + } +} + +void unlock_flock(int fd) +{ + int error; + + error = flock(fd, LOCK_UN); + if (error < 0) { + printf("%d unlock failed %d errno %d\n", + our_pid, error, errno); + } +} + +int do_plock(int fd, int offset, int len, int type) +{ + struct flock lock; + int action; + + lock.l_type = type; + lock.l_start = offset; + lock.l_whence = SEEK_SET; + lock.l_len = len; + + if (blocking) + action = F_SETLKW; + else + action = F_SETLK; + + return fcntl(fd, action, &lock); +} + +int rand_int(int a, int b) +{ + return a + (int) (((float)(b - a + 1)) * random() / (RAND_MAX+1.0)); +} + +void rand_range(int *offset, int *len) +{ + switch (rand_int(0, 2)) { + case 0: + *offset = 0; + *len = 10; + return; + case 1: + *offset = 0; + *len = 5; + return; + case 2: + *offset = 5; + *len = 5; + return; + } +} + +static uint64_t dt_usec(struct timeval *start, struct timeval *stop) +{ + uint64_t dt; + + dt = stop->tv_sec - start->tv_sec; + dt *= 1000000; + dt += stop->tv_usec - start->tv_usec; + return dt; +} + +void loop_plock(void) +{ + struct timeval t1, t2; + int i, fdi, fd, offset, len, rv; + + for (i = 0;; i++) { + + fdi = rand_int(0, filecount-1); + fd = fda[fdi]; + + rand_range(&offset, &len); + + switch (rand_int(0, 2)) { + case 0: + gettimeofday(&t1, NULL); + rv = do_plock(fd, offset, len, F_UNLCK); + gettimeofday(&t2, NULL); + + printf("%06d file%04d ino %04x U %02d-%02d pid %d err %02d sec %.6f\n", + i, fdi, inodea[fdi], offset, offset+len-1, our_pid, + rv ? errno : 0, 1.e-6 * dt_usec(&t1, &t2)); + break; + + case 1: + gettimeofday(&t1, NULL); + rv = do_plock(fd, offset, len, F_RDLCK); + gettimeofday(&t2, NULL); + + printf("%06d file%04d ino %04x R %02d-%02d pid %d err %02d sec %.6f\n", + i, fdi, inodea[fdi], offset, offset+len-1, our_pid, + rv ? errno : 0, 1.e-6 * dt_usec(&t1, &t2)); + + break; + case 2: + gettimeofday(&t1, NULL); + rv = do_plock(fd, offset, len, F_WRLCK); + gettimeofday(&t2, NULL); + + printf("%06d file%04d ino %04x W %02d-%02d pid %d err %02d sec %.6f\n", + i, fdi, inodea[fdi], offset, offset+len-1, our_pid, + rv ? errno : 0, 1.e-6 * dt_usec(&t1, &t2)); + break; + } + + if (iterations && i == iterations) + break; + + if (delay) + usleep(delay * 1000); + } +} + +void loop_flock(void) +{ + return; +} + +int open_all_files(void) +{ + int i, fd; + struct stat st; + char path[64]; + + for (i = 0; i < filecount; i++) { + memset(path, 0, sizeof(path)); + sprintf(path, "file%04u", i); + + fd = open(path, O_RDWR | O_CREAT, 0644); + if (fd < 0) + die("can't open file %s\n", strerror(errno)); + fda[i] = fd; + + memset(&st, 0, sizeof(st)); + fstat(fd, &st); + inodea[i] = (unsigned int)st.st_ino; + } +} + +void close_all_files(void) +{ + int i; + + for (i = 0; i < filecount; i++) + close(fda[i]); +} + +void print_usage(void) +{ + fprintf(stderr, "lock_load\n"); + fprintf(stderr, " -i <n> iterations (default 0, no limit)\n"); + fprintf(stderr, " -n <n> number of files (default 100)\n"); + fprintf(stderr, " -c only create files\n"); + fprintf(stderr, " -f use flock\n"); + fprintf(stderr, " -p use plock (default)\n"); + fprintf(stderr, " -d <ms> millisecond delay between each op (default 10)\n"); + fprintf(stderr, " -b use blocking locks (default non-blocking)\n"); + fprintf(stderr, " (warning: can easily deadlock)\n"); + exit(EXIT_FAILURE); +} + +int main(int argc, char *argv[]) +{ + int cont = 1; + int optchar; + + do_create = 0; + use_flock = 0; + use_plock = 1; + filecount = 100; + iterations = 0; + blocking = 0; + delay = 10; + + while (cont) { + optchar = getopt(argc, argv, "cfpn:i:d:bh"); + + switch (optchar) { + case 'c': + do_create = 1; + break; + + case 'f': + use_flock = 1; + break; + + case 'p': + use_plock = 1; + break; + + case 'n': + filecount = atoi(optarg); + break; + + case 'i': + iterations = atoi(optarg); + break; + + case 'd': + delay = atoi(optarg); + break; + + case 'b': + blocking = 1; + break; + + + case EOF: + cont = 0; + break; + + case 'h': + default: + print_usage(); + break; + }; + } + + srandom(time(NULL)); + prog_name = argv[0]; + our_pid = getpid(); + + if (filecount > MAX_FILES) { + fprintf(stderr, "max files is %d\n", MAX_FILES); + return -1; + } + + if (do_create) { + open_all_files(); + close_all_files(); + return 0; + } + + open_all_files(); + + if (use_flock) + loop_flock(); + else if (use_plock) + loop_plock(); + else + fprintf(stderr, "use -f or -p for flock or plock\n"); + + close_all_files(); + + return 0; +} + diff --git a/fs/make_panic b/fs/make_panic new file mode 100755 index 0000000..fd27fb8 --- /dev/null +++ b/fs/make_panic @@ -0,0 +1,162 @@ +#!/usr/bin/perl + +############################################################# +############################################################# +## +## Copyright 2001 Sistina Software Inc. +## +## This is free software released under the GNU General +## Public License. There is no warranty for this +## software. See the file COPYING for details. +## +############################################################# +############################################################# + +use Getopt::Std; + +exit(1) unless getopts('s:f:e:hdqr:l:'); + +if (defined $opt_h) +{ + print << "EndHelp"; +Usage: make_panic [OPTION] + -e <iterations> number of iterations, infinite if not defined + -f <forks> number of processes to fork + -h help + -s <seed> seed for random number generator + -d drop seed so you could use it next time + -q Don't print out the status updates. (slient) + -r Number of directories + -l Number of files +EndHelp + + exit(0); +} + + +if (defined $opt_f) +{ + $opt_f = 1 if $opt_f <=0; + while (--$opt_f) + { + if ($pid = fork()) + { + #parent + } + elsif (defined $pid) + { + last; + } + else + { + die "Fork error $!"; + } + } +} + +if(defined $opt_s) +{ + $seed = $opt_s; +} +else +{ + $seed = time ^ $$; +} +if(defined($opt_d)) +{ + system("echo $seed > /make_panic_seed.$$"); +} +srand($seed); + +if (defined $opt_r) +{ + $dirs = $opt_r; +} +else +{ + $dirs = 50; +} + +if (defined $opt_l) +{ + $files = $opt_l; +} +else +{ + $files = 1000; +} + + +for ($x = 0; $x < $dirs; $x++) +{ + mkdir(sprintf("dir%.10u", $x), 0755); +} + +$last = time(); +$ops_at_last_tick = 0; + +while ( (defined $opt_e)?($opt_e-- > 0):1 ) +{ + $v = int(rand(6)); + + $x = int(rand($dirs)); + $y = int(rand($files)); + $file = sprintf("dir%.10u/file%.10u", $x, $y); + + if ($v == 0) + { + open(DATAFILE, ">> $file") || die; + close(DATAFILE); + } + elsif ($v == 1 || $v == 2) + { + $z = int(rand(1000000000)); + if (open(DATAFILE, "+< $file")) + { + seek(DATAFILE, $z, 0); + print DATAFILE "$z\n"; + close(DATAFILE); + } + } + elsif ($v == 3 || $v == 4) + { + $z = int(rand(1000000000)); + if (open(DATAFILE, "< $file")) + { + seek(DATAFILE, -100, 2); + read(DATAFILE, $tmp, 100) == 100; + close(DATAFILE); + } + } + elsif ($v == 5) + { + unlink "$file"; + } + + + $ops++; +# if ($ops % 250 == 0) +# { +# $new = time(); +# $last-- if ($new == $last); +# $rate = 250 / ($new - $last); +# $pretty_rate = sprintf("%.2f", $rate); +# $last = $new; +# } + + $new = time(); + + if ($new != $last) { + $rate = ($ops - $ops_at_last_tick) / ($new - $last); + $pretty_rate = sprintf("%.2f", $rate); + $ops_at_last_tick = $ops; + $last = $new; + } + + if( ! defined $opt_q ) { + print "$ops:$v: $pretty_rate\n"; + } +} + + + |