summaryrefslogtreecommitdiffstats
path: root/tools/h5recover/trecover_main.c
blob: fe2d1ef4b08f0a21ad583b684db55ca59f22083a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*  
 * This is the Main body of the HDF5 Test program for the h5recover tool.
 * It creates two HDF5 files, one as the Data file, the other the Control file.
 * The two files are intended to contain identical data. The Control file will
 * be completed with no error but the Data file, though written with the same
 * data, is intentional crashed without proper file flush or close.
 * 
 * (The two files are then verified by processes outside of this program.)
 * The crashed Data file is restored by the h5recover tool and compared with
 * the Control file, expecting identical file content up to the last successful
 * file flush or close of the Data file.
 *
 * Creator: Albert Cheng, Jan 28, 2008.
 */
 
#include "trecover.h"

/* Global variables */
CrasherParam_t	AsyncCrashParam;
int		CrashMode = SyncCrash;	/* default to synchronous crash */
hid_t		file, ctl_file;         /* file id and control file id*/

/* local variables */
#if 0
static int	DSTypes=DSNone;		/* set to none first. */
#else
static int	DSTypes=DSChunked;	/* set to Chunked temp. first. */
#endif

/* 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 */
		if (--ac > 0){
		    av++;
		    AsyncCrashParam.tinterval = atof(*av);
		}else{
		    fprintf(stderr, "Missing async time value\n");
		    help();
		    exit(1);
		}
		break;
	    case 'd':	/* -d dataset type */
		if (--ac > 0){
		    av++;
		    switch (**av){
		    case 'C':
			DSTypes=DSTypes|DSContig;
			break;
		    case 'K':
			DSTypes=DSTypes|DSChunked;
			break;
		    case 'G':
			DSTypes=DSTypes|DSZip;
			break;
		    case 'S':
			DSTypes=DSTypes|DSSZip;
			break;
		    case 'A':
			DSTypes=DSTypes|DSAll;
			break;
		    default:
			fprintf(stderr, "Unknown Dataset type (%c)\n", **av);
			help();
			exit(1);
		    }
		}else{
		    fprintf(stderr, "Missing async time value\n");
		    help();
		    exit(1);
		}
		break;
	    case 'h':	/* -h help option */
		help();
		exit(0);
		break;
	    default:
		fprintf(stderr, "Unknown command option(%s)\n", *av);
		help();
		exit(1);
	    }
	}else{
	    fprintf(stderr, "Unknown command option(%s)\n", *av);
	    help(); 
	    exit(1);
	}
    } /* end of while */
    if (DSTypes==DSNone){
	/* reset to default all datasets */
	DSTypes=DSAll;
    }
}


/* initialization */
void
init(void)
{
    AsyncCrashParam.tinterval = 0;
}


/* show help pages */
void
help(void)
{
    fprintf(stderr, "Usage: trecover [-a <seconds>] [-d <dataset-type>] [-h]\n"
		"\t-a\tAsync crash seconds where <seconds> is a real number.\n"
		"\t-d\tDataset to create. <dataset-type> can be:\n"
		"\t\t  A\tAll datasets\n"
		"\t\t  C\tContingous datasets\n"
		"\t\t  G\tGzip compressed datasets\n"
		"\t\t  K\tChunked datasets\n"
		"\t\t  S\tSzip compressed datasets\n"
		"\t\tDefault is all datasets\n"
		"\t\tTemp Default is Chunked datasets\n"
	    );
}


int
main (int ac, char **av)
{
    hsize_t     dims[RANK]={NX,NY};              /* dataset dimensions */
    hsize_t     dimschunk[RANK]={ChunkX,ChunkY}; /* dataset chunk dimensions */

    init();
    parser(ac, av);

    /* create/open both files. */
    create_files(H5FILE_NAME, CTL_H5FILE_NAME, JNL_H5FILE_NAME);

    /* create datasets in Control file first. */
    writer(ctl_file, DSTypes, RANK, dims, dimschunk);
    close_file(ctl_file);

    /* Schedule Async crash if requested. */
    if (AsyncCrashParam.tinterval > 0)
	crasher(AsyncCrash, &AsyncCrashParam);

    /* create datasets in data file. */
    writer(file, DSTypes, RANK, dims, dimschunk);
    
    /* Do a sync crash. */
    if (AsyncCrashParam.tinterval == 0)
	CRASH;

    /* Close file only if Async crash is scheduled but has not occurred yet. */
    close_file(file);

    return(0);
}