summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib/h5tools_utils.c')
-rw-r--r--tools/lib/h5tools_utils.c320
1 files changed, 141 insertions, 179 deletions
diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c
index b733106..cc9270b 100644
--- a/tools/lib/h5tools_utils.c
+++ b/tools/lib/h5tools_utils.c
@@ -388,8 +388,6 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
* Programmer: Jacob Smith
* 2017-11-10
*
- * Changes: None.
- *
*****************************************************************************
*/
herr_t
@@ -721,7 +719,7 @@ find_objs_cb(const char *name, const H5O_info_t *oinfo, const char *already_seen
case H5O_TYPE_DATASET:
if(NULL == already_seen) {
- hid_t dset = -1;
+ hid_t dset = H5I_INVALID_HID;
/* Add the dataset to the list of objects */
add_obj(info->dset_table, oinfo->addr, name, TRUE);
@@ -802,7 +800,7 @@ init_objs(hid_t fid, find_objs_t *info, table_t **group_table,
/* Find all shared objects */
if((ret_value = h5trav_visit(fid, "/", TRUE, TRUE, find_objs_cb, NULL, info, H5O_INFO_BASIC)) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "finding shared objects failed")
+ H5TOOLS_GOTO_ERROR(FAIL, "finding shared objects failed");
done:
/* Release resources */
@@ -903,39 +901,39 @@ H5tools_get_symlink_info(hid_t file_id, const char * linkpath, h5tool_link_info_
/* if path is root, return group type */
if(!HDstrcmp(linkpath,"/")) {
link_info->trg_type = H5O_TYPE_GROUP;
- HGOTO_DONE(2);
+ H5TOOLS_GOTO_DONE(2);
}
/* check if link itself exist */
if(H5Lexists(file_id, linkpath, H5P_DEFAULT) <= 0) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: link <%s> doesn't exist \n",linkpath);
- HGOTO_DONE(FAIL);
+ H5TOOLS_GOTO_DONE(FAIL);
} /* end if */
/* get info from link */
if(H5Lget_info(file_id, linkpath, &(link_info->linfo), H5P_DEFAULT) < 0) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: unable to get link info from <%s>\n",linkpath);
- HGOTO_DONE(FAIL);
+ H5TOOLS_GOTO_DONE(FAIL);
} /* end if */
/* given path is hard link (object) */
if(link_info->linfo.type == H5L_TYPE_HARD)
- HGOTO_DONE(2);
+ H5TOOLS_GOTO_DONE(2);
/* trg_path must be freed out of this function when finished using */
if((link_info->trg_path = (char*)HDcalloc(link_info->linfo.u.val_size, sizeof(char))) == NULL) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: unable to allocate buffer for <%s>\n",linkpath);
- HGOTO_DONE(FAIL);
+ H5TOOLS_GOTO_DONE(FAIL);
} /* end if */
/* get link value */
if(H5Lget_val(file_id, linkpath, (void *)link_info->trg_path, link_info->linfo.u.val_size, H5P_DEFAULT) < 0) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: unable to get link value from <%s>\n",linkpath);
- HGOTO_DONE(FAIL);
+ H5TOOLS_GOTO_DONE(FAIL);
} /* end if */
/*-----------------------------------------------------
@@ -944,13 +942,13 @@ H5tools_get_symlink_info(hid_t file_id, const char * linkpath, h5tool_link_info_
*/
if(link_info->linfo.type == H5L_TYPE_EXTERNAL) {
if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
- HGOTO_DONE(FAIL);
+ H5TOOLS_GOTO_DONE(FAIL);
if(H5Pset_fapl_sec2(fapl) < 0)
- HGOTO_DONE(FAIL);
+ H5TOOLS_GOTO_DONE(FAIL);
if((lapl = H5Pcreate(H5P_LINK_ACCESS)) < 0)
- HGOTO_DONE(FAIL);
+ H5TOOLS_GOTO_DONE(FAIL);
if(H5Pset_elink_fapl(lapl, fapl) < 0)
- HGOTO_DONE(FAIL);
+ H5TOOLS_GOTO_DONE(FAIL);
} /* end if */
/* Check for retrieving object info */
@@ -963,24 +961,24 @@ H5tools_get_symlink_info(hid_t file_id, const char * linkpath, h5tool_link_info_
/* detect dangling link */
if(l_ret == FALSE) {
- HGOTO_DONE(0);
+ H5TOOLS_GOTO_DONE(0);
}
else if(l_ret < 0) { /* function failed */
- HGOTO_DONE(FAIL);
+ H5TOOLS_GOTO_DONE(FAIL);
}
/* get target object info */
if(H5Oget_info_by_name2(file_id, linkpath, &trg_oinfo, H5O_INFO_BASIC, lapl) < 0) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: unable to get object information for <%s>\n", linkpath);
- HGOTO_DONE(FAIL);
+ H5TOOLS_GOTO_DONE(FAIL);
} /* end if */
/* check unknown type */
if(trg_oinfo.type < H5O_TYPE_GROUP || trg_oinfo.type >=H5O_TYPE_NTYPES) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: target object of <%s> is unknown type\n", linkpath);
- HGOTO_DONE(FAIL);
+ H5TOOLS_GOTO_DONE(FAIL);
} /* end if */
/* set target obj type to return */
@@ -1048,14 +1046,14 @@ h5tools_getenv_update_hyperslab_bufsize(void)
{
const char *env_str = NULL;
long hyperslab_bufsize_mb;
- int ret_value = 1;
+ int ret_value = 1;
/* check if environment variable is set for the hyperslab buffer size */
if (NULL != (env_str = HDgetenv ("H5TOOLS_BUFSIZE"))) {
errno = 0;
hyperslab_bufsize_mb = HDstrtol(env_str, (char**)NULL, 10);
if (errno != 0 || hyperslab_bufsize_mb <= 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "hyperslab buffer size failed");
+ H5TOOLS_GOTO_ERROR(FAIL, "hyperslab buffer size failed");
/* convert MB to byte */
H5TOOLS_BUFSIZE = (hsize_t)hyperslab_bufsize_mb * 1024 * 1024;
@@ -1067,6 +1065,52 @@ done:
return ret_value;
}
+#ifdef H5_HAVE_ROS3_VFD
+/*----------------------------------------------------------------------------
+ *
+ * Function: h5tools_parse_ros3_fapl_tuple
+ *
+ * Purpose: A convenience function that parses a string containing a tuple
+ * of S3 VFD credential information and then passes the result to
+ * `h5tools_populate_ros3_fapl()` in order to setup a valid
+ * configuration for the S3 VFD.
+ *
+ * Return: SUCCEED/FAIL
+ *
+ *----------------------------------------------------------------------------
+ */
+herr_t
+h5tools_parse_ros3_fapl_tuple(const char *tuple_str, int delim,
+ H5FD_ros3_fapl_t *fapl_config_out)
+{
+ const char *ccred[3];
+ unsigned nelems = 0;
+ char *s3cred_src = NULL;
+ char **s3cred = NULL;
+ herr_t ret_value = SUCCEED;
+
+ /* Attempt to parse S3 credentials tuple */
+ if (parse_tuple(tuple_str, delim, &s3cred_src, &nelems, &s3cred) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "failed to parse S3 VFD info tuple");
+
+ /* Sanity-check tuple count */
+ if (nelems != 3)
+ H5TOOLS_GOTO_ERROR(FAIL, "invalid S3 VFD credentials");
+
+ ccred[0] = (const char *)s3cred[0];
+ ccred[1] = (const char *)s3cred[1];
+ ccred[2] = (const char *)s3cred[2];
+
+ if (h5tools_populate_ros3_fapl(fapl_config_out, ccred) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "failed to populate S3 VFD FAPL config");
+
+done:
+ HDfree(s3cred);
+ HDfree(s3cred_src);
+
+ return ret_value;
+}
+
/*----------------------------------------------------------------------------
*
@@ -1096,7 +1140,7 @@ done:
*
* Return:
*
- * 0 (failure) if...
+ * FAIL if...
* * Read-Only S3 VFD is not enabled.
* * NULL fapl pointer: (NULL, {...} )
* * Warning: In all cases below, fapl will be set as "default"
@@ -1113,7 +1157,7 @@ done:
* * (&fa, {"...", "", "...")
* * Any string would overflow allowed space in fapl definition.
* or
- * 1 (success)
+ * SUCCEED
* * Sets components in fapl_t pointer, copying strings as appropriate.
* * "Default" fapl (valid version, authenticate->False, empty strings)
* * `values` pointer is NULL
@@ -1130,197 +1174,115 @@ done:
*
*----------------------------------------------------------------------------
*/
-#ifdef H5_HAVE_ROS3_VFD
-int
-h5tools_populate_ros3_fapl(H5FD_ros3_fapl_t *fa,
- const char **values)
+herr_t
+h5tools_populate_ros3_fapl(H5FD_ros3_fapl_t *fa, const char **values)
{
- int show_progress = 0; /* set to 1 for debugging */
- int ret_value = 1; /* 1 for success, 0 for failure */
- /* e.g.? if (!populate()) { then failed } */
-
- if (show_progress) {
- HDprintf("called h5tools_populate_ros3_fapl\n");
- }
+ herr_t ret_value = SUCCEED;
- if (fa == NULL) {
- if (show_progress) {
- HDprintf(" ERROR: null pointer to fapl_t\n");
- }
- ret_value = 0;
- goto done;
- }
+ if (fa == NULL)
+ H5TOOLS_GOTO_ERROR(FAIL, "fa cannot be NULL");
- if (show_progress) {
- HDprintf(" preset fapl with default values\n");
- }
fa->version = H5FD_CURR_ROS3_FAPL_T_VERSION;
fa->authenticate = FALSE;
*(fa->aws_region) = '\0';
*(fa->secret_id) = '\0';
*(fa->secret_key) = '\0';
- /* sanity-check supplied values
- */
+ /* Sanity checks */
if (values != NULL) {
- if (values[0] == NULL) {
- if (show_progress) {
- HDprintf(" ERROR: aws_region value cannot be NULL\n");
- }
- ret_value = 0;
- goto done;
- }
- if (values[1] == NULL) {
- if (show_progress) {
- HDprintf(" ERROR: secret_id value cannot be NULL\n");
- }
- ret_value = 0;
- goto done;
- }
- if (values[2] == NULL) {
- if (show_progress) {
- HDprintf(" ERROR: secret_key value cannot be NULL\n");
- }
- ret_value = 0;
- goto done;
- }
+ if (values[0] == NULL || values[1] == NULL || values[2] == NULL)
+ H5TOOLS_GOTO_ERROR(FAIL, "values data cannot be NULL");
/* if region and ID are supplied (key optional), write to fapl...
* fail if value would overflow
*/
- if (*values[0] != '\0' &&
- *values[1] != '\0')
- {
- if (HDstrlen(values[0]) > H5FD_ROS3_MAX_REGION_LEN) {
- if (show_progress) {
- HDprintf(" ERROR: aws_region value too long\n");
- }
- ret_value = 0;
- goto done;
- }
- HDmemcpy(fa->aws_region, values[0],
- (HDstrlen(values[0]) + 1));
- if (show_progress) {
- HDprintf(" aws_region set\n");
- }
+ if (*values[0] != '\0' && *values[1] != '\0') {
+ if (HDstrlen(values[0]) > H5FD_ROS3_MAX_REGION_LEN)
+ H5TOOLS_GOTO_ERROR(FAIL, "can't exceed max region length");
+ HDmemcpy(fa->aws_region, values[0], (HDstrlen(values[0]) + 1));
+ if (HDstrlen(values[1]) > H5FD_ROS3_MAX_SECRET_ID_LEN)
+ H5TOOLS_GOTO_ERROR(FAIL, "can't exceed max secret ID length");
+ HDmemcpy(fa->secret_id, values[1], (HDstrlen(values[1]) + 1));
- if (HDstrlen(values[1]) > H5FD_ROS3_MAX_SECRET_ID_LEN) {
- if (show_progress) {
- HDprintf(" ERROR: secret_id value too long\n");
- }
- ret_value = 0;
- goto done;
- }
- HDmemcpy(fa->secret_id,
- values[1],
- (HDstrlen(values[1]) + 1));
- if (show_progress) {
- HDprintf(" secret_id set\n");
- }
-
- if (HDstrlen(values[2]) > H5FD_ROS3_MAX_SECRET_KEY_LEN) {
- if (show_progress) {
- HDprintf(" ERROR: secret_key value too long\n");
- }
- ret_value = 0;
- goto done;
- }
- HDmemcpy(fa->secret_key,
- values[2],
- (HDstrlen(values[2]) + 1));
- if (show_progress) {
- HDprintf(" secret_key set\n");
- }
+ if (HDstrlen(values[2]) > H5FD_ROS3_MAX_SECRET_KEY_LEN)
+ H5TOOLS_GOTO_ERROR(FAIL, "can't exceed max secret key length");
+ HDmemcpy(fa->secret_key, values[2], (HDstrlen(values[2]) + 1));
fa->authenticate = TRUE;
- if (show_progress) {
- HDprintf(" set to authenticate\n");
- }
-
- } else if (*values[0] != '\0' ||
- *values[1] != '\0' ||
- *values[2] != '\0')
- {
- if (show_progress) {
- HDprintf(
- " ERROR: invalid assortment of empty/non-empty values\n"
- );
- }
- ret_value = 0;
- goto done;
}
- } /* values != NULL */
+ else if (*values[0] != '\0' || *values[1] != '\0' || *values[2] != '\0')
+ H5TOOLS_GOTO_ERROR(FAIL, "all values cannot be empty strings");
+ }
done:
return ret_value;
-
} /* h5tools_populate_ros3_fapl */
#endif /* H5_HAVE_ROS3_VFD */
-
-/*-----------------------------------------------------------------------------
- *
- * Function: h5tools_set_configured_fapl
- *
- * Purpose: prepare fapl_id with the given property list, according to
- * VFD prototype.
+#ifdef H5_HAVE_LIBHDFS
+/*----------------------------------------------------------------------------
*
- * Return: 0 on failure, 1 on success
+ * Function: h5tools_parse_hdfs_fapl_tuple
*
- * Programmer: Jacob Smith
- * 2018-05-21
+ * Purpose: A convenience function that parses a string containing a tuple
+ * of HDFS VFD configuration information.
*
- * Changes: None.
+ * Return: SUCCEED/FAIL
*
- *-----------------------------------------------------------------------------
+ *----------------------------------------------------------------------------
*/
-int
-h5tools_set_configured_fapl(hid_t fapl_id,
- const char vfd_name[],
- void *fapl_t_ptr)
+herr_t
+h5tools_parse_hdfs_fapl_tuple(const char *tuple_str, int delim,
+ H5FD_hdfs_fapl_t *fapl_config_out)
{
- int ret_value = 1;
-
- if (fapl_id < 0) {
- return 0;
+ unsigned long k = 0;
+ unsigned nelems = 0;
+ char *props_src = NULL;
+ char **props = NULL;
+ herr_t ret_value = SUCCEED;
+
+ /* Attempt to parse HDFS configuration tuple */
+ if (parse_tuple(tuple_str, delim, &props_src, &nelems, &props) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "failed to parse HDFS VFD configuration tuple");
+
+ /* Sanity-check tuple count */
+ if (nelems != 5)
+ H5TOOLS_GOTO_ERROR(FAIL, "invalid HDFS VFD configuration");
+
+ /* Populate fapl configuration structure with given properties.
+ * WARNING: No error-checking is done on length of input strings...
+ * Silent overflow is possible, albeit unlikely.
+ */
+ if (HDstrncmp(props[0], "", 1)) {
+ HDstrncpy(fapl_config_out->namenode_name, (const char *)props[0], HDstrlen(props[0]));
}
-
- if (!strcmp("", vfd_name)) {
- goto done;
-
-#ifdef H5_HAVE_ROS3_VFD
- } else if (!strcmp("ros3", vfd_name)) {
- if ((fapl_id == H5P_DEFAULT) ||
- (fapl_t_ptr == NULL) ||
- (FAIL == H5Pset_fapl_ros3(
- fapl_id,
- (H5FD_ros3_fapl_t *)fapl_t_ptr)))
- {
- ret_value = 0;
- goto done;
- }
-#endif /* H5_HAVE_ROS3_VFD */
-
-#ifdef H5_HAVE_LIBHDFS
- } else if (!strcmp("hdfs", vfd_name)) {
- if ((fapl_id == H5P_DEFAULT) ||
- (fapl_t_ptr == NULL) ||
- (FAIL == H5Pset_fapl_hdfs(
- fapl_id,
- (H5FD_hdfs_fapl_t *)fapl_t_ptr)))
- {
- ret_value = 0;
- goto done;
- }
-#endif /* H5_HAVE_LIBHDFS */
-
- } else {
- ret_value = 0; /* unrecognized fapl type "name" */
+ if (HDstrncmp(props[1], "", 1)) {
+ k = strtoul((const char *)props[1], NULL, 0);
+ if (errno == ERANGE)
+ H5TOOLS_GOTO_ERROR(FAIL, "supposed port number wasn't");
+ fapl_config_out->namenode_port = (int32_t)k;
+ }
+ if (HDstrncmp(props[2], "", 1)) {
+ HDstrncpy(fapl_config_out->kerberos_ticket_cache, (const char *)props[2], HDstrlen(props[2]));
+ }
+ if (HDstrncmp(props[3], "", 1)) {
+ HDstrncpy(fapl_config_out->user_name, (const char *)props[3], HDstrlen(props[3]));
+ }
+ if (HDstrncmp(props[4], "", 1)) {
+ k = HDstrtoul((const char *)props[4], NULL, 0);
+ if (errno == ERANGE)
+ H5TOOLS_GOTO_ERROR(FAIL, "supposed buffersize number wasn't");
+ fapl_config_out->stream_buffer_size = (int32_t)k;
}
done:
- return ret_value;
+ if (props)
+ HDfree(props);
+ if (props_src)
+ HDfree(props_src);
-} /* h5tools_set_configured_fapl() */
+ return ret_value;
+}
+#endif /* H5_HAVE_LIBHDFS */