summaryrefslogtreecommitdiffstats
path: root/src/H5Dvirtual.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2018-01-05 17:45:44 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2018-01-05 17:45:44 (GMT)
commit2a1a2c59937657cf318232e6bfde456cbd297ef1 (patch)
tree1369ec6ada8ef50855d808a74695f612d6492472 /src/H5Dvirtual.c
parentdb918c06b549ef8dc8d106d69da277bcf8d0aa11 (diff)
downloadhdf5-2a1a2c59937657cf318232e6bfde456cbd297ef1.zip
hdf5-2a1a2c59937657cf318232e6bfde456cbd297ef1.tar.gz
hdf5-2a1a2c59937657cf318232e6bfde456cbd297ef1.tar.bz2
HDDFV-10361 combine duplicated prefix utility functions
Diffstat (limited to 'src/H5Dvirtual.c')
-rw-r--r--src/H5Dvirtual.c319
1 files changed, 35 insertions, 284 deletions
diff --git a/src/H5Dvirtual.c b/src/H5Dvirtual.c
index 306fe62..9e1ebe8 100644
--- a/src/H5Dvirtual.c
+++ b/src/H5Dvirtual.c
@@ -147,7 +147,7 @@ H5FL_DEFINE(H5O_storage_virtual_name_seg_t);
H5FL_DEFINE_STATIC(H5D_virtual_held_file_t);
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_check_mapping_pre
*
@@ -217,7 +217,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_check_mapping_pre() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_check_mapping_post
*
@@ -285,7 +285,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_check_mapping_post() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_update_min_dims
*
@@ -344,7 +344,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_update_min_dims() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_check_min_dims
*
@@ -389,7 +389,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_check_min_dims() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_copy_layout
*
@@ -553,7 +553,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_copy_layout() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_reset_layout
*
@@ -637,7 +637,7 @@ H5D__virtual_reset_layout(H5O_layout_t *layout)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_reset_layout() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_copy
*
@@ -683,7 +683,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_copy() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_delete
*
@@ -733,255 +733,6 @@ done:
} /* end H5D__virtual_delete */
-/*--------------------------------------------------------------------------
- * Function: H5D__virtual_build_name
- *
- * Purpose: Prepend PREFIX to FILE_NAME and store in FULL_NAME
- *
- * Return: Non-negative on success/Negative on failure
- *--------------------------------------------------------------------------*/
-static herr_t
-H5D__virtual_build_name(char *prefix, char *file_name, char **full_name/*out*/)
-{
- size_t prefix_len; /* length of prefix */
- size_t fname_len; /* Length of external link file name */
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI_NOINIT
-
- prefix_len = HDstrlen(prefix);
- fname_len = HDstrlen(file_name);
-
- /* Allocate a buffer to hold the filename + prefix + possibly the delimiter + terminating null byte */
- if(NULL == (*full_name = (char *)H5MM_malloc(prefix_len + fname_len + 2)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate filename buffer")
-
- /* Compose the full file name */
- HDsnprintf(*full_name, (prefix_len + fname_len + 2), "%s%s%s", prefix,
- (H5_CHECK_DELIMITER(prefix[prefix_len - 1]) ? "" : H5_DIR_SEPS), file_name);
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* H5D__virtual_build_name() */
-
-
-/*--------------------------------------------------------------------------
- * Function: H5D_getenv_prefix_name --
- *
- * Purpose: Get the first pathname in the list of pathnames stored in env_prefix,
- * which is separated by the environment delimiter.
- * env_prefix is modified to point to the remaining pathnames
- * in the list.
- *
- * Return: A pointer to a pathname
---------------------------------------------------------------------------*/
-static char *
-H5D_getenv_prefix_name(char **env_prefix/*in,out*/)
-{
- char *retptr=NULL;
- char *strret=NULL;
-
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- strret = HDstrchr(*env_prefix, H5_COLON_SEPC);
- if (strret == NULL) {
- retptr = *env_prefix;
- *env_prefix = strret;
- } else {
- retptr = *env_prefix;
- *env_prefix = strret + 1;
- *strret = '\0';
- }
-
- FUNC_LEAVE_NOAPI(retptr)
-} /* end H5D_getenv_prefix_name() */
-
-/*-------------------------------------------------------------------------
- * Function: H5D__virtual_open_file
- *
- * Purpose: Attempts to open a source dataset file.
- *
- * Return: Non-negative on success/Negative on failure
- *-------------------------------------------------------------------------
- */
-static H5F_t *
-H5D__virtual_open_file(hid_t plist_id, const H5F_t *vdset_file,
- const char *file_name,
- hid_t fapl_id, hid_t dxpl_id)
-{
- H5F_t *src_file = NULL; /* Source file */
- H5F_t *ret_value = NULL; /* Actual return value */
- char *full_name = NULL; /* File name with prefix */
- char *my_prefix = NULL; /* Library's copy of the prefix */
- unsigned intent; /* File access permissions */
- char *actual_file_name = NULL; /* Virtual file's actual name */
- char *temp_file_name = NULL; /* Temporary pointer to file name */
- size_t temp_file_name_len; /* Length of temporary file name */
-
- FUNC_ENTER_STATIC
-
- /* Simplify intent flags for open calls */
- intent = H5F_INTENT(vdset_file);
- intent &= (H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE | H5F_ACC_SWMR_READ);
-
- /* Copy the file name to use */
- if(NULL == (temp_file_name = H5MM_strdup(file_name)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
- temp_file_name_len = HDstrlen(temp_file_name);
-
- /* target file_name is an absolute pathname: see RM for detailed description */
- if(H5_CHECK_ABSOLUTE(file_name) || H5_CHECK_ABS_PATH(file_name)) {
- /* Try opening file */
- if(NULL == (src_file = H5F_open(file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id))) {
- char *ptr;
-
- H5E_clear_stack(NULL);
-
- /* get last component of file_name */
- H5_GET_LAST_DELIMITER(file_name, ptr)
- HDassert(ptr);
-
- /* Increment past delimiter */
- ptr++;
-
- /* Copy into the temp. file name */
- HDstrncpy(temp_file_name, ptr, temp_file_name_len);
- temp_file_name[temp_file_name_len - 1] = '\0';
- } /* end if */
- } /* end if */
- else if(H5_CHECK_ABS_DRIVE(file_name)) {
- /* Try opening file */
- if(NULL == (src_file = H5F_open(file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id))) {
-
- H5E_clear_stack(NULL);
-
- /* strip "<drive-letter>:" */
- HDstrncpy(temp_file_name, &file_name[2], temp_file_name_len);
- temp_file_name[temp_file_name_len - 1] = '\0';
- } /* end if */
- } /* end if */
-
- /* try searching from paths set in the environment variable */
- if(src_file == NULL) {
- char *env_prefix;
-
- if(NULL != (env_prefix = HDgetenv("HDF5_VDS_PREFIX"))) {
- char *tmp_env_prefix, *saved_env;
-
- if(NULL == (saved_env = tmp_env_prefix = H5MM_strdup(env_prefix)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
-
- while((tmp_env_prefix) && (*tmp_env_prefix)) {
- char *out_prefix_name;
-
- out_prefix_name = H5D_getenv_prefix_name(&tmp_env_prefix/*in,out*/);
- if(out_prefix_name && (*out_prefix_name)) {
- if(H5D__virtual_build_name(out_prefix_name, temp_file_name, &full_name/*out*/) < 0) {
- saved_env = (char *)H5MM_xfree(saved_env);
- HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, NULL, "can't prepend prefix to filename")
- } /* end if */
-
- src_file = H5F_open(full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id);
- full_name = (char *)H5MM_xfree(full_name);
- if(src_file != NULL)
- break;
- H5E_clear_stack(NULL);
- } /* end if */
- } /* end while */
- saved_env = (char *)H5MM_xfree(saved_env);
- } /* end if */
- } /* end if */
-
- /* try searching from property list */
- if(src_file == NULL) {
- size_t size = 0;
- H5E_BEGIN_TRY {
- size = H5Pget_virtual_prefix(plist_id, NULL, 0);
- } H5E_END_TRY;
- if(size <= 0)
- my_prefix = NULL;
- else {
- /* Allocate a buffer to hold the filename + prefix + possibly the delimiter + terminating null byte */
- if(NULL == (my_prefix = (char *)H5MM_malloc(size + 1)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate prefix buffer")
- if(H5Pget_virtual_prefix(plist_id, my_prefix, size+1) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get vds prefix")
- if(my_prefix) {
- if(H5D__virtual_build_name(my_prefix, temp_file_name, &full_name/*out*/) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, NULL, "can't prepend prefix to filename")
- my_prefix = (char *)H5MM_xfree(my_prefix);
- if(NULL == (src_file = H5F_open(full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- H5E_clear_stack(NULL);
- full_name = (char *)H5MM_xfree(full_name);
- }
- } /* end if */
- } /* end if */
-
- /* try searching from main file's "extpath": see description in H5F_open() & H5_build_extpath() */
- if(src_file == NULL) {
- char *vdspath;
-
- if(NULL != (vdspath = H5F_EXTPATH(vdset_file))) {
- if(H5D__virtual_build_name(vdspath, temp_file_name, &full_name/*out*/) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, NULL, "can't prepend prefix to filename")
- if(NULL == (src_file = H5F_open(full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- H5E_clear_stack(NULL);
- full_name = (char *)H5MM_xfree(full_name);
- } /* end if */
- } /* end if */
-
- /* try the relative file_name stored in temp_file_name */
- if(src_file == NULL) {
- if(NULL == (src_file = H5F_open(temp_file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- H5E_clear_stack(NULL);
- } /* end if */
-
- /* try the 'resolved' name for the virtual file */
- if(src_file == NULL) {
- char *ptr = NULL;
-
- /* Copy resolved file name */
- if(NULL == (actual_file_name = H5MM_strdup(H5F_ACTUAL_NAME(vdset_file))))
- HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, NULL, "can't duplicate resolved file name string")
-
- /* get last component of file_name */
- H5_GET_LAST_DELIMITER(actual_file_name, ptr)
- if(!ptr)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENFILE, NULL, "unable to open vds file, vds file name = '%s', temp_file_name = '%s'", file_name, temp_file_name)
-
- /* Truncate filename portion from actual file name path */
- *ptr = '\0';
-
- /* Build new file name for the external file */
- if(H5D__virtual_build_name(actual_file_name, temp_file_name, &full_name/*out*/) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, NULL, "can't prepend prefix to filename")
- actual_file_name = (char *)H5MM_xfree(actual_file_name);
-
- /* Try opening with the resolved name */
- if(NULL == (src_file = H5F_open(full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENFILE, NULL, "unable to open vds file, vds file name = '%s', temp_file_name = '%s'", file_name, temp_file_name)
- full_name = (char *)H5MM_xfree(full_name);
- } /* end if */
-
- /* Success */
- ret_value = src_file;
-done:
- if((NULL == ret_value) && src_file)
- if(H5F_try_close(src_file, NULL) < 0)
- HDONE_ERROR(H5E_DATASET, H5E_CANTCLOSEFILE, NULL, "can't close source file")
- if(my_prefix)
- my_prefix = (char *)H5MM_xfree(my_prefix);
- if(full_name)
- full_name = (char *)H5MM_xfree(full_name);
- if(temp_file_name)
- temp_file_name = (char *)H5MM_xfree(temp_file_name);
- if(actual_file_name)
- actual_file_name = (char *)H5MM_xfree(actual_file_name);
-
- FUNC_LEAVE_NOAPI(ret_value)
-} /* H5D__virtual_open_file() */
-
-
/*-------------------------------------------------------------------------
* Function: H5D__virtual_open_source_dset
*
@@ -1000,13 +751,11 @@ H5D__virtual_open_source_dset(const H5D_t *vdset,
H5O_storage_virtual_srcdset_t *source_dset, hid_t dxpl_id)
{
H5F_t *src_file = NULL; /* Source file */
- char *vds_prefix = NULL; /* Source file vds_prefix */
hbool_t src_file_open = FALSE; /* Whether we have opened and need to close src_file */
H5G_loc_t src_root_loc; /* Object location of source file root group */
herr_t ret_value = SUCCEED; /* Return value */
- char *full_name = NULL; /* File name with prefix */
- unsigned intent; /* File access permissions */
hid_t plist_id = -1; /* Property list pointer */
+ unsigned intent; /* File access permissions */
FUNC_ENTER_STATIC
@@ -1019,9 +768,11 @@ H5D__virtual_open_source_dset(const H5D_t *vdset,
/* Check if we need to open the source file */
if(HDstrcmp(source_dset->file_name, ".")) {
- if((plist_id = H5D_get_access_plist(vdset)) < 0)
+ if((plist_id = H5D_get_access_plist((H5D_t *)vdset)) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "Can't get access plist")
- if(NULL == (src_file = H5D__virtual_open_file(plist_id, vdset->oloc.file, source_dset->file_name, vdset->shared->layout.storage.u.virt.source_fapl, dxpl_id)))
+ intent = H5F_INTENT(vdset->oloc.file);
+ if(NULL == (src_file = H5F_prefix_open_file(plist_id, vdset->oloc.file, H5D_ACS_VDS_PREFIX_NAME, source_dset->file_name, intent,
+ vdset->shared->layout.storage.u.virt.source_fapl, dxpl_id)))
H5E_clear_stack(NULL); /* Quick hack until proper support for H5Fopen with missing file is implemented */
else
src_file_open = TRUE;
@@ -1062,13 +813,13 @@ done:
H5Pclose(plist_id);
/* Close source file */
if(src_file_open)
- if(H5F_try_close(src_file, NULL) < 0)
+ if(H5F_efc_close(vdset->oloc.file, src_file) < 0)
HDONE_ERROR(H5E_DATASET, H5E_CANTCLOSEFILE, FAIL, "can't close source file")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_open_source_dset() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_reset_source_dset
*
@@ -1155,7 +906,7 @@ H5D__virtual_reset_source_dset(H5O_storage_virtual_ent_t *virtual_ent,
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_reset_source_dset() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_str_append
*
@@ -1231,7 +982,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5D__virtual_str_append() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_parse_source_name
*
@@ -1347,7 +1098,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_parse_source_name() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_copy_parsed_name
*
@@ -1404,7 +1155,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_copy_parsed_name() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_free_parsed_name
*
@@ -1437,7 +1188,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_free_parsed_name() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_build_source_name
*
@@ -1539,7 +1290,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_build_source_name() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_set_extent_unlim
*
@@ -1967,7 +1718,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_set_extent_unlim() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_init_all
*
@@ -2191,7 +1942,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_init_all() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_init
*
@@ -2286,7 +2037,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_init() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_is_space_alloc
*
@@ -2318,7 +2069,7 @@ H5D__virtual_is_space_alloc(const H5O_storage_t H5_ATTR_UNUSED *storage)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_is_space_alloc() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_pre_io
*
@@ -2559,7 +2310,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_pre_io() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_post_io
*
@@ -2609,7 +2360,7 @@ H5D__virtual_post_io(H5O_storage_virtual_t *storage)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_post_io() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_read_one
*
@@ -2666,7 +2417,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_read_one() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_read
*
@@ -2799,7 +2550,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_read() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_write_one
*
@@ -2858,7 +2609,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_write_one() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_write
*
@@ -2935,7 +2686,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_write() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_flush
*
@@ -2983,7 +2734,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_flush() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_hold_source_dset_files
*
@@ -3061,7 +2812,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_hold_source_dset_files() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_refresh_source_dset
*
@@ -3101,7 +2852,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_refresh_source_dsets() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_refresh_source_dsets
*
@@ -3154,7 +2905,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_refresh_source_dsets() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_release_source_dset_files
*