From 2bcaea564e20ea5a47d1bcae61fc76e2e990f0f3 Mon Sep 17 00:00:00 2001 From: Jean-Yves VET Date: Mon, 17 Sep 2018 11:38:57 +0200 Subject: [PATCH] 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. --- src/aiori.c | 106 +++++++++++++++++++++++++++++++++++----------- src/aiori.h | 4 +- src/ior.c | 10 ++--- src/ior.h | 4 +- src/mdtest-main.c | 4 +- 5 files changed, 94 insertions(+), 34 deletions(-) diff --git a/src/aiori.c b/src/aiori.c index f5d5719..292ef19 100644 --- a/src/aiori.c +++ b/src/aiori.c @@ -12,6 +12,8 @@ * \******************************************************************************/ +#include +#include #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-', 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-', 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) diff --git a/src/aiori.h b/src/aiori.h index 0b0ffda..feb19b1 100755 --- a/src/aiori.h +++ b/src/aiori.h @@ -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); diff --git a/src/ior.c b/src/ior.c index 57c186c..cac5a00 100755 --- a/src/ior.c +++ b/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; } diff --git a/src/ior.h b/src/ior.h index c283be7..67198c3 100755 --- a/src/ior.h +++ b/src/ior.h @@ -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 ) */ diff --git a/src/mdtest-main.c b/src/mdtest-main.c index 854456f..8f4e608 100644 --- a/src/mdtest-main.c +++ b/src/mdtest-main.c @@ -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; }