X-Git-Url: https://git.whamcloud.com/gitweb?a=blobdiff_plain;f=lustre%2Ftests%2Fwritemany.c;h=ff9a21c566616fb40a896f03e00583870e9197ba;hb=784263efe38cf5b4ac73cafba3ef1ec6b730c35b;hp=5d4e42efa01860c1961a2dd23f208f657e0d1575;hpb=6c1dc070c19bc8c00a6ac21dd616c17e0e11a059;p=fs%2Flustre-release.git diff --git a/lustre/tests/writemany.c b/lustre/tests/writemany.c index 5d4e42e..ff9a21c 100644 --- a/lustre/tests/writemany.c +++ b/lustre/tests/writemany.c @@ -25,6 +25,16 @@ char cmdname[512]; int o_abort = 0; int o_quiet = 0; +void usage(char *name) +{ + fprintf(stderr, "usage: %s [opts] \n", + name); + fprintf(stderr, " -q quiet\n"); + fprintf(stderr, " -a abort other children on first err\n"); + exit(1); +} + + struct kid_list_t { pid_t kid; struct kid_list_t *next; @@ -49,19 +59,26 @@ void kill_kids(void) } } +static int usr1_received; +void usr1_handler(int unused) +{ + usr1_received = 1; + kill_kids(); +} + int wait_for_threads(int live_threads) { int rc = 0; - + while (live_threads > 0) { int status; pid_t ret; - + ret = waitpid(0, &status, 0); if (ret == 0) { continue; } - + if (ret < 0) { fprintf(stderr, "%s: error: wait - %s\n", cmdname, strerror(errno)); @@ -75,7 +92,7 @@ int wait_for_threads(int live_threads) * always returns 1 (OK). See wait(2). */ int err = WEXITSTATUS(status); - if (err || WIFSIGNALED(status)) + if (err) fprintf(stderr, "%s: error: PID %d had rc=%d\n", cmdname, ret, err); @@ -100,7 +117,7 @@ int wait_for_threads(int live_threads) void print_err(char *op, char *filename, struct timeval *time, int err) { fprintf(stderr, "%s: %d.%.06d error: %s(%s): %s\n", - cmdname, (int)(time->tv_sec), (int)(time->tv_usec), op, + cmdname, (int)(time->tv_sec), (int)(time->tv_usec), op, filename, strerror(errno)); } @@ -113,11 +130,11 @@ int run_one_child(char *file, int thread, int seconds) int fd, rc = 0, rand, maxrand, len; long nfiles = 0, nbytes = 0; - if (!o_quiet) + if (!o_quiet) printf("%s: running thread #%d\n", cmdname, thread); - + srandom(thread); - /* Higher thread numbers will produce bigger random files. + /* Higher thread numbers will produce bigger random files. Thread 1 will produce only 0-len files. */ maxrand = 1; rand = thread; while (--rand) @@ -126,20 +143,25 @@ int run_one_child(char *file, int thread, int seconds) gettimeofday(&start, NULL); while(!rc) { - gettimeofday(&cur, NULL); - if (cur.tv_sec > (start.tv_sec + seconds)) + if (usr1_received) break; - sprintf(filename, "%s-%d-%ld", file, thread, nfiles); + gettimeofday(&cur, NULL); + if (seconds) { + if (cur.tv_sec > (start.tv_sec + seconds)) + break; + } + sprintf(filename, "%s-%d-%ld", file, thread, nfiles); + fd = open(filename, O_RDWR | O_CREAT, 0666); if (fd < 0) { print_err("open", filename, &cur, errno); rc = errno; break; } - - sprintf(buf, "%s %010ld %.19s.%012d\n", cmdname, + + sprintf(buf, "%s %010ld %.19s.%012d\n", cmdname, nfiles++, ctime(&cur.tv_sec), (int)cur.tv_usec); len = strlen(buf); @@ -149,10 +171,10 @@ int run_one_child(char *file, int thread, int seconds) print_err("write", filename, &cur, errno); rc = errno; break; - } + } nbytes += len; - } - + } + if (close(fd) < 0) { print_err("close", filename, &cur, errno); rc = errno; @@ -164,10 +186,10 @@ int run_one_child(char *file, int thread, int seconds) break; } } - + diff = difftime(&cur, &start); - if (!o_quiet) - printf("%s: %7ld files, %4ld MB in %.2fs (%7.2f files/s, " + if (!o_quiet) + printf("%s: %7ld files, %4ld MB in %.2fs (%7.2f files/s, " "%5.2f MB/s): rc = %d\n", cmdname, nfiles, nbytes >> 20, diff, (double)nfiles / diff, (double)nbytes/1024/1024 / diff, @@ -176,16 +198,6 @@ int run_one_child(char *file, int thread, int seconds) return rc; } -void usage(char *name) -{ - fprintf(stderr, - "usage: %s [opts] \n", - name); - fprintf(stderr, " -q quiet\n"); - fprintf(stderr, " -a abort other children on first err\n"); - exit(1); -} - int main(int argc, char *argv[]) { unsigned long duration; @@ -194,7 +206,7 @@ int main(int argc, char *argv[]) char *directory; int i = 1, rc = 0; - sprintf(cmdname, "%s", argv[0]); + sprintf(cmdname, "%s", argv[0]); while((i < argc) && (argv[i][0] == '-')) { switch (argv[i][1]) { @@ -226,6 +238,8 @@ int main(int argc, char *argv[]) exit(2); } + signal(SIGUSR1, usr1_handler); + for (i = 1; i <= threads; i++) { rc = fork(); if (rc < 0) { @@ -244,7 +258,7 @@ int main(int argc, char *argv[]) } } /* parent process */ - if (!o_quiet) + if (!o_quiet) printf("%s will run for %ld minutes\n", cmdname, duration/60); return (wait_for_threads(threads)); }