summaryrefslogtreecommitdiffstats
path: root/src/H5Lexternal.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2018-03-15 21:54:30 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2018-03-15 21:54:30 (GMT)
commit4a17aff4085ad6ee265b95730aca3f493056dec8 (patch)
tree8bfb665c6d95a2e3520fa1bb0ff54d95aff3923f /src/H5Lexternal.c
parent853ae26333592faf69cd8c454ef92ffea8549df5 (diff)
downloadhdf5-4a17aff4085ad6ee265b95730aca3f493056dec8.zip
hdf5-4a17aff4085ad6ee265b95730aca3f493056dec8.tar.gz
hdf5-4a17aff4085ad6ee265b95730aca3f493056dec8.tar.bz2
Add API context interface and use it throughout the library.
Diffstat (limited to 'src/H5Lexternal.c')
-rw-r--r--src/H5Lexternal.c132
1 files changed, 61 insertions, 71 deletions
diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c
index b4a173f..6c132ab 100644
--- a/src/H5Lexternal.c
+++ b/src/H5Lexternal.c
@@ -24,6 +24,7 @@
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5ACprivate.h" /* Metadata cache */
+#include "H5CXprivate.h" /* API Contexts */
#include "H5Eprivate.h" /* Error handling */
#include "H5Gpkg.h" /* Groups */
#include "H5Iprivate.h" /* IDs */
@@ -55,10 +56,12 @@
/********************/
/* Local Prototypes */
/********************/
-
-static hid_t H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
- const void *udata, size_t H5_ATTR_UNUSED udata_size, hid_t lapl_id);
-static ssize_t H5L_extern_query(const char H5_ATTR_UNUSED * link_name, const void *udata,
+static char *H5L__getenv_prefix_name(char **env_prefix/*in,out*/);
+static herr_t H5L__build_name(const char *prefix, const char *file_name,
+ char **full_name/*out*/);
+static hid_t H5L__extern_traverse(const char *link_name, hid_t cur_group,
+ const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id);
+static ssize_t H5L__extern_query(const char *link_name, const void *udata,
size_t udata_size, void * buf /*out*/, size_t buf_size);
@@ -84,15 +87,15 @@ static const H5L_class_t H5L_EXTERN_LINK_CLASS[1] = {{
NULL, /* Creation callback */
NULL, /* Move callback */
NULL, /* Copy callback */
- H5L_extern_traverse, /* The actual traversal function */
+ H5L__extern_traverse, /* The actual traversal function */
NULL, /* Deletion callback */
- H5L_extern_query /* Query callback */
+ H5L__extern_query /* Query callback */
}};
/*--------------------------------------------------------------------------
- * Function: H5L_getenv_prefix_name --
+ * Function: H5L__getenv_prefix_name
*
* Purpose: Get the first pathname in the list of pathnames stored in ENV_PREFIX,
* which is separated by the environment delimiter.
@@ -105,29 +108,30 @@ static const H5L_class_t H5L_EXTERN_LINK_CLASS[1] = {{
*
--------------------------------------------------------------------------*/
static char *
-H5L_getenv_prefix_name(char **env_prefix/*in,out*/)
+H5L__getenv_prefix_name(char **env_prefix/*in,out*/)
{
- char *retptr=NULL;
- char *strret=NULL;
+ char *retptr = NULL;
+ char *strret = NULL;
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
strret = HDstrchr(*env_prefix, H5_COLON_SEPC);
- if (strret == NULL) {
+ if(strret == NULL) {
retptr = *env_prefix;
*env_prefix = strret;
- } else {
+ } /* end if */
+ else {
retptr = *env_prefix;
*env_prefix = strret + 1;
*strret = '\0';
- }
+ } /* end else */
FUNC_LEAVE_NOAPI(retptr)
-} /* end H5L_getenv_prefix_name() */
+} /* end H5L__getenv_prefix_name() */
/*--------------------------------------------------------------------------
- * Function: H5L_build_name
+ * Function: H5L__build_name
*
* Purpose: Prepend PREFIX to FILE_NAME and store in FULL_NAME
*
@@ -137,13 +141,13 @@ H5L_getenv_prefix_name(char **env_prefix/*in,out*/)
*
--------------------------------------------------------------------------*/
static herr_t
-H5L_build_name(char *prefix, char *file_name, char **full_name/*out*/)
+H5L__build_name(const char *prefix, const 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
+ FUNC_ENTER_STATIC
prefix_len = HDstrlen(prefix);
fname_len = HDstrlen(file_name);
@@ -158,11 +162,11 @@ H5L_build_name(char *prefix, char *file_name, char **full_name/*out*/)
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* H5L_build_name() */
+} /* H5L__build_name() */
/*-------------------------------------------------------------------------
- * Function: H5L_extern_traverse
+ * Function: H5L__extern_traverse
*
* Purpose: Default traversal function for external links. This can
* be overridden using H5Lregister().
@@ -177,27 +181,13 @@ done:
*
* Programmer: James Laird
* Monday, July 10, 2006
- * Modifications:
- * Vailin Choi, April 2, 2008
- * Add handling to search for the target file
- * See description in RM: H5Lcreate_external
- *
- * Vailin Choi; Sept. 12th, 2008; bug #1247
- * Retrieve the file access property list identifer that is set
- * for link access property via H5Pget_elink_fapl().
- * If the return value is H5P_DEFAULT, the parent's file access
- * property is used to H5F_open() the target file;
- * Otherwise, the file access property retrieved from H5Pget_elink_fapl()
- * is used to H5F_open() the target file.
- *
- * Vailin Choi; Nov 2010
- * Free memory pointed to by tmp_env_prefix for HDF5_EXT_PREFIX case.
*
*-------------------------------------------------------------------------
*/
static hid_t
-H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
- const void *_udata, size_t H5_ATTR_UNUSED udata_size, hid_t lapl_id)
+H5L__extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
+ const void *_udata, size_t H5_ATTR_UNUSED udata_size, hid_t lapl_id,
+ hid_t H5_ATTR_UNUSED dxpl_id)
{
H5P_genplist_t *plist; /* Property list pointer */
char *my_prefix; /* Library's copy of the prefix */
@@ -220,10 +210,9 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
char *actual_file_name = NULL; /* Parent file's actual name */
H5P_genplist_t *fa_plist; /* File access property list pointer */
H5F_close_degree_t fc_degree = H5F_CLOSE_WEAK; /* File close degree for target file */
- hid_t dxpl_id = H5AC_ind_read_dxpl_id; /* dxpl used by library */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
- FUNC_ENTER_NOAPI(FAIL)
+ FUNC_ENTER_STATIC
/* Sanity checks */
HDassert(p);
@@ -244,10 +233,6 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
if(NULL == (plist = H5P_object_verify(lapl_id, H5P_LINK_ACCESS)))
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
- /* Verify access property list and get correct dxpl */
- if(H5P_verify_apl_and_dxpl(&lapl_id, H5P_CLS_LACC, &dxpl_id, cur_group, FALSE) < 0)
- HGOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set access and transfer property lists")
-
/* Get the fapl_id set for lapl_id if any */
if(H5P_get(plist, H5L_ACS_ELINK_FAPL_NAME, &fapl_id) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fapl for links")
@@ -285,7 +270,7 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
parent_file_name = H5F_OPEN_NAME(loc.oloc->file);
/* Query length of parent group name */
- if((group_name_len = H5G_get_name(&loc, NULL, (size_t) 0, NULL, lapl_id, dxpl_id)) < 0)
+ if((group_name_len = H5G_get_name(&loc, NULL, (size_t) 0, NULL)) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "unable to retrieve length of group name")
/* Account for null terminator */
@@ -300,7 +285,7 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
parent_group_name = local_group_name;
/* Get parent group name */
- if(H5G_get_name(&loc, parent_group_name, (size_t) group_name_len, NULL, lapl_id, dxpl_id) < 0)
+ if(H5G_get_name(&loc, parent_group_name, (size_t) group_name_len, NULL) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "unable to retrieve group name")
/* Make callback */
@@ -331,7 +316,7 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
/* 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 == (ext_file = H5F_efc_open(loc.oloc->file, file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id))) {
+ if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id))) {
char *ptr;
H5E_clear_stack(NULL);
@@ -350,7 +335,7 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
} /* end if */
else if(H5_CHECK_ABS_DRIVE(file_name)) {
/* Try opening file */
- if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id))) {
+ if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id))) {
H5E_clear_stack(NULL);
@@ -373,14 +358,14 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
while((tmp_env_prefix) && (*tmp_env_prefix)) {
char *out_prefix_name;
- out_prefix_name = H5L_getenv_prefix_name(&tmp_env_prefix/*in,out*/);
+ out_prefix_name = H5L__getenv_prefix_name(&tmp_env_prefix/*in,out*/);
if(out_prefix_name && (*out_prefix_name)) {
- if(H5L_build_name(out_prefix_name, temp_file_name, &full_name/*out*/) < 0) {
+ if(H5L__build_name(out_prefix_name, temp_file_name, &full_name/*out*/) < 0) {
saved_env = (char *)H5MM_xfree(saved_env);
HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
} /* end if */
- ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id);
+ ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id);
full_name = (char *)H5MM_xfree(full_name);
if(ext_file != NULL)
break;
@@ -396,9 +381,9 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
if(H5P_peek(plist, H5L_ACS_ELINK_PREFIX_NAME, &my_prefix) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get external link prefix")
if(my_prefix) {
- if(H5L_build_name(my_prefix, temp_file_name, &full_name/*out*/) < 0)
+ if(H5L__build_name(my_prefix, temp_file_name, &full_name/*out*/) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
- if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
+ if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id)))
H5E_clear_stack(NULL);
full_name = (char *)H5MM_xfree(full_name);
} /* end if */
@@ -409,9 +394,9 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
char *extpath;
if(NULL != (extpath = H5F_EXTPATH(loc.oloc->file))) {
- if(H5L_build_name(extpath, temp_file_name, &full_name/*out*/) < 0)
+ if(H5L__build_name(extpath, temp_file_name, &full_name/*out*/) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
- if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
+ if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id)))
H5E_clear_stack(NULL);
full_name = (char *)H5MM_xfree(full_name);
} /* end if */
@@ -419,7 +404,7 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
/* try the relative file_name stored in temp_file_name */
if(ext_file == NULL) {
- if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, temp_file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
+ if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, temp_file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id)))
H5E_clear_stack(NULL);
} /* end if */
@@ -442,23 +427,22 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
*ptr = '\0';
/* Build new file name for the external file */
- if(H5L_build_name(actual_file_name, temp_file_name, &full_name/*out*/) < 0)
+ if(H5L__build_name(actual_file_name, temp_file_name, &full_name/*out*/) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
/* Try opening with the resolved name */
- if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
+ if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id)))
HGOTO_ERROR(H5E_LINK, H5E_CANTOPENFILE, FAIL, "unable to open external file, external link file name = '%s', temp_file_name = '%s'", file_name, temp_file_name)
full_name = (char *)H5MM_xfree(full_name);
} /* end if */
-
/* Retrieve the "group location" for the file's root group */
if(H5G_root_loc(ext_file, &root_loc) < 0)
- HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "unable to create location for file")
+ HGOTO_ERROR(H5E_LINK, H5E_BADVALUE, FAIL, "unable to create location for file")
/* Open the object referenced in the external file */
- if((ext_obj = H5O_open_name(&root_loc, obj_name, lapl_id, dxpl_id, FALSE)) < 0)
- HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open object")
+ if((ext_obj = H5O_open_name(&root_loc, obj_name, FALSE)) < 0)
+ HGOTO_ERROR(H5E_LINK, H5E_CANTOPENOBJ, FAIL, "unable to open object")
/* Set return value */
ret_value = ext_obj;
@@ -482,11 +466,11 @@ done:
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5L_extern_traverse() */
+} /* end H5L__extern_traverse() */
/*-------------------------------------------------------------------------
- * Function: H5L_extern_query
+ * Function: H5L__extern_query
*
* Purpose: Default query function for external links. This can
* be overridden using H5Lregister().
@@ -503,7 +487,7 @@ done:
*-------------------------------------------------------------------------
*/
static ssize_t
-H5L_extern_query(const char H5_ATTR_UNUSED * link_name, const void *_udata, size_t udata_size,
+H5L__extern_query(const char H5_ATTR_UNUSED * link_name, const void *_udata, size_t udata_size,
void *buf /*out*/, size_t buf_size)
{
const uint8_t *udata = (const uint8_t *)_udata; /* Pointer to external link buffer */
@@ -532,7 +516,7 @@ H5L_extern_query(const char H5_ATTR_UNUSED * link_name, const void *_udata, size
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5L_extern_query() */
+} /* end H5L__extern_query() */
/*-------------------------------------------------------------------------
@@ -566,7 +550,7 @@ H5Lcreate_external(const char *file_name, const char *obj_name,
size_t file_name_len; /* Length of file name string */
size_t norm_obj_name_len; /* Length of normalized object name string */
uint8_t *p; /* Pointer into external link buffer */
- hid_t dxpl_id = H5AC_ind_read_dxpl_id; /* dxpl used by library */
+hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
@@ -585,7 +569,7 @@ H5Lcreate_external(const char *file_name, const char *obj_name,
/* Get normalized copy of the link target */
if(NULL == (norm_obj_name = H5G_normalize(obj_name)))
- HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "can't normalize object name")
+ HGOTO_ERROR(H5E_LINK, H5E_BADVALUE, FAIL, "can't normalize object name")
/* Combine the filename and link name into a single buffer to give to the UD link */
file_name_len = HDstrlen(file_name) + 1;
@@ -601,18 +585,24 @@ H5Lcreate_external(const char *file_name, const char *obj_name,
p += file_name_len;
HDstrncpy((char *)p, norm_obj_name, buf_size - (file_name_len + 1)); /* External link's object */
- /* Verify access property list and get correct dxpl */
- if(H5P_verify_apl_and_dxpl(&lapl_id, H5P_CLS_LACC, &dxpl_id, link_loc_id, TRUE) < 0)
- HGOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set access and transfer property lists")
+/* Set API context */
+if(H5CX_push() < 0)
+ HGOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set API context")
+api_ctx_pushed = TRUE;
+/* Verify access property list and set up collective metadata if appropriate */
+if(H5CX_set_apl(&lapl_id, H5P_CLS_LACC, link_loc_id, TRUE) < 0)
+ HGOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set access property list info")
/* Create an external link */
- if(H5L_create_ud(&link_loc, link_name, ext_link_buf, buf_size, H5L_TYPE_EXTERNAL, lcpl_id, lapl_id, dxpl_id) < 0)
+ if(H5L__create_ud(&link_loc, link_name, ext_link_buf, buf_size, H5L_TYPE_EXTERNAL, lcpl_id) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link")
done:
H5MM_xfree(ext_link_buf);
H5MM_xfree(norm_obj_name);
+if(api_ctx_pushed && H5CX_pop() < 0)
+ HDONE_ERROR(H5E_LINK, H5E_CANTRESET, FAIL, "can't reset API context")
FUNC_LEAVE_API(ret_value)
} /* end H5Lcreate_external() */