Initialize only the required backends
Context: IOR initializes all available backends. If one backend fails to initialize IOR cannot be used. This patch makes IOR initialize only the backends which will be used. The initialization is done after that the parameters are checked so that the help message can still be dispayed is something goes wrong.master
parent
fd34b08e05
commit
2bcaea564e
106
src/aiori.c
106
src/aiori.c
|
@ -12,6 +12,8 @@
|
|||
*
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include "aiori.h"
|
||||
|
||||
#if defined(HAVE_SYS_STATVFS_H)
|
||||
|
@ -131,34 +133,90 @@ char* aiori_get_version()
|
|||
return "";
|
||||
}
|
||||
|
||||
static int is_initialized = FALSE;
|
||||
static bool is_initialized = false;
|
||||
|
||||
void aiori_initialize(){
|
||||
if (is_initialized) return;
|
||||
is_initialized = TRUE;
|
||||
|
||||
/* Sanity check, we were compiled with SOME backend, right? */
|
||||
if (0 == aiori_count ()) {
|
||||
ERR("No IO backends compiled into aiori. "
|
||||
"Run 'configure --with-<backend>', and recompile.");
|
||||
}
|
||||
|
||||
for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp) {
|
||||
if((*tmp)->initialize){
|
||||
(*tmp)->initialize();
|
||||
}
|
||||
}
|
||||
static void init_or_fini_internal(const ior_aiori_t *test_backend,
|
||||
const bool init)
|
||||
{
|
||||
if (init)
|
||||
{
|
||||
if (test_backend->initialize)
|
||||
test_backend->initialize();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (test_backend->finalize)
|
||||
test_backend->finalize();
|
||||
}
|
||||
}
|
||||
|
||||
void aiori_finalize(){
|
||||
if (! is_initialized) return;
|
||||
is_initialized = FALSE;
|
||||
static void init_or_fini(IOR_test_t *tests, const bool init)
|
||||
{
|
||||
/* Sanity check, we were compiled with SOME backend, right? */
|
||||
if (0 == aiori_count ()) {
|
||||
ERR("No IO backends compiled into aiori. "
|
||||
"Run 'configure --with-<backend>', and recompile.");
|
||||
}
|
||||
|
||||
for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp) {
|
||||
if((*tmp)->finalize){
|
||||
(*tmp)->finalize();
|
||||
}
|
||||
}
|
||||
/* Pointer to the initialize of finalize function */
|
||||
|
||||
|
||||
/* if tests is NULL, initialize or finalize all available backends */
|
||||
if (tests == NULL)
|
||||
{
|
||||
for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp)
|
||||
init_or_fini_internal(*tmp, init);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (IOR_test_t *t = tests; t != NULL; t = t->next)
|
||||
{
|
||||
IOR_param_t *params = &t->params;
|
||||
assert(params != NULL);
|
||||
|
||||
const ior_aiori_t *test_backend = params->backend;
|
||||
assert(test_backend != NULL);
|
||||
|
||||
init_or_fini_internal(test_backend, init);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize IO backends.
|
||||
*
|
||||
* @param[in] tests Pointers to the first test
|
||||
*
|
||||
* This function initializes all backends which will be used. If tests is NULL
|
||||
* all available backends are initialized.
|
||||
*/
|
||||
void aiori_initialize(IOR_test_t *tests)
|
||||
{
|
||||
if (is_initialized)
|
||||
return;
|
||||
|
||||
init_or_fini(tests, true);
|
||||
|
||||
is_initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize IO backends.
|
||||
*
|
||||
* @param[in] tests Pointers to the first test
|
||||
*
|
||||
* This function finalizes all backends which were used. If tests is NULL
|
||||
* all available backends are finialized.
|
||||
*/
|
||||
void aiori_finalize(IOR_test_t *tests)
|
||||
{
|
||||
if (!is_initialized)
|
||||
return;
|
||||
|
||||
is_initialized = false;
|
||||
|
||||
init_or_fini(tests, false);
|
||||
}
|
||||
|
||||
const ior_aiori_t *aiori_select (const char *api)
|
||||
|
|
|
@ -97,8 +97,8 @@ extern ior_aiori_t s3_plus_aiori;
|
|||
extern ior_aiori_t s3_emc_aiori;
|
||||
extern ior_aiori_t rados_aiori;
|
||||
|
||||
void aiori_initialize();
|
||||
void aiori_finalize();
|
||||
void aiori_initialize(IOR_test_t * tests);
|
||||
void aiori_finalize(IOR_test_t * tests);
|
||||
const ior_aiori_t *aiori_select (const char *api);
|
||||
int aiori_count (void);
|
||||
void aiori_supported_apis(char * APIs);
|
||||
|
|
10
src/ior.c
10
src/ior.c
|
@ -98,8 +98,6 @@ int ior_main(int argc, char **argv)
|
|||
out_logfile = stdout;
|
||||
out_resultfile = stdout;
|
||||
|
||||
aiori_initialize();
|
||||
|
||||
/*
|
||||
* check -h option from commandline without starting MPI;
|
||||
*/
|
||||
|
@ -123,6 +121,8 @@ int ior_main(int argc, char **argv)
|
|||
InitTests(tests_head, mpi_comm_world);
|
||||
verbose = tests_head->params.verbose;
|
||||
|
||||
aiori_initialize(tests_head);
|
||||
|
||||
PrintHeader(argc, argv);
|
||||
|
||||
/* perform each test */
|
||||
|
@ -151,11 +151,11 @@ int ior_main(int argc, char **argv)
|
|||
/* display finish time */
|
||||
PrintTestEnds();
|
||||
|
||||
DestroyTests(tests_head);
|
||||
|
||||
MPI_CHECK(MPI_Finalize(), "cannot finalize MPI");
|
||||
|
||||
aiori_finalize();
|
||||
aiori_finalize(tests_head);
|
||||
|
||||
DestroyTests(tests_head);
|
||||
|
||||
return totalErrorCount;
|
||||
}
|
||||
|
|
|
@ -77,9 +77,11 @@ typedef struct IO_BUFFERS
|
|||
* USER_GUIDE
|
||||
*/
|
||||
|
||||
struct ior_aiori;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const void * backend;
|
||||
const struct ior_aiori * backend;
|
||||
char * debug; /* debug info string */
|
||||
unsigned int mode; /* file permissions */
|
||||
unsigned int openFlags; /* open flags (see also <open>) */
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
#include "aiori.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
aiori_initialize();
|
||||
aiori_initialize(NULL);
|
||||
MPI_Init(&argc, &argv);
|
||||
|
||||
mdtest_run(argc, argv, MPI_COMM_WORLD, stdout);
|
||||
|
||||
MPI_Finalize();
|
||||
aiori_finalize();
|
||||
aiori_finalize(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue