Skip to content

Commit

Permalink
Fix issue with Subfiling VFD and multiple opens of same file (HDFGrou…
Browse files Browse the repository at this point in the history
…p#4194)

* Fix issue with Subfiling VFD and multiple opens of same file

* Update H5_subfile_fid_to_context to return error value instead of ID

* Add helper routine to initialize open file mapping
  • Loading branch information
jhendersonHDF authored Mar 22, 2024
1 parent 23d3d63 commit c4cc33a
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 200 deletions.
10 changes: 10 additions & 0 deletions release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,16 @@ Bug Fixes since HDF5-1.14.0 release

Library
-------
- Fixed an issue with the Subfiling VFD and multiple opens of a
file

An issue with the way the Subfiling VFD handles multiple opens
of the same file caused the file structures for the extra opens
to occasionally get mapped to an incorrect subfiling context
object. The VFD now correctly maps the file structures for
additional opens of an already open file to the same context
object.

- Fixed a bug that causes the library to incorrectly identify
the endian-ness of 16-bit and smaller C floating-point datatypes

Expand Down
29 changes: 21 additions & 8 deletions src/H5FDsubfiling/H5FDioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,12 +843,17 @@ H5FD__ioc_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
H5_SUBFILING_GOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open subfiles for file '%s'",
name);

/* Initialize I/O concentrator threads if this MPI rank is an I/O concentrator */
/*
* Initialize I/O concentrator threads if this MPI rank is an I/O
* concentrator and the threads haven't already been initialized by
* a different open of this file
*/
sf_context = H5_get_subfiling_object(file_ptr->context_id);
if (sf_context && sf_context->topology->rank_is_ioc) {
if (sf_context && sf_context->topology->rank_is_ioc && !sf_context->threads_inited) {
if (initialize_ioc_threads(sf_context) < 0)
H5_SUBFILING_GOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL,
"unable to initialize I/O concentrator threads");
sf_context->threads_inited = true;
}

ret_value = (H5FD_t *)file_ptr;
Expand Down Expand Up @@ -917,14 +922,22 @@ H5FD__ioc_close_int(H5FD_ioc_t *file_ptr)
if (MPI_SUCCESS != (mpi_code = MPI_Barrier(file_ptr->comm)))
H5_SUBFILING_MPI_GOTO_ERROR(FAIL, "MPI_Barrier failed", mpi_code);

if (sf_context && sf_context->topology->rank_is_ioc) {
if (finalize_ioc_threads(sf_context) < 0)
/* Note that closing of subfiles is collective */
H5_SUBFILING_DONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL, "unable to finalize IOC threads");
/* Only finalize IOC threads and close subfiles if this is
* the last file holding a reference to the context
*/
if (sf_context && sf_context->file_ref == 1) {
if (sf_context->topology->rank_is_ioc && sf_context->threads_inited) {
if (finalize_ioc_threads(sf_context) < 0)
/* Note that closing of subfiles is collective */
H5_SUBFILING_DONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL,
"unable to finalize IOC threads");
}

if (H5_close_subfiles(file_ptr->context_id, file_ptr->comm) < 0)
H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL,
"unable to close subfiling file(s)");
}

if (H5_close_subfiles(file_ptr->context_id, file_ptr->comm) < 0)
H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL, "unable to close subfiling file(s)");
file_ptr->context_id = -1;
}

Expand Down
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
Loading

0 comments on commit c4cc33a

Please sign in to comment.