Skip to content

Commit

Permalink
Update H5_subfile_fid_to_context to return error value instead of ID
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendersonHDF committed Mar 20, 2024
1 parent bdc1d52 commit 15e14be
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
4 changes: 3 additions & 1 deletion src/H5FDsubfiling/H5FDsubfiling.c
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,9 @@ H5FD__subfiling_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t ma

if (driver->value == H5_VFD_IOC) {
/* Get a copy of the context ID for later use */
file_ptr->context_id = H5_subfile_fid_to_context(file_ptr->file_id);
if (H5_subfile_fid_to_context(file_ptr->file_id, &file_ptr->context_id) < 0)
H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL,
"unable to retrieve subfiling context ID for this file");
file_ptr->fa.require_ioc = true;
}
else if (driver->value == H5_VFD_SEC2) {
Expand Down
35 changes: 19 additions & 16 deletions src/H5FDsubfiling/H5subfiling_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ H5_open_subfiles(const char *base_filename, uint64_t file_id, H5FD_subfiling_par
int64_t context_id = -1;
bool recorded_fid = false;
int mpi_code;
herr_t status;
herr_t ret_value = SUCCEED;

if (!base_filename)
Expand All @@ -660,12 +661,12 @@ H5_open_subfiles(const char *base_filename, uint64_t file_id, H5FD_subfiling_par
/* Check if this file is already open */
H5E_BEGIN_TRY
{
context_id = H5_subfile_fid_to_context(file_id);
status = H5_subfile_fid_to_context(file_id, &context_id);
}
H5E_END_TRY

if (context_id >= 0) {
/* Retrieve the subfiling object for the newly-created context ID */
if (status >= 0 && context_id >= 0) {
/* Retrieve the subfiling object for the cached context ID */
if (NULL == (sf_context = H5_get_subfiling_object(context_id)))
H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL,
"couldn't get subfiling object from context ID");
Expand Down Expand Up @@ -3019,27 +3020,29 @@ H5_subfiling_get_file_id_prop(H5P_genplist_t *plist_ptr, uint64_t *file_id)
* Function: H5_subfile_fid_to_context
*
* Purpose: This is a basic lookup function which returns the subfiling
* context id associated with the specified file ID.
* context ID associated with the specified file ID. If no
* such context ID exists, `context_id_out` will be set to a
* negative value.
*
* Return: Non-negative subfiling context ID if the context exists
* Negative on failure or if the subfiling context doesn't
* exist
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
int64_t
H5_subfile_fid_to_context(uint64_t file_id)
herr_t
H5_subfile_fid_to_context(uint64_t file_id, int64_t *context_id_out)
{
int64_t ret_value = -1;
herr_t ret_value = SUCCEED;

assert(context_id_out);

*context_id_out = -1;

if (!sf_open_file_map)
H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_BADVALUE, -1, "open file map is NULL");
H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "open file map is NULL");

for (int i = 0; i < sf_file_map_size; i++) {
if (sf_open_file_map[i].file_id == file_id) {
return sf_open_file_map[i].sf_context_id;
}
}
for (int i = 0; i < sf_file_map_size; i++)
if (sf_open_file_map[i].file_id == file_id)
*context_id_out = sf_open_file_map[i].sf_context_id;

done:
H5_SUBFILING_FUNC_LEAVE;
Expand Down
12 changes: 6 additions & 6 deletions src/H5FDsubfiling/H5subfiling_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ H5_DLL herr_t H5_get_subfiling_config_from_file(FILE *config_file, int64_t *str
int64_t *num_subfiles);
H5_DLL herr_t H5_resolve_pathname(const char *filepath, MPI_Comm comm, char **resolved_filepath);

H5_DLL herr_t H5_subfiling_set_config_prop(H5P_genplist_t *plist_ptr,
const H5FD_subfiling_params_t *vfd_config);
H5_DLL herr_t H5_subfiling_get_config_prop(H5P_genplist_t *plist_ptr, H5FD_subfiling_params_t *vfd_config);
H5_DLL herr_t H5_subfiling_set_file_id_prop(H5P_genplist_t *plist_ptr, uint64_t file_id);
H5_DLL herr_t H5_subfiling_get_file_id_prop(H5P_genplist_t *plist_ptr, uint64_t *file_id);
H5_DLL int64_t H5_subfile_fid_to_context(uint64_t file_id);
H5_DLL herr_t H5_subfiling_set_config_prop(H5P_genplist_t *plist_ptr,
const H5FD_subfiling_params_t *vfd_config);
H5_DLL herr_t H5_subfiling_get_config_prop(H5P_genplist_t *plist_ptr, H5FD_subfiling_params_t *vfd_config);
H5_DLL herr_t H5_subfiling_set_file_id_prop(H5P_genplist_t *plist_ptr, uint64_t file_id);
H5_DLL herr_t H5_subfiling_get_file_id_prop(H5P_genplist_t *plist_ptr, uint64_t *file_id);
H5_DLL herr_t H5_subfile_fid_to_context(uint64_t file_id, int64_t *context_id_out);

H5_DLL herr_t H5_subfiling_validate_config(const H5FD_subfiling_params_t *subf_config);

Expand Down

0 comments on commit 15e14be

Please sign in to comment.