From 597ce3cdbf233fd1810e34e8452049d3285ab170 Mon Sep 17 00:00:00 2001 From: jhendersonHDF Date: Fri, 5 Aug 2022 22:17:16 -0500 Subject: Fix issues in tools code after Subfiling VFD updates (#1973) --- src/H5FDsubfiling/H5FDioc.c | 22 +++++++++++++++------- src/H5FDsubfiling/H5FDsubfiling.c | 27 +++++++++++++++++---------- tools/lib/h5tools.c | 15 +++++++++++++-- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/H5FDsubfiling/H5FDioc.c b/src/H5FDsubfiling/H5FDioc.c index f779c46..6bfb1b7 100644 --- a/src/H5FDsubfiling/H5FDioc.c +++ b/src/H5FDsubfiling/H5FDioc.c @@ -380,6 +380,7 @@ done: if (ioc_conf) { if (ioc_conf->under_fapl_id >= 0 && H5I_dec_ref(ioc_conf->under_fapl_id) < 0) H5_SUBFILING_DONE_ERROR(H5E_PLIST, H5E_CANTDEC, FAIL, "can't close IOC under FAPL"); + ioc_conf->under_fapl_id = H5I_INVALID_HID; H5FL_FREE(H5FD_ioc_config_t, ioc_conf); } @@ -749,6 +750,7 @@ H5FD__ioc_fapl_free(void *_fapl) if (fapl->under_fapl_id >= 0 && H5I_dec_ref(fapl->under_fapl_id) < 0) H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_CANTDEC, FAIL, "can't close IOC under FAPL ID"); + fapl->under_fapl_id = H5I_INVALID_HID; /* Free the property list */ fapl = H5FL_FREE(H5FD_ioc_config_t, fapl); @@ -841,6 +843,12 @@ H5FD__ioc_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) /* Fill in the file config values */ HDmemcpy(&file_ptr->fa, config_ptr, sizeof(H5FD_ioc_config_t)); + /* Copy the ioc FAPL. */ + if (H5FD__copy_plist(config_ptr->under_fapl_id, &(file_ptr->fa.under_fapl_id)) < 0) { + file_ptr->fa.under_fapl_id = H5I_INVALID_HID; + H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't copy IOC under FAPL"); + } + if (NULL != (file_ptr->file_path = HDrealpath(name, NULL))) { char *path = NULL; char *directory = dirname(path); @@ -866,12 +874,8 @@ H5FD__ioc_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) H5_SUBFILING_SYS_GOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "can't resolve subfile path"); } - /* Copy the ioc FAPL. */ - if (H5FD__copy_plist(config_ptr->under_fapl_id, &(file_ptr->fa.under_fapl_id)) < 0) - H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't copy IOC under FAPL"); - /* Check the underlying driver (sec2/mpio/etc.) */ - if (NULL == (plist_ptr = (H5P_genplist_t *)H5I_object(config_ptr->under_fapl_id))) + if (NULL == (plist_ptr = (H5P_genplist_t *)H5I_object(file_ptr->fa.under_fapl_id))) H5_SUBFILING_GOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list"); if (H5P_peek(plist_ptr, H5F_ACS_FILE_DRV_NAME, &driver_prop) < 0) @@ -900,9 +904,9 @@ H5FD__ioc_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) if (H5F_ACC_EXCL & flags) ioc_flags |= O_EXCL; - file_ptr->ioc_file = H5FD_open(file_ptr->file_path, flags, config_ptr->under_fapl_id, HADDR_UNDEF); + file_ptr->ioc_file = H5FD_open(file_ptr->file_path, flags, file_ptr->fa.under_fapl_id, HADDR_UNDEF); if (file_ptr->ioc_file) { - if (H5FDget_vfd_handle(file_ptr->ioc_file, config_ptr->under_fapl_id, &file_handle) < 0) + if (H5FDget_vfd_handle(file_ptr->ioc_file, file_ptr->fa.under_fapl_id, &file_handle) < 0) H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "can't get file handle"); } else { @@ -956,6 +960,10 @@ done: H5_SUBFILING_MPI_DONE_ERROR(NULL, "MPI_Barrier failed", mpi_code); } + if (config_ptr == &default_config) + if (H5I_dec_ref(config_ptr->under_fapl_id) < 0) + H5_SUBFILING_DONE_ERROR(H5E_PLIST, H5E_CANTCLOSEOBJ, NULL, "can't close IOC under FAPL"); + if (NULL == ret_value) { if (file_ptr) { if (H5FD__ioc_close_int(file_ptr) < 0) diff --git a/src/H5FDsubfiling/H5FDsubfiling.c b/src/H5FDsubfiling/H5FDsubfiling.c index a38c020..4cdded3 100644 --- a/src/H5FDsubfiling/H5FDsubfiling.c +++ b/src/H5FDsubfiling/H5FDsubfiling.c @@ -354,13 +354,7 @@ H5FD_subfiling_init(void) "Subfiling VFD requires the use of MPI_Init_thread with MPI_THREAD_MULTIPLE"); } else { - char *env_var; - int required = MPI_THREAD_MULTIPLE; - - /* Ensure that Subfiling VFD has been loaded dynamically */ - env_var = HDgetenv(HDF5_DRIVER); - if (!env_var || HDstrcmp(env_var, H5FD_SUBFILING_NAME)) - H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_CANTINIT, H5I_INVALID_HID, "MPI isn't initialized"); + int required = MPI_THREAD_MULTIPLE; if (MPI_SUCCESS != (mpi_code = MPI_Init_thread(NULL, NULL, required, &provided))) H5_SUBFILING_MPI_GOTO_ERROR(H5I_INVALID_HID, "MPI_Init_thread failed", mpi_code); @@ -467,6 +461,10 @@ H5Pset_fapl_subfiling(hid_t fapl_id, const H5FD_subfiling_config_t *vfd_config) /*NO TRACE*/ + /* Ensure Subfiling (and therefore MPI) is initialized before doing anything */ + if (H5FD_subfiling_init() < 0) + H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize subfiling VFD"); + if (NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS))) H5_SUBFILING_GOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list"); @@ -913,6 +911,10 @@ H5FD__subfiling_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t ma } HDmemcpy(&file_ptr->fa, config_ptr, sizeof(H5FD_subfiling_config_t)); + if (H5FD__copy_plist(config_ptr->ioc_fapl_id, &(file_ptr->fa.ioc_fapl_id)) < 0) { + file_ptr->fa.ioc_fapl_id = H5I_INVALID_HID; + H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't copy FAPL"); + } if (NULL != (file_ptr->file_path = HDrealpath(name, NULL))) { char *path = NULL; @@ -939,9 +941,6 @@ H5FD__subfiling_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t ma H5_SUBFILING_SYS_GOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "can't resolve subfile path"); } - if (H5FD__copy_plist(config_ptr->ioc_fapl_id, &(file_ptr->fa.ioc_fapl_id)) < 0) - H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't copy FAPL"); - file_ptr->sf_file = H5FD_open(name, flags, file_ptr->fa.ioc_fapl_id, HADDR_UNDEF); if (!file_ptr->sf_file) H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL, "unable to open IOC file"); @@ -1011,6 +1010,10 @@ H5FD__subfiling_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t ma ret_value = (H5FD_t *)file_ptr; done: + if (config_ptr == &default_config) + if (H5I_dec_ref(config_ptr->ioc_fapl_id) < 0) + H5_SUBFILING_DONE_ERROR(H5E_PLIST, H5E_CANTCLOSEOBJ, NULL, "can't close IOC FAPL"); + if (NULL == ret_value) { if (file_ptr) { /* Participate in possible MPI collectives on failure */ @@ -2389,6 +2392,10 @@ H5FD__subfiling_del(const char *name, hid_t fapl) H5_SUBFILING_GOTO_ERROR(H5E_FILE, H5E_CANTDELETE, FAIL, "unable to delete file"); done: + if (subfiling_config == &default_config) + if (H5I_dec_ref(subfiling_config->ioc_fapl_id) < 0) + H5_SUBFILING_DONE_ERROR(H5E_PLIST, H5E_CANTCLOSEOBJ, FAIL, "unable to close IOC FAPL"); + H5_SUBFILING_FUNC_LEAVE_API; } diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index e0de100..ca21ccd 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -873,6 +873,12 @@ h5tools_get_vfd_name(hid_t fapl_id, char *drivername, size_t drivername_size) else if (driver_id == H5FD_HDFS) driver_name = drivernames[HDFS_VFD_IDX]; #endif +#ifdef H5_HAVE_SUBFILING_VFD + else if (driver_id == H5FD_SUBFILING) + driver_name = drivernames[SUBFILING_VFD_IDX]; +#endif + else if (driver_id == H5FD_ONION) + driver_name = drivernames[ONION_VFD_IDX]; else driver_name = "unknown"; @@ -1016,8 +1022,13 @@ h5tools_fopen(const char *fname, unsigned flags, hid_t fapl_id, hbool_t use_spec continue; /* Can we open the file with this combo? */ - if ((fid = h5tools_fopen(fname, flags, tmp_fapl_id, TRUE, drivername, drivername_size)) >= - 0) { + H5E_BEGIN_TRY + { + fid = h5tools_fopen(fname, flags, tmp_fapl_id, TRUE, drivername, drivername_size); + } + H5E_END_TRY; + + if (fid >= 0) { used_fapl_id = tmp_fapl_id; H5TOOLS_GOTO_DONE(fid); } -- cgit v0.12