From d3e926b897b42d27e1c5f8533a8a413c448738e2 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Mon, 4 Feb 2008 16:39:49 -0500 Subject: [svn-r14491] Feature: Added async crash support. Added command line option support. Tested: kagiso, smirom, linew. --- tools/h5recover/trecover.h | 21 +++++++++++++- tools/h5recover/trecover_crasher.c | 28 +++++++++++++++--- tools/h5recover/trecover_main.c | 58 +++++++++++++++++++++++++++++++++++++- tools/h5recover/trecover_writer.c | 2 ++ 4 files changed, 103 insertions(+), 6 deletions(-) diff --git a/tools/h5recover/trecover.h b/tools/h5recover/trecover.h index 79635dc..6e96545 100644 --- a/tools/h5recover/trecover.h +++ b/tools/h5recover/trecover.h @@ -13,9 +13,15 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "hdf5.h" +#include +#include +#include +#include /* * Header file for the trecover test program. + * + * Creator: Albert Cheng, Jan 28, 2008. */ /* Macro definitions */ @@ -24,7 +30,20 @@ #define AsyncCrash 1 #define CRASH crasher(SyncCrash, 0) +/* Data Structures */ +typedef union CrasherParam_t { + float tinterval; /* time interval to schedule an Async Crash */ +} CrasherParam_t; + + +/* Global variables */ +extern CrasherParam_t AsyncCrashParam; +extern int CrashMode; /* protocol definitions */ -void crasher(int crash_mode, int crash_param); +void crasher(int crash_mode, CrasherParam_t *crash_param); void writer(void); +void wakeup(int signum); +void parser(int ac, char **av); /* command option parser */ +void init(void); /* initialization */ +void help(void); /* initialization */ diff --git a/tools/h5recover/trecover_crasher.c b/tools/h5recover/trecover_crasher.c index dd79331..4e558d5 100644 --- a/tools/h5recover/trecover_crasher.c +++ b/tools/h5recover/trecover_crasher.c @@ -14,6 +14,8 @@ /* * crasher HDF5 API module of the trecover test program. + * + * Creator: Albert Cheng, Jan 28, 2008. */ #include "trecover.h" @@ -26,17 +28,35 @@ * Crash_param: used by AsyncCrash mode and ignored by SyncCrash mode. */ void -crasher(int crash_mode, int crash_param) +crasher(int crash_mode, CrasherParam_t *crash_param) { + float fraction, integral; + struct itimerval old, new; + switch (crash_mode) { case SyncCrash: _exit(0); break; case AsyncCrash: - printf("AsyncCrash not implemented yet\n"); + /* Setup a wakeup call in the future */ + signal(SIGALRM, wakeup); + fraction = modff(crash_param->tinterval, &integral); + new.it_interval.tv_usec = 0; + new.it_interval.tv_sec = 0; + new.it_value.tv_usec = fraction * 1.0e6; + new.it_value.tv_sec = integral; + setitimer(ITIMER_REAL, &new, &old); break; - otherwise: - print("Unknown Crash Mode (%d)\n", crash_mode); + default: + fprintf(stderr, "Unknown Crash Mode (%d)\n", crash_mode); break; } } + + +void wakeup(int signum) +{ + printf("wakeup, call sync crash\n"); + /* call crasher with sync mode */ + crasher(SyncCrash, 0); +} diff --git a/tools/h5recover/trecover_main.c b/tools/h5recover/trecover_main.c index bb19159..a0283da 100644 --- a/tools/h5recover/trecover_main.c +++ b/tools/h5recover/trecover_main.c @@ -17,12 +17,68 @@ * It creates three datasets, first one as a regular dataset, second one * uses gzip compression if supported, and the third one use szip compression * if supported. + * + * Creator: Albert Cheng, Jan 28, 2008. */ #include "trecover.h" +CrasherParam_t AsyncCrashParam; +int CrashMode = SyncCrash; /* default to synchronous crash */ + +/* Command arguments parser. + * -a Do Async crash with a floating value of seconds + */ +void +parser(int ac, char **av) +{ + while (--ac > 0) { + av++; + if (av[0][0] == '-'){ + switch (av[0][1]){ + case 'a': /* -a async option */ + ac--; av++; + AsyncCrashParam.tinterval = atof(*av); + break; + case 'h': /* -h help option */ + help(); + break; + default: + fprintf(stderr, "Unknown command option(%s)\n", *av); + help(); + return; + } + }else{ + fprintf(stderr, "Unknown command option(%s)\n", *av); + help(); + return; + } + } /* end of while */ +} + + +/* initialization */ +void +init() +{ + AsyncCrashParam.tinterval = 0; +} + + +/* show help pages */ +void +help() +{ + fprintf(stderr, "Usage: trecover [-a ]\n"); +} + + int -main (void) +main (int ac, char **av) { + init(); + parser(ac, av); + if (AsyncCrashParam.tinterval > 0) + crasher(AsyncCrash, &AsyncCrashParam); writer(); } diff --git a/tools/h5recover/trecover_writer.c b/tools/h5recover/trecover_writer.c index d7b3bb2..4154953 100644 --- a/tools/h5recover/trecover_writer.c +++ b/tools/h5recover/trecover_writer.c @@ -14,6 +14,8 @@ /* * writer HDF5 API module of the trecover test program. + * + * Creator: Albert Cheng, Jan 28, 2008. */ #include "trecover.h" -- cgit v0.12