summaryrefslogtreecommitdiffstats
path: root/tools/h5recover
diff options
context:
space:
mode:
authorAlbert Cheng <acheng@hdfgroup.org>2008-02-04 21:39:49 (GMT)
committerAlbert Cheng <acheng@hdfgroup.org>2008-02-04 21:39:49 (GMT)
commitd3e926b897b42d27e1c5f8533a8a413c448738e2 (patch)
tree1c522e98d88be315dee37a2fbd295e58c18b0d3d /tools/h5recover
parent76958a8e308fc1f0b80929f30dcee9ef43fa3cec (diff)
downloadhdf5-d3e926b897b42d27e1c5f8533a8a413c448738e2.zip
hdf5-d3e926b897b42d27e1c5f8533a8a413c448738e2.tar.gz
hdf5-d3e926b897b42d27e1c5f8533a8a413c448738e2.tar.bz2
[svn-r14491] Feature:
Added async crash support. Added command line option support. Tested: kagiso, smirom, linew.
Diffstat (limited to 'tools/h5recover')
-rw-r--r--tools/h5recover/trecover.h21
-rw-r--r--tools/h5recover/trecover_crasher.c28
-rw-r--r--tools/h5recover/trecover_main.c58
-rw-r--r--tools/h5recover/trecover_writer.c2
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 <signal.h>
+#include <sys/time.h>
+#include <math.h>
+#include <stdlib.h>
/*
* 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 <seconds> 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 <seconds>]\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"