diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7bb852d2fb4..b72ebe364db 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -236,6 +236,7 @@ set (H5FD_SOURCES ${HDF5_SRC_DIR}/H5FDmpi.c ${HDF5_SRC_DIR}/H5FDmpio.c ${HDF5_SRC_DIR}/H5FDmulti.c + ${HDF5_SRC_DIR}/H5FDmulti_int.c ${HDF5_SRC_DIR}/H5FDonion.c ${HDF5_SRC_DIR}/H5FDonion_header.c ${HDF5_SRC_DIR}/H5FDonion_history.c @@ -246,6 +247,7 @@ set (H5FD_SOURCES ${HDF5_SRC_DIR}/H5FDspace.c ${HDF5_SRC_DIR}/H5FDsplitter.c ${HDF5_SRC_DIR}/H5FDstdio.c + ${HDF5_SRC_DIR}/H5FDstdio_int.c ${HDF5_SRC_DIR}/H5FDtest.c ${HDF5_SRC_DIR}/H5FDwindows.c ) diff --git a/src/H5.c b/src/H5.c index 9d0aa3f658e..75b6f287b0f 100644 --- a/src/H5.c +++ b/src/H5.c @@ -235,7 +235,7 @@ H5_init_library(void) * Also initialize some interfaces that might not be able to initialize * themselves soon enough. * - * Interfaces returning variables through a macro: H5E, H5O, H5P, H5T + * Interfaces returning variables through a macro: H5E, H5FD, H5O, H5P, H5T * * The link interface needs to be initialized so that the external link * class is registered. @@ -248,12 +248,15 @@ H5_init_library(void) * The dataspace interface needs to be initialized so that future IDs for * dataspaces work. * - * The VOL interface needs to be initialized so that the default VOL - * connector and the VOL-managed interfaces are set up. + * The VFD & VOL interfaces need to be initialized before the H5P interface + * so that the default VFD and default VOL connector are ready for the + * default FAPL. * */ if (H5E_init() < 0) HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize error interface"); + if (H5FD_init() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize VFL interface"); if (H5VL_init_phase1() < 0) HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize vol interface"); if (H5P_init_phase1() < 0) diff --git a/src/H5FD.c b/src/H5FD.c index 473f3acd6be..4bf9b6d30be 100644 --- a/src/H5FD.c +++ b/src/H5FD.c @@ -62,6 +62,9 @@ static herr_t H5FD__query(const H5FD_t *f, unsigned long *flags /*out*/); /* Package initialization variable */ bool H5_PKG_INIT_VAR = false; +/* Whether to ignore file locks when disabled (env var value) */ +htri_t H5FD_ignore_disabled_file_locks_p = FAIL; + /*****************************/ /* Library Private Variables */ /*****************************/ @@ -92,6 +95,28 @@ static const H5I_class_t H5I_VFL_CLS[1] = {{ (H5I_free_t)H5FD__free_cls /* Callback routine for closing objects of this class */ }}; +/*------------------------------------------------------------------------- + * Function: H5FD_init + * + * Purpose: Initialize the interface from some other package. + * + * Return: Success: non-negative + * Failure: negative + * + *------------------------------------------------------------------------- + */ +herr_t +H5FD_init(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + /* FUNC_ENTER() does all the work */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD_init() */ + /*------------------------------------------------------------------------- * Function: H5FD__init_package * @@ -104,6 +129,7 @@ static const H5I_class_t H5I_VFL_CLS[1] = {{ herr_t H5FD__init_package(void) { + char *lock_env_var = NULL; /* Environment variable pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -114,6 +140,61 @@ H5FD__init_package(void) /* Reset the file serial numbers */ H5FD_file_serial_no_g = 0; + /* Check the use disabled file locks environment variable */ + lock_env_var = getenv(HDF5_USE_FILE_LOCKING); + if (lock_env_var && !strcmp(lock_env_var, "BEST_EFFORT")) + H5FD_ignore_disabled_file_locks_p = true; /* Override: Ignore disabled locks */ + else if (lock_env_var && (!strcmp(lock_env_var, "TRUE") || !strcmp(lock_env_var, "1"))) + H5FD_ignore_disabled_file_locks_p = false; /* Override: Don't ignore disabled locks */ + else + H5FD_ignore_disabled_file_locks_p = FAIL; /* Environment variable not set, or not set correctly */ + + /* Initialize all internal VFD drivers, so their driver IDs are set up */ + if (H5FD__core_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register core VFD"); +#ifdef H5_HAVE_DIRECT + if (H5FD__direct_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register direct VFD"); +#endif + if (H5FD__family_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register family VFD"); +#ifdef H5_HAVE_LIBHDFS + if (H5FD__hdfs_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register hdfs VFD"); +#endif +#ifdef H5_HAVE_IOC_VFD + if (H5FD__ioc_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register ioc VFD"); +#endif + if (H5FD__log_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register log VFD"); +#ifdef H5_HAVE_MIRROR_VFD + if (H5FD__mirror_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register mirror VFD"); +#endif +#ifdef H5_HAVE_PARALLEL + if (H5FD__mpio_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register mpio VFD"); +#endif + if (H5FD__multi_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register multi VFD"); + if (H5FD__onion_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register onion VFD"); +#ifdef H5_HAVE_ROS3_VFD + if (H5FD__ros3_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register ros3 VFD"); +#endif + if (H5FD__sec2_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register sec2 VFD"); + if (H5FD__splitter_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register splitter VFD"); + if (H5FD__stdio_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register stdio VFD"); +#ifdef H5_HAVE_SUBFILING_VFD + if (H5FD__subfiling_register() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register subfiling VFD"); +#endif + done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD__init_package() */ @@ -143,6 +224,38 @@ H5FD_term_package(void) if (H5_PKG_INIT_VAR) { if (H5I_nmembers(H5I_VFL) > 0) { (void)H5I_clear_type(H5I_VFL, false, false); + + /* Reset all internal VFD driver IDs */ + H5FD__core_unregister(); +#ifdef H5_HAVE_DIRECT + H5FD__direct_unregister(); +#endif + H5FD__family_unregister(); +#ifdef H5_HAVE_LIBHDFS + H5FD__hdfs_unregister(); +#endif +#ifdef H5_HAVE_IOC_VFD + H5FD__ioc_unregister(); +#endif + H5FD__log_unregister(); +#ifdef H5_HAVE_MIRROR_VFD + H5FD__mirror_unregister(); +#endif +#ifdef H5_HAVE_PARALLEL + H5FD__mpio_unregister(); +#endif + H5FD__multi_unregister(); + H5FD__onion_unregister(); +#ifdef H5_HAVE_ROS3_VFD + H5FD__ros3_unregister(); +#endif + H5FD__sec2_unregister(); + H5FD__splitter_unregister(); + H5FD__stdio_unregister(); +#ifdef H5_HAVE_SUBFILING_VFD + H5FD__subfiling_unregister(); +#endif + n++; /*H5I*/ } /* end if */ else { diff --git a/src/H5FDcore.c b/src/H5FDcore.c index f6e97f38f0a..766ac70cc78 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -16,13 +16,13 @@ * access to small, temporary hdf5 files. */ -#include "H5FDdrvr_module.h" /* This source code file is part of the H5FD driver module */ +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* File access */ -#include "H5FDprivate.h" /* File drivers */ #include "H5FDcore.h" /* Core file driver */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FLprivate.h" /* Free lists */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ @@ -30,10 +30,7 @@ #include "H5SLprivate.h" /* Skip lists */ /* The driver identification number, initialized at runtime */ -static hid_t H5FD_CORE_g = 0; - -/* Whether to ignore file locks when disabled (env var value) */ -static htri_t ignore_disabled_file_locks_s = FAIL; +hid_t H5FD_CORE_id_g = H5I_INVALID_HID; /* The skip list node type. Represents a region in the file. */ typedef struct H5FD_core_region_t { @@ -126,7 +123,6 @@ typedef struct H5FD_core_fapl_t { static herr_t H5FD__core_add_dirty_region(H5FD_core_t *file, haddr_t start, haddr_t end); static herr_t H5FD__core_destroy_dirty_list(H5FD_core_t *file); static herr_t H5FD__core_write_to_bstore(H5FD_core_t *file, haddr_t addr, size_t size); -static herr_t H5FD__core_term(void); static void *H5FD__core_fapl_get(H5FD_t *_file); static H5FD_t *H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr); static herr_t H5FD__core_close(H5FD_t *_file); @@ -153,7 +149,7 @@ static const H5FD_class_t H5FD_core_g = { "core", /* name */ MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD__core_term, /* terminate */ + NULL, /* terminate */ NULL, /* sb_size */ NULL, /* sb_encode */ NULL, /* sb_decode */ @@ -443,85 +439,48 @@ H5FD__core_get_default_config(void) } /* end H5FD__core_get_default_config() */ /*------------------------------------------------------------------------- - * Function: H5FD__init_package + * Function: H5FD__core_register * - * Purpose: Initializes any interface-specific data or routines. + * Purpose: Register the driver with the library. * - * Return: Non-negative on success/Negative on failure + * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ -static herr_t -H5FD__init_package(void) +herr_t +H5FD__core_register(void) { - char *lock_env_var = NULL; /* Environment variable pointer */ - herr_t ret_value = SUCCEED; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE - /* Check the use disabled file locks environment variable */ - lock_env_var = getenv(HDF5_USE_FILE_LOCKING); - if (lock_env_var && !strcmp(lock_env_var, "BEST_EFFORT")) - ignore_disabled_file_locks_s = true; /* Override: Ignore disabled locks */ - else if (lock_env_var && (!strcmp(lock_env_var, "TRUE") || !strcmp(lock_env_var, "1"))) - ignore_disabled_file_locks_s = false; /* Override: Don't ignore disabled locks */ - else - ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */ - - if (H5FD_core_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize core VFD"); + if (H5I_VFL != H5I_get_type(H5FD_CORE_id_g)) + if ((H5FD_CORE_id_g = H5FD_register(&H5FD_core_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register core driver"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__init_package() */ - -/*------------------------------------------------------------------------- - * Function: H5FD_core_init - * - * Purpose: Initialize this driver by registering the driver with the - * library. - * - * Return: Success: The driver ID for the core driver - * Failure: H5I_INVALID_HID - * - *------------------------------------------------------------------------- - */ -hid_t -H5FD_core_init(void) -{ - hid_t ret_value = H5I_INVALID_HID; /* Return value */ - - FUNC_ENTER_NOAPI(H5I_INVALID_HID) - - if (H5I_VFL != H5I_get_type(H5FD_CORE_g)) - H5FD_CORE_g = H5FD_register(&H5FD_core_g, sizeof(H5FD_class_t), false); - - /* Set return value */ - ret_value = H5FD_CORE_g; - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_core_init() */ +} /* end H5FD__core_register() */ /*--------------------------------------------------------------------------- - * Function: H5FD__core_term + * Function: H5FD__core_unregister * - * Purpose: Shut down the VFD + * Purpose: Reset library driver info. * * Returns: SUCCEED (Can't fail) * *--------------------------------------------------------------------------- */ -static herr_t -H5FD__core_term(void) +herr_t +H5FD__core_unregister(void) { FUNC_ENTER_PACKAGE_NOERR /* Reset VFL ID */ - H5FD_CORE_g = 0; + H5FD_CORE_id_g = H5I_INVALID_HID; FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5FD__core_term() */ +} /* end H5FD__core_unregister() */ /*------------------------------------------------------------------------- * Function: H5Pset_core_write_tracking @@ -822,9 +781,9 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr file->fi_callbacks = file_image_info.callbacks; /* Check the file locking flags in the fapl */ - if (ignore_disabled_file_locks_s != FAIL) + if (H5FD_ignore_disabled_file_locks_p != FAIL) /* The environment variable was set, so use that preferentially */ - file->ignore_disabled_file_locks = ignore_disabled_file_locks_s; + file->ignore_disabled_file_locks = H5FD_ignore_disabled_file_locks_p; else { /* Use the value in the property list */ if (H5P_get(plist, H5F_ACS_IGNORE_DISABLED_FILE_LOCKS_NAME, &file->ignore_disabled_file_locks) < 0) diff --git a/src/H5FDcore.h b/src/H5FDcore.h index b472f42b5f9..c27081ccdab 100644 --- a/src/H5FDcore.h +++ b/src/H5FDcore.h @@ -16,7 +16,21 @@ #ifndef H5FDcore_H #define H5FDcore_H -#define H5FD_CORE (H5FD_core_init()) +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the core VFD */ +#define H5FD_CORE (H5OPEN H5FD_CORE_id_g) + +/** Identifier for the core VFD */ #define H5FD_CORE_VALUE H5_VFD_CORE #ifdef __cplusplus @@ -25,9 +39,9 @@ extern "C" { /** @private * - * \brief Private initializer for the core VFD + * \brief ID for the core VFD */ -H5_DLL hid_t H5FD_core_init(void); +H5_DLLVAR hid_t H5FD_CORE_id_g; /** * \ingroup FAPL diff --git a/src/H5FDdirect.c b/src/H5FDdirect.c index 4a209c0a5a7..1710d2453ad 100644 --- a/src/H5FDdirect.c +++ b/src/H5FDdirect.c @@ -16,13 +16,13 @@ * buffer. The main system support this feature is Linux. */ -#include "H5FDdrvr_module.h" /* This source code file is part of the H5FD driver module */ +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* File access */ -#include "H5FDprivate.h" /* File drivers */ #include "H5FDdirect.h" /* Direct file driver */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ @@ -31,10 +31,7 @@ #ifdef H5_HAVE_DIRECT /* The driver identification number, initialized at runtime */ -static hid_t H5FD_DIRECT_g = 0; - -/* Whether to ignore file locks when disabled (env var value) */ -static htri_t ignore_disabled_file_locks_s = FAIL; +hid_t H5FD_DIRECT_id_g = H5I_INVALID_HID; /* File operations */ #define OP_UNKNOWN 0 @@ -115,7 +112,6 @@ typedef struct H5FD_direct_t { (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) /* Prototypes */ -static herr_t H5FD__direct_term(void); static herr_t H5FD__direct_populate_config(size_t boundary, size_t block_size, size_t cbuf_size, H5FD_direct_fapl_t *fa_out); static void *H5FD__direct_fapl_get(H5FD_t *file); @@ -143,7 +139,7 @@ static const H5FD_class_t H5FD_direct_g = { "direct", /* name */ MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD__direct_term, /* terminate */ + NULL, /* terminate */ NULL, /* sb_size */ NULL, /* sb_encode */ NULL, /* sb_decode */ @@ -183,92 +179,49 @@ static const H5FD_class_t H5FD_direct_g = { /* Declare a free list to manage the H5FD_direct_t struct */ H5FL_DEFINE_STATIC(H5FD_direct_t); -/*-------------------------------------------------------------------------- -NAME - H5FD__init_package -- Initialize interface-specific information -USAGE - herr_t H5FD__init_package() -RETURNS - Non-negative on success/Negative on failure -DESCRIPTION - Initializes any interface-specific data or routines. (Just calls - H5FD_direct_init currently). - ---------------------------------------------------------------------------*/ -static herr_t -H5FD__init_package(void) -{ - char *lock_env_var = NULL; /* Environment variable pointer */ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_PACKAGE - - /* Check the use disabled file locks environment variable */ - lock_env_var = getenv(HDF5_USE_FILE_LOCKING); - if (lock_env_var && !strcmp(lock_env_var, "BEST_EFFORT")) - ignore_disabled_file_locks_s = true; /* Override: Ignore disabled locks */ - else if (lock_env_var && (!strcmp(lock_env_var, "TRUE") || !strcmp(lock_env_var, "1"))) - ignore_disabled_file_locks_s = false; /* Override: Don't ignore disabled locks */ - else - ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */ - - if (H5FD_direct_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize direct VFD"); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__init_package() */ - /*------------------------------------------------------------------------- - * Function: H5FD_direct_init + * Function: H5FD__direct_register * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Purpose: Register the driver with the library. * - * Return: Success: The driver ID for the direct driver - * Failure: H5I_INVALID_HID + * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ -hid_t -H5FD_direct_init(void) +herr_t +H5FD__direct_register(void) { - hid_t ret_value = H5I_INVALID_HID; /* Return value */ - - FUNC_ENTER_NOAPI(H5I_INVALID_HID) + herr_t ret_value = SUCCEED; /* Return value */ - if (H5I_VFL != H5I_get_type(H5FD_DIRECT_g)) { - H5FD_DIRECT_g = H5FD_register(&H5FD_direct_g, sizeof(H5FD_class_t), false); - if (H5I_INVALID_HID == H5FD_DIRECT_g) - HGOTO_ERROR(H5E_ID, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register direct"); - } + FUNC_ENTER_PACKAGE - /* Set return value */ - ret_value = H5FD_DIRECT_g; + if (H5I_VFL != H5I_get_type(H5FD_DIRECT_id_g)) + if ((H5FD_DIRECT_id_g = H5FD_register(&H5FD_direct_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register direct driver"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_direct_init() */ +} /* end H5FD__direct_register() */ /*--------------------------------------------------------------------------- - * Function: H5FD__direct_term + * Function: H5FD__direct_unregister * - * Purpose: Shut down the VFD + * Purpose: Reset library driver info. * * Returns: Non-negative on success or negative on failure * *--------------------------------------------------------------------------- */ -static herr_t -H5FD__direct_term(void) +herr_t +H5FD__direct_unregister(void) { FUNC_ENTER_PACKAGE_NOERR /* Reset VFL ID */ - H5FD_DIRECT_g = 0; + H5FD_DIRECT_id_g = H5I_INVALID_HID; FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5FD__direct_term() */ +} /* end H5FD__direct_unregister() */ /*------------------------------------------------------------------------- * Function: H5Pset_fapl_direct @@ -537,9 +490,9 @@ H5FD__direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxad file->fa.cbsize = fa->cbsize; /* Check the file locking flags in the fapl */ - if (ignore_disabled_file_locks_s != FAIL) + if (H5FD_ignore_disabled_file_locks_p != FAIL) /* The environment variable was set, so use that preferentially */ - file->ignore_disabled_file_locks = ignore_disabled_file_locks_s; + file->ignore_disabled_file_locks = H5FD_pgnore_disabled_file_locks_p; else { /* Use the value in the property list */ if (H5P_get(plist, H5F_ACS_IGNORE_DISABLED_FILE_LOCKS_NAME, &file->ignore_disabled_file_locks) < 0) diff --git a/src/H5FDdirect.h b/src/H5FDdirect.h index 76a809aabde..1b75d75d5b2 100644 --- a/src/H5FDdirect.h +++ b/src/H5FDdirect.h @@ -16,10 +16,21 @@ #ifndef H5FDdirect_H #define H5FDdirect_H +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + #ifdef H5_HAVE_DIRECT -/** Initializer for the direct VFD */ -#define H5FD_DIRECT (H5FD_direct_init()) +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the direct VFD */ +#define H5FD_DIRECT (H5OPEN H5FD_DIRECT_id_g) /** Identifier for the direct VFD */ #define H5FD_DIRECT_VALUE H5_VFD_DIRECT @@ -50,9 +61,9 @@ extern "C" { /** @private * - * \brief Private initializer for the direct VFD + * \brief ID for the direct VFD */ -H5_DLL hid_t H5FD_direct_init(void); +H5_DLLVAR hid_t H5FD_DIRECT_id_g; /** * \ingroup FAPL diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c index 6d61b155841..441dd90b59b 100644 --- a/src/H5FDfamily.c +++ b/src/H5FDfamily.c @@ -28,13 +28,13 @@ * */ -#include "H5FDdrvr_module.h" /* This source code file is part of the H5FD driver module */ +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* File access */ -#include "H5FDprivate.h" /* File drivers */ #include "H5FDfamily.h" /* Family file driver */ +#include "H5FDpkg.h" /* File drivers */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5Pprivate.h" /* Property lists */ @@ -46,7 +46,7 @@ #define H5FD_FAM_DEF_MEM_SIZE ((hsize_t)(100 * H5_MB)) /* The driver identification number, initialized at runtime */ -static hid_t H5FD_FAMILY_g = 0; +hid_t H5FD_FAMILY_id_g = H5I_INVALID_HID; /* The description of a file belonging to this driver. */ typedef struct H5FD_family_t { @@ -80,7 +80,6 @@ static herr_t H5FD__family_get_default_config(H5FD_family_fapl_t *fa_out); static char *H5FD__family_get_default_printf_filename(const char *old_filename); /* Callback prototypes */ -static herr_t H5FD__family_term(void); static void *H5FD__family_fapl_get(H5FD_t *_file); static void *H5FD__family_fapl_copy(const void *_old_fa); static herr_t H5FD__family_fapl_free(void *_fa); @@ -112,7 +111,7 @@ static const H5FD_class_t H5FD_family_g = { "family", /* name */ HADDR_MAX, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD__family_term, /* terminate */ + NULL, /* terminate */ H5FD__family_sb_size, /* sb_size */ H5FD__family_sb_encode, /* sb_encode */ H5FD__family_sb_decode, /* sb_decode */ @@ -266,79 +265,49 @@ H5FD__family_get_default_printf_filename(const char *old_filename) FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD__family_get_default_printf_filename() */ -/*-------------------------------------------------------------------------- -NAME - H5FD__init_package -- Initialize interface-specific information -USAGE - herr_t H5FD__init_package() -RETURNS - Non-negative on success/Negative on failure -DESCRIPTION - Initializes any interface-specific data or routines. (Just calls - H5FD_family_init currently). - ---------------------------------------------------------------------------*/ -static herr_t -H5FD__init_package(void) -{ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_PACKAGE - - if (H5FD_family_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize family VFD"); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__init_package() */ - /*------------------------------------------------------------------------- - * Function: H5FD_family_init + * Function: H5FD__family_register * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Purpose: Register the driver with the library. * - * Return: Success: The driver ID for the family driver - * Failure: H5I_INVALID_HID + * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ -hid_t -H5FD_family_init(void) +herr_t +H5FD__family_register(void) { - hid_t ret_value = H5I_INVALID_HID; - - FUNC_ENTER_NOAPI(H5I_INVALID_HID) + herr_t ret_value = SUCCEED; /* Return value */ - if (H5I_VFL != H5I_get_type(H5FD_FAMILY_g)) - H5FD_FAMILY_g = H5FD_register(&H5FD_family_g, sizeof(H5FD_class_t), false); + FUNC_ENTER_PACKAGE - /* Set return value */ - ret_value = H5FD_FAMILY_g; + if (H5I_VFL != H5I_get_type(H5FD_FAMILY_id_g)) + if ((H5FD_FAMILY_id_g = H5FD_register(&H5FD_family_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register family driver"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD_family_init() */ +} /* H5FD__family_register() */ /*--------------------------------------------------------------------------- - * Function: H5FD__family_term + * Function: H5FD__family_unregister * - * Purpose: Shut down the VFD + * Purpose: Reset library driver info. * * Returns: Non-negative on success or negative on failure * *--------------------------------------------------------------------------- */ -static herr_t -H5FD__family_term(void) +herr_t +H5FD__family_unregister(void) { FUNC_ENTER_PACKAGE_NOERR /* Reset VFL ID */ - H5FD_FAMILY_g = 0; + H5FD_FAMILY_id_g = H5I_INVALID_HID; FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5FD__family_term() */ +} /* end H5FD__family_unregister() */ /*------------------------------------------------------------------------- * Function: H5Pset_fapl_family diff --git a/src/H5FDfamily.h b/src/H5FDfamily.h index 68bb6b45beb..644455268f9 100644 --- a/src/H5FDfamily.h +++ b/src/H5FDfamily.h @@ -16,8 +16,19 @@ #ifndef H5FDfamily_H #define H5FDfamily_H -/** Initializer for the family VFD */ -#define H5FD_FAMILY (H5FD_family_init()) +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the family VFD */ +#define H5FD_FAMILY (H5OPEN H5FD_FAMILY_id_g) /** Identifier for the family VFD */ #define H5FD_FAMILY_VALUE H5_VFD_FAMILY @@ -28,9 +39,9 @@ extern "C" { /** @private * - * \brief Private initializer for the family VFD + * \brief ID for the family VFD */ -H5_DLL hid_t H5FD_family_init(void); +H5_DLLVAR hid_t H5FD_FAMILY_id_g; /** * \ingroup FAPL diff --git a/src/H5FDhdfs.c b/src/H5FDhdfs.c index bfa9624e8cc..0a7430a4756 100644 --- a/src/H5FDhdfs.c +++ b/src/H5FDhdfs.c @@ -15,21 +15,19 @@ * File System (HDFS). */ -#ifdef H5_HAVE_LIBHDFS -/* This source code file is part of the H5FD driver module */ -#include "H5FDdrvr_module.h" -#endif +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ + +#ifdef H5_HAVE_LIBHDFS + #include "H5Eprivate.h" /* Error handling */ -#include "H5FDprivate.h" /* File drivers */ #include "H5FDhdfs.h" /* hdfs file driver */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ -#ifdef H5_HAVE_LIBHDFS - /* HDFS routines */ #include "hdfs.h" @@ -40,7 +38,12 @@ #define HDFS_STATS 0 /* The driver identification number, initialized at runtime */ -static hid_t H5FD_HDFS_g = 0; +hid_t H5FD_HDFS_id_g = H5I_INVALID_HID; + +/* Flag to indicate whether global driver resources & settings have been + * initialized. + */ +static bool H5FD_hdfs_init_s = false; #if HDFS_STATS @@ -241,7 +244,6 @@ typedef struct H5FD_hdfs_t { #define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) /* Prototypes */ -static herr_t H5FD__hdfs_term(void); static void *H5FD__hdfs_fapl_get(H5FD_t *_file); static void *H5FD__hdfs_fapl_copy(const void *_old_fa); static herr_t H5FD__hdfs_fapl_free(void *_fa); @@ -267,7 +269,7 @@ static const H5FD_class_t H5FD_hdfs_g = { "hdfs", /* name */ MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD__hdfs_term, /* terminate */ + NULL, /* terminate */ NULL, /* sb_size */ NULL, /* sb_encode */ NULL, /* sb_decode */ @@ -308,60 +310,81 @@ static const H5FD_class_t H5FD_hdfs_g = { H5FL_DEFINE_STATIC(H5FD_hdfs_t); /*------------------------------------------------------------------------- - * Function: H5FD__init_package + * Function: H5FD__hdfs_register * - * Purpose: Initializes any interface-specific data or routines. + * Purpose: Register the driver with the library. * - * Return: Non-negative on success/Negative on failure + * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ -static herr_t -H5FD__init_package(void) +herr_t +H5FD__hdfs_register(void) { - herr_t ret_value = SUCCEED; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE - if (H5FD_hdfs_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize hdfs VFD"); +#if HDFS_DEBUG + fprintf(stdout, "called %s.\n", __func__); +#endif + + if (H5I_VFL != H5I_get_type(H5FD_HDFS_id_g)) + if ((H5FD_HDFS_id_g = H5FD_register(&H5FD_hdfs_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register hdfs driver"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__init_package() */ +} /* end H5FD__hdfs_register() */ + +/*--------------------------------------------------------------------------- + * Function: H5FD__hdfs_unregister + * + * Purpose: Reset library driver info. + * + * Returns: SUCCEED (Can't fail) + * + *--------------------------------------------------------------------------- + */ +herr_t +H5FD__hdfs_unregister(void) +{ + FUNC_ENTER_PACKAGE_NOERR + +#if HDFS_DEBUG + fprintf(stdout, "called %s.\n", __func__); +#endif + + /* Reset VFL ID */ + H5FD_HDFS_id_g = H5I_INVALID_HID; + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5FD__hdfs_unregister() */ /*------------------------------------------------------------------------- - * Function: H5FD_hdfs_init + * Function: H5FD__hdfs_init * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Purpose: Singleton to initialize global driver settings & resources. * - * Return: Success: The driver ID for the hdfs driver. - * Failure: Negative + * Return: Non-negative on success/Negative on failure * *------------------------------------------------------------------------- */ -hid_t -H5FD_hdfs_init(void) +static herr_t +H5FD__hdfs_init(void) { - hid_t ret_value = H5I_INVALID_HID; -#if HDFS_STATS - unsigned int bin_i; -#endif + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5I_INVALID_HID) + FUNC_ENTER_PACKAGE #if HDFS_DEBUG fprintf(stdout, "called %s.\n", __func__); #endif - if (H5I_VFL != H5I_get_type(H5FD_HDFS_g)) - H5FD_HDFS_g = H5FD_register(&H5FD_hdfs_g, sizeof(H5FD_class_t), false); - #if HDFS_STATS /* pre-compute statsbin boundaries */ - for (bin_i = 0; bin_i < HDFS_STATS_BIN_COUNT; bin_i++) { + for (unsigned bin_i = 0; bin_i < HDFS_STATS_BIN_COUNT; bin_i++) { unsigned long long value = 0; HDFS_STATS_POW(bin_i, &value) @@ -369,35 +392,12 @@ H5FD_hdfs_init(void) } #endif - ret_value = H5FD_HDFS_g; + /* Indicate that driver is set up */ + H5FD_hdfs_init_s = true; done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_hdfs_init() */ - -/*--------------------------------------------------------------------------- - * Function: H5FD__hdfs_term - * - * Purpose: Shut down the VFD - * - * Returns: SUCCEED (Can't fail) - * - *--------------------------------------------------------------------------- - */ -static herr_t -H5FD__hdfs_term(void) -{ - FUNC_ENTER_PACKAGE_NOERR - -#if HDFS_DEBUG - fprintf(stdout, "called %s.\n", __func__); -#endif - - /* Reset VFL ID */ - H5FD_HDFS_g = 0; - - FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5FD__hdfs_term() */ +} /* end H5FD__hdfs_init() */ /*-------------------------------------------------------------------------- * Function: H5FD__hdfs_handle_open @@ -424,6 +424,11 @@ H5FD__hdfs_handle_open(const char *path, const char *namenode_name, const int32_ fprintf(stdout, "called %s.\n", __func__); #endif + /* Initialize driver, if it's not yet */ + if (!H5FD_hdfs_init_s) + if (H5FD__hdfs_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, NULL, "can't initialize driver"); + if (path == NULL || path[0] == '\0') HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "path cannot be null"); if (namenode_name == NULL) diff --git a/src/H5FDhdfs.h b/src/H5FDhdfs.h index 08e30db80da..5178de841b2 100644 --- a/src/H5FDhdfs.h +++ b/src/H5FDhdfs.h @@ -18,10 +18,21 @@ #ifndef H5FDhdfs_H #define H5FDhdfs_H +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + #ifdef H5_HAVE_LIBHDFS -/** Initializer for the hdfs VFD */ -#define H5FD_HDFS (H5FD_hdfs_init()) +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the HDFS VFD */ +#define H5FD_HDFS (H5OPEN H5FD_HDFS_id_g) /** Identifier for the hdfs VFD */ #define H5FD_HDFS_VALUE H5_VFD_HDFS @@ -37,9 +48,6 @@ #endif /* H5_HAVE_LIBHDFS */ #ifdef H5_HAVE_LIBHDFS -#ifdef __cplusplus -extern "C" { -#endif /** * The version number of the H5FD_hdfs_fapl_t configuration @@ -93,11 +101,15 @@ typedef struct H5FD_hdfs_fapl_t { int32_t stream_buffer_size; } H5FD_hdfs_fapl_t; +#ifdef __cplusplus +extern "C" { +#endif + /** @private * - * \brief Private initializer for the hdfs VFD + * \brief ID for the HDFS VFD */ -H5_DLL hid_t H5FD_hdfs_init(void); +H5_DLLVAR hid_t H5FD_HDFS_id_g; /** * \ingroup FAPL diff --git a/src/H5FDlog.c b/src/H5FDlog.c index a350d8164a1..54c484c7a34 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -20,23 +20,20 @@ * With custom modifications... */ -#include "H5FDdrvr_module.h" /* This source code file is part of the H5FD driver module */ +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* File access */ -#include "H5FDprivate.h" /* File drivers */ #include "H5FDlog.h" /* Logging file driver */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5Pprivate.h" /* Property lists */ /* The driver identification number, initialized at runtime */ -static hid_t H5FD_LOG_g = 0; - -/* Whether to ignore file locks when disabled (env var value) */ -static htri_t ignore_disabled_file_locks_s = FAIL; +hid_t H5FD_LOG_id_g = H5I_INVALID_HID; /* Driver-specific file access properties */ typedef struct H5FD_log_fapl_t { @@ -154,7 +151,6 @@ typedef struct H5FD_log_t { (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) /* Prototypes */ -static herr_t H5FD__log_term(void); static void *H5FD__log_fapl_get(H5FD_t *file); static void *H5FD__log_fapl_copy(const void *_old_fa); static herr_t H5FD__log_fapl_free(void *_fa); @@ -183,7 +179,7 @@ static const H5FD_class_t H5FD_log_g = { "log", /* name */ MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD__log_term, /* terminate */ + NULL, /* terminate */ NULL, /* sb_size */ NULL, /* sb_encode */ NULL, /* sb_decode */ @@ -227,85 +223,48 @@ static const H5FD_log_fapl_t H5FD_log_default_config_g = {NULL, H5FD_LOG_LOC_IO H5FL_DEFINE_STATIC(H5FD_log_t); /*------------------------------------------------------------------------- - * Function: H5FD__init_package + * Function: H5FD__log_register * - * Purpose: Initializes any interface-specific data or routines. + * Purpose: Register the driver with the library. * - * Return: Non-negative on success/Negative on failure + * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ -static herr_t -H5FD__init_package(void) +herr_t +H5FD__log_register(void) { - char *lock_env_var = NULL; /* Environment variable pointer */ - herr_t ret_value = SUCCEED; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE - /* Check the use disabled file locks environment variable */ - lock_env_var = getenv(HDF5_USE_FILE_LOCKING); - if (lock_env_var && !strcmp(lock_env_var, "BEST_EFFORT")) - ignore_disabled_file_locks_s = true; /* Override: Ignore disabled locks */ - else if (lock_env_var && (!strcmp(lock_env_var, "TRUE") || !strcmp(lock_env_var, "1"))) - ignore_disabled_file_locks_s = false; /* Override: Don't ignore disabled locks */ - else - ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */ - - if (H5FD_log_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize log VFD"); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__init_package() */ - -/*------------------------------------------------------------------------- - * Function: H5FD_log_init - * - * Purpose: Initialize this driver by registering the driver with the - * library. - * - * Return: Success: The driver ID for the log driver - * Failure: H5I_INVALID_HID - * - *------------------------------------------------------------------------- - */ -hid_t -H5FD_log_init(void) -{ - hid_t ret_value = H5I_INVALID_HID; /* Return value */ - - FUNC_ENTER_NOAPI(H5I_INVALID_HID) - - if (H5I_VFL != H5I_get_type(H5FD_LOG_g)) - H5FD_LOG_g = H5FD_register(&H5FD_log_g, sizeof(H5FD_class_t), false); - - /* Set return value */ - ret_value = H5FD_LOG_g; + if (H5I_VFL != H5I_get_type(H5FD_LOG_id_g)) + if ((H5FD_LOG_id_g = H5FD_register(&H5FD_log_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register log driver"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_log_init() */ +} /* end H5FD__log_register() */ /*--------------------------------------------------------------------------- - * Function: H5FD__log_term + * Function: H5FD__log_unregister * - * Purpose: Shut down the VFD + * Purpose: Reset library driver info. * * Returns: SUCCEED (Can't fail) * *--------------------------------------------------------------------------- */ -static herr_t -H5FD__log_term(void) +herr_t +H5FD__log_unregister(void) { FUNC_ENTER_PACKAGE_NOERR /* Reset VFL ID */ - H5FD_LOG_g = 0; + H5FD_LOG_id_g = H5I_INVALID_HID; FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5FD__log_term() */ +} /* end H5FD__log_unregister() */ /*------------------------------------------------------------------------- * Function: H5Pset_fapl_log @@ -623,9 +582,9 @@ H5FD__log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) } /* Check the file locking flags in the fapl */ - if (ignore_disabled_file_locks_s != FAIL) + if (H5FD_ignore_disabled_file_locks_p != FAIL) /* The environment variable was set, so use that preferentially */ - file->ignore_disabled_file_locks = ignore_disabled_file_locks_s; + file->ignore_disabled_file_locks = H5FD_ignore_disabled_file_locks_p; else { /* Use the value in the property list */ if (H5P_get(plist, H5F_ACS_IGNORE_DISABLED_FILE_LOCKS_NAME, &file->ignore_disabled_file_locks) < 0) diff --git a/src/H5FDlog.h b/src/H5FDlog.h index 25c3c02022e..93721da7757 100644 --- a/src/H5FDlog.h +++ b/src/H5FDlog.h @@ -17,7 +17,19 @@ #define H5FDlog_H /** Initializer for the log VFD */ -#define H5FD_LOG (H5FD_log_init()) +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the log VFD */ +#define H5FD_LOG (H5OPEN H5FD_LOG_id_g) /** Identifier for the log VFD */ #define H5FD_LOG_VALUE H5_VFD_LOG @@ -67,9 +79,10 @@ extern "C" { /** @private * - * \brief Private initializer for the log VFD + * \brief ID for the log VFD */ -H5_DLL hid_t H5FD_log_init(void); +H5_DLLVAR hid_t H5FD_LOG_id_g; + /** * \ingroup FAPL diff --git a/src/H5FDmirror.c b/src/H5FDmirror.c index decc26a27a9..cfcf540236c 100644 --- a/src/H5FDmirror.c +++ b/src/H5FDmirror.c @@ -15,7 +15,7 @@ * a remote host. */ -#include "H5FDdrvr_module.h" /* This source code file is part of the H5FD driver module */ +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ @@ -23,16 +23,16 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* File access */ -#include "H5FDprivate.h" /* File drivers */ #include "H5FDmirror.h" /* "Mirror" definitions */ #include "H5FDmirror_priv.h" /* Private header for the mirror VFD */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5Pprivate.h" /* Property lists */ /* The driver identification number, initialized at runtime */ -static hid_t H5FD_MIRROR_g = 0; +hid_t H5FD_MIRROR_id_g = H5I_INVALID_HID; /* Virtual file structure for a Mirror Driver */ typedef struct H5FD_mirror_t { @@ -139,7 +139,6 @@ typedef struct H5FD_mirror_t { #endif /* MIRROR_DEBUG_OP_CALLS */ /* Prototypes */ -static herr_t H5FD__mirror_term(void); static void *H5FD__mirror_fapl_get(H5FD_t *_file); static void *H5FD__mirror_fapl_copy(const void *_old_fa); static herr_t H5FD__mirror_fapl_free(void *_fa); @@ -165,7 +164,7 @@ static const H5FD_class_t H5FD_mirror_g = { "mirror", /* name */ MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD__mirror_term, /* terminate */ + NULL, /* terminate */ NULL, /* sb_size */ NULL, /* sb_encode */ NULL, /* sb_decode */ @@ -212,79 +211,52 @@ H5FL_DEFINE_STATIC(H5FD_mirror_t); H5FL_DEFINE_STATIC(H5FD_mirror_xmit_open_t); /* ------------------------------------------------------------------------- - * Function: H5FD__init_package + * Function: H5FD__mirror_register * - * Purpose: Initializes any interface-specific data or routines. + * Purpose: Register the driver with the library. * - * Return: Non-negative on success/Negative on failure - *------------------------------------------------------------------------- - */ -static herr_t -H5FD__init_package(void) -{ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_PACKAGE - - LOG_OP_CALL(__func__); - - if (H5FD_mirror_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize mirror VFD"); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__init_package() */ - -/* ------------------------------------------------------------------------- - * Function: H5FD_mirror_init - * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Return: SUCCEED/FAIL * - * Return: Success: The driver ID for the mirror driver. - * Failure: Negative * ------------------------------------------------------------------------- */ -hid_t -H5FD_mirror_init(void) +herr_t +H5FD__mirror_register(void) { - hid_t ret_value = H5I_INVALID_HID; + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5I_INVALID_HID) + FUNC_ENTER_PACKAGE LOG_OP_CALL(__func__); - if (H5I_VFL != H5I_get_type(H5FD_MIRROR_g)) { - H5FD_MIRROR_g = H5FD_register(&H5FD_mirror_g, sizeof(H5FD_class_t), false); - if (H5I_INVALID_HID == H5FD_MIRROR_g) - HGOTO_ERROR(H5E_ID, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register mirror"); - } - ret_value = H5FD_MIRROR_g; + if (H5I_VFL != H5I_get_type(H5FD_MIRROR_id_g)) + if ((H5FD_MIRROR_id_g = H5FD_register(&H5FD_mirror_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register mirror driver"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_mirror_init() */ +} /* end H5FD__mirror_register() */ /* --------------------------------------------------------------------------- - * Function: H5FD__mirror_term + * Function: H5FD__mirror_unregister * - * Purpose: Shut down the VFD + * Purpose: Reset library driver info. * * Returns: SUCCEED (Can't fail) + * * --------------------------------------------------------------------------- */ -static herr_t -H5FD__mirror_term(void) +herr_t +H5FD__mirror_unregister(void) { FUNC_ENTER_PACKAGE_NOERR - /* Reset VFL ID */ - H5FD_MIRROR_g = 0; - LOG_OP_CALL(__func__); + /* Reset VFL ID */ + H5FD_MIRROR_id_g = H5I_INVALID_HID; + FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5FD__mirror_term() */ +} /* end H5FD__mirror_unregister() */ /* --------------------------------------------------------------------------- * Function: H5FD__mirror_xmit_decode_uint16 diff --git a/src/H5FDmirror.h b/src/H5FDmirror.h index e5678bf6439..beee959a8f3 100644 --- a/src/H5FDmirror.h +++ b/src/H5FDmirror.h @@ -17,10 +17,21 @@ #ifndef H5FDmirror_H #define H5FDmirror_H +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + #ifdef H5_HAVE_MIRROR_VFD -/** Initializer for the mirror VFD */ -#define H5FD_MIRROR (H5FD_mirror_init()) +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the mirror VFD */ +#define H5FD_MIRROR (H5OPEN H5FD_MIRROR_id_g) /** Identifier for the mirror VFD */ #define H5FD_MIRROR_VALUE H5_VFD_MIRROR @@ -75,9 +86,9 @@ extern "C" { /** @private * - * \brief Private initializer for the mirror VFD + * \brief ID for the mirror VFD */ -H5_DLL hid_t H5FD_mirror_init(void); +H5_DLLVAR hid_t H5FD_MIRROR_id_g; /** * \ingroup FAPL diff --git a/src/H5FDmpi.c b/src/H5FDmpi.c index bfa21253af8..e7860de77b9 100644 --- a/src/H5FDmpi.c +++ b/src/H5FDmpi.c @@ -14,13 +14,16 @@ * Purpose: Common routines for all MPI-based VFL drivers. */ +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ + #include "H5private.h" /* Generic Functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5FDprivate.h" /* File drivers */ -#include "H5FDmpi.h" /* Common MPI file driver */ #ifdef H5_HAVE_PARALLEL +#include "H5Eprivate.h" /* Error handling */ +#include "H5FDmpi.h" /* Common MPI file driver */ +#include "H5FDpkg.h" /* File drivers */ + /*------------------------------------------------------------------------- * Function: H5FD_mpi_get_rank * diff --git a/src/H5FDmpio.c b/src/H5FDmpio.c index 6f50aef4af3..74175477709 100644 --- a/src/H5FDmpio.c +++ b/src/H5FDmpio.c @@ -14,34 +14,40 @@ * Purpose: This is the MPI I/O driver. */ -#include "H5FDdrvr_module.h" /* This source code file is part of the H5FD driver module */ +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ + +#ifdef H5_HAVE_PARALLEL + #include "H5CXprivate.h" /* API Contexts */ #include "H5Dprivate.h" /* Dataset functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* File access */ -#include "H5FDprivate.h" /* File drivers */ #include "H5FDmpi.h" /* MPI-based file drivers */ +#include "H5FDpkg.h" /* File drivers */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5Pprivate.h" /* Property lists */ -#ifdef H5_HAVE_PARALLEL - /* * The driver identification number, initialized at runtime if H5_HAVE_PARALLEL * is defined. This allows applications to still have the H5FD_MPIO * "constants" in their source code. */ -static hid_t H5FD_MPIO_g = 0; +hid_t H5FD_MPIO_id_g = H5I_INVALID_HID; + +/* Flag to indicate whether global driver resources & settings have been + * initialized. + */ +static bool H5FD_mpio_init_s = false; /* Whether to allow collective I/O operations */ /* (Can be changed by setting "HDF5_MPI_OPT_TYPES" environment variable to '0' or '1') */ bool H5FD_mpi_opt_types_g = true; /* Whether the driver initialized MPI on its own */ -static bool H5FD_mpi_self_initialized = false; +static bool H5FD_mpi_self_initialized_s = false; /* * The view is set to this value @@ -186,35 +192,6 @@ static int H5FD_mpio_debug_rank_s = -1; (H5FD_mpio_debug_rank_s < 0 || H5FD_mpio_debug_rank_s == (file)->mpi_rank) #endif -/*-------------------------------------------------------------------------- -NAME - H5FD__init_package -- Initialize interface-specific information - -USAGE - herr_t H5FD__init_package() - -RETURNS - SUCCEED/FAIL - -DESCRIPTION - Initializes any interface-specific data or routines. (Just calls - H5FD_mpio_init currently). - ---------------------------------------------------------------------------*/ -static herr_t -H5FD__init_package(void) -{ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_PACKAGE - - if (H5FD_mpio_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize mpio VFD"); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__init_package() */ - #ifdef H5FDmpio_DEBUG /*--------------------------------------------------------------------------- @@ -285,79 +262,121 @@ H5FD__mem_t_to_str(H5FD_mem_t mem_type) #endif /* H5FDmpio_DEBUG */ /*------------------------------------------------------------------------- - * Function: H5FD_mpio_init + * Function: H5FD__mpio_register * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Purpose: Register the driver with the library. * - * Return: Success: The driver ID for the mpio driver - * Failure: H5I_INVALID_HID + * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ -hid_t -H5FD_mpio_init(void) +herr_t +H5FD__mpio_register(void) { - static int H5FD_mpio_Debug_inited = 0; - char *env = NULL; - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5I_INVALID_HID) + FUNC_ENTER_PACKAGE /* Register the MPI-IO VFD, if it isn't already */ - if (H5I_VFL != H5I_get_type(H5FD_MPIO_g)) { - H5FD_MPIO_g = H5FD_register((const H5FD_class_t *)&H5FD_mpio_g, sizeof(H5FD_class_t), false); - - /* Check if MPI driver has been loaded dynamically */ - env = getenv(HDF5_DRIVER); - if (env && !strcmp(env, "mpio")) { - int mpi_initialized = 0; - - /* Initialize MPI if not already initialized */ - if (MPI_SUCCESS != MPI_Initialized(&mpi_initialized)) - HGOTO_ERROR(H5E_VFL, H5E_UNINITIALIZED, H5I_INVALID_HID, "can't check if MPI is initialized"); - if (!mpi_initialized) { - if (MPI_SUCCESS != MPI_Init(NULL, NULL)) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, "can't initialize MPI"); - H5FD_mpi_self_initialized = true; - } - } + if (H5I_VFL != H5I_get_type(H5FD_MPIO_id_g)) + if ((H5FD_MPIO_id_g = H5FD_register(&H5FD_mpio_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register mpio driver"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD__mpio_register() */ + +/*--------------------------------------------------------------------------- + * Function: H5FD__mpio_unregister + * + * Purpose: Reset library driver info. + * + * Returns: SUCCEED (Can't fail) + * + *--------------------------------------------------------------------------- + */ +herr_t +H5FD__mpio_unregister(void) +{ + FUNC_ENTER_PACKAGE_NOERR + + /* Terminate MPI if the driver initialized it */ + if (H5FD_mpi_self_initialized_s) { + int mpi_finalized = 0; + + MPI_Finalized(&mpi_finalized); + if (!mpi_finalized) + MPI_Finalize(); + + H5FD_mpi_self_initialized_s = false; } - if (!H5FD_mpio_Debug_inited) { - const char *s; /* String for environment variables */ + /* Reset VFL ID */ + H5FD_MPIO_id_g = H5I_INVALID_HID; + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5FD__mpio_unregister() */ + +/*------------------------------------------------------------------------- + * Function: H5FD__mpio_init + * + * Purpose: Singleton to initialize global driver settings & resources. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__mpio_init(void) +{ + char *env = NULL; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE - /* Allow MPI buf-and-file-type optimizations? */ - s = getenv("HDF5_MPI_OPT_TYPES"); - if (s && isdigit(*s)) - H5FD_mpi_opt_types_g = (0 == strtol(s, NULL, 0)) ? false : true; + /* Check if MPI driver has been loaded dynamically */ + env = getenv(HDF5_DRIVER); + if (env && !strcmp(env, "mpio")) { + int mpi_initialized = 0; + + /* Initialize MPI if not already initialized */ + if (MPI_SUCCESS != MPI_Initialized(&mpi_initialized)) + HGOTO_ERROR(H5E_VFL, H5E_UNINITIALIZED, FAIL, "can't check if MPI is initialized"); + if (!mpi_initialized) { + if (MPI_SUCCESS != MPI_Init(NULL, NULL)) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize MPI"); + H5FD_mpi_self_initialized_s = true; + } + } + + /* Allow MPI buf-and-file-type optimizations? */ + env = getenv("HDF5_MPI_OPT_TYPES"); + if (env && isdigit(*env)) + H5FD_mpi_opt_types_g = (0 == strtol(env, NULL, 0)) ? false : true; #ifdef H5FDmpio_DEBUG - /* Clear the flag buffer */ - memset(H5FD_mpio_debug_flags_s, 0, sizeof(H5FD_mpio_debug_flags_s)); + /* Clear the flag buffer */ + memset(H5FD_mpio_debug_flags_s, 0, sizeof(H5FD_mpio_debug_flags_s)); - /* Retrieve MPI-IO debugging environment variable */ - s = getenv("H5FD_mpio_Debug"); - if (s) - H5FD__mpio_parse_debug_str(s); + /* Retrieve MPI-IO debugging environment variable */ + env = getenv("H5FD_mpio_Debug"); + if (env) + H5FD__mpio_parse_debug_str(env); #endif /* H5FDmpio_DEBUG */ - H5FD_mpio_Debug_inited++; - } /* end if */ - - /* Set return value */ - ret_value = H5FD_MPIO_g; + /* Indicate that driver is set up */ + H5FD_mpio_init_s = true; done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_mpio_init() */ +} /* end H5FD__mpio_init() */ /*--------------------------------------------------------------------------- * Function: H5FD__mpio_term * * Purpose: Shut down the VFD * - * Returns: Non-negative on success or negative on failure + * Returns: SUCCEED (Can't fail) * *--------------------------------------------------------------------------- */ @@ -367,19 +386,16 @@ H5FD__mpio_term(void) FUNC_ENTER_PACKAGE_NOERR /* Terminate MPI if the driver initialized it */ - if (H5FD_mpi_self_initialized) { + if (H5FD_mpi_self_initialized_s) { int mpi_finalized = 0; MPI_Finalized(&mpi_finalized); if (!mpi_finalized) MPI_Finalize(); - H5FD_mpi_self_initialized = false; + H5FD_mpi_self_initialized_s = false; } - /* Reset VFL ID */ - H5FD_MPIO_g = 0; - FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5FD__mpio_term() */ @@ -853,11 +869,16 @@ H5FD__mpio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t H5_ATTR FUNC_ENTER_PACKAGE + /* Initialize driver, if it's not yet */ + if (!H5FD_mpio_init_s) + if (H5FD__mpio_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, NULL, "can't initialize driver"); + /* Get a pointer to the fapl */ if (NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list"); - if (H5FD_mpi_self_initialized) { + if (H5FD_mpi_self_initialized_s) { comm = MPI_COMM_WORLD; } else { @@ -3767,11 +3788,16 @@ H5FD__mpio_delete(const char *filename, hid_t fapl_id) assert(filename); + /* Initialize driver, if it's not yet */ + if (!H5FD_mpio_init_s) + if (H5FD__mpio_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize driver"); + if (NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list"); assert(H5FD_MPIO == H5P_peek_driver(plist)); - if (H5FD_mpi_self_initialized) { + if (H5FD_mpi_self_initialized_s) { comm = MPI_COMM_WORLD; } else { diff --git a/src/H5FDmpio.h b/src/H5FDmpio.h index 43f38502fb5..f2bd5b1fa8e 100644 --- a/src/H5FDmpio.h +++ b/src/H5FDmpio.h @@ -16,10 +16,21 @@ #ifndef H5FDmpio_H #define H5FDmpio_H +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + #ifdef H5_HAVE_PARALLEL -/** Initializer for the mpio VFD */ -#define H5FD_MPIO (H5FD_mpio_init()) +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the mpio VFD */ +#define H5FD_MPIO (H5OPEN H5FD_MPIO_id_g) #else @@ -35,19 +46,19 @@ #define H5FDmpio_DEBUG #endif -/* Global var whose value comes from environment variable */ -/* (Defined in H5FDmpio.c) */ -H5_DLLVAR hbool_t H5FD_mpi_opt_types_g; - #ifdef __cplusplus extern "C" { #endif +/* Global var whose value comes from environment variable */ +/* (Defined in H5FDmpio.c) */ +H5_DLLVAR hbool_t H5FD_mpi_opt_types_g; + /** @private * - * \brief Private initializer for the mpio VFD + * \brief ID for the mpio VFD */ -H5_DLL hid_t H5FD_mpio_init(void); +H5_DLLVAR hid_t H5FD_MPIO_id_g; /** * \ingroup FAPL diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c index 2838ed00bff..c43d7820851 100644 --- a/src/H5FDmulti.c +++ b/src/H5FDmulti.c @@ -98,9 +98,6 @@ #define H5FD_MULT_MAX_FILE_NAME_LEN 1024 -/* The driver identification number, initialized at runtime */ -static hid_t H5FD_MULTI_g = 0; - /* Driver-specific file access properties */ typedef struct H5FD_multi_fapl_t { H5FD_mem_t memb_map[H5FD_MEM_NTYPES]; /*memory usage map */ @@ -145,7 +142,6 @@ static int compute_next(H5FD_multi_t *file); static int open_members(H5FD_multi_t *file); /* Callback prototypes */ -static herr_t H5FD_multi_term(void); static hsize_t H5FD_multi_sb_size(H5FD_t *file); static herr_t H5FD_multi_sb_encode(H5FD_t *file, char *name /*out*/, unsigned char *buf /*out*/); static herr_t H5FD_multi_sb_decode(H5FD_t *file, const char *name, const unsigned char *buf); @@ -176,13 +172,13 @@ static herr_t H5FD_multi_ctl(H5FD_t *_file, uint64_t op_code, uint64_t flags, c void **output); /* The class struct */ -static const H5FD_class_t H5FD_multi_g = { +const H5FD_class_t H5FD_multi_g = { H5FD_CLASS_VERSION, /* struct version */ H5_VFD_MULTI, /* value */ "multi", /* name */ HADDR_MAX, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD_multi_term, /* terminate */ + NULL, /* terminate */ H5FD_multi_sb_size, /* sb_size */ H5FD_multi_sb_encode, /* sb_encode */ H5FD_multi_sb_decode, /* sb_decode */ @@ -219,47 +215,6 @@ static const H5FD_class_t H5FD_multi_g = { H5FD_FLMAP_DEFAULT /* fl_map */ }; -/*------------------------------------------------------------------------- - * Function: H5FD_multi_init - * - * Purpose: Initialize this driver by registering the driver with the - * library. - * - * Return: Success: The driver ID for the multi driver - * Failure: H5I_INVALID_HID - * - *------------------------------------------------------------------------- - */ -hid_t -H5FD_multi_init(void) -{ - /* Clear the error stack */ - H5Eclear2(H5E_DEFAULT); - - if (H5I_VFL != H5Iget_type(H5FD_MULTI_g)) - H5FD_MULTI_g = H5FDregister(&H5FD_multi_g); - - return H5FD_MULTI_g; -} /* end H5FD_multi_init() */ - -/*--------------------------------------------------------------------------- - * Function: H5FD_multi_term - * - * Purpose: Shut down the VFD - * - * Returns: Non-negative on success or negative on failure - * - *--------------------------------------------------------------------------- - */ -static herr_t -H5FD_multi_term(void) -{ - /* Reset VFL ID */ - H5FD_MULTI_g = 0; - - return 0; -} /* end H5FD_multi_term() */ - /*------------------------------------------------------------------------- * Function: H5Pset_fapl_split * @@ -278,13 +233,12 @@ H5Pset_fapl_split(hid_t fapl, const char *meta_ext, hid_t meta_plist_id, const c hid_t raw_plist_id) { H5FD_multi_fapl_t fa; - static const char *func = "H5Pset_fapl_split"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); if (H5FD_split_populate_config(meta_ext, meta_plist_id, raw_ext, raw_plist_id, true, &fa) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, "can't setup split driver configuration", + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, "can't setup split driver configuration", -1); return H5Pset_driver(fapl, H5FD_MULTI, &fa); @@ -368,16 +322,15 @@ H5Pset_fapl_multi(hid_t fapl_id, const H5FD_mem_t *memb_map, const hid_t *memb_f const char *const *memb_name, const haddr_t *memb_addr, hbool_t relax) { H5FD_multi_fapl_t fa; - static const char *func = "H5FDset_fapl_multi"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); /* Check arguments and supply default values */ if (H5I_GENPROP_LST != H5Iget_type(fapl_id) || true != H5Pisa_class(fapl_id, H5P_FILE_ACCESS)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_PLIST, H5E_BADVALUE, "not an access list", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_PLIST, H5E_BADVALUE, "not an access list", -1); if (H5FD_multi_populate_config(memb_map, memb_fapl, memb_name, memb_addr, relax, &fa) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, "can't setup driver configuration", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, "can't setup driver configuration", -1); return H5Pset_driver(fapl_id, H5FD_MULTI, &fa); } @@ -402,15 +355,14 @@ H5Pget_fapl_multi(hid_t fapl_id, H5FD_mem_t *memb_map /*out*/, hid_t *memb_fapl const H5FD_multi_fapl_t *fa; H5FD_multi_fapl_t default_fa; H5FD_mem_t mt; - static const char *func = "H5FDget_fapl_multi"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); if (H5I_GENPROP_LST != H5Iget_type(fapl_id) || true != H5Pisa_class(fapl_id, H5P_FILE_ACCESS)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_PLIST, H5E_BADTYPE, "not an access list", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_PLIST, H5E_BADTYPE, "not an access list", -1); if (H5FD_MULTI != H5Pget_driver(fapl_id)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_PLIST, H5E_BADVALUE, "incorrect VFL driver", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_PLIST, H5E_BADVALUE, "incorrect VFL driver", -1); H5E_BEGIN_TRY { fa = (const H5FD_multi_fapl_t *)H5Pget_driver_info(fapl_id); @@ -418,7 +370,7 @@ H5Pget_fapl_multi(hid_t fapl_id, H5FD_mem_t *memb_map /*out*/, hid_t *memb_fapl H5E_END_TRY if (!fa || (H5P_FILE_ACCESS_DEFAULT == fapl_id)) { if (H5FD_multi_populate_config(NULL, NULL, NULL, NULL, true, &default_fa) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_CANTSET, "can't setup default driver configuration", + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_CANTSET, "can't setup default driver configuration", -1); fa = &default_fa; } @@ -464,7 +416,6 @@ static herr_t H5FD_split_populate_config(const char *meta_ext, hid_t meta_plist_id, const char *raw_ext, hid_t raw_plist_id, bool relax, H5FD_multi_fapl_t *fa_out) { - static const char *func = "H5FD_split_populate_config"; /* Function Name for error reporting */ static char meta_name_g[H5FD_MULT_MAX_FILE_NAME_LEN]; /* Static scratch buffer to store metadata member name */ static char @@ -536,18 +487,18 @@ H5FD_split_populate_config(const char *meta_ext, hid_t meta_plist_id, const char /* Map usage type */ H5FD_mem_t mmt = _memb_map[mt]; if (mmt < 0 || mmt >= H5FD_MEM_NTYPES) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADRANGE, "file resource type out of range", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADRANGE, "file resource type out of range", -1); /* * All members of MEMB_FAPL must be either defaults or actual file * access property lists. */ if (H5P_DEFAULT != _memb_fapl[mmt] && true != H5Pisa_class(_memb_fapl[mmt], H5P_FILE_ACCESS)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "file resource type incorrect", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "file resource type incorrect", -1); /* All names must be defined */ if (!_memb_name[mmt] || !_memb_name[mmt][0]) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "file resource type not set", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "file resource type not set", -1); } END_MEMBERS @@ -567,7 +518,7 @@ H5FD_split_populate_config(const char *meta_ext, hid_t meta_plist_id, const char if (fa_out->memb_fapl[mt] == H5P_DEFAULT) { fa_out->memb_fapl[mt] = H5Pcreate(H5P_FILE_ACCESS); if (H5Pset_fapl_sec2(fa_out->memb_fapl[mt]) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, "can't set sec2 driver on member FAPL", -1); } } @@ -590,7 +541,6 @@ static herr_t H5FD_multi_populate_config(const H5FD_mem_t *memb_map, const hid_t *memb_fapl, const char *const *memb_name, const haddr_t *memb_addr, bool relax, H5FD_multi_fapl_t *fa_out) { - static const char *func = "H5FD_multi_populate_config"; /* Function Name for error reporting */ static const char *letters = "Xsbrglo"; static char _memb_name_g[H5FD_MEM_NTYPES][16]; /* Static scratch buffer to store member names */ H5FD_mem_t mt, mmt; @@ -611,7 +561,7 @@ H5FD_multi_populate_config(const H5FD_mem_t *memb_map, const hid_t *memb_fapl, c for (mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; mt = (H5FD_mem_t)(mt + 1)) { _memb_fapl[mt] = H5Pcreate(H5P_FILE_ACCESS); if (H5Pset_fapl_sec2(_memb_fapl[mt]) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, "can't set sec2 driver on member FAPL", -1); } memb_fapl = _memb_fapl; @@ -634,7 +584,7 @@ H5FD_multi_populate_config(const H5FD_mem_t *memb_map, const hid_t *memb_fapl, c /* Map usage type */ mmt = memb_map[mt]; if (mmt < 0 || mmt >= H5FD_MEM_NTYPES) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADRANGE, "file resource type out of range", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADRANGE, "file resource type out of range", -1); if (H5FD_MEM_DEFAULT == mmt) mmt = mt; @@ -643,11 +593,11 @@ H5FD_multi_populate_config(const H5FD_mem_t *memb_map, const hid_t *memb_fapl, c * access property lists. */ if (H5P_DEFAULT != memb_fapl[mmt] && true != H5Pisa_class(memb_fapl[mmt], H5P_FILE_ACCESS)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "file resource type incorrect", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "file resource type incorrect", -1); /* All names must be defined */ if (!memb_name[mmt] || !memb_name[mmt][0]) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "file resource type not set", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "file resource type not set", -1); } /* @@ -666,7 +616,7 @@ H5FD_multi_populate_config(const H5FD_mem_t *memb_map, const hid_t *memb_fapl, c if (fa_out->memb_fapl[mt] == H5P_DEFAULT) { fa_out->memb_fapl[mt] = H5Pcreate(H5P_FILE_ACCESS); if (H5Pset_fapl_sec2(fa_out->memb_fapl[mt]) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, "can't set sec2 driver on member FAPL", -1); } } @@ -744,7 +694,6 @@ H5FD_multi_sb_encode(H5FD_t *_file, char *name /*out*/, unsigned char *buf /*out size_t nseen; size_t i; H5FD_mem_t m; - static const char *func = "H5FD_multi_sb_encode"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -780,7 +729,7 @@ H5FD_multi_sb_encode(H5FD_t *_file, char *name /*out*/, unsigned char *buf /*out } END_MEMBERS if (H5Tconvert(H5T_NATIVE_HADDR, H5T_STD_U64LE, nseen * 2, buf + 8, NULL, H5P_DEFAULT) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_DATATYPE, H5E_CANTCONVERT, "can't convert superblock info", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_DATATYPE, H5E_CANTCONVERT, "can't convert superblock info", -1); /* Encode all name templates */ p = buf + 8 + nseen * 2 * 8; @@ -827,14 +776,13 @@ H5FD_multi_sb_decode(H5FD_t *_file, const char *name, const unsigned char *buf) haddr_t memb_addr[H5FD_MEM_NTYPES]; haddr_t memb_eoa[H5FD_MEM_NTYPES]; haddr_t *ap; - static const char *func = "H5FD_multi_sb_decode"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); /* Make sure the name/version number is correct */ if (strcmp(name, "NCSAmult") != 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_BADVALUE, "invalid multi superblock", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_FILE, H5E_BADVALUE, "invalid multi superblock", -1); /* Set default values */ ALL_MEMBERS (mt) { @@ -866,7 +814,7 @@ H5FD_multi_sb_decode(H5FD_t *_file, const char *name, const unsigned char *buf) memcpy(x, buf, (nseen * 2 * 8)); buf += nseen * 2 * 8; if (H5Tconvert(H5T_STD_U64LE, H5T_NATIVE_HADDR, nseen * 2, x, NULL, H5P_DEFAULT) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_DATATYPE, H5E_CANTCONVERT, "can't convert superblock info", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_DATATYPE, H5E_CANTCONVERT, "can't convert superblock info", -1); ap = (haddr_t *)((void *)x); /* Extra (void *) cast to quiet "cast to create alignment" warning - 2019/07/05, QAK */ UNIQUE_MEMBERS (map, mt) { @@ -923,17 +871,17 @@ H5FD_multi_sb_decode(H5FD_t *_file, const char *name, const unsigned char *buf) } END_MEMBERS if (compute_next(file) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "compute_next() failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "compute_next() failed", -1); /* Open all necessary files */ if (open_members(file) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "open_members() failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "open_members() failed", -1); /* Set the EOA marker for all open files */ UNIQUE_MEMBERS (file->fa.memb_map, mt) { if (file->memb[mt]) if (H5FDset_eoa(file->memb[mt], mt, memb_eoa[mt]) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, "set_eoa() failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_CANTSET, "set_eoa() failed", -1); /* Save the individual EOAs in one place for later comparison (in H5FD_multi_set_eoa) */ @@ -986,7 +934,6 @@ H5FD_multi_fapl_copy(const void *_old_fa) const H5FD_multi_fapl_t *old_fa = (const H5FD_multi_fapl_t *)_old_fa; H5FD_multi_fapl_t *new_fa = (H5FD_multi_fapl_t *)calloc(1, sizeof(H5FD_multi_fapl_t)); int nerrors = 0; - static const char *func = "H5FD_multi_fapl_copy"; /* Function Name for error reporting */ assert(new_fa); @@ -1021,7 +968,7 @@ H5FD_multi_fapl_copy(const void *_old_fa) } END_MEMBERS free(new_fa); - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "can't release object on error", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "can't release object on error", NULL); } return new_fa; } @@ -1041,7 +988,6 @@ static herr_t H5FD_multi_fapl_free(void *_fa) { H5FD_multi_fapl_t *fa = (H5FD_multi_fapl_t *)_fa; - static const char *func = "H5FD_multi_fapl_free"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -1049,7 +995,7 @@ H5FD_multi_fapl_free(void *_fa) ALL_MEMBERS (mt) { if (fa->memb_fapl[mt] >= 0) if (H5Idec_ref(fa->memb_fapl[mt]) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTCLOSEOBJ, "can't close property list", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_FILE, H5E_CANTCLOSEOBJ, "can't close property list", -1); if (fa->memb_name[mt]) free(fa->memb_name[mt]); } @@ -1079,16 +1025,15 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr hid_t close_fapl = -1; const H5FD_multi_fapl_t *fa; H5FD_mem_t m; - static const char *func = "H5FD_multi_open"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); /* Check arguments */ if (!name || !*name) - H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADVALUE, "invalid file name", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_ARGS, H5E_BADVALUE, "invalid file name", NULL); if (0 == maxaddr || HADDR_UNDEF == maxaddr) - H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADRANGE, "bogus maxaddr", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_ARGS, H5E_BADRANGE, "bogus maxaddr", NULL); /* * Initialize the file from the file access properties, using default @@ -1097,7 +1042,7 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr * in H5FD_multi_t. */ if (NULL == (file = (H5FD_multi_t *)calloc((size_t)1, sizeof(H5FD_multi_t)))) - H5Epush_ret(func, H5E_ERR_CLS, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed", NULL); H5E_BEGIN_TRY { fa = (const H5FD_multi_fapl_t *)H5Pget_driver_info(fapl_id); @@ -1109,11 +1054,11 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr close_fapl = fapl_id = H5Pcreate(H5P_FILE_ACCESS); if (env && !strcmp(env, "split")) { if (H5Pset_fapl_split(fapl_id, NULL, H5P_DEFAULT, NULL, H5P_DEFAULT) < 0) - H5Epush_goto(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTSET, "can't set property value", error); + H5Epush_goto(__func__, H5E_ERR_CLS, H5E_FILE, H5E_CANTSET, "can't set property value", error); } else { if (H5Pset_fapl_multi(fapl_id, NULL, NULL, NULL, NULL, true) < 0) - H5Epush_goto(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTSET, "can't set property value", error); + H5Epush_goto(__func__, H5E_ERR_CLS, H5E_FILE, H5E_CANTSET, "can't set property value", error); } fa = (const H5FD_multi_fapl_t *)H5Pget_driver_info(fapl_id); @@ -1136,13 +1081,13 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr file->name = my_strdup(name); if (close_fapl >= 0) if (H5Pclose(close_fapl) < 0) - H5Epush_goto(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTCLOSEOBJ, "can't close property list", error); + H5Epush_goto(__func__, H5E_ERR_CLS, H5E_FILE, H5E_CANTCLOSEOBJ, "can't close property list", error); /* Compute derived properties and open member files */ if (compute_next(file) < 0) - H5Epush_goto(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "compute_next() failed", error); + H5Epush_goto(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "compute_next() failed", error); if (open_members(file) < 0) - H5Epush_goto(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "open_members() failed", error); + H5Epush_goto(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "open_members() failed", error); /* We must have opened at least the superblock file */ if (H5FD_MEM_DEFAULT == (m = file->fa.memb_map[H5FD_MEM_SUPER])) @@ -1189,7 +1134,6 @@ H5FD_multi_close(H5FD_t *_file) { H5FD_multi_t *file = (H5FD_multi_t *)_file; int nerrors = 0; - static const char *func = "H5FD_multi_close"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -1207,7 +1151,7 @@ H5FD_multi_close(H5FD_t *_file) } END_MEMBERS if (nerrors) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error closing member files", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error closing member files", -1); /* Clean up other stuff */ ALL_MEMBERS (mt) { @@ -1337,7 +1281,6 @@ H5FD_multi_get_eoa(const H5FD_t *_file, H5FD_mem_t type) { const H5FD_multi_t *file = (const H5FD_multi_t *)_file; haddr_t eoa = 0; - static const char *func = "H5FD_multi_get_eoa"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -1361,7 +1304,7 @@ H5FD_multi_get_eoa(const H5FD_t *_file, H5FD_mem_t type) H5E_END_TRY if (HADDR_UNDEF == memb_eoa) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "member file has unknown eoa", + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "member file has unknown eoa", HADDR_UNDEF); if (memb_eoa > 0) memb_eoa += file->fa.memb_addr[mt]; @@ -1375,7 +1318,7 @@ H5FD_multi_get_eoa(const H5FD_t *_file, H5FD_mem_t type) assert(HADDR_UNDEF != memb_eoa); } else { - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "bad eoa", HADDR_UNDEF); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "bad eoa", HADDR_UNDEF); } if (memb_eoa > eoa) @@ -1397,7 +1340,7 @@ H5FD_multi_get_eoa(const H5FD_t *_file, H5FD_mem_t type) H5E_END_TRY if (HADDR_UNDEF == eoa) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "member file has unknown eoa", + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "member file has unknown eoa", HADDR_UNDEF); if (eoa > 0) eoa += file->fa.memb_addr[mmt]; @@ -1411,7 +1354,7 @@ H5FD_multi_get_eoa(const H5FD_t *_file, H5FD_mem_t type) assert(HADDR_UNDEF != eoa); } else { - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "bad eoa", HADDR_UNDEF); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "bad eoa", HADDR_UNDEF); } } @@ -1438,7 +1381,6 @@ H5FD_multi_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t eoa) H5FD_multi_t *file = (H5FD_multi_t *)_file; H5FD_mem_t mmt; herr_t status; - static const char *func = "H5FD_multi_set_eoa"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -1474,7 +1416,7 @@ H5FD_multi_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t eoa) } H5E_END_TRY if (status < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_BADVALUE, "member H5FDset_eoa failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_FILE, H5E_BADVALUE, "member H5FDset_eoa failed", -1); return 0; } /* end H5FD_multi_set_eoa() */ @@ -1498,7 +1440,6 @@ H5FD_multi_get_eof(const H5FD_t *_file, H5FD_mem_t type) { const H5FD_multi_t *file = (const H5FD_multi_t *)_file; haddr_t eof = 0; - static const char *func = "H5FD_multi_get_eof"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -1516,7 +1457,7 @@ H5FD_multi_get_eof(const H5FD_t *_file, H5FD_mem_t type) H5E_END_TRY if (HADDR_UNDEF == tmp_eof) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "member file has unknown eof", + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "member file has unknown eof", HADDR_UNDEF); if (tmp_eof > 0) tmp_eof += file->fa.memb_addr[mt]; @@ -1530,7 +1471,7 @@ H5FD_multi_get_eof(const H5FD_t *_file, H5FD_mem_t type) assert(HADDR_UNDEF != tmp_eof); } else { - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "bad eof", HADDR_UNDEF); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "bad eof", HADDR_UNDEF); } if (tmp_eof > eof) eof = tmp_eof; @@ -1552,7 +1493,7 @@ H5FD_multi_get_eof(const H5FD_t *_file, H5FD_mem_t type) H5E_END_TRY if (HADDR_UNDEF == eof) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "member file has unknown eof", + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "member file has unknown eof", HADDR_UNDEF); if (eof > 0) eof += file->fa.memb_addr[mmt]; @@ -1566,7 +1507,7 @@ H5FD_multi_get_eof(const H5FD_t *_file, H5FD_mem_t type) assert(HADDR_UNDEF != eof); } else { - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "bad eof", HADDR_UNDEF); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "bad eof", HADDR_UNDEF); } } return eof; @@ -1586,14 +1527,13 @@ H5FD_multi_get_handle(H5FD_t *_file, hid_t fapl, void **file_handle) { H5FD_multi_t *file = (H5FD_multi_t *)_file; H5FD_mem_t type, mmt; - static const char *func = "H5FD_multi_get_handle"; /* Function Name for error reporting */ /* Get data type for multi driver */ if (H5Pget_multi_type(fapl, &type) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "can't get data type for multi driver", + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "can't get data type for multi driver", -1); if (type < H5FD_MEM_DEFAULT || type >= H5FD_MEM_NTYPES) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "data type is out of range", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "data type is out of range", -1); mmt = file->fa.memb_map[type]; if (H5FD_MEM_DEFAULT == mmt) mmt = type; @@ -1618,7 +1558,6 @@ H5FD_multi_alloc(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, hsize_t size) H5FD_multi_t *file = (H5FD_multi_t *)_file; H5FD_mem_t mmt; haddr_t addr; - static const char *func = "H5FD_multi_alloc"; /* Function Name for error reporting */ mmt = file->fa.memb_map[type]; if (H5FD_MEM_DEFAULT == mmt) @@ -1634,23 +1573,9 @@ H5FD_multi_alloc(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, hsize_t size) } if (HADDR_UNDEF == (addr = H5FDalloc(file->memb[mmt], mmt, dxpl_id, size))) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "member file can't alloc", HADDR_UNDEF); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "member file can't alloc", HADDR_UNDEF); addr += file->fa.memb_addr[mmt]; - /*#ifdef TMP - if ( addr + size > file->eoa ) { - - if ( H5FD_multi_set_eoa(_file, addr + size) < 0 ) { - - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, \ - "can't set eoa", HADDR_UNDEF); - } - } - #else - if ( addr + size > file->eoa ) - file->eoa = addr + size; - #endif */ - return addr; } @@ -1787,39 +1712,6 @@ H5FD_multi_flush(H5FD_t *_file, hid_t dxpl_id, bool closing) H5FD_multi_t *file = (H5FD_multi_t *)_file; H5FD_mem_t mt; int nerrors = 0; - static const char *func = "H5FD_multi_flush"; /* Function Name for error reporting */ - -#if 0 - H5FD_mem_t mmt; - - /* Debugging stuff... */ - fprintf(stderr, "multifile access information:\n"); - - /* print the map */ - fprintf(stderr, " map="); - for (mt=1; mtmemb_map[mt]; - if (H5FD_MEM_DEFAULT==mmt) mmt = mt; - fprintf(stderr, "%s%d", 1==mt?"":",", (int)mmt); - } - fprintf(stderr, "\n"); - - /* print info about each file */ - fprintf(stderr, " File Starting Allocated Next Member\n"); - fprintf(stderr, " Number Address Size Address Name\n"); - fprintf(stderr, " ------ -------------------- -------------------- -------------------- ------------------------------\n"); - - for (mt=1; mtmemb_addr[mt]) { - haddr_t eoa = H5FDget_eoa(file->memb[mt], mt); - fprintf(stderr, " %6d %20llu %20llu %20llu %s\n", - (int)mt, (unsigned long long)(file->memb_addr[mt]), - (unsigned long long)eoa, - (unsigned long long)(file->memb_next[mt]), - file->memb_name[mt]); - } - } -#endif /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -1836,7 +1728,7 @@ H5FD_multi_flush(H5FD_t *_file, hid_t dxpl_id, bool closing) } } if (nerrors) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error flushing member files", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error flushing member files", -1); return 0; } @@ -1857,7 +1749,6 @@ H5FD_multi_truncate(H5FD_t *_file, hid_t dxpl_id, bool closing) H5FD_multi_t *file = (H5FD_multi_t *)_file; H5FD_mem_t mt; int nerrors = 0; - static const char *func = "H5FD_multi_truncate"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -1874,7 +1765,7 @@ H5FD_multi_truncate(H5FD_t *_file, hid_t dxpl_id, bool closing) } } if (nerrors) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error truncating member files", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error truncating member files", -1); return 0; } /* end H5FD_multi_truncate() */ @@ -1898,7 +1789,6 @@ H5FD_multi_lock(H5FD_t *_file, bool rw) H5FD_multi_t *file = (H5FD_multi_t *)_file; int nerrors = 0; H5FD_mem_t out_mt = H5FD_MEM_DEFAULT; - static const char *func = "H5FD_multi_unlock"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -1934,7 +1824,7 @@ H5FD_multi_lock(H5FD_t *_file, bool rw) } /* end if */ if (nerrors) - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_CANTLOCKFILE, "error locking member files", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_CANTLOCKFILE, "error locking member files", -1); return 0; } /* H5FD_multi_lock() */ @@ -1956,7 +1846,6 @@ H5FD_multi_unlock(H5FD_t *_file) { H5FD_multi_t *file = (H5FD_multi_t *)_file; int nerrors = 0; - static const char *func = "H5FD_multi_unlock"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -1969,7 +1858,7 @@ H5FD_multi_unlock(H5FD_t *_file) END_MEMBERS if (nerrors) - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_CANTUNLOCKFILE, "error unlocking member files", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_CANTUNLOCKFILE, "error unlocking member files", -1); return 0; } /* H5FD_multi_unlock() */ @@ -2039,7 +1928,6 @@ open_members(H5FD_multi_t *file) char tmp[H5FD_MULT_MAX_FILE_NAME_LEN]; int nerrors = 0; int nchars; - static const char *func = "(H5FD_multi)open_members"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -2051,7 +1939,7 @@ open_members(H5FD_multi_t *file) nchars = snprintf(tmp, sizeof(tmp), file->fa.memb_name[mt], file->name); if (nchars < 0 || nchars >= (int)sizeof(tmp)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_BADVALUE, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_BADVALUE, "filename is too long and would be truncated", -1); H5E_BEGIN_TRY @@ -2066,7 +1954,7 @@ open_members(H5FD_multi_t *file) } END_MEMBERS if (nerrors) - H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error opening member files", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error opening member files", -1); return 0; } @@ -2089,7 +1977,6 @@ H5FD_multi_delete(const char *filename, hid_t fapl_id) int nchars; const H5FD_multi_fapl_t *fa; H5FD_multi_fapl_t default_fa; - static const char *func = "H5FD_multi_delete"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -2107,11 +1994,11 @@ H5FD_multi_delete(const char *filename, hid_t fapl_id) if (env && !strcmp(env, "split")) { if (H5FD_split_populate_config(NULL, H5P_DEFAULT, NULL, H5P_DEFAULT, true, &default_fa) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_CANTSET, "can't setup driver configuration", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_CANTSET, "can't setup driver configuration", -1); } else { if (H5FD_multi_populate_config(NULL, NULL, NULL, NULL, true, &default_fa) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_CANTSET, "can't setup driver configuration", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_CANTSET, "can't setup driver configuration", -1); } fa = &default_fa; @@ -2125,11 +2012,11 @@ H5FD_multi_delete(const char *filename, hid_t fapl_id) nchars = snprintf(full_filename, sizeof(full_filename), fa->memb_name[mt], filename); if (nchars < 0 || nchars >= (int)sizeof(full_filename)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_BADVALUE, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_BADVALUE, "filename is too long and would be truncated", -1); if (H5FDdelete(full_filename, fa->memb_fapl[mt]) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_BADVALUE, "error deleting member files", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_BADVALUE, "error deleting member files", -1); } END_MEMBERS @@ -2161,7 +2048,6 @@ static herr_t H5FD_multi_ctl(H5FD_t *_file, uint64_t op_code, uint64_t flags, const void *input, void **output) { H5FD_multi_t *file = (H5FD_multi_t *)_file; - static const char *func = "H5FD_multi_ctl"; /* Function Name for error reporting */ herr_t ret_value = 0; /* Silence compiler */ @@ -2176,7 +2062,7 @@ H5FD_multi_ctl(H5FD_t *_file, uint64_t op_code, uint64_t flags, const void *inpu /* Unknown op code */ default: if (flags & H5FD_CTL_FAIL_IF_UNKNOWN_FLAG) - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_FCNTL, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_FCNTL, "VFD ctl request failed (unknown op code and fail if unknown flag is set)", -1); break; diff --git a/src/H5FDmulti.h b/src/H5FDmulti.h index 1f9c367cd93..d21103fd42b 100644 --- a/src/H5FDmulti.h +++ b/src/H5FDmulti.h @@ -16,8 +16,20 @@ #ifndef H5FDmulti_H #define H5FDmulti_H -/** Initializer for the multi VFD */ -#define H5FD_MULTI (H5FD_multi_init()) +/* Public header files */ +#include "H5Ipublic.h" /* IDs */ +#include "H5FDpublic.h" /* File drivers */ + +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the multi VFD */ +#define H5FD_MULTI (H5OPEN H5FD_MULTI_id_g) #ifdef __cplusplus extern "C" { @@ -25,9 +37,9 @@ extern "C" { /** @private * - * \brief Private initializer for the multi VFD + * \brief ID for the multi VFD */ -H5_DLL hid_t H5FD_multi_init(void); +H5_DLLVAR hid_t H5FD_MULTI_id_g; /** * \ingroup FAPL diff --git a/src/H5FDmulti_int.c b/src/H5FDmulti_int.c new file mode 100644 index 00000000000..059b76fa7b7 --- /dev/null +++ b/src/H5FDmulti_int.c @@ -0,0 +1,85 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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 COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://www.hdfgroup.org/licenses. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Purpose: Private routines for the multi VFD. + * + * Necessary for using internal library routines, which are + * disallowed within the actual multi VFD code. + * + */ + +/****************/ +/* Module Setup */ +/****************/ + +#define H5FD_FRIEND /* Suppress error about including H5FDpkg */ + +/***********/ +/* Headers */ +/***********/ + +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Iprivate.h" /* IDs */ +#include "H5FDpkg.h" /* File drivers */ + +#include "H5FDmulti_private.h" /* multi VFD */ + +/* The driver identification number, initialized at runtime */ +hid_t H5FD_MULTI_id_g = H5I_INVALID_HID; + +/*------------------------------------------------------------------------- + * Function: H5FD__multi_register + * + * Purpose: Register the driver with the library. + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5FD__multi_register(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + if (H5I_VFL != H5I_get_type(H5FD_MULTI_id_g)) + if ((H5FD_MULTI_id_g = H5FD_register(&H5FD_multi_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register multi driver"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD__multi_register() */ + +/*--------------------------------------------------------------------------- + * Function: H5FD__multi_unregister + * + * Purpose: Reset library driver info. + * + * Returns: SUCCEED (Can't fail) + * + *--------------------------------------------------------------------------- + */ +herr_t +H5FD__multi_unregister(void) +{ + FUNC_ENTER_PACKAGE_NOERR + + /* Reset VFL ID */ + H5FD_MULTI_id_g = H5I_INVALID_HID; + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5FD_multi_unregister() */ + + diff --git a/src/H5FDonion_module.h b/src/H5FDmulti_private.h similarity index 53% rename from src/H5FDonion_module.h rename to src/H5FDmulti_private.h index bb78a5abdbb..4b6006eee5d 100644 --- a/src/H5FDonion_module.h +++ b/src/H5FDmulti_private.h @@ -11,18 +11,37 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* - * Purpose: This file contains declarations which define macros for the - * H5FD onion package. Including this header means that the source file - * is part of the H5FD onion package. + * Purpose: The private header file for the multi VFD */ -#ifndef H5FDonion_module_H -#define H5FDonion_module_H -/* Define the proper control macros for the generic FUNC_ENTER/LEAVE and error - * reporting macros. - */ -#define H5_MY_PKG H5FD__onion -#define H5_MY_PKG_ERR H5E_VFL -#define H5_MY_PKG_INIT YES +#ifndef H5FDmulti_private_H +#define H5FDmulti_private_H + +/* Include VFD's public header */ +#include "H5FDmulti.h" /* multi VFD */ + +/* Private headers needed by this file */ +#include "H5FDprivate.h" /* File drivers */ + +/**************************/ +/* Library Private Macros */ +/**************************/ + +/****************************/ +/* Library Private Typedefs */ +/****************************/ + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + +/* multi VFD's class struct */ +H5_DLLVAR const H5FD_class_t H5FD_multi_g; + +/******************************/ +/* Library Private Prototypes */ +/******************************/ + +#endif /* H5FDmulti_private_H */ + -#endif /* H5FDonion_module_H */ diff --git a/src/H5FDonion.c b/src/H5FDonion.c index f51a3ac3c41..21f618d596a 100644 --- a/src/H5FDonion.c +++ b/src/H5FDonion.c @@ -16,25 +16,20 @@ * Purpose: Provide in-file provenance and revision/version control. */ -/* This source code file is part of the H5FD onion module */ -#include "H5FDonion_module.h" +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* Files */ -#include "H5FDprivate.h" /* File drivers */ -#include "H5FDonion.h" /* Onion file driver */ +#include "H5FDsec2.h" /* Sec2 file driver */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FDonion_priv.h" /* Onion file driver internals */ -#include "H5FDsec2.h" /* Sec2 file driver */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ /* The driver identification number, initialized at runtime */ -static hid_t H5FD_ONION_g = H5I_INVALID_HID; - -/* Package initialization variable */ -bool H5_PKG_INIT_VAR = false; +hid_t H5FD_ONION_id_g = H5I_INVALID_HID; /****************************************************************************** * @@ -163,7 +158,6 @@ static haddr_t H5FD__onion_get_eof(const H5FD_t *, H5FD_mem_t); static H5FD_t *H5FD__onion_open(const char *, unsigned int, hid_t, haddr_t); static herr_t H5FD__onion_read(H5FD_t *, H5FD_mem_t, hid_t, haddr_t, size_t, void *); static herr_t H5FD__onion_set_eoa(H5FD_t *, H5FD_mem_t, haddr_t); -static herr_t H5FD__onion_term(void); static herr_t H5FD__onion_write(H5FD_t *, H5FD_mem_t, hid_t, haddr_t, size_t, const void *); static herr_t H5FD__onion_open_rw(H5FD_onion_t *, unsigned int, haddr_t, bool new_open); @@ -183,7 +177,7 @@ static const H5FD_class_t H5FD_onion_g = { "onion", /* name */ MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD__onion_term, /* terminate */ + NULL, /* terminate */ H5FD__onion_sb_size, /* sb_size */ H5FD__onion_sb_encode, /* sb_encode */ H5FD__onion_sb_decode, /* sb_decode */ @@ -220,74 +214,49 @@ static const H5FD_class_t H5FD_onion_g = { H5FD_FLMAP_DICHOTOMY /* fl_map */ }; -/*------------------------------------------------------------------------- - * Function: H5FD__onion__init_package +/*----------------------------------------------------------------------------- + * Function: H5FD__onion_register * - * Purpose: Initializes any interface-specific data or routines. + * Purpose: Register the driver with the library. * - * Return: Non-negative on success/Negative on failure + * Return: SUCCEED/FAIL * - *------------------------------------------------------------------------- + *----------------------------------------------------------------------------- */ herr_t -H5FD__onion__init_package(void) +H5FD__onion_register(void) { - herr_t ret_value = SUCCEED; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE - if (H5FD_onion_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize onion VFD"); + if (H5I_VFL != H5I_get_type(H5FD_ONION_id_g)) + if ((H5FD_ONION_id_g = H5FD_register(&H5FD_onion_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register onion driver"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__onion__init_package() */ +} /* end H5FD__onion_register() */ /*----------------------------------------------------------------------------- - * Function: H5FD_onion_init + * Function: H5FD__onion_unregister * - * Purpose: Initialize this driver by registering the driver with the - * library. - * - * Return: Success: The driver ID for the onion driver. - * Failure: Negative - *----------------------------------------------------------------------------- - */ -hid_t -H5FD_onion_init(void) -{ - hid_t ret_value = H5I_INVALID_HID; - - FUNC_ENTER_NOAPI(H5I_INVALID_HID) - - if (H5I_VFL != H5I_get_type(H5FD_ONION_g)) - H5FD_ONION_g = H5FD_register(&H5FD_onion_g, sizeof(H5FD_class_t), false); - - /* Set return value */ - ret_value = H5FD_ONION_g; - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_onion_init() */ - -/*----------------------------------------------------------------------------- - * Function: H5FD__onion_term - * - * Purpose: Shut down the Onion VFD. + * Purpose: Reset library driver info. * * Returns: SUCCEED (Can't fail) + * *----------------------------------------------------------------------------- */ -static herr_t -H5FD__onion_term(void) +herr_t +H5FD__onion_unregister(void) { FUNC_ENTER_PACKAGE_NOERR /* Reset VFL ID */ - H5FD_ONION_g = H5I_INVALID_HID; + H5FD_ONION_id_g = H5I_INVALID_HID; FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5FD__onion_term() */ +} /* end H5FD__onion_unregister() */ /*----------------------------------------------------------------------------- * Function: H5Pget_fapl_onion diff --git a/src/H5FDonion.h b/src/H5FDonion.h index 24f6d6d7957..9302b09647d 100644 --- a/src/H5FDonion.h +++ b/src/H5FDonion.h @@ -16,8 +16,19 @@ #ifndef H5FDonion_H #define H5FDonion_H -/** Initializer for the onion VFD */ -#define H5FD_ONION (H5FD_onion_init()) +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the onion VFD */ +#define H5FD_ONION (H5OPEN H5FD_ONION_id_g) /** Identifier for the onion VFD */ #define H5FD_ONION_VALUE H5_VFD_ONION @@ -115,9 +126,9 @@ extern "C" { /** @private * - * \brief Private initializer for the onion VFD + * \brief ID for the onion VFD */ -H5_DLL hid_t H5FD_onion_init(void); +H5_DLLVAR hid_t H5FD_ONION_id_g; /** * -------------------------------------------------------------------------- diff --git a/src/H5FDonion_header.c b/src/H5FDonion_header.c index 4dce530b9e0..718731020ee 100644 --- a/src/H5FDonion_header.c +++ b/src/H5FDonion_header.c @@ -16,13 +16,11 @@ * Purpose: Code for the onion file's header */ -/* This source code file is part of the H5FD onion module */ -#include "H5FDonion_module.h" +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ -#include "H5FDprivate.h" /* File drivers */ -#include "H5FDonion.h" /* Onion file driver */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FDonion_priv.h" /* Onion file driver internals */ #include "H5MMprivate.h" /* Memory management */ diff --git a/src/H5FDonion_history.c b/src/H5FDonion_history.c index 7aaece1d6bd..47822447f85 100644 --- a/src/H5FDonion_history.c +++ b/src/H5FDonion_history.c @@ -16,13 +16,11 @@ * Purpose: Code for the onion file's history */ -/* This source code file is part of the H5FD onion module */ -#include "H5FDonion_module.h" +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ -#include "H5FDprivate.h" /* File drivers */ -#include "H5FDonion.h" /* Onion file driver */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FDonion_priv.h" /* Onion file driver internals */ #include "H5MMprivate.h" /* Memory management */ diff --git a/src/H5FDonion_index.c b/src/H5FDonion_index.c index cbbdd05352e..c73b75e1f01 100644 --- a/src/H5FDonion_index.c +++ b/src/H5FDonion_index.c @@ -16,13 +16,11 @@ * Purpose: Code for the archival and revision indexes */ -/* This source code file is part of the H5FD onion module */ -#include "H5FDonion_module.h" +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ -#include "H5FDprivate.h" /* File drivers */ -#include "H5FDonion.h" /* Onion file driver */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FDonion_priv.h" /* Onion file driver internals */ #include "H5MMprivate.h" /* Memory management */ diff --git a/src/H5FDonion_priv.h b/src/H5FDonion_priv.h index 907d39f668a..3325c603ea4 100644 --- a/src/H5FDonion_priv.h +++ b/src/H5FDonion_priv.h @@ -21,6 +21,10 @@ #ifndef H5FDonion_priv_H #define H5FDonion_priv_H +/* Public headers */ +#include "H5FDonion.h" + +/* Private headers */ #include "H5FDonion_header.h" #include "H5FDonion_history.h" #include "H5FDonion_index.h" diff --git a/src/H5FDpkg.h b/src/H5FDpkg.h index 0d0a7b706c9..34597dd1527 100644 --- a/src/H5FDpkg.h +++ b/src/H5FDpkg.h @@ -39,6 +39,9 @@ /* Package Private Variables */ /*****************************/ +/* Whether to ignore file locks when disabled (env var value) */ +H5_DLLVAR htri_t H5FD_ignore_disabled_file_locks_p; + /******************************/ /* Package Private Prototypes */ /******************************/ @@ -46,6 +49,52 @@ H5_DLL haddr_t H5FD__alloc_real(H5FD_t *file, H5FD_mem_t type, hsize_t size, had hsize_t *align_size); H5_DLL herr_t H5FD__free_real(H5FD_t *file, H5FD_mem_t type, haddr_t addr, hsize_t size); +/* Internal VFD init/term routines */ +H5_DLL herr_t H5FD__core_register(void); +H5_DLL herr_t H5FD__core_unregister(void); +#ifdef H5_HAVE_DIRECT +H5_DLL herr_t H5FD__direct_register(void); +H5_DLL herr_t H5FD__direct_unregister(void); +#endif +H5_DLL herr_t H5FD__family_register(void); +H5_DLL herr_t H5FD__family_unregister(void); +#ifdef H5_HAVE_LIBHDFS +H5_DLL herr_t H5FD__hdfs_register(void); +H5_DLL herr_t H5FD__hdfs_unregister(void); +#endif +#ifdef H5_HAVE_IOC_VFD +H5_DLL herr_t H5FD__ioc_register(void); +H5_DLL herr_t H5FD__ioc_unregister(void); +#endif +H5_DLL herr_t H5FD__log_register(void); +H5_DLL herr_t H5FD__log_unregister(void); +#ifdef H5_HAVE_MIRROR_VFD +H5_DLL herr_t H5FD__mirror_register(void); +H5_DLL herr_t H5FD__mirror_unregister(void); +#endif +#ifdef H5_HAVE_PARALLEL +H5_DLL herr_t H5FD__mpio_register(void); +H5_DLL herr_t H5FD__mpio_unregister(void); +#endif +H5_DLL herr_t H5FD__multi_register(void); +H5_DLL herr_t H5FD__multi_unregister(void); +H5_DLL herr_t H5FD__onion_register(void); +H5_DLL herr_t H5FD__onion_unregister(void); +#ifdef H5_HAVE_ROS3_VFD +H5_DLL herr_t H5FD__ros3_register(void); +H5_DLL herr_t H5FD__ros3_unregister(void); +#endif +H5_DLL herr_t H5FD__sec2_register(void); +H5_DLL herr_t H5FD__sec2_unregister(void); +H5_DLL herr_t H5FD__splitter_register(void); +H5_DLL herr_t H5FD__splitter_unregister(void); +H5_DLL herr_t H5FD__stdio_register(void); +H5_DLL herr_t H5FD__stdio_unregister(void); +#ifdef H5_HAVE_SUBFILING_VFD +H5_DLL herr_t H5FD__subfiling_register(void); +H5_DLL herr_t H5FD__subfiling_unregister(void); +#endif + /* Testing functions */ #ifdef H5FD_TESTING H5_DLL bool H5FD__supports_swmr_test(const char *vfd_name); diff --git a/src/H5FDprivate.h b/src/H5FDprivate.h index cd0326de516..24bd4953a2f 100644 --- a/src/H5FDprivate.h +++ b/src/H5FDprivate.h @@ -109,6 +109,7 @@ struct H5S_t; struct H5F_t; union H5PL_key_t; +H5_DLL herr_t H5FD_init(void); H5_DLL int H5FD_term_interface(void); H5_DLL herr_t H5FD_locate_signature(H5FD_t *file, haddr_t *sig_addr); H5_DLL H5FD_class_t *H5FD_get_class(hid_t id); diff --git a/src/H5FDros3.c b/src/H5FDros3.c index 0d9b1f50808..079a0a93e55 100644 --- a/src/H5FDros3.c +++ b/src/H5FDros3.c @@ -17,21 +17,19 @@ * Relies on "s3comms" utility layer to implement the AWS REST API. */ -#ifdef H5_HAVE_ROS3_VFD -/* This source code file is part of the H5FD driver module */ -#include "H5FDdrvr_module.h" -#endif +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ + +#ifdef H5_HAVE_ROS3_VFD + #include "H5Eprivate.h" /* Error handling */ -#include "H5FDprivate.h" /* File drivers */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FDros3.h" /* ros3 file driver */ +#include "H5FDs3comms.h" /* S3 Communications */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ -#include "H5FDs3comms.h" /* S3 Communications */ - -#ifdef H5_HAVE_ROS3_VFD /* Define to turn on stats collection and reporting */ /* #define ROS3_STATS */ @@ -40,7 +38,12 @@ #define ROS3_MAX_CACHE_SIZE 16777216 /* The driver identification number, initialized at runtime */ -static hid_t H5FD_ROS3_g = 0; +hid_t H5FD_ROS3_id_g = H5I_INVALID_HID; + +/* Flag to indicate whether global driver resources & settings have been + * initialized. + */ +static bool H5FD_ros3_init_s = false; /* Session/security token property name */ #define ROS3_TOKEN_PROP_NAME "ros3_token_prop" @@ -139,7 +142,6 @@ typedef struct H5FD_ros3_t { #define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) /* Prototypes */ -static herr_t H5FD__ros3_term(void); static void *H5FD__ros3_fapl_get(H5FD_t *_file); static void *H5FD__ros3_fapl_copy(const void *_old_fa); static herr_t H5FD__ros3_fapl_free(void *_fa); @@ -176,7 +178,7 @@ static const H5FD_class_t H5FD_ros3_g = { "ros3", /* name */ MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD__ros3_term, /* terminate */ + NULL, /* terminate */ NULL, /* sb_size */ NULL, /* sb_encode */ NULL, /* sb_decode */ @@ -217,82 +219,77 @@ static const H5FD_class_t H5FD_ros3_g = { H5FL_DEFINE_STATIC(H5FD_ros3_t); /*------------------------------------------------------------------------- - * Function: H5FD__init_package + * Function: H5FD__ros3_register * - * Purpose: Initializes any interface-specific data or routines. + * Purpose: Register the driver with the library. * - * Return: Non-negative on success/Negative on failure + * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ -static herr_t -H5FD__init_package(void) +herr_t +H5FD__ros3_register(void) { - herr_t ret_value = SUCCEED; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE - if (H5FD_ros3_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize ros3 VFD"); + if (H5I_VFL != H5I_get_type(H5FD_ROS3_g)) + if ((H5FD_ROS3_id_g = H5FD_register(&H5FD_ros3_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register ros3 driver"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD__init_package() */ +} /* end H5FD__ros3_register() */ -/*------------------------------------------------------------------------- - * Function: H5FD_ros3_init +/*--------------------------------------------------------------------------- + * Function: H5FD__ros3_unregister * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Purpose: Reset library driver info. * - * Return: Success: The driver ID for the ros3 driver - * Failure: H5I_INVALID_HID - *------------------------------------------------------------------------- + * Returns: SUCCEED (Can't fail) + * + *--------------------------------------------------------------------------- */ -hid_t -H5FD_ros3_init(void) +herr_t +H5FD__ros3_unregister(void) { - hid_t ret_value = H5I_INVALID_HID; - - FUNC_ENTER_NOAPI(H5I_INVALID_HID) - - if (H5I_VFL != H5I_get_type(H5FD_ROS3_g)) { - H5FD_ROS3_g = H5FD_register(&H5FD_ros3_g, sizeof(H5FD_class_t), false); - if (H5I_INVALID_HID == H5FD_ROS3_g) { - HGOTO_ERROR(H5E_ID, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register ros3"); - } - -#ifdef ROS3_STATS - /* Pre-compute stats bin boundaries on powers of 2 >= 10 */ - for (int i = 0; i < ROS3_STATS_BIN_COUNT; i++) - ros3_stats_boundaries_g[i] = 1 << (10 + i); -#endif - } + FUNC_ENTER_PACKAGE_NOERR - ret_value = H5FD_ROS3_g; + /* Reset VFL ID */ + H5FD_ROS3_id_g = H5I_INVALID_HID; -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_ros3_init() */ + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5FD__ros3_unregister() */ -/*--------------------------------------------------------------------------- - * Function: H5FD__ros3_term +/*------------------------------------------------------------------------- + * Function: H5FD__ros3_init * - * Purpose: Shut down the VFD + * Purpose: Singleton to initialize global driver settings & resources. * - * Returns: SUCCEED (Can't fail) - *--------------------------------------------------------------------------- + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- */ static herr_t -H5FD__ros3_term(void) +H5FD__ros3_init(void) { - FUNC_ENTER_PACKAGE_NOERR + herr_t ret_value = SUCCEED; /* Return value */ - /* Reset VFL ID */ - H5FD_ROS3_g = 0; + FUNC_ENTER_PACKAGE - FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5FD__ros3_term() */ +#ifdef ROS3_STATS + /* Pre-compute stats bin boundaries on powers of 2 >= 10 */ + for (int i = 0; i < ROS3_STATS_BIN_COUNT; i++) + ros3_stats_boundaries_g[i] = 1 << (10 + i); +#endif + + /* Indicate that driver is set up */ + H5FD_ros3_init_s = true; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD__ros3_init() */ /*------------------------------------------------------------------------- * Function: H5Pset_fapl_ros3 @@ -738,6 +735,11 @@ H5FD__ros3_open(const char *url, unsigned flags, hid_t fapl_id, haddr_t maxaddr) if (NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list"); + /* Initialize driver, if it's not yet */ + if (!H5FD_ros3_init_s) + if (H5FD__ros3_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, NULL, "can't initialize driver"); + /* Init curl */ if (CURLE_OK != curl_global_init(CURL_GLOBAL_DEFAULT)) HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "unable to initialize curl global (placeholder flags)"); diff --git a/src/H5FDros3.h b/src/H5FDros3.h index bd312928207..2807c5f651c 100644 --- a/src/H5FDros3.h +++ b/src/H5FDros3.h @@ -16,12 +16,25 @@ #ifndef H5FDros3_H #define H5FDros3_H +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + #ifdef H5_HAVE_ROS3_VFD -/** Initializer for the ros3 VFD */ -#define H5FD_ROS3 (H5FD_ros3_init()) + +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the ros3 VFD */ +#define H5FD_ROS3 (H5OPEN H5FD_ROS3_id_g) /** Identifier for the ros3 VFD */ #define H5FD_ROS3_VALUE H5_VFD_ROS3 + #else /** Initializer for the ros3 VFD (disabled) */ #define H5FD_ROS3 (H5I_INVALID_HID) @@ -32,48 +45,6 @@ #ifdef H5_HAVE_ROS3_VFD -/**************************************************************************** - * - * Structure: H5FD_ros3_fapl_t - * - * Purpose: - * - * H5FD_ros3_fapl_t is a public structure that is used to pass S3 - * authentication data to the appropriate S3 VFD via the FAPL. A pointer - * to an instance of this structure is a parameter to H5Pset_fapl_ros3() - * and H5Pget_fapl_ros3(). - * - * - * - * `version` (int32_t) - * - * Version number of the H5FD_ros3_fapl_t structure. Any instance passed - * to the above calls must have a recognized version number, or an error - * will be flagged. - * - * This field should be set to H5FD_CURR_ROS3_FAPL_T_VERSION. - * - * `authenticate` (hbool_t) - * - * Flag true or false whether or not requests are to be authenticated - * with the AWS4 algorithm. - * If true, `aws_region`, `secret_id`, and `secret_key` must be populated. - * If false, those three components are unused. - * - * `aws_region` (char[]) - * - * String: name of the AWS "region" of the host, e.g. "us-east-1". - * - * `secret_id` (char[]) - * - * String: "Access ID" for the resource. - * - * `secret_key` (char[]) - * - * String: "Secret Access Key" associated with the ID and resource. - * - ****************************************************************************/ - /** * \def H5FD_CURR_ROS3_FAPL_T_VERSION * The version number of the H5FD_ros3_fapl_t configuration @@ -120,9 +91,11 @@ * \var hbool_t H5FD_ros3_fapl_t::authenticate * A Boolean which specifies if security credentials should be used for * accessing a S3 bucket. + * If true, `aws_region`, `secret_id`, and `secret_key` must be populated. + * If false, those three components are unused. * * \var char H5FD_ros3_fapl_t::aws_region[H5FD_ROS3_MAX_REGION_LEN + 1] - * A string which specifies the AWS region of the S3 bucket. + * A string which specifies the AWS region of the S3 bucket, e.g. "us-east-1". * * \var char H5FD_ros3_fapl_t::secret_id[H5FD_ROS3_MAX_SECRET_ID_LEN + 1] * A string which specifies the security ID. @@ -145,9 +118,9 @@ extern "C" { /** @private * - * \brief Private initializer for the ros3 VFD + * \brief ID for the ros3 VFD */ -H5_DLL hid_t H5FD_ros3_init(void); +H5_DLLVAR hid_t H5FD_ROS3_id_g; /** * \ingroup FAPL diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c index 65c94c638ac..eac61412164 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -19,22 +19,19 @@ * application to the same file). */ -#include "H5FDdrvr_module.h" /* This source code file is part of the H5FD driver module */ +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* File access */ -#include "H5FDprivate.h" /* File drivers */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FDsec2.h" /* Sec2 file driver */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ #include "H5Pprivate.h" /* Property lists */ /* The driver identification number, initialized at runtime */ -static hid_t H5FD_SEC2_g = 0; - -/* Whether to ignore file locks when disabled (env var value) */ -static htri_t ignore_disabled_file_locks_s = FAIL; +hid_t H5FD_SEC2_id_g = H5I_INVALID_HID; /* The description of a file belonging to this driver. The 'eoa' and 'eof' * determine the amount of hdf5 address space in use and the high-water mark @@ -119,7 +116,6 @@ typedef struct H5FD_sec2_t { (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) /* Prototypes */ -static herr_t H5FD__sec2_term(void); static H5FD_t *H5FD__sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr); static herr_t H5FD__sec2_close(H5FD_t *_file); static int H5FD__sec2_cmp(const H5FD_t *_f1, const H5FD_t *_f2); @@ -145,7 +141,7 @@ static const H5FD_class_t H5FD_sec2_g = { "sec2", /* name */ MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD__sec2_term, /* terminate */ + NULL, /* terminate */ NULL, /* sb_size */ NULL, /* sb_encode */ NULL, /* sb_decode */ @@ -186,85 +182,48 @@ static const H5FD_class_t H5FD_sec2_g = { H5FL_DEFINE_STATIC(H5FD_sec2_t); /*------------------------------------------------------------------------- - * Function: H5FD__init_package + * Function: H5FD__sec2_register * - * Purpose: Initializes any interface-specific data or routines. + * Purpose: Register the driver with the library. * - * Return: Non-negative on success/Negative on failure + * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ -static herr_t -H5FD__init_package(void) +herr_t +H5FD__sec2_register(void) { - char *lock_env_var = NULL; /* Environment variable pointer */ - herr_t ret_value = SUCCEED; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE - /* Check the use disabled file locks environment variable */ - lock_env_var = getenv(HDF5_USE_FILE_LOCKING); - if (lock_env_var && !strcmp(lock_env_var, "BEST_EFFORT")) - ignore_disabled_file_locks_s = true; /* Override: Ignore disabled locks */ - else if (lock_env_var && (!strcmp(lock_env_var, "TRUE") || !strcmp(lock_env_var, "1"))) - ignore_disabled_file_locks_s = false; /* Override: Don't ignore disabled locks */ - else - ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */ - - if (H5FD_sec2_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize sec2 VFD"); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__init_package() */ - -/*------------------------------------------------------------------------- - * Function: H5FD_sec2_init - * - * Purpose: Initialize this driver by registering the driver with the - * library. - * - * Return: Success: The driver ID for the sec2 driver - * Failure: H5I_INVALID_HID - * - *------------------------------------------------------------------------- - */ -hid_t -H5FD_sec2_init(void) -{ - hid_t ret_value = H5I_INVALID_HID; /* Return value */ - - FUNC_ENTER_NOAPI(H5I_INVALID_HID) - - if (H5I_VFL != H5I_get_type(H5FD_SEC2_g)) - H5FD_SEC2_g = H5FD_register(&H5FD_sec2_g, sizeof(H5FD_class_t), false); - - /* Set return value */ - ret_value = H5FD_SEC2_g; + if (H5I_VFL != H5I_get_type(H5FD_SEC2_id_g)) + if ((H5FD_SEC2_id_g = H5FD_register(&H5FD_sec2_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register sec2 driver"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_sec2_init() */ +} /* end H5FD__sec2_register() */ /*--------------------------------------------------------------------------- - * Function: H5FD__sec2_term + * Function: H5FD__sec2_unregister * - * Purpose: Shut down the VFD + * Purpose: Reset library driver info. * * Returns: SUCCEED (Can't fail) * *--------------------------------------------------------------------------- */ -static herr_t -H5FD__sec2_term(void) +herr_t +H5FD__sec2_unregister(void) { FUNC_ENTER_PACKAGE_NOERR /* Reset VFL ID */ - H5FD_SEC2_g = 0; + H5FD_SEC2_id_g = H5I_INVALID_HID; FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5FD__sec2_term() */ +} /* end H5FD__sec2_unregister() */ /*------------------------------------------------------------------------- * Function: H5Pset_fapl_sec2 @@ -385,9 +344,9 @@ H5FD__sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr HGOTO_ERROR(H5E_VFL, H5E_BADTYPE, NULL, "not a file access property list"); /* Check the file locking flags in the fapl */ - if (ignore_disabled_file_locks_s != FAIL) + if (H5FD_ignore_disabled_file_locks_p != FAIL) /* The environment variable was set, so use that preferentially */ - file->ignore_disabled_file_locks = ignore_disabled_file_locks_s; + file->ignore_disabled_file_locks = H5FD_ignore_disabled_file_locks_p; else { /* Use the value in the property list */ if (H5P_get(plist, H5F_ACS_IGNORE_DISABLED_FILE_LOCKS_NAME, &file->ignore_disabled_file_locks) < 0) diff --git a/src/H5FDsec2.h b/src/H5FDsec2.h index 01ae5084325..d51df368ac0 100644 --- a/src/H5FDsec2.h +++ b/src/H5FDsec2.h @@ -17,8 +17,19 @@ #ifndef H5FDsec2_H #define H5FDsec2_H -/** Initializer for the sec2 VFD */ -#define H5FD_SEC2 (H5FD_sec2_init()) +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the sec2 VFD */ +#define H5FD_SEC2 (H5OPEN H5FD_SEC2_id_g) /** Identifier for the sec2 VFD */ #define H5FD_SEC2_VALUE H5_VFD_SEC2 @@ -29,9 +40,9 @@ extern "C" { /** @private * - * \brief Private initializer for the sec2 VFD + * \brief ID for the sec2 VFD */ -H5_DLL hid_t H5FD_sec2_init(void); +H5_DLLVAR hid_t H5FD_SEC2_id_g; /** * \ingroup FAPL diff --git a/src/H5FDsplitter.c b/src/H5FDsplitter.c index 4f7e78cf808..310eb1d77d6 100644 --- a/src/H5FDsplitter.c +++ b/src/H5FDsplitter.c @@ -16,13 +16,12 @@ * another underlying VFD. Maintains two files simultaneously. */ -/* This source code file is part of the H5FD driver module */ -#include "H5FDdrvr_module.h" +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* File access */ -#include "H5FDprivate.h" /* File drivers */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FDsplitter.h" /* Splitter file driver */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ @@ -30,7 +29,7 @@ #include "H5Pprivate.h" /* Property lists */ /* The driver identification number, initialized at runtime */ -static hid_t H5FD_SPLITTER_g = 0; +hid_t H5FD_SPLITTER_id_g = H5I_INVALID_HID; /* Driver-specific file access properties */ typedef struct H5FD_splitter_fapl_t { @@ -103,7 +102,6 @@ static herr_t H5FD__splitter_log_error(const H5FD_splitter_t *file, const char * static int H5FD__copy_plist(hid_t fapl_id, hid_t *id_out_ptr); /* Prototypes */ -static herr_t H5FD__splitter_term(void); static herr_t H5FD__splitter_populate_config(H5FD_splitter_vfd_config_t *vfd_config, H5FD_splitter_fapl_t *fapl_out); static herr_t H5FD__splitter_get_default_wo_path(char *new_path, size_t new_path_len, @@ -143,7 +141,7 @@ static const H5FD_class_t H5FD_splitter_g = { "splitter", /* name */ MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD__splitter_term, /* terminate */ + NULL, /* terminate */ H5FD__splitter_sb_size, /* sb_size */ H5FD__splitter_sb_encode, /* sb_encode */ H5FD__splitter_sb_decode, /* sb_decode */ @@ -187,77 +185,52 @@ H5FL_DEFINE_STATIC(H5FD_splitter_t); H5FL_DEFINE_STATIC(H5FD_splitter_fapl_t); /*------------------------------------------------------------------------- - * Function: H5FD__init_package + * Function: H5FD__splitter_register * - * Purpose: Initializes any interface-specific data or routines. + * Purpose: Register the driver with the library. * * Return: SUCCEED/FAIL - *------------------------------------------------------------------------- - */ -static herr_t -H5FD__init_package(void) -{ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_PACKAGE - - H5FD_SPLITTER_LOG_CALL(__func__); - - if (H5FD_splitter_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize splitter VFD"); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__init_package() */ - -/*------------------------------------------------------------------------- - * Function: H5FD_splitter_init - * - * Purpose: Initialize the splitter driver by registering it with the - * library. * - * Return: Success: The driver ID for the splitter driver. - * Failure: Negative *------------------------------------------------------------------------- */ -hid_t -H5FD_splitter_init(void) +herr_t +H5FD__splitter_register(void) { - hid_t ret_value = H5I_INVALID_HID; + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5I_INVALID_HID) + FUNC_ENTER_PACKAGE H5FD_SPLITTER_LOG_CALL(__func__); - if (H5I_VFL != H5I_get_type(H5FD_SPLITTER_g)) - H5FD_SPLITTER_g = H5FDregister(&H5FD_splitter_g); - - ret_value = H5FD_SPLITTER_g; + if (H5I_VFL != H5I_get_type(H5FD_SPLITTER_id_g)) + if ((H5FD_SPLITTER_id_g = H5FD_register(&H5FD_splitter_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register splitter driver"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_splitter_init() */ +} /* end H5FD__splitter_register() */ /*--------------------------------------------------------------------------- - * Function: H5FD__splitter_term + * Function: H5FD__splitter_unregister * - * Purpose: Shut down the splitter VFD. + * Purpose: Reset library driver info. * * Returns: SUCCEED (Can't fail) + * *--------------------------------------------------------------------------- */ -static herr_t -H5FD__splitter_term(void) +herr_t +H5FD__splitter_unregister(void) { FUNC_ENTER_PACKAGE_NOERR H5FD_SPLITTER_LOG_CALL(__func__); /* Reset VFL ID */ - H5FD_SPLITTER_g = 0; + H5FD_SPLITTER_id_g = H5I_INVALID_HID; FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5FD__splitter_term() */ +} /* end H5FD__splitter_unregister() */ /*------------------------------------------------------------------------- * Function: H5FD__copy_plist diff --git a/src/H5FDsplitter.h b/src/H5FDsplitter.h index 249c91ff164..b1fa029adf7 100644 --- a/src/H5FDsplitter.h +++ b/src/H5FDsplitter.h @@ -17,8 +17,19 @@ #ifndef H5FDsplitter_H #define H5FDsplitter_H -/** Initializer for the splitter VFD */ -#define H5FD_SPLITTER (H5FD_splitter_init()) +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the splitter VFD */ +#define H5FD_SPLITTER (H5OPEN H5FD_SPLITTER_id_g) /** Identifier for the splitter VFD */ #define H5FD_SPLITTER_VALUE H5_VFD_SPLITTER @@ -61,9 +72,9 @@ extern "C" { /** @private * - * \brief Private initializer for the splitter VFD + * \brief ID for the splitter VFD */ -H5_DLL hid_t H5FD_splitter_init(void); +H5_DLLVAR hid_t H5FD_SPLITTER_id_g; /** * \ingroup FAPL diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c index 00971e44bfb..d8d1a6af227 100644 --- a/src/H5FDstdio.c +++ b/src/H5FDstdio.c @@ -47,8 +47,10 @@ #endif /* H5_HAVE_WIN32_API */ -/* The driver identification number, initialized at runtime */ -static hid_t H5FD_STDIO_g = 0; +/* Flag to indicate whether global driver resources & settings have been + * initialized. + */ +static bool H5FD_stdio_init_s = false; /* Whether to ignore file locks when disabled (env var value) */ static htri_t ignore_disabled_file_locks_s = -1; @@ -160,7 +162,6 @@ typedef struct H5FD_stdio_t { (file_offset_t)((A) + (Z)) < (file_offset_t)(A)) /* Prototypes */ -static herr_t H5FD_stdio_term(void); static H5FD_t *H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr); static herr_t H5FD_stdio_close(H5FD_t *lf); static int H5FD_stdio_cmp(const H5FD_t *_f1, const H5FD_t *_f2); @@ -180,13 +181,13 @@ static herr_t H5FD_stdio_lock(H5FD_t *_file, bool rw); static herr_t H5FD_stdio_unlock(H5FD_t *_file); static herr_t H5FD_stdio_delete(const char *filename, hid_t fapl_id); -static const H5FD_class_t H5FD_stdio_g = { +const H5FD_class_t H5FD_stdio_g = { H5FD_CLASS_VERSION, /* struct version */ H5_VFD_STDIO, /* value */ "stdio", /* name */ MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ - H5FD_stdio_term, /* terminate */ + NULL, /* terminate */ NULL, /* sb_size */ NULL, /* sb_encode */ NULL, /* sb_decode */ @@ -224,25 +225,19 @@ static const H5FD_class_t H5FD_stdio_g = { }; /*------------------------------------------------------------------------- - * Function: H5FD_stdio_init - * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Function: H5FD__stdio_init * - * Return: Success: The driver ID for the stdio driver. + * Purpose: Singleton to initialize global driver settings & resources. * - * Failure: Negative. + * Return: Non-negative on success/Negative on failure * *------------------------------------------------------------------------- */ -hid_t -H5FD_stdio_init(void) +static herr_t +H5FD__stdio_init(void) { char *lock_env_var = NULL; /* Environment variable pointer */ - /* Clear the error stack */ - H5Eclear2(H5E_DEFAULT); - /* Check the use disabled file locks environment variable */ lock_env_var = getenv(HDF5_USE_FILE_LOCKING); if (lock_env_var && !strcmp(lock_env_var, "BEST_EFFORT")) @@ -252,29 +247,11 @@ H5FD_stdio_init(void) else ignore_disabled_file_locks_s = -1; /* Environment variable not set, or not set correctly */ - if (H5I_VFL != H5Iget_type(H5FD_STDIO_g)) - H5FD_STDIO_g = H5FDregister(&H5FD_stdio_g); - - return H5FD_STDIO_g; -} /* end H5FD_stdio_init() */ - -/*--------------------------------------------------------------------------- - * Function: H5FD_stdio_term - * - * Purpose: Shut down the VFD - * - * Returns: Non-negative on success or negative on failure - * - *--------------------------------------------------------------------------- - */ -static herr_t -H5FD_stdio_term(void) -{ - /* Reset VFL ID */ - H5FD_STDIO_g = 0; + /* Indicate that driver is set up */ + H5FD_stdio_init_s = true; return 0; -} /* end H5FD_stdio_term() */ +} /* end H5FD__stdio_init() */ /*------------------------------------------------------------------------- * Function: H5Pset_fapl_stdio @@ -290,13 +267,12 @@ H5FD_stdio_term(void) herr_t H5Pset_fapl_stdio(hid_t fapl_id) { - static const char *func = "H5FDset_fapl_stdio"; /*for error reporting*/ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); if (0 == H5Pisa_class(fapl_id, H5P_FILE_ACCESS)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_PLIST, H5E_BADTYPE, "not a file access property list", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_PLIST, H5E_BADTYPE, "not a file access property list", -1); return H5Pset_driver(fapl_id, H5FD_STDIO, NULL); } /* end H5Pset_fapl_stdio() */ @@ -328,7 +304,6 @@ H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr FILE *f = NULL; unsigned write_access = 0; /* File opened with write access? */ H5FD_stdio_t *file = NULL; - static const char *func = "H5FD_stdio_open"; /* Function Name for error reporting */ #ifdef H5_HAVE_WIN32_API struct _BY_HANDLE_FILE_INFORMATION fileinfo; #else /* H5_HAVE_WIN32_API */ @@ -344,13 +319,18 @@ H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); + /* Initialize driver, if it's not yet */ + if (!H5FD_stdio_init_s) + if (H5FD__stdio_init() < 0) + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_CANTINIT, "can't initialize driver", NULL); + /* Check arguments */ if (!name || !*name) - H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADVALUE, "invalid file name", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_ARGS, H5E_BADVALUE, "invalid file name", NULL); if (0 == maxaddr || HADDR_UNDEF == maxaddr) - H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADRANGE, "bogus maxaddr", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_ARGS, H5E_BADRANGE, "bogus maxaddr", NULL); if (ADDR_OVERFLOW(maxaddr)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_OVERFLOW, "maxaddr too large", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_ARGS, H5E_OVERFLOW, "maxaddr too large", NULL); /* Tentatively open file in read-only mode, to check for existence */ if (flags & H5F_ACC_RDWR) @@ -366,14 +346,14 @@ H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr write_access = 1; /* Note the write access */ } else - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_CANTOPENFILE, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_CANTOPENFILE, "file doesn't exist and CREAT wasn't specified", NULL); } else if (flags & H5F_ACC_EXCL) { /* File exists, but EXCL is passed. Fail. */ assert(flags & H5F_ACC_CREAT); fclose(f); - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FILEEXISTS, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_FILEEXISTS, "file exists but CREAT and EXCL were specified", NULL); } else if (flags & H5F_ACC_RDWR) { @@ -385,12 +365,12 @@ H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr * as the tentative open will work */ if (!f) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_CANTOPENFILE, "fopen failed", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_CANTOPENFILE, "fopen failed", NULL); /* Build the return value */ if (NULL == (file = (H5FD_stdio_t *)calloc((size_t)1, sizeof(H5FD_stdio_t)))) { fclose(f); - H5Epush_ret(func, H5E_ERR_CLS, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed", NULL); } /* end if */ file->fp = f; file->op = H5FD_STDIO_OP_SEEK; @@ -416,7 +396,7 @@ H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr if (H5Pget_file_locking(fapl_id, &unused, &file->ignore_disabled_file_locks) < 0) { free(file); fclose(f); - H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTGET, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_FILE, H5E_CANTGET, "unable to get use disabled file locks property", NULL); } } @@ -430,7 +410,7 @@ H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr if (file->fd < 0) { free(file); fclose(f); - H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, "unable to get file descriptor", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, "unable to get file descriptor", NULL); } /* end if */ #ifdef H5_HAVE_WIN32_API @@ -438,13 +418,13 @@ H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr if (INVALID_HANDLE_VALUE == file->hFile) { free(file); fclose(f); - H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, "unable to get Windows file handle", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, "unable to get Windows file handle", NULL); } /* end if */ if (!GetFileInformationByHandle((HANDLE)file->hFile, &fileinfo)) { free(file); fclose(f); - H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, "unable to get Windows file descriptor information", NULL); } /* end if */ @@ -455,7 +435,7 @@ H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr if (fstat(file->fd, &sb) < 0) { free(file); fclose(f); - H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_BADFILE, "unable to fstat file", NULL); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_FILE, H5E_BADFILE, "unable to fstat file", NULL); } /* end if */ file->device = sb.st_dev; file->inode = sb.st_ino; @@ -480,13 +460,12 @@ static herr_t H5FD_stdio_close(H5FD_t *_file) { H5FD_stdio_t *file = (H5FD_stdio_t *)_file; - static const char *func = "H5FD_stdio_close"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); if (fclose(file->fp) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_CLOSEERROR, "fclose failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_CLOSEERROR, "fclose failed", -1); free(file); @@ -728,7 +707,6 @@ static herr_t H5FD_stdio_get_handle(H5FD_t *_file, hid_t /*UNUSED*/ fapl, void **file_handle) { H5FD_stdio_t *file = (H5FD_stdio_t *)_file; - static const char *func = "H5FD_stdio_get_handle"; /* Function Name for error reporting */ /* Quiet the compiler */ (void)fapl; @@ -738,7 +716,7 @@ H5FD_stdio_get_handle(H5FD_t *_file, hid_t /*UNUSED*/ fapl, void **file_handle) *file_handle = &(file->fp); if (*file_handle == NULL) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "get handle failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "get handle failed", -1); return 0; } /* end H5FD_stdio_get_handle() */ @@ -763,7 +741,6 @@ H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl size_t size, void /*OUT*/ *buf) { H5FD_stdio_t *file = (H5FD_stdio_t *)_file; - static const char *func = "H5FD_stdio_read"; /* Function Name for error reporting */ /* Quiet the compiler */ (void)type; @@ -774,9 +751,9 @@ H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl /* Check for overflow */ if (HADDR_UNDEF == addr) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); if (REGION_OVERFLOW(addr, size)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); /* Check easy cases */ if (0 == size) @@ -791,7 +768,7 @@ H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl if (file_fseek(file->fp, (file_offset_t)addr, SEEK_SET) < 0) { file->op = H5FD_STDIO_OP_UNKNOWN; file->pos = HADDR_UNDEF; - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "fseek failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "fseek failed", -1); } file->pos = addr; } @@ -823,7 +800,7 @@ H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl if (0 == bytes_read && ferror(file->fp)) { /* error */ file->op = H5FD_STDIO_OP_UNKNOWN; file->pos = HADDR_UNDEF; - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_READERROR, "fread failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_READERROR, "fread failed", -1); } /* end if */ if (0 == bytes_read && feof(file->fp)) { @@ -863,7 +840,6 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxp size_t size, const void *buf) { H5FD_stdio_t *file = (H5FD_stdio_t *)_file; - static const char *func = "H5FD_stdio_write"; /* Function Name for error reporting */ /* Quiet the compiler */ (void)dxpl_id; @@ -874,16 +850,16 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxp /* Check for overflow conditions */ if (HADDR_UNDEF == addr) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); if (REGION_OVERFLOW(addr, size)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); /* Seek to the correct file position. */ if ((file->op != H5FD_STDIO_OP_WRITE && file->op != H5FD_STDIO_OP_SEEK) || file->pos != addr) { if (file_fseek(file->fp, (file_offset_t)addr, SEEK_SET) < 0) { file->op = H5FD_STDIO_OP_UNKNOWN; file->pos = HADDR_UNDEF; - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "fseek failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "fseek failed", -1); } file->pos = addr; } @@ -908,7 +884,7 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxp if (bytes_wrote != bytes_in || (0 == bytes_wrote && ferror(file->fp))) { /* error */ file->op = H5FD_STDIO_OP_UNKNOWN; file->pos = HADDR_UNDEF; - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fwrite failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fwrite failed", -1); } /* end if */ assert(bytes_wrote > 0); @@ -947,7 +923,6 @@ static herr_t H5FD_stdio_flush(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, bool closing) { H5FD_stdio_t *file = (H5FD_stdio_t *)_file; - static const char *func = "H5FD_stdio_flush"; /* Function Name for error reporting */ /* Quiet the compiler */ (void)dxpl_id; @@ -959,7 +934,7 @@ H5FD_stdio_flush(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, bool closing) if (file->write_access) { if (!closing) { if (fflush(file->fp) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1); /* Reset last file I/O information */ file->pos = HADDR_UNDEF; @@ -988,7 +963,6 @@ static herr_t H5FD_stdio_truncate(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, bool /*UNUSED*/ closing) { H5FD_stdio_t *file = (H5FD_stdio_t *)_file; - static const char *func = "H5FD_stdio_truncate"; /* Function Name for error reporting */ /* Quiet the compiler */ (void)dxpl_id; @@ -1025,12 +999,12 @@ H5FD_stdio_truncate(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, bool /*UNUSED*/ clo if (INVALID_SET_FILE_POINTER == dwPtrLow) { dwError = GetLastError(); if (dwError != NO_ERROR) - H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_FILEOPEN, "unable to set file pointer", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_FILE, H5E_FILEOPEN, "unable to set file pointer", -1); } bError = SetEndOfFile(file->hFile); if (0 == bError) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "unable to truncate/extend file properly", -1); #else /* H5_HAVE_WIN32_API */ /* Reset seek offset to beginning of file, so that file isn't re-extended later */ @@ -1038,7 +1012,7 @@ H5FD_stdio_truncate(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, bool /*UNUSED*/ clo /* Truncate file to proper length */ if (-1 == file_ftruncate(file->fd, (file_offset_t)file->eoa)) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "unable to truncate/extend file properly", -1); #endif /* H5_HAVE_WIN32_API */ @@ -1053,7 +1027,7 @@ H5FD_stdio_truncate(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, bool /*UNUSED*/ clo else { /* Double-check for problems */ if (file->eoa > file->eof) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_TRUNCATED, "eoa > eof!", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_TRUNCATED, "eoa > eof!", -1); } /* end else */ return 0; @@ -1078,7 +1052,6 @@ H5FD_stdio_lock(H5FD_t *_file, bool rw) #ifdef H5_HAVE_FLOCK H5FD_stdio_t *file = (H5FD_stdio_t *)_file; /* VFD file struct */ int lock_flags; /* file locking flags */ - static const char *func = "H5FD_stdio_lock"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -1096,12 +1069,12 @@ H5FD_stdio_lock(H5FD_t *_file, bool rw) */ errno = 0; else - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_CANTLOCKFILE, "file lock failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_CANTLOCKFILE, "file lock failed", -1); } /* end if */ /* Flush the stream */ if (fflush(file->fp) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1); #endif /* H5_HAVE_FLOCK */ @@ -1126,7 +1099,6 @@ H5FD_stdio_unlock(H5FD_t *_file) { #ifdef H5_HAVE_FLOCK H5FD_stdio_t *file = (H5FD_stdio_t *)_file; /* VFD file struct */ - static const char *func = "H5FD_stdio_unlock"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear2(H5E_DEFAULT); @@ -1135,7 +1107,7 @@ H5FD_stdio_unlock(H5FD_t *_file) /* Flush the stream */ if (fflush(file->fp) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1); /* Place a non-blocking lock on the file */ if (flock(file->fd, LOCK_UN) < 0) { @@ -1145,7 +1117,7 @@ H5FD_stdio_unlock(H5FD_t *_file) */ errno = 0; else - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_CANTUNLOCKFILE, "file unlock failed", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_CANTUNLOCKFILE, "file unlock failed", -1); } /* end if */ #endif /* H5_HAVE_FLOCK */ @@ -1165,18 +1137,22 @@ H5FD_stdio_unlock(H5FD_t *_file) static herr_t H5FD_stdio_delete(const char *filename, hid_t /*UNUSED*/ fapl_id) { - static const char *func = "H5FD_stdio_delete"; /* Function Name for error reporting */ - - /* Clear the error stack */ - H5Eclear2(H5E_DEFAULT); assert(filename); /* Quiet compiler */ (void)fapl_id; + /* Clear the error stack */ + H5Eclear2(H5E_DEFAULT); + + /* Initialize driver, if it's not yet */ + if (!H5FD_stdio_init_s) + if (H5FD__stdio_init() < 0) + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_CANTINIT, "can't initialize driver", -1); + if (remove(filename) < 0) - H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_CANTDELETEFILE, "can't delete file)", -1); + H5Epush_ret(__func__, H5E_ERR_CLS, H5E_VFL, H5E_CANTDELETEFILE, "can't delete file)", -1); return 0; } /* end H5FD_stdio_delete() */ diff --git a/src/H5FDstdio.h b/src/H5FDstdio.h index d9ae5ff3d8f..c0d11a8c7e3 100644 --- a/src/H5FDstdio.h +++ b/src/H5FDstdio.h @@ -16,10 +16,20 @@ #ifndef H5FDstdio_H #define H5FDstdio_H -#include "H5Ipublic.h" +/* Public header files */ +#include "H5Ipublic.h" /* IDs */ +#include "H5FDpublic.h" /* File drivers */ -/** Initializer for the stdio VFD */ -#define H5FD_STDIO (H5FD_stdio_init()) +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the stdio VFD */ +#define H5FD_STDIO (H5OPEN H5FD_STDIO_id_g) #ifdef __cplusplus extern "C" { @@ -27,9 +37,9 @@ extern "C" { /** @private * - * \brief Private initializer for the stdio VFD + * \brief ID for the stdio VFD */ -H5_DLL hid_t H5FD_stdio_init(void); +H5_DLLVAR hid_t H5FD_STDIO_id_g; /** * \ingroup FAPL diff --git a/src/H5FDstdio_int.c b/src/H5FDstdio_int.c new file mode 100644 index 00000000000..528bd2bce25 --- /dev/null +++ b/src/H5FDstdio_int.c @@ -0,0 +1,84 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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 COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://www.hdfgroup.org/licenses. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Purpose: Private routines for the stdio VFD. + * + * Necessary for using internal library routines, which are + * disallowed within the actual stdio VFD code. + * + */ + +/****************/ +/* Module Setup */ +/****************/ + +#define H5FD_FRIEND /* Suppress error about including H5FDpkg */ + +/***********/ +/* Headers */ +/***********/ + +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Iprivate.h" /* IDs */ +#include "H5FDpkg.h" /* File drivers */ + +#include "H5FDstdio_private.h" /* stdio VFD */ + +/* The driver identification number, initialized at runtime */ +hid_t H5FD_STDIO_id_g = H5I_INVALID_HID; + +/*------------------------------------------------------------------------- + * Function: H5FD__stdio_register + * + * Purpose: Register the driver with the library. + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5FD__stdio_register(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + if (H5I_VFL != H5I_get_type(H5FD_STDIO_id_g)) + if ((H5FD_STDIO_id_g = H5FD_register(&H5FD_stdio_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register stdio driver"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD__stdio_register() */ + +/*--------------------------------------------------------------------------- + * Function: H5FD_stdio_unregister + * + * Purpose: Reset library driver info. + * + * Returns: SUCCEED (Can't fail) + * + *--------------------------------------------------------------------------- + */ +herr_t +H5FD__stdio_unregister(void) +{ + FUNC_ENTER_PACKAGE_NOERR + + /* Reset VFL ID */ + H5FD_STDIO_id_g = H5I_INVALID_HID; + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5FD_stdio_unregister() */ + diff --git a/src/H5FDdrvr_module.h b/src/H5FDstdio_private.h similarity index 53% rename from src/H5FDdrvr_module.h rename to src/H5FDstdio_private.h index 47630569275..47da1ac6d38 100644 --- a/src/H5FDdrvr_module.h +++ b/src/H5FDstdio_private.h @@ -11,19 +11,36 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* - * Purpose: This file contains declarations which define macros for the - * H5FD driver package. Including this header means that the source file - * is part of the H5FD driver package. + * Purpose: The private header file for the stdio VFD */ -#ifndef H5FDdrvr_module_H -#define H5FDdrvr_module_H -/* Define the proper control macros for the generic FUNC_ENTER/LEAVE and error - * reporting macros. - */ -#define H5_MY_PKG H5FD -#define H5_MY_PKG_ERR H5E_VFL -#define H5_MY_PKG_INIT YES -#define H5_PKG_SINGLE_SOURCE +#ifndef H5FDstdio_private_H +#define H5FDstdio_private_H + +/* Include VFD's public header */ +#include "H5FDstdio.h" /* stdio VFD */ + +/* Private headers needed by this file */ +#include "H5FDprivate.h" /* File drivers */ + +/**************************/ +/* Library Private Macros */ +/**************************/ + +/****************************/ +/* Library Private Typedefs */ +/****************************/ + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + +/* stdio VFD's class struct */ +H5_DLLVAR const H5FD_class_t H5FD_stdio_g; + +/******************************/ +/* Library Private Prototypes */ +/******************************/ + +#endif /* H5FDstdio_private_H */ -#endif /* H5FDdrvr_module_H */ diff --git a/src/H5FDsubfiling/H5FDioc.c b/src/H5FDsubfiling/H5FDioc.c index 27ca1224999..7136dfed787 100644 --- a/src/H5FDsubfiling/H5FDioc.c +++ b/src/H5FDsubfiling/H5FDioc.c @@ -16,27 +16,29 @@ * another underlying VFD. Maintains two files simultaneously. */ -/* This source code file is part of the H5FD driver module */ -#include "H5FDdrvr_module.h" +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ -#include "H5FDpublic.h" /* Basic H5FD definitions */ #include "H5Eprivate.h" /* Error handling */ -#include "H5FDprivate.h" /* File drivers */ -#include "H5FDioc.h" /* IOC file driver */ -#include "H5FDioc_priv.h" /* IOC file driver */ +#include "H5Fprivate.h" /* File access */ +#include "H5FDpkg.h" /* File drivers */ +#include "H5FDioc_priv.h" /* I/O concetrator file driver */ #include "H5FDmpio.h" /* MPI I/O VFD */ #include "H5FLprivate.h" /* Free Lists */ -#include "H5Fprivate.h" /* File access */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5Pprivate.h" /* Property lists */ /* The driver identification number, initialized at runtime */ -static hid_t H5FD_IOC_g = H5I_INVALID_HID; +hid_t H5FD_IOC_id_g = H5I_INVALID_HID; + +/* Flag to indicate whether global driver resources & settings have been + * initialized. + */ +static bool H5FD_ioc_init_s = false; /* Whether the driver initialized MPI on its own */ -static bool H5FD_mpi_self_initialized = false; +static bool H5FD_mpi_self_initialized_s = false; /* Pointer to value for MPI_TAG_UB */ int *H5FD_IOC_tag_ub_val_ptr = NULL; @@ -113,7 +115,7 @@ static herr_t H5FD__ioc_read_vector(H5FD_t *file, hid_t dxpl_id, uint32_t count static herr_t H5FD__ioc_write_vector(H5FD_t *file, hid_t dxpl_id, uint32_t count, H5FD_mem_t types[], haddr_t addrs[], size_t sizes[], const void *bufs[] /* in */); static herr_t H5FD__ioc_truncate(H5FD_t *_file, hid_t dxpl_id, bool closing); -static herr_t H5FD__ioc_del(const char *name, hid_t fapl); +static herr_t H5FD__ioc_delete(const char *name, hid_t fapl); /* static herr_t H5FD__ioc_ctl(H5FD_t *file, uint64_t op_code, uint64_t flags, const void *input, void **result); @@ -167,7 +169,7 @@ static const H5FD_class_t H5FD_ioc_g = { H5FD__ioc_truncate, /* truncate */ NULL, /* lock */ NULL, /* unlock */ - H5FD__ioc_del, /* del */ + H5FD__ioc_delete, /* del */ NULL, /* ctl */ H5FD_FLMAP_DICHOTOMY /* fl_map */ }; @@ -179,100 +181,109 @@ H5FL_DEFINE_STATIC(H5FD_ioc_t); H5FL_DEFINE_STATIC(H5FD_ioc_config_t); /*------------------------------------------------------------------------- - * Function: H5FD__init_package + * Function: H5FD__ioc_register * - * Purpose: Initializes any interface-specific data or routines. + * Purpose: Register the driver with the library. * - * Return: Non-negative on success/Negative on failure + * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ -static herr_t -H5FD__init_package(void) +herr_t +H5FD__ioc_register(void) { herr_t ret_value = SUCCEED; FUNC_ENTER_PACKAGE - if (H5FD_ioc_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize ioc VFD"); + /* Register the IOC VFD, if it isn't already registered */ + if (H5I_VFL != H5I_get_type(H5FD_IOC_id_g)) + if ((H5FD_IOC_id_g = H5FD_register(&H5FD_ioc_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "can't register IOC VFD"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__init_package() */ +} /* end H5FD__ioc_register() */ + +/*--------------------------------------------------------------------------- + * Function: H5FD__ioc_unregister + * + * Purpose: Reset library driver info. + * + * Return: SUCCEED/FAIL + * + *--------------------------------------------------------------------------- + */ +herr_t +H5FD__ioc_unregister(void) +{ + FUNC_ENTER_PACKAGE_NOERR + + /* Reset VFL ID */ + H5FD_IOC_id_g = H5I_INVALID_HID; + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5FD__ioc_unregister() */ /*------------------------------------------------------------------------- - * Function: H5FD_ioc_init + * Function: H5FD__ioc_init + * + * Purpose: Singleton to initialize global driver settings & resources. * - * Purpose: Initialize the IOC driver by registering it with the - * library. + * Return: Non-negative on success/Negative on failure * - * Return: Success: The driver ID for the ioc driver. - * Failure: Negative *------------------------------------------------------------------------- */ -hid_t -H5FD_ioc_init(void) +static herr_t +H5FD__ioc_init(void) { - hid_t ret_value = H5I_INVALID_HID; + char *env_var; + int key_val_retrieved = 0; + int mpi_code; + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5I_INVALID_HID) + FUNC_ENTER_PACKAGE - /* Register the IOC VFD, if it isn't already registered */ - if (H5I_VFL != H5I_get_type(H5FD_IOC_g)) { - char *env_var; - int key_val_retrieved = 0; - int mpi_code; - - if ((H5FD_IOC_g = H5FD_register(&H5FD_ioc_g, sizeof(H5FD_class_t), false)) < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, H5I_INVALID_HID, "can't register IOC VFD"); - - /* Check if IOC VFD has been loaded dynamically */ - env_var = getenv(HDF5_DRIVER); - if (env_var && strlen(env_var) > 0 && !strcmp(env_var, H5FD_IOC_NAME)) { - int mpi_initialized = 0; - int provided = 0; - - /* Initialize MPI if not already initialized */ - if (MPI_SUCCESS != (mpi_code = MPI_Initialized(&mpi_initialized))) - HMPI_GOTO_ERROR(H5I_INVALID_HID, "MPI_Initialized failed", mpi_code); - if (mpi_initialized) { - /* If MPI is initialized, validate that it was initialized with MPI_THREAD_MULTIPLE */ - if (MPI_SUCCESS != (mpi_code = MPI_Query_thread(&provided))) - HMPI_GOTO_ERROR(H5I_INVALID_HID, "MPI_Query_thread failed", mpi_code); - if (provided != MPI_THREAD_MULTIPLE) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, - "IOC VFD requires the use of MPI_Init_thread with MPI_THREAD_MULTIPLE"); - } - else { - int required = MPI_THREAD_MULTIPLE; - - /* Otherwise, initialize MPI */ - if (MPI_SUCCESS != (mpi_code = MPI_Init_thread(NULL, NULL, required, &provided))) - HMPI_GOTO_ERROR(H5I_INVALID_HID, "MPI_Init_thread failed", mpi_code); - - H5FD_mpi_self_initialized = true; - - if (provided != required) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, - "MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE"); - } + /* Check if IOC VFD has been loaded dynamically */ + env_var = getenv(HDF5_DRIVER); + if (env_var && strlen(env_var) > 0 && !strcmp(env_var, H5FD_IOC_NAME)) { + int mpi_initialized = 0; + int provided = 0; + + /* Initialize MPI if not already initialized */ + if (MPI_SUCCESS != (mpi_code = MPI_Initialized(&mpi_initialized))) + HMPI_GOTO_ERROR(FAIL, "MPI_Initialized failed", mpi_code); + if (mpi_initialized) { + /* If MPI is initialized, validate that it was initialized with MPI_THREAD_MULTIPLE */ + if (MPI_SUCCESS != (mpi_code = MPI_Query_thread(&provided))) + HMPI_GOTO_ERROR(FAIL, "MPI_Query_thread failed", mpi_code); + if (provided != MPI_THREAD_MULTIPLE) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "IOC VFD requires the use of MPI_Init_thread with MPI_THREAD_MULTIPLE"); } + else { + /* Otherwise, initialize MPI */ + if (MPI_SUCCESS != (mpi_code = MPI_Init_thread(NULL, NULL, MPI_THREAD_MULTIPLE, &provided))) + HMPI_GOTO_ERROR(FAIL, "MPI_Init_thread failed", mpi_code); - /* Retrieve upper bound for MPI message tag value */ - if (MPI_SUCCESS != (mpi_code = MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_TAG_UB, &H5FD_IOC_tag_ub_val_ptr, - &key_val_retrieved))) - HMPI_GOTO_ERROR(H5I_INVALID_HID, "MPI_Comm_get_attr failed", mpi_code); + H5FD_mpi_self_initialized_s = true; - if (!key_val_retrieved) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, "couldn't retrieve value for MPI_TAG_UB"); + if (provided != MPI_THREAD_MULTIPLE) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE"); + } } - ret_value = H5FD_IOC_g; + /* Retrieve upper bound for MPI message tag value */ + if (MPI_SUCCESS != (mpi_code = MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_TAG_UB, &H5FD_IOC_tag_ub_val_ptr, &key_val_retrieved))) + HMPI_GOTO_ERROR(FAIL, "MPI_Comm_get_attr failed", mpi_code); + if (!key_val_retrieved) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "couldn't retrieve value for MPI_TAG_UB"); + + /* Indicate that driver is set up */ + H5FD_ioc_init_s = true; done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_ioc_init() */ +} /* end H5FD__ioc_init() */ /*--------------------------------------------------------------------------- * Function: H5FD__ioc_term @@ -280,6 +291,7 @@ H5FD_ioc_init(void) * Purpose: Shut down the IOC VFD. * * Return: SUCCEED/FAIL + * *--------------------------------------------------------------------------- */ static herr_t @@ -289,26 +301,21 @@ H5FD__ioc_term(void) FUNC_ENTER_PACKAGE - if (H5FD_IOC_g >= 0) { - /* Terminate MPI if the driver initialized it */ - if (H5FD_mpi_self_initialized) { - int mpi_finalized = 0; - int mpi_code; + /* Terminate MPI if the driver initialized it */ + if (H5FD_mpi_self_initialized_s) { + int mpi_finalized = 0; + int mpi_code; - if (MPI_SUCCESS != (mpi_code = MPI_Finalized(&mpi_finalized))) - HMPI_GOTO_ERROR(FAIL, "MPI_Finalized failed", mpi_code); - if (!mpi_finalized) - if (MPI_SUCCESS != (mpi_code = MPI_Finalize())) - HMPI_GOTO_ERROR(FAIL, "MPI_Finalize failed", mpi_code); + if (MPI_SUCCESS != (mpi_code = MPI_Finalized(&mpi_finalized))) + HMPI_GOTO_ERROR(FAIL, "MPI_Finalized failed", mpi_code); + if (!mpi_finalized) + if (MPI_SUCCESS != (mpi_code = MPI_Finalize())) + HMPI_GOTO_ERROR(FAIL, "MPI_Finalize failed", mpi_code); - H5FD_mpi_self_initialized = false; - } + H5FD_mpi_self_initialized_s = false; } done: - /* Reset VFL ID */ - H5FD_IOC_g = H5I_INVALID_HID; - FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD__ioc_term() */ @@ -702,6 +709,11 @@ H5FD__ioc_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) if (ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr"); + /* Initialize driver, if it's not yet */ + if (!H5FD_ioc_init_s) + if (H5FD__ioc_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, NULL, "can't initialize driver"); + if (NULL == (file = (H5FD_ioc_t *)H5FL_CALLOC(H5FD_ioc_t))) HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "unable to allocate file struct"); file->comm = MPI_COMM_NULL; @@ -718,7 +730,7 @@ H5FD__ioc_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) if (NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list"); - if (H5FD_mpi_self_initialized) { + if (H5FD_mpi_self_initialized_s) { file->comm = MPI_COMM_WORLD; file->info = MPI_INFO_NULL; @@ -1215,8 +1227,17 @@ H5FD__ioc_truncate(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, bool H5_ATTR_UNU FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD__ioc_truncate */ +/*------------------------------------------------------------------------- + * Function: H5FD__ioc_delete + * + * Purpose: Delete a file + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ static herr_t -H5FD__ioc_del(const char *name, hid_t fapl) +H5FD__ioc_delete(const char *name, hid_t fapl) { H5P_genplist_t *plist; MPI_Comm comm = MPI_COMM_NULL; @@ -1231,11 +1252,16 @@ H5FD__ioc_del(const char *name, hid_t fapl) FUNC_ENTER_PACKAGE + /* Initialize driver, if it's not yet */ + if (!H5FD_ioc_init_s) + if (H5FD__ioc_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize driver"); + if (NULL == (plist = H5P_object_verify(fapl, H5P_FILE_ACCESS))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list"); assert(H5FD_IOC == H5P_peek_driver(plist)); - if (H5FD_mpi_self_initialized) + if (H5FD_mpi_self_initialized_s) comm = MPI_COMM_WORLD; else { /* Get the MPI communicator and info from the fapl */ @@ -1337,7 +1363,7 @@ H5FD__ioc_del(const char *name, hid_t fapl) HMPI_DONE_ERROR(FAIL, "MPI_Barrier failed", mpi_code); } - if (!H5FD_mpi_self_initialized) { + if (!H5FD_mpi_self_initialized_s) { /* Free duplicated MPI Communicator and Info objects */ if (H5_mpi_comm_free(&comm) < 0) HDONE_ERROR(H5E_VFL, H5E_CANTFREE, FAIL, "unable to free MPI communicator"); diff --git a/src/H5FDsubfiling/H5FDioc.h b/src/H5FDsubfiling/H5FDioc.h index 08c561b74a4..ea7e62dcf7f 100644 --- a/src/H5FDsubfiling/H5FDioc.h +++ b/src/H5FDsubfiling/H5FDioc.h @@ -20,14 +20,24 @@ #ifndef H5FDioc_H #define H5FDioc_H -#include "H5FDsubfiling.h" +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ #ifdef H5_HAVE_IOC_VFD + +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + /** * \def H5FD_IOC * Macro that returns the identifier for the #H5FD_IOC driver. \hid_t{file driver} */ -#define H5FD_IOC (H5FD_ioc_init()) +#define H5FD_IOC (H5OPEN H5FD_IOC_id_g) #else #define H5FD_IOC (H5I_INVALID_HID) #endif @@ -114,11 +124,12 @@ typedef struct H5FD_ioc_config_t { extern "C" { #endif -/** - * \brief Internal routine to initialize #H5FD_IOC driver. Not meant to be - * called directly by an HDF5 application +/** @private + * + * \brief ID for the IOC VFD */ -H5_DLL hid_t H5FD_ioc_init(void); +H5_DLLVAR hid_t H5FD_IOC_id_g; + /** * \ingroup FAPL * diff --git a/src/H5FDsubfiling/H5FDioc_int.c b/src/H5FDsubfiling/H5FDioc_int.c index e528a362f80..b685b016c98 100644 --- a/src/H5FDsubfiling/H5FDioc_int.c +++ b/src/H5FDsubfiling/H5FDioc_int.c @@ -14,7 +14,12 @@ * Purpose: This is part of an I/O concentrator driver. */ -#include "H5FDioc_priv.h" +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ + +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5FDpkg.h" /* File drivers */ +#include "H5FDioc_priv.h" /* I/O concetrator file driver */ /* * Given a file offset, the stripe size, the number of IOCs and the number of diff --git a/src/H5FDsubfiling/H5FDioc_priv.h b/src/H5FDsubfiling/H5FDioc_priv.h index 2f17dbe221d..338f25e3412 100644 --- a/src/H5FDsubfiling/H5FDioc_priv.h +++ b/src/H5FDsubfiling/H5FDioc_priv.h @@ -21,16 +21,12 @@ /* H5 Headers */ /**************/ -#include "H5private.h" /* Generic Functions */ -#include "H5CXprivate.h" /* API Contexts */ -#include "H5Dprivate.h" /* Datasets */ -#include "H5Eprivate.h" /* Error handling */ +/* Public header */ #include "H5FDioc.h" /* IOC VFD */ -#include "H5Iprivate.h" /* IDs */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5Pprivate.h" /* Property lists */ -#include "H5TSprivate.h" /* Threadsafety */ +/* Private headers */ +#include "H5private.h" /* Generic Functions */ +#include "H5TSprivate.h" /* Threadsafety */ #include "H5subfiling_common.h" /* diff --git a/src/H5FDsubfiling/H5FDioc_threads.c b/src/H5FDsubfiling/H5FDioc_threads.c index da110e72bd7..c43b39e637f 100644 --- a/src/H5FDsubfiling/H5FDioc_threads.c +++ b/src/H5FDsubfiling/H5FDioc_threads.c @@ -10,9 +10,12 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "H5FDioc_priv.h" +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ -#include "H5FDsubfiling.h" +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5FDpkg.h" /* File drivers */ +#include "H5FDioc_priv.h" /* I/O concetrator file driver */ #define MIN_READ_RETRIES 10 diff --git a/src/H5FDsubfiling/H5FDsubfile_int.c b/src/H5FDsubfiling/H5FDsubfile_int.c index bf01fc0a2e4..49e14f0a977 100644 --- a/src/H5FDsubfiling/H5FDsubfile_int.c +++ b/src/H5FDsubfiling/H5FDsubfile_int.c @@ -19,7 +19,13 @@ /* Headers */ /***********/ -#include "H5FDsubfiling_priv.h" +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ + +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5FDpkg.h" /* File drivers */ +#include "H5FDsubfiling_priv.h" /* Subfiling file driver */ + /*------------------------------------------------------------------------- * Function: H5FD__subfiling__truncate_sub_files diff --git a/src/H5FDsubfiling/H5FDsubfiling.c b/src/H5FDsubfiling/H5FDsubfiling.c index cb9fab8e593..1938303b06e 100644 --- a/src/H5FDsubfiling/H5FDsubfiling.c +++ b/src/H5FDsubfiling/H5FDsubfiling.c @@ -16,27 +16,30 @@ * mirror, and family VFDs. */ -#include "H5FDdrvr_module.h" /* This source code file is part of the H5FD driver module */ +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ #include "H5private.h" /* Generic Functions */ #include "H5CXprivate.h" /* API contexts, etc. */ -#include "H5Dprivate.h" /* Dataset stuff */ #include "H5Eprivate.h" /* Error handling */ -#include "H5FDprivate.h" /* File drivers */ -#include "H5FDsubfiling.h" /* Subfiling file driver */ -#include "H5FDsubfiling_priv.h" /* Subfiling file driver */ +#include "H5Fprivate.h" /* File access */ +#include "H5FDpkg.h" /* File drivers */ #include "H5FDsec2.h" /* Sec2 VFD */ +#include "H5FDsubfiling_priv.h" /* Subfiling file driver */ #include "H5FLprivate.h" /* Free Lists */ -#include "H5Fprivate.h" /* File access */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5Pprivate.h" /* Property lists */ /* The driver identification number, initialized at runtime */ -static hid_t H5FD_SUBFILING_g = H5I_INVALID_HID; +hid_t H5FD_SUBFILING_id_g = H5I_INVALID_HID; + +/* Flag to indicate whether global driver resources & settings have been + * initialized. + */ +static bool H5FD_subfiling_init_s = false; /* Whether the driver initialized MPI on its own */ -static bool H5FD_mpi_self_initialized = false; +static bool H5FD_mpi_self_initialized_s = false; /* The description of a file belonging to this driver. The 'eoa' and 'eof' * determine the amount of hdf5 address space in use and the high-water mark @@ -178,7 +181,7 @@ static herr_t H5FD__subfiling_read_vector(H5FD_t *file, hid_t dxpl_id, uint32_t static herr_t H5FD__subfiling_write_vector(H5FD_t *file, hid_t dxpl_id, uint32_t count, H5FD_mem_t types[], haddr_t addrs[], size_t sizes[], const void *bufs[] /* in */); static herr_t H5FD__subfiling_truncate(H5FD_t *_file, hid_t dxpl_id, bool closing); -static herr_t H5FD__subfiling_del(const char *name, hid_t fapl); +static herr_t H5FD__subfiling_delete(const char *name, hid_t fapl); static herr_t H5FD__subfiling_ctl(H5FD_t *_file, uint64_t op_code, uint64_t flags, const void *input, void **output); @@ -238,8 +241,6 @@ static void H5_subfiling_dump_iovecs(subfiling_context_t *sf_context, size_t ior haddr_t *io_addrs, size_t *io_sizes, H5_flexible_const_ptr_t *io_bufs); #endif -void H5FD__subfiling_mpi_finalize(void); - static const H5FD_class_t H5FD_subfiling_g = { H5FD_CLASS_VERSION, /* VFD interface version */ H5_VFD_SUBFILING, /* value */ @@ -278,7 +279,7 @@ static const H5FD_class_t H5FD_subfiling_g = { H5FD__subfiling_truncate, /* truncate */ NULL, /* lock */ NULL, /* unlock */ - H5FD__subfiling_del, /* del */ + H5FD__subfiling_delete, /* del */ H5FD__subfiling_ctl, /* ctl */ H5FD_FLMAP_DICHOTOMY /* fl_map */ }; @@ -286,124 +287,108 @@ static const H5FD_class_t H5FD_subfiling_g = { /* Declare a free list to manage the H5FD_subfiling_t struct */ H5FL_DEFINE_STATIC(H5FD_subfiling_t); -/* - * If this VFD initialized MPI, this routine will be registered - * as an atexit handler in order to finalize MPI before the - * application exits. - */ -void -H5FD__subfiling_mpi_finalize(void) -{ - /* - * Don't call normal FUNC_ENTER() since we don't want to initialize the - * whole library just to release it all right away. It is safe to call - * this function for an uninitialized library. - */ - FUNC_ENTER_NOAPI_NOINIT_NOERR - - H5_term_library(); - MPI_Finalize(); - - FUNC_LEAVE_NOAPI_VOID -} - /*------------------------------------------------------------------------- - * Function: H5FD__init_package + * Function: H5FD__subfiling_register * - * Purpose: Initializes any interface-specific data or routines. + * Purpose: Register the driver with the library. * - * Return: Non-negative on success/Negative on failure + * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ -static herr_t -H5FD__init_package(void) +herr_t +H5FD__subfiling_register(void) { - herr_t ret_value = SUCCEED; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE - if (H5FD_subfiling_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize subfiling VFD"); + /* Register the Subfiling VFD, if it isn't already registered */ + if (H5I_VFL != H5I_get_type(H5FD_SUBFILING_id_g)) + if ((H5FD_SUBFILING_id_g = H5FD_register(&H5FD_subfiling_g, sizeof(H5FD_class_t), false)) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "can't register subfiling VFD"); done: FUNC_LEAVE_NOAPI(ret_value) -} /* H5FD__init_package() */ +} /* end H5FD__subfiling_register() */ -/*------------------------------------------------------------------------- - * Function: H5FD_subfiling_init +/*--------------------------------------------------------------------------- + * Function: H5FD__subfiling_unregister * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Purpose: Reset library driver info. * - * Return: Success: The driver ID for the subfiling driver - * Failure: H5I_INVALID_HID + * Returns: SUCCEED (Can't fail) * - *------------------------------------------------------------------------- + *--------------------------------------------------------------------------- */ -hid_t -H5FD_subfiling_init(void) +herr_t +H5FD__subfiling_unregister(void) { - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + FUNC_ENTER_PACKAGE_NOERR - FUNC_ENTER_NOAPI(H5I_INVALID_HID) + /* Reset VFL ID */ + H5FD_SUBFILING_id_g = H5I_INVALID_HID; - /* Register the Subfiling VFD, if it isn't already registered */ - if (H5I_VFL != H5I_get_type(H5FD_SUBFILING_g)) { - int mpi_initialized = 0; - int provided = 0; - int mpi_code; - - if ((H5FD_SUBFILING_g = H5FD_register(&H5FD_subfiling_g, sizeof(H5FD_class_t), false)) < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, H5I_INVALID_HID, "can't register subfiling VFD"); - - /* Initialize MPI if not already initialized */ - if (MPI_SUCCESS != (mpi_code = MPI_Initialized(&mpi_initialized))) - HMPI_GOTO_ERROR(H5I_INVALID_HID, "MPI_Initialized failed", mpi_code); - if (mpi_initialized) { - /* If MPI is initialized, validate that it was initialized with MPI_THREAD_MULTIPLE */ - if (MPI_SUCCESS != (mpi_code = MPI_Query_thread(&provided))) - HMPI_GOTO_ERROR(H5I_INVALID_HID, "MPI_Query_thread failed", mpi_code); - if (provided != MPI_THREAD_MULTIPLE) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, - "Subfiling VFD requires the use of MPI_Init_thread with MPI_THREAD_MULTIPLE"); - } - else { - int required = MPI_THREAD_MULTIPLE; + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5FD__subfiling_unregister() */ + +/*------------------------------------------------------------------------- + * Function: H5FD__subfiling_init + * + * Purpose: Singleton to initialize global driver settings & resources. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__subfiling_init(void) +{ + int mpi_initialized = 0; + int provided = 0; + int mpi_code; + herr_t ret_value = SUCCEED; /* Return value */ - if (MPI_SUCCESS != (mpi_code = MPI_Init_thread(NULL, NULL, required, &provided))) - HMPI_GOTO_ERROR(H5I_INVALID_HID, "MPI_Init_thread failed", mpi_code); + FUNC_ENTER_PACKAGE - H5FD_mpi_self_initialized = true; + /* Initialize MPI if not already initialized */ + if (MPI_SUCCESS != (mpi_code = MPI_Initialized(&mpi_initialized))) + HMPI_GOTO_ERROR(FAIL, "MPI_Initialized failed", mpi_code); + if (mpi_initialized) { + /* If MPI is initialized, validate that it was initialized with MPI_THREAD_MULTIPLE */ + if (MPI_SUCCESS != (mpi_code = MPI_Query_thread(&provided))) + HMPI_GOTO_ERROR(FAIL, "MPI_Query_thread failed", mpi_code); + if (provided != MPI_THREAD_MULTIPLE) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "Subfiling VFD requires the use of MPI_Init_thread with MPI_THREAD_MULTIPLE"); + } + else { + if (MPI_SUCCESS != (mpi_code = MPI_Init_thread(NULL, NULL, MPI_THREAD_MULTIPLE, &provided))) + HMPI_GOTO_ERROR(FAIL, "MPI_Init_thread failed", mpi_code); - if (provided != required) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, - "MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE"); + H5FD_mpi_self_initialized_s = true; - if (atexit(H5FD__subfiling_mpi_finalize) < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, - "can't register atexit handler for MPI_Finalize"); - } + if (provided != MPI_THREAD_MULTIPLE) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE"); + } - /* - * Create the MPI Datatype that will be used - * for sending/receiving RPC messages - */ - HDcompile_assert(sizeof(((sf_work_request_t *)NULL)->header) == 3 * sizeof(int64_t)); - if (H5_subfiling_rpc_msg_type == MPI_DATATYPE_NULL) { - if (MPI_SUCCESS != (mpi_code = MPI_Type_contiguous(3, MPI_INT64_T, &H5_subfiling_rpc_msg_type))) - HMPI_GOTO_ERROR(H5I_INVALID_HID, "MPI_Type_contiguous failed", mpi_code); - if (MPI_SUCCESS != (mpi_code = MPI_Type_commit(&H5_subfiling_rpc_msg_type))) - HMPI_GOTO_ERROR(H5I_INVALID_HID, "MPI_Type_commit failed", mpi_code); - } + /* + * Create the MPI Datatype that will be used + * for sending/receiving RPC messages + */ + HDcompile_assert(sizeof(((sf_work_request_t *)NULL)->header) == 3 * sizeof(int64_t)); + if (H5_subfiling_rpc_msg_type == MPI_DATATYPE_NULL) { + if (MPI_SUCCESS != (mpi_code = MPI_Type_contiguous(3, MPI_INT64_T, &H5_subfiling_rpc_msg_type))) + HMPI_GOTO_ERROR(FAIL, "MPI_Type_contiguous failed", mpi_code); + if (MPI_SUCCESS != (mpi_code = MPI_Type_commit(&H5_subfiling_rpc_msg_type))) + HMPI_GOTO_ERROR(FAIL, "MPI_Type_commit failed", mpi_code); } - /* Set return value */ - ret_value = H5FD_SUBFILING_g; + /* Indicate that driver is set up */ + H5FD_subfiling_init_s = true; done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FD_subfiling_init() */ +} /* end H5FD__subfiling_init() */ /*--------------------------------------------------------------------------- * Function: H5FD__subfiling_term @@ -417,44 +402,45 @@ H5FD_subfiling_init(void) static herr_t H5FD__subfiling_term(void) { + int mpi_finalized; + int mpi_code; herr_t ret_value = SUCCEED; FUNC_ENTER_PACKAGE - if (H5FD_SUBFILING_g >= 0) { - int mpi_finalized; - int mpi_code; - - /* - * Retrieve status of whether MPI has already been terminated. - * This can happen if an HDF5 ID is left unclosed and HDF5 - * shuts down after MPI_Finalize() is called in an application. - */ - if (MPI_SUCCESS != (mpi_code = MPI_Finalized(&mpi_finalized))) - HMPI_GOTO_ERROR(FAIL, "MPI_Finalized failed", mpi_code); + /* + * Retrieve status of whether MPI has already been terminated. + * This can happen if an HDF5 ID is left unclosed and HDF5 + * shuts down after MPI_Finalize() is called in an application. + */ + if (MPI_SUCCESS != (mpi_code = MPI_Finalized(&mpi_finalized))) + HMPI_GOTO_ERROR(FAIL, "MPI_Finalized failed", mpi_code); + if (!mpi_finalized) { /* Free RPC message MPI Datatype */ - if (H5_subfiling_rpc_msg_type != MPI_DATATYPE_NULL) { - if (!mpi_finalized) { - if (MPI_SUCCESS != (mpi_code = MPI_Type_free(&H5_subfiling_rpc_msg_type))) - HMPI_GOTO_ERROR(FAIL, "MPI_Type_free failed", mpi_code); - } + if (H5_subfiling_rpc_msg_type != MPI_DATATYPE_NULL) + if (MPI_SUCCESS != (mpi_code = MPI_Type_free(&H5_subfiling_rpc_msg_type))) + HMPI_GOTO_ERROR(FAIL, "MPI_Type_free failed", mpi_code); + + /* Terminate MPI if the driver initialized it */ + if (H5FD_mpi_self_initialized_s) { + if (MPI_SUCCESS != (mpi_code = MPI_Finalize())) + HMPI_GOTO_ERROR(FAIL, "MPI_Finalize failed", mpi_code); + + H5FD_mpi_self_initialized_s = false; + } + } #ifdef H5_SUBFILING_DEBUG - else - printf("** WARNING **: HDF5 is terminating the Subfiling VFD after MPI_Finalize() was called " - "- an HDF5 ID was probably left unclosed\n"); + else + printf("** WARNING **: HDF5 is terminating the Subfiling VFD after MPI_Finalize() was called " + "- an HDF5 ID was probably left unclosed\n"); #endif - } - /* Clean up resources */ - if (H5FD__subfiling_terminate() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTFREE, FAIL, "can't cleanup internal subfiling resources"); - } + /* Clean up resources */ + if (H5FD__subfiling_terminate() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTRELEASE, FAIL, "can't cleanup internal subfiling resources"); done: - /* Reset VFL ID */ - H5FD_SUBFILING_g = H5I_INVALID_HID; - FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD__subfiling_term() */ @@ -484,10 +470,6 @@ H5Pset_fapl_subfiling(hid_t fapl_id, const H5FD_subfiling_config_t *vfd_config) FUNC_ENTER_API(FAIL) - /* Ensure Subfiling (and therefore MPI) is initialized before doing anything */ - if (H5FD_subfiling_init() < 0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize subfiling VFD"); - if (NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list"); @@ -1136,6 +1118,11 @@ H5FD__subfiling_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t ma if (ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr"); + /* Initialize driver, if it's not yet */ + if (!H5FD_subfiling_init_s) + if (H5FD__subfiling_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, NULL, "can't initialize driver"); + if (NULL == (file = (H5FD_subfiling_t *)H5FL_CALLOC(H5FD_subfiling_t))) HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "unable to allocate file struct"); file->comm = MPI_COMM_NULL; @@ -1150,7 +1137,7 @@ H5FD__subfiling_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t ma if (NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list"); - if (H5FD_mpi_self_initialized) { + if (H5FD_mpi_self_initialized_s) { file->comm = MPI_COMM_WORLD; file->info = MPI_INFO_NULL; } @@ -1782,8 +1769,17 @@ H5FD__subfiling_truncate(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, bool H5_AT FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD__subfiling_truncate() */ +/*------------------------------------------------------------------------- + * Function: H5FD__subfiling_delete + * + * Purpose: Delete a file + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ static herr_t -H5FD__subfiling_del(const char *name, hid_t fapl) +H5FD__subfiling_delete(const char *name, hid_t fapl) { const H5FD_subfiling_config_t *subfiling_config = NULL; H5FD_subfiling_config_t default_config; @@ -1792,6 +1788,11 @@ H5FD__subfiling_del(const char *name, hid_t fapl) FUNC_ENTER_PACKAGE + /* Initialize driver, if it's not yet */ + if (!H5FD_subfiling_init_s) + if (H5FD__subfiling_init() < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize driver"); + if (NULL == (plist = H5P_object_verify(fapl, H5P_FILE_ACCESS))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list"); diff --git a/src/H5FDsubfiling/H5FDsubfiling.h b/src/H5FDsubfiling/H5FDsubfiling.h index 56e0baf2306..5838938e4af 100644 --- a/src/H5FDsubfiling/H5FDsubfiling.h +++ b/src/H5FDsubfiling/H5FDsubfiling.h @@ -14,12 +14,24 @@ #ifndef H5FDsubfiling_H #define H5FDsubfiling_H +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + #ifdef H5_HAVE_SUBFILING_VFD + +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + /** * \def H5FD_SUBFILING * Macro that returns the identifier for the #H5FD_SUBFILING driver. \hid_t{file driver} */ -#define H5FD_SUBFILING (H5FD_subfiling_init()) +#define H5FD_SUBFILING (H5OPEN H5FD_SUBFILING_id_g) #else #define H5FD_SUBFILING (H5I_INVALID_HID) #endif @@ -319,11 +331,12 @@ typedef struct H5FD_subfiling_config_t { extern "C" { #endif -/** - * \brief Internal routine to initialize #H5FD_SUBFILING driver. Not meant to be - * called directly by an HDF5 application +/** @private + * + * \brief ID for the SUBFILING VFD */ -H5_DLL hid_t H5FD_subfiling_init(void); +H5_DLLVAR hid_t H5FD_SUBFILING_id_g; + /** * \ingroup FAPL * diff --git a/src/H5FDsubfiling/H5FDsubfiling_priv.h b/src/H5FDsubfiling/H5FDsubfiling_priv.h index fdb946e73ef..76dd49a5c0e 100644 --- a/src/H5FDsubfiling/H5FDsubfiling_priv.h +++ b/src/H5FDsubfiling/H5FDsubfiling_priv.h @@ -21,16 +21,11 @@ /* H5 Headers */ /**************/ -#include "H5private.h" /* Generic Functions */ -#include "H5CXprivate.h" /* API Contexts */ -#include "H5Dprivate.h" /* Datasets */ -#include "H5Eprivate.h" /* Error handling */ +/* Public header */ #include "H5FDsubfiling.h" /* Subfiling VFD */ -#include "H5FDioc.h" /* IOC VFD */ -#include "H5Iprivate.h" /* IDs */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5Pprivate.h" /* Property lists */ +/* Private headers */ +#include "H5private.h" /* Generic Functions */ #include "H5subfiling_common.h" #define DRIVER_INFO_MESSAGE_MAX_INFO 65536 diff --git a/src/H5FDsubfiling/H5subfiling_common.c b/src/H5FDsubfiling/H5subfiling_common.c index 00a2b7017c4..651f68e945b 100644 --- a/src/H5FDsubfiling/H5subfiling_common.c +++ b/src/H5FDsubfiling/H5subfiling_common.c @@ -14,12 +14,16 @@ * Generic code for integrating an HDF5 VFD with the subfiling feature */ +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ + +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5FDpkg.h" /* File drivers */ +#include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5TSprivate.h" /* Threadsafety */ #include "H5subfiling_common.h" -#include "H5Eprivate.h" -#include "H5MMprivate.h" -#include "H5TSprivate.h" /* Threadsafety */ - typedef struct { /* Format of a context map entry */ uint64_t file_id; /* key value (linear search of the cache) */ int64_t sf_context_id; /* The return value if matching file_handle */ @@ -94,7 +98,7 @@ static int64_t H5FD__subfiling_new_object_id(sf_obj_type_t obj_type) { int64_t index_val = 0; - int64_t ret_value; + int64_t ret_value = 0; FUNC_ENTER_PACKAGE diff --git a/src/H5FDsubfiling/H5subfiling_common.h b/src/H5FDsubfiling/H5subfiling_common.h index 7e7ada5bcfe..7fd3e6c69e0 100644 --- a/src/H5FDsubfiling/H5subfiling_common.h +++ b/src/H5FDsubfiling/H5subfiling_common.h @@ -18,14 +18,11 @@ #define H5_SUBFILING_COMMON_H #include "H5private.h" /* Generic Functions */ -#include "H5FDprivate.h" /* File Drivers */ -#include "H5Iprivate.h" /* IDs */ +#include "H5FDsubfiling.h" /* Subfiling file driver */ +#include "H5FDioc.h" /* I/O concentrator file driver */ #include "H5Pprivate.h" /* Property lists */ #include "H5TSprivate.h" /* Threads */ -#include "H5FDsubfiling.h" -#include "H5FDioc.h" - #ifndef PATH_MAX #define PATH_MAX 4096 #endif diff --git a/src/H5FDwindows.c b/src/H5FDwindows.c index 74389db913d..15d63ec12f6 100644 --- a/src/H5FDwindows.c +++ b/src/H5FDwindows.c @@ -10,15 +10,18 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#include "H5FDmodule.h" /* This source code file is part of the H5FD module */ + #include "H5private.h" /* Generic Functions */ + +#ifdef H5_HAVE_WINDOWS + #include "H5Eprivate.h" /* Error handling */ -#include "H5FDprivate.h" /* File drivers */ -#include "H5FDwindows.h" /* Windows file driver */ #include "H5FDsec2.h" /* Windows file driver */ +#include "H5FDpkg.h" /* File drivers */ +#include "H5FDwindows.h" /* Windows file driver */ #include "H5Pprivate.h" /* Property lists */ -#ifdef H5_HAVE_WINDOWS - /*------------------------------------------------------------------------- * Function: H5Pset_fapl_windows * diff --git a/src/H5FDwindows.h b/src/H5FDwindows.h index 673d1c93b59..07a11cd8f1a 100644 --- a/src/H5FDwindows.h +++ b/src/H5FDwindows.h @@ -20,13 +20,30 @@ #ifndef H5FDwindows_H #define H5FDwindows_H -/** Initializer for the Windows VFD */ -#define H5FD_WINDOWS (H5FD_sec2_init()) +/* Public header files */ +#include "H5FDpublic.h" /* File drivers */ + +/* When this header is included from a private header, don't make calls to H5open() */ +#undef H5OPEN +#ifndef H5private_H +#define H5OPEN H5open(), +#else /* H5private_H */ +#define H5OPEN +#endif /* H5private_H */ + +/** ID for the windows VFD */ +#define H5FD_WINDOWS (H5OPEN H5FD_SEC2_id_g) #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ +/** @private + * + * \brief ID for the windows (sec2) VFD + */ +H5_DLLVAR hid_t H5FD_SEC2_id_g; + /** * \ingroup FAPL * diff --git a/src/H5private.h b/src/H5private.h index 98ffd09a25a..4c4e6684697 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1596,19 +1596,11 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); } /*end scope from beginning of FUNC_ENTER*/ /* Macros to declare package initialization function, if a package initialization routine is defined */ -#ifdef H5_PKG_SINGLE_SOURCE -#define H5_PKG_DECLARE_YES_FUNC(pkg) static herr_t H5_PACKAGE_INIT_FUNC(pkg)(void); -#else #define H5_PKG_DECLARE_YES_FUNC(pkg) extern herr_t H5_PACKAGE_INIT_FUNC(pkg)(void); -#endif #define H5_PKG_DECLARE_NO_FUNC(pkg) /* Declare package initialization symbols (if in a package) */ -#ifdef H5_PKG_SINGLE_SOURCE -#define H5_PKG_DECLARE_VAR(pkg) static bool H5_PACKAGE_INIT_VAR(pkg); -#else #define H5_PKG_DECLARE_VAR(pkg) extern bool H5_PACKAGE_INIT_VAR(pkg); -#endif #define H5_PKG_DECLARE_FUNC(pkg_init, pkg) H5_GLUE3(H5_PKG_DECLARE_, pkg_init, _FUNC)(pkg) #ifdef H5_MY_PKG diff --git a/src/Makefile.am b/src/Makefile.am index 9d09893c3be..c8ae6cafca5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -53,9 +53,10 @@ libhdf5_la_SOURCES= H5.c H5build_settings.c H5checksum.c H5dbg.c H5system.c \ H5FA.c H5FAcache.c H5FAdbg.c H5FAdblock.c H5FAdblkpage.c H5FAhdr.c \ H5FAint.c H5FAstat.c H5FAtest.c \ H5FD.c H5FDcore.c H5FDfamily.c H5FDint.c H5FDlog.c H5FDmulti.c \ + H5FDmulti_int.c \ H5FDonion.c H5FDonion_header.c H5FDonion_history.c H5FDonion_index.c \ H5FDsec2.c H5FDspace.c \ - H5FDsplitter.c H5FDstdio.c H5FDtest.c H5FDwindows.c \ + H5FDsplitter.c H5FDstdio.c H5FDstdio_int.c H5FDtest.c H5FDwindows.c \ H5FL.c H5FO.c H5FS.c H5FScache.c H5FSdbg.c H5FSint.c H5FSsection.c \ H5FSstat.c H5FStest.c \ H5G.c H5Gbtree2.c H5Gcache.c H5Gcompact.c H5Gdense.c H5Gdeprec.c \