From 171fa10928ec0166e03ec15170753a80532d708e Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Mon, 16 Nov 2020 00:42:02 -0600 Subject: [PATCH] Added selective async APIs to H5M, H5R, and H5T No tests added yet Platforms tested: Linux/64 (jelly) --- src/H5M.c | 490 ++++++++++++++++++++++++++++++++++++++-------- src/H5Mpublic.h | 4 + src/H5R.c | 370 +++++++++++++++++++++++++--------- src/H5Rpublic.h | 3 + src/H5T.c | 178 +++++++++++++++-- src/H5Tcommit.c | 237 +++++++++++++++++----- src/H5Tpublic.h | 7 +- src/H5VLint.c | 93 ++++++--- src/H5VLprivate.h | 17 +- 9 files changed, 1129 insertions(+), 270 deletions(-) diff --git a/src/H5M.c b/src/H5M.c index 98b1a086b83..90c9aa43b28 100644 --- a/src/H5M.c +++ b/src/H5M.c @@ -24,6 +24,7 @@ #include "H5CXprivate.h" /* API Contexts */ #include "H5Mpkg.h" /* Maps */ #include "H5Eprivate.h" /* Error handling */ +#include "H5ESprivate.h" /* Event Sets */ #include "H5Iprivate.h" /* IDs */ #include "H5VLprivate.h" /* Virtual Object Layer */ @@ -39,6 +40,10 @@ /* Local Prototypes */ /********************/ static herr_t H5M__close_cb(H5VL_object_t *map_vol_obj, void **request); +static hid_t H5M__create_api_common(hid_t loc_id, const char *name, hid_t key_type_id, hid_t val_type_id, hid_t lcpl_id, hid_t mcpl_id, hid_t mapl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr); +static hid_t H5M__open_api_common(hid_t loc_id, const char *name, hid_t mapl_id, void **token_ptr, H5VL_object_t ** _vol_obj_ptr); +static herr_t H5M__put_api_common(hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_id, const void *value, hid_t dxpl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr); +static herr_t H5M__get_api_common(hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_id, void *value, hid_t dxpl_id, void **token_ptr, H5VL_object_t ** _vol_obj_ptr); /*********************/ /* Package Variables */ @@ -219,15 +224,9 @@ H5M__close_cb(H5VL_object_t *map_vol_obj, void **request) #ifdef H5_HAVE_MAP_API /*------------------------------------------------------------------------- - * Function: H5Mcreate + * Function: H5M__create_api_common * - * Purpose: Creates a new map object for storing key-value pairs. The - * in-file datatype for keys is defined by KEY_TYPE_ID and - * the in-file datatype for values is defined by VAL_TYPE_ID. - * LOC_ID specifies the location to create the map object and - * NAME specifies the name of the link to the object - * (relative to LOC_ID). Other options can be specified - * through the property lists LCPL_ID, MCPL_ID, and MAPL_ID. + * Purpose: This is the common function for creating the HDF5 map. * * Return: Success: The object ID of the new map. * @@ -235,17 +234,18 @@ H5M__close_cb(H5VL_object_t *map_vol_obj, void **request) * *------------------------------------------------------------------------- */ -hid_t -H5Mcreate(hid_t loc_id, const char *name, hid_t key_type_id, hid_t val_type_id, hid_t lcpl_id, hid_t mcpl_id, - hid_t mapl_id) +static hid_t +H5M__create_api_common(hid_t loc_id, const char *name, hid_t key_type_id, hid_t val_type_id, hid_t lcpl_id, + hid_t mcpl_id, hid_t mapl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr) { - void * map = NULL; /* New map's info */ - H5VL_object_t * vol_obj = NULL; /* object of loc_id */ - H5VL_loc_params_t loc_params; - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + void * map = NULL; /* New map's info */ + H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */ + H5VL_object_t **vol_obj_ptr = + (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ - FUNC_ENTER_API(H5I_INVALID_HID) - H5TRACE7("i", "i*siiiii", loc_id, name, key_type_id, val_type_id, lcpl_id, mcpl_id, mapl_id); + FUNC_ENTER_STATIC /* Check arguments */ if (!name) @@ -265,36 +265,109 @@ H5Mcreate(hid_t loc_id, const char *name, hid_t key_type_id, hid_t val_type_id, else if (TRUE != H5P_isa_class(mcpl_id, H5P_MAP_CREATE)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "mcpl_id is not a map create property list ID") - /* Verify access property list and set up collective metadata if appropriate */ - if (H5CX_set_apl(&mapl_id, H5P_CLS_MACC, loc_id, TRUE) < 0) - HGOTO_ERROR(H5E_MAP, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") - - /* Get the location object */ - if (NULL == (vol_obj = (H5VL_object_t *)H5I_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") - - /* Set location parameters */ - loc_params.type = H5VL_OBJECT_BY_SELF; - loc_params.obj_type = H5I_get_type(loc_id); + /* Set up object access arguments */ + if (H5VL_setup_acc_args(loc_id, H5P_CLS_MACC, TRUE, &mapl_id, vol_obj_ptr, &loc_params) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments") /* Create the map */ - if (H5VL_optional(vol_obj, H5VL_MAP_CREATE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &loc_params, name, + if (H5VL_optional(*vol_obj_ptr, H5VL_MAP_CREATE, H5P_DATASET_XFER_DEFAULT, token_ptr, &loc_params, name, lcpl_id, key_type_id, val_type_id, mcpl_id, mapl_id, &map) < 0) HGOTO_ERROR(H5E_MAP, H5E_CANTINIT, H5I_INVALID_HID, "unable to create map") /* Get an atom for the map */ - if ((ret_value = H5VL_register(H5I_MAP, map, vol_obj->connector, TRUE)) < 0) + if ((ret_value = H5VL_register(H5I_MAP, map, (*vol_obj_ptr)->connector, TRUE)) < 0) HGOTO_ERROR(H5E_MAP, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize map handle") done: /* Cleanup on failure */ if (H5I_INVALID_HID == ret_value) - if (map && H5VL_optional(vol_obj, H5VL_MAP_CLOSE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if (map && H5VL_optional(*vol_obj_ptr, H5VL_MAP_CLOSE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, H5I_INVALID_HID, "unable to release map") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5M__create_api_common() */ + +/*------------------------------------------------------------------------- + * Function: H5Mcreate + * + * Purpose: Creates a new map object for storing key-value pairs. The + * in-file datatype for keys is defined by KEY_TYPE_ID and + * the in-file datatype for values is defined by VAL_TYPE_ID. + * LOC_ID specifies the location to create the map object and + * NAME specifies the name of the link to the object + * (relative to LOC_ID). Other options can be specified + * through the property lists LCPL_ID, MCPL_ID, and MAPL_ID. + * + * Return: Success: The object ID of the new map. + * + * Failure: H5I_INVALID_HID + * + *------------------------------------------------------------------------- + */ +hid_t +H5Mcreate(hid_t loc_id, const char *name, hid_t key_type_id, hid_t val_type_id, hid_t lcpl_id, hid_t mcpl_id, + hid_t mapl_id) +{ + void * map = NULL; /* New map's info */ + H5VL_object_t * vol_obj = NULL; /* object of loc_id */ + H5VL_loc_params_t loc_params; + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE7("i", "i*siiiii", loc_id, name, key_type_id, val_type_id, lcpl_id, mcpl_id, mapl_id); + + /* Create the map synchronously */ + if ((ret_value = H5M__create_api_common(loc_id, name, key_type_id, val_type_id, lcpl_id, mcpl_id, mapl_id, + NULL, NULL)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTCREATE, H5I_INVALID_HID, "unable to synchronously create map") + +done: FUNC_LEAVE_API(ret_value) } /* end H5Mcreate() */ +/*------------------------------------------------------------------------- + * Function: H5Mcreate_async + * + * Purpose: Asynchronous version of H5Mcreate + * + * Return: Success: The object ID of the new map. + * + * Failure: H5I_INVALID_HID + * + *------------------------------------------------------------------------- + */ +hid_t +H5Mcreate_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, + hid_t key_type_id, hid_t val_type_id, hid_t lcpl_id, hid_t mcpl_id, hid_t mapl_id, + hid_t es_id) +{ + void * map = NULL; /* New map's info */ + H5VL_object_t * vol_obj = NULL; /* object of loc_id */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE11("i", "*s*sIui*siiiiii", app_file, app_func, app_line, loc_id, name, key_type_id, val_type_id, + lcpl_id, mcpl_id, mapl_id, es_id); + + /* Set up request token pointer for asynchronous operation */ + if (H5ES_NONE != es_id) + token_ptr = &token; + + /* Create the map asynchronously */ + if ((ret_value = H5M__create_api_common(loc_id, name, key_type_id, val_type_id, lcpl_id, mcpl_id, mapl_id, + token_ptr, &vol_obj)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTCREATE, H5I_INVALID_HID, "unable to asynchronously create map") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, + H5ARG_TRACE11(FUNC, "*s*sIui*siiiiii", app_file, app_func, app_line, loc_id, name, key_type_id, val_type_id, lcpl_id, mcpl_id, mapl_id, es_id)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTINSERT, FAIL, "can't insert token into event set") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Mcreate_async() */ + /*------------------------------------------------------------------------- * Function: H5Mcreate_anon * @@ -366,6 +439,56 @@ H5Mcreate_anon(hid_t loc_id, hid_t key_type_id, hid_t val_type_id, hid_t mcpl_id FUNC_LEAVE_API(ret_value) } /* end H5Mcreate_anon() */ +/*------------------------------------------------------------------------ + * Function: H5M__open_api_common + * + * Purpose: This is the common function for opening the HDF5 map. + * + * Return: Success: Object ID of the map + * + * Failure: H5I_INVALID_HID + * + *------------------------------------------------------------------------- + */ +static hid_t +H5M__open_api_common(hid_t loc_id, const char *name, hid_t mapl_id, void **token_ptr, H5VL_object_t ** _vol_obj_ptr) +{ + void * map = NULL; /* map object from VOL connector */ + H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */ + H5VL_object_t ** vol_obj_ptr = (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_STATIC + + /* Check args */ + if (!name) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "name parameter cannot be NULL") + if (!*name) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "name parameter cannot be an empty string") + + /* Set up object access arguments */ + if (H5VL_setup_acc_args(loc_id, H5P_CLS_MACC, FALSE, &mapl_id, vol_obj_ptr, &loc_params) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments") + + /* Open the map */ + if (H5VL_optional(*vol_obj_ptr, H5VL_MAP_OPEN, H5P_DATASET_XFER_DEFAULT, token_ptr, &loc_params, name, + mapl_id, &map) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open map") + + /* Register an atom for the map */ + if ((ret_value = H5VL_register(H5I_MAP, map, (*vol_obj_ptr)->connector, TRUE)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTREGISTER, H5I_INVALID_HID, "can't register map atom") + +done: + /* Cleanup on failure */ + if (H5I_INVALID_HID == ret_value) + if (map && H5VL_optional(*vol_obj_ptr, H5VL_MAP_CLOSE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, H5I_INVALID_HID, "unable to release map") + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5M__open_api_common() */ + /*------------------------------------------------------------------------ * Function: H5Mopen * @@ -392,32 +515,54 @@ H5Mopen(hid_t loc_id, const char *name, hid_t mapl_id) FUNC_ENTER_API(H5I_INVALID_HID) H5TRACE3("i", "i*si", loc_id, name, mapl_id); - /* Check args */ - if (!name) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "name parameter cannot be NULL") - if (!*name) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "name parameter cannot be an empty string") + /* Open the map synchronously */ + if ((ret_value = H5M__open_api_common(loc_id, name, mapl_id, NULL, NULL)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTCREATE, H5I_INVALID_HID, "unable to synchronously open map") - /* Verify access property list and set up collective metadata if appropriate */ - if (H5CX_set_apl(&mapl_id, H5P_CLS_MACC, loc_id, FALSE) < 0) - HGOTO_ERROR(H5E_MAP, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") +done: + /* Cleanup on failure */ + if (H5I_INVALID_HID == ret_value) + if (map && H5VL_optional(vol_obj, H5VL_MAP_CLOSE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, H5I_INVALID_HID, "unable to release map") - /* get the location object */ - if (NULL == (vol_obj = (H5VL_object_t *)H5I_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") + FUNC_LEAVE_API(ret_value) +} /* end H5Mopen() */ - /* Set the location parameters */ - loc_params.type = H5VL_OBJECT_BY_SELF; - loc_params.obj_type = H5I_get_type(loc_id); +/*------------------------------------------------------------------------ + * Function: H5Mopen_async + * + * Purpose: Asynchronous version of H5Mopen + * + * Return: Success: Object ID of the map + * + * Failure: H5I_INVALID_HID + * + *------------------------------------------------------------------------- + */ +hid_t +H5Mopen_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, hid_t mapl_id, hid_t es_id) +{ + void * map = NULL; /* map object from VOL connector */ + H5VL_object_t * vol_obj = NULL; /* object of loc_id */ + H5VL_loc_params_t loc_params; + hid_t ret_value = H5I_INVALID_HID; /* Return value */ - /* Open the map */ - if (H5VL_optional(vol_obj, H5VL_MAP_OPEN, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &loc_params, name, - mapl_id, &map) < 0) - HGOTO_ERROR(H5E_MAP, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open map") + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE7("i", "*s*sIui*sii", app_file, app_func, app_line, loc_id, name, mapl_id, es_id); - /* Register an atom for the map */ - if ((ret_value = H5VL_register(H5I_MAP, map, vol_obj->connector, TRUE)) < 0) - HGOTO_ERROR(H5E_MAP, H5E_CANTREGISTER, H5I_INVALID_HID, "can't register map atom") + /* Set up request token pointer for asynchronous operation */ + if (H5ES_NONE != es_id) + token_ptr = &token; + + /* Open the map synchronously */ + if ((ret_value = H5M__open_api_common(loc_id, name, mapl_id, token_ptr, &vol_obj)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTCREATE, H5I_INVALID_HID, "unable to asynchronously open map") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, + H5ARG_TRACE7(FUNC, "*s*sIui*sii", app_file, app_func, app_line, loc_id, name, mapl_id, es_id)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTINSERT, FAIL, "can't insert token into event set") done: /* Cleanup on failure */ @@ -426,7 +571,7 @@ H5Mopen(hid_t loc_id, const char *name, hid_t mapl_id) HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, H5I_INVALID_HID, "unable to release map") FUNC_LEAVE_API(ret_value) -} /* end H5Mopen() */ +} /* end H5Mopen_async() */ /*------------------------------------------------------------------------- * Function: H5Mclose @@ -461,6 +606,61 @@ H5Mclose(hid_t map_id) FUNC_LEAVE_API(ret_value) } /* end H5Mclose() */ +/*------------------------------------------------------------------------- + * Function: H5Mclose + * + * Purpose: Asynchronous version of H5Mclose + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5Mclose(const char *app_file, const char *app_func, unsigned app_line, hid_t map_id, hid_t es_id) +{ + void * token = NULL; /* Request token for async operation */ + void **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ + H5VL_object_t *vol_obj = NULL; /* VOL object of dset_id */ + H5VL_t * connector = NULL; /* VOL connector */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE5("e", "*s*sIuii", app_file, app_func, app_line, map_id, es_id); + + /* Check args */ + if (H5I_MAP != H5I_get_type(map_id)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a map ID") + + /* Get dataset object's connector */ + if (NULL == (vol_obj = H5VL_vol_object(dset_id))) + HGOTO_ERROR(H5E_MAP, H5E_CANTGET, FAIL, "can't get VOL object for dataset") + + /* Prepare for possible asynchronous operation */ + if (H5ES_NONE != es_id) { + /* Increase connector's refcount, so it doesn't get closed if closing + * the dataset closes the file */ + connector = vol_obj->connector; + H5VL_conn_inc_rc(connector); + + /* Point at token for operation to set up */ + token_ptr = &token; + } /* end if */ + + /* Decrement the counter on the map. It will be freed if the count + * reaches zero. + */ + if (H5I_dec_app_ref_always_close_async(map_id, token_ptr) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTDEC, FAIL, "can't decrement count on dataset ID") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, H5ARG_TRACE5(FUNC, "*s*sIuii", app_file, app_func, app_line, map_id, es_id)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTINSERT, FAIL, "can't insert token into event set") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Mclose() */ + /*------------------------------------------------------------------------- * Function: H5Mget_key_type * @@ -646,6 +846,54 @@ H5Mget_count(hid_t map_id, hsize_t *count /*out*/, hid_t dxpl_id) FUNC_LEAVE_API(ret_value) } /* end H5Mget_count() */ +/*------------------------------------------------------------------------- + * Function: H5M__put_api_common + * + * Purpose: This is the common function for putting value to map. + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ +static herr_t +H5M__put_api_common(hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_id, const void *value, + hid_t dxpl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr) +{ + H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */ + H5VL_object_t **vol_obj_ptr = + (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Check arguments */ + if (key_mem_type_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid key memory datatype ID") + if (val_mem_type_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid value memory datatype ID") + + /* Get map pointer */ + if (NULL == (*vol_obj_ptr = (H5VL_object_t *)H5I_object_verify(map_id, H5I_MAP))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "map_id is not a map ID") + + /* Get the default dataset transfer property list if the user didn't provide one */ + if (H5P_DEFAULT == dxpl_id) + dxpl_id = H5P_DATASET_XFER_DEFAULT; + else if (TRUE != H5P_isa_class(dxpl_id, H5P_DATASET_XFER)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms") + + /* Set DXPL for operation */ + H5CX_set_dxpl(dxpl_id); + + /* Set the key/value pair */ + if (H5VL_optional(*vol_obj_ptr, H5VL_MAP_PUT, dxpl_id, token_ptr, key_mem_type_id, key, val_mem_type_id, + value) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTSET, FAIL, "unable to put key/value pair") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5M__put_api_common() */ + /*------------------------------------------------------------------------- * Function: H5Mput * @@ -672,6 +920,71 @@ H5Mput(hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_ FUNC_ENTER_API(FAIL) H5TRACE6("e", "ii*xi*xi", map_id, key_mem_type_id, key, val_mem_type_id, value, dxpl_id); + /* Add key-value pair to the map synchronously */ + if ((ret_value = H5M__put_api_common(map_id, key_mem_type_id, key, val_mem_type_id, value, dxpl_id, NULL, NULL)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTPUT, H5I_INVALID_HID, "unable to synchronously put value to map") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Mput() */ + +/*------------------------------------------------------------------------- + * Function: H5Mput_async + * + * Purpose: Asynchronous version of H5Mput + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5Mput_async(const char *app_file, const char *app_func, unsigned app_line, hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_id, const void *value, hid_t dxpl_id, hid_t es_id) +{ + H5VL_object_t *vol_obj = NULL; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE10("e", "*s*sIuii*xi*xii", app_file, app_func, app_line, map_id, key_mem_type_id, key, + val_mem_type_id, value, dxpl_id, es_id); + + /* Set up request token pointer for asynchronous operation */ + if (H5ES_NONE != es_id) + token_ptr = &token; + + /* Add key-value pair to the map asynchronously */ + if ((ret_value = H5M__put_api_common(map_id, key_mem_type_id, key, val_mem_type_id, value, dxpl_id, + token_ptr, &vol_obj)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTPUT, H5I_INVALID_HID, "unable to asynchronously put value to map") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, + H5ARG_TRACE10(FUNC, "*s*sIuii*xi*xii", app_file, app_func, app_line, map_id, key_mem_type_id, key, val_mem_type_id, value, dxpl_id, es_id)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTINSERT, FAIL, "can't insert token into event set") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Mput_async() */ + +/*------------------------------------------------------------------------- + * Function: H5M__get_api_common + * + * Purpose: This is common function for getting value from the map. + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ +static herr_t +H5M__get_api_common(hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_id, void *value, hid_t dxpl_id, void **token_ptr, H5VL_object_t ** _vol_obj_ptr) +{ + H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */ + H5VL_object_t ** vol_obj_ptr = (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + /* Check arguments */ if (key_mem_type_id < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid key memory datatype ID") @@ -679,7 +992,7 @@ H5Mput(hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid value memory datatype ID") /* Get map pointer */ - if (NULL == (vol_obj = (H5VL_object_t *)H5I_object_verify(map_id, H5I_MAP))) + if (NULL == (*vol_obj_ptr = (H5VL_object_t *)H5I_object_verify(map_id, H5I_MAP))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "map_id is not a map ID") /* Get the default dataset transfer property list if the user didn't provide one */ @@ -691,14 +1004,14 @@ H5Mput(hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_ /* Set DXPL for operation */ H5CX_set_dxpl(dxpl_id); - /* Set the key/value pair */ - if (H5VL_optional(vol_obj, H5VL_MAP_PUT, dxpl_id, H5_REQUEST_NULL, key_mem_type_id, key, val_mem_type_id, - value) < 0) - HGOTO_ERROR(H5E_MAP, H5E_CANTSET, FAIL, "unable to put key/value pair") + /* Get the value for the key */ + if (H5VL_optional(*vol_obj_ptr, H5VL_MAP_GET_VAL, dxpl_id, token_ptr, key_mem_type_id, key, + val_mem_type_id, value) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTGET, FAIL, "unable to get value from map") done: - FUNC_LEAVE_API(ret_value) -} /* end H5Mput() */ + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5M__get_api_common() */ /*------------------------------------------------------------------------- * Function: H5Mget @@ -729,33 +1042,50 @@ H5Mget(hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_ FUNC_ENTER_API(FAIL) H5TRACE6("e", "ii*xi*xi", map_id, key_mem_type_id, key, val_mem_type_id, value, dxpl_id); - /* Check arguments */ - if (key_mem_type_id < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid key memory datatype ID") - if (val_mem_type_id < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid value memory datatype ID") + /* Get key-value pair from the map synchronously */ + if ((ret_value = H5M__get_api_common(map_id, key_mem_type_id, key, val_mem_type_id, value, dxpl_id, NULL, NULL)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTGET, H5I_INVALID_HID, "unable to synchronously get value from map") - /* Get map pointer */ - if (NULL == (vol_obj = (H5VL_object_t *)H5I_object_verify(map_id, H5I_MAP))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "map_id is not a map ID") +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Mget() */ - /* Get the default dataset transfer property list if the user didn't provide one */ - if (H5P_DEFAULT == dxpl_id) - dxpl_id = H5P_DATASET_XFER_DEFAULT; - else if (TRUE != H5P_isa_class(dxpl_id, H5P_DATASET_XFER)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms") +/*------------------------------------------------------------------------- + * Function: H5Mget_async + * + * Purpose: Asynchronous version of H5Mget + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5Mget_async(const char *app_file, const char *app_func, unsigned app_line, hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_id, void *value, hid_t dxpl_id, hid_t es_id) +{ + H5VL_object_t *vol_obj = NULL; + herr_t ret_value = SUCCEED; /* Return value */ - /* Set DXPL for operation */ - H5CX_set_dxpl(dxpl_id); + FUNC_ENTER_API(FAIL) + H5TRACE10("e", "*s*sIuii*xi*xii", app_file, app_func, app_line, map_id, key_mem_type_id, key, + val_mem_type_id, value, dxpl_id, es_id); - /* Get the value for the key */ - if (H5VL_optional(vol_obj, H5VL_MAP_GET_VAL, dxpl_id, H5_REQUEST_NULL, key_mem_type_id, key, - val_mem_type_id, value) < 0) - HGOTO_ERROR(H5E_MAP, H5E_CANTGET, FAIL, "unable to get value from map") + /* Set up request token pointer for asynchronous operation */ + if (H5ES_NONE != es_id) + token_ptr = &token; + + /* Get key-value pair from the map asynchronously */ + if ((ret_value = H5M__get_api_common(map_id, key_mem_type_id, key, val_mem_type_id, value, dxpl_id, NULL, NULL)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTGET, H5I_INVALID_HID, "unable to synchronously get value from map") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, + H5ARG_TRACE10(FUNC, "*s*sIuii*xi*xii", app_file, app_func, app_line, map_id, key_mem_type_id, key, val_mem_type_id, value, dxpl_id, es_id)) < 0) + HGOTO_ERROR(H5E_MAP, H5E_CANTINSERT, FAIL, "can't insert token into event set") done: FUNC_LEAVE_API(ret_value) -} /* end H5Mget() */ +} /* end H5Mget_async() */ /*------------------------------------------------------------------------- * Function: H5Mexists diff --git a/src/H5Mpublic.h b/src/H5Mpublic.h index 643a1e6f4ed..fc6f3280dcf 100644 --- a/src/H5Mpublic.h +++ b/src/H5Mpublic.h @@ -83,8 +83,10 @@ extern "C" { H5_DLL hid_t H5Mcreate(hid_t loc_id, const char *name, hid_t key_type_id, hid_t val_type_id, hid_t lcpl_id, hid_t mcpl_id, hid_t mapl_id); +H5_DLL hid_t H5Mcreate_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, hid_t key_type_id, hid_t val_type_id, hid_t lcpl_id, hid_t mcpl_id, hid_t mapl_id, hid_t es_id); H5_DLL hid_t H5Mcreate_anon(hid_t loc_id, hid_t key_type_id, hid_t val_type_id, hid_t mcpl_id, hid_t mapl_id); H5_DLL hid_t H5Mopen(hid_t loc_id, const char *name, hid_t mapl_id); +H5_DLL hid_t H5Mopen_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, hid_t mapl_id, hid_t es_id); H5_DLL herr_t H5Mclose(hid_t map_id); H5_DLL hid_t H5Mget_key_type(hid_t map_id); H5_DLL hid_t H5Mget_val_type(hid_t map_id); @@ -93,8 +95,10 @@ H5_DLL hid_t H5Mget_access_plist(hid_t map_id); H5_DLL herr_t H5Mget_count(hid_t map_id, hsize_t *count, hid_t dxpl_id); H5_DLL herr_t H5Mput(hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_id, const void *value, hid_t dxpl_id); +H5_DLL herr_t H5Mput_async(const char *app_file, const char *app_func, unsigned app_line, hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_id, const void *value, hid_t dxpl_id, hid_t es_id); H5_DLL herr_t H5Mget(hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_id, void *value, hid_t dxpl_id); +H5_DLL herr_t H5Mget_async(const char *app_file, const char *app_func, unsigned app_line, hid_t map_id, hid_t key_mem_type_id, const void *key, hid_t val_mem_type_id, void *value, hid_t dxpl_id, hid_t es_id); H5_DLL herr_t H5Mexists(hid_t map_id, hid_t key_mem_type_id, const void *key, hbool_t *exists, hid_t dxpl_id); H5_DLL herr_t H5Miterate(hid_t map_id, hsize_t *idx, hid_t key_mem_type_id, H5M_iterate_t op, void *op_data, hid_t dxpl_id); diff --git a/src/H5R.c b/src/H5R.c index 037d08c9546..a7d5859e5fc 100644 --- a/src/H5R.c +++ b/src/H5R.c @@ -27,10 +27,12 @@ #include "H5private.h" /* Generic Functions */ #include "H5CXprivate.h" /* API Contexts */ #include "H5Eprivate.h" /* Error handling */ +#include "H5ESprivate.h" /* Event Sets */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5Rpkg.h" /* References */ #include "H5Sprivate.h" /* Dataspaces */ +#include "H5VLprivate.h" /* Virtual Object Layer */ /****************/ /* Local Macros */ @@ -44,6 +46,11 @@ /* Local Prototypes */ /********************/ +/* Helper routines for sync/async API calls */ +static hid_t H5R__open_object_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr); +static hid_t H5R__open_region_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr); +static hid_t H5R__open_attr_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr); + /*********************/ /* Package Variables */ /*********************/ @@ -448,28 +455,28 @@ H5Rcopy(const H5R_ref_t *src_ref_ptr, H5R_ref_t *dst_ref_ptr) } /* end H5Rcopy() */ /*------------------------------------------------------------------------- - * Function: H5Ropen_object + * Function: H5R__open_object_api_common * - * Purpose: Given a reference to some object, open that object and - * return an ID for that object. + * Purpose: This is the common function for opening an object via a reference. * * Return: Valid ID on success / H5I_INVALID_HID on failure * *------------------------------------------------------------------------- */ -hid_t -H5Ropen_object(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id) +static hid_t +H5R__open_object_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr) { - hid_t loc_id; /* Reference location ID */ - H5VL_object_t * vol_obj = NULL; /* Object of loc_id */ - H5VL_loc_params_t loc_params; /* Location parameters */ - H5O_token_t obj_token = {0}; /* Object token */ - H5I_type_t opened_type; /* Opened object type */ - void * opened_obj = NULL; /* Opened object */ - hid_t ret_value = H5I_INVALID_HID; /* Return value */ - - FUNC_ENTER_API(H5I_INVALID_HID) - H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, oapl_id); + hid_t loc_id; /* Reference location ID */ + H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */ + H5VL_object_t **vol_obj_ptr = + (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5O_token_t obj_token = {0}; /* Object token */ + H5I_type_t opened_type; /* Opened object type */ + void * opened_obj = NULL; /* Opened object */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_STATIC /* Check args */ if (ref_ptr == NULL) @@ -489,63 +496,120 @@ H5Ropen_object(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENFILE, H5I_INVALID_HID, "cannot re-open referenced file") } - /* Get object token */ - if (H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get object token") - /* Verify access property list and set up collective metadata if appropriate */ if (H5CX_set_apl(&oapl_id, H5P_CLS_DACC, loc_id, FALSE) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") - /* Get the VOL object */ - if (NULL == (vol_obj = H5VL_vol_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") + /* Get object token */ + if (H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get object token") - /* Set location parameters */ - loc_params.type = H5VL_OBJECT_BY_TOKEN; - loc_params.loc_data.loc_by_token.token = &obj_token; - loc_params.obj_type = H5I_get_type(loc_id); + /* Set up arguments for object access by token */ + if (H5VL_setup_token_args(loc_id, ref_ptr, obj_token, vol_obj_ptr, &loc_params) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments") /* Open object by token */ - if (NULL == (opened_obj = H5VL_object_open(vol_obj, &loc_params, &opened_type, H5P_DATASET_XFER_DEFAULT, - H5_REQUEST_NULL))) + if (NULL == (opened_obj = H5VL_object_open(*vol_obj_ptr, &loc_params, &opened_type, H5P_DATASET_XFER_DEFAULT, token_ptr))) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object by token") /* Register object */ - if ((ret_value = H5VL_register(opened_type, opened_obj, vol_obj->connector, TRUE)) < 0) + if ((ret_value = H5VL_register(opened_type, opened_obj, (*vol_obj_ptr)->connector, TRUE)) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle") +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__open_object_api_common() */ + +/*------------------------------------------------------------------------- + * Function: H5Ropen_object + * + * Purpose: Given a reference to some object, open that object and + * return an ID for that object. + * + * Return: Valid ID on success / H5I_INVALID_HID on failure + * + *------------------------------------------------------------------------- + */ +hid_t +H5Ropen_object(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id) +{ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, oapl_id); + + /* Open the dataset synchronously */ + if ((ret_value = H5R__open_object_api_common(ref_ptr, rapl_id, oapl_id, NULL, NULL)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to synchronously open object") + done: FUNC_LEAVE_API(ret_value) } /* end H5Ropen_object() */ /*------------------------------------------------------------------------- - * Function: H5Ropen_region + * Function: H5Ropen_object_async * - * Purpose: Given a reference to some object, creates a copy of the dataset - * pointed to's dataspace and defines a selection in the copy - * which is the region pointed to. + * Purpose: Asynchronous version of H5Ropen_object * * Return: Valid ID on success / H5I_INVALID_HID on failure * *------------------------------------------------------------------------- */ hid_t -H5Ropen_region(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id) +H5Ropen_object_async(const char *app_file, const char *app_func, unsigned app_line, H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, hid_t es_id) { - hid_t loc_id; /* Reference location ID */ - H5VL_object_t * vol_obj = NULL; /* Object of loc_id */ - H5VL_loc_params_t loc_params; /* Location parameters */ - H5O_token_t obj_token = {0}; /* Object token */ - H5I_type_t opened_type; /* Opened object type */ - void * opened_obj = NULL; /* Opened object */ - hid_t opened_obj_id = H5I_INVALID_HID; /* Opened object ID */ - H5S_t * space = NULL; /* Dataspace pointer (copy) */ - hid_t space_id = H5I_INVALID_HID; /* Dataspace ID */ - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + H5VL_object_t *vol_obj = NULL; /* Object of loc_id */ + void * token = NULL; /* Request token for async operation */ + void ** token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) - H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, oapl_id); + H5TRACE7("i", "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, oapl_id, es_id); + + /* Set up request token pointer for asynchronous operation */ + if (H5ES_NONE != es_id) + token_ptr = &token; /* Point at token for VOL connector to set up */ + + /* Open the object asynchronously */ + if ((ret_value = H5R__open_object_api_common(ref_ptr, rapl_id, oapl_id, token_ptr, &vol_obj)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to asynchronously open object") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, + H5ARG_TRACE7(FUNC, "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, oapl_id, es_id)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINSERT, H5I_INVALID_HID, "can't insert token into event set") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Ropen_object_async() */ + +/*------------------------------------------------------------------------- + * Function: H5R__open_region_api_common + * + * Purpose: This is the common function for opening a region. + * + * Return: Valid ID on success / H5I_INVALID_HID on failure + * + *------------------------------------------------------------------------- + */ +static hid_t +H5R__open_region_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr) +{ + hid_t loc_id; /* Reference location ID */ + H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */ + H5VL_object_t **vol_obj_ptr = + (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5O_token_t obj_token = {0}; /* Object token */ + H5I_type_t opened_type; /* Opened object type */ + void * opened_obj = NULL; /* Opened object */ + hid_t opened_obj_id = H5I_INVALID_HID; /* Opened object ID */ + H5S_t * space = NULL; /* Dataspace pointer (copy) */ + hid_t space_id = H5I_INVALID_HID; /* Dataspace ID */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_STATIC /* Check args */ if (ref_ptr == NULL) @@ -569,22 +633,17 @@ H5Ropen_region(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id) if (H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get object token") - /* Get the VOL object */ - if (NULL == (vol_obj = H5VL_vol_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") - - /* Set location parameters */ - loc_params.type = H5VL_OBJECT_BY_TOKEN; - loc_params.loc_data.loc_by_token.token = &obj_token; - loc_params.obj_type = H5I_get_type(loc_id); + /* Set up arguments for object access by token */ + if (H5VL_setup_token_args(loc_id, ref_ptr, obj_token, vol_obj_ptr, &loc_params) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments") /* Open object by token */ - if (NULL == (opened_obj = H5VL_object_open(vol_obj, &loc_params, &opened_type, H5P_DATASET_XFER_DEFAULT, - H5_REQUEST_NULL))) + if (NULL == (opened_obj = H5VL_object_open(*vol_obj_ptr, &loc_params, &opened_type, + H5P_DATASET_XFER_DEFAULT, token_ptr))) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object by token") /* Register object */ - if ((opened_obj_id = H5VL_register(opened_type, opened_obj, vol_obj->connector, FALSE)) < 0) + if ((opened_obj_id = H5VL_register(opened_type, opened_obj, (*vol_obj_ptr)->connector, FALSE)) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle") /* Get VOL object object */ @@ -612,34 +671,116 @@ H5Ropen_region(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id) if ((space_id != H5I_INVALID_HID) && (H5I_dec_ref(space_id) < 0)) HDONE_ERROR(H5E_REFERENCE, H5E_CLOSEERROR, H5I_INVALID_HID, "can't close dataspace") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__open_region_api_common() */ + +/*------------------------------------------------------------------------- + * Function: H5Ropen_region + * + * Purpose: Given a reference to some object, creates a copy of the dataset + * pointed to's dataspace and defines a selection in the copy + * which is the region pointed to. + * + * Return: Valid ID on success / H5I_INVALID_HID on failure + * + *------------------------------------------------------------------------- + */ +hid_t +H5Ropen_region(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id) +{ + hid_t loc_id; /* Reference location ID */ + H5VL_object_t * vol_obj = NULL; /* Object of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5O_token_t obj_token = {0}; /* Object token */ + H5I_type_t opened_type; /* Opened object type */ + void * opened_obj = NULL; /* Opened object */ + hid_t opened_obj_id = H5I_INVALID_HID; /* Opened object ID */ + H5S_t * space = NULL; /* Dataspace pointer (copy) */ + hid_t space_id = H5I_INVALID_HID; /* Dataspace ID */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, oapl_id); + + /* Open the region synchronously */ + if ((ret_value = H5R__open_region_api_common(ref_ptr, rapl_id, oapl_id, NULL, NULL)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to synchronously open region") + +done: FUNC_LEAVE_API(ret_value) } /* end H5Ropen_region() */ /*------------------------------------------------------------------------- - * Function: H5Ropen_attr + * Function: H5Ropen_region_async * - * Purpose: Given a reference to some attribute, open that attribute and - * return an ID for that attribute. + * Purpose: Asynchronous version of H5Ropen_region * * Return: Valid ID on success / H5I_INVALID_HID on failure * *------------------------------------------------------------------------- */ hid_t -H5Ropen_attr(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id) +H5Ropen_region_async(const char *app_file, const char *app_func, unsigned app_line, H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, hid_t es_id) { hid_t loc_id; /* Reference location ID */ H5VL_object_t * vol_obj = NULL; /* Object of loc_id */ H5VL_loc_params_t loc_params; /* Location parameters */ H5O_token_t obj_token = {0}; /* Object token */ + void * token = NULL; /* Request token for async operation */ + void ** token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ H5I_type_t opened_type; /* Opened object type */ void * opened_obj = NULL; /* Opened object */ hid_t opened_obj_id = H5I_INVALID_HID; /* Opened object ID */ - void * opened_attr = NULL; /* Opened attribute */ + H5S_t * space = NULL; /* Dataspace pointer (copy) */ + hid_t space_id = H5I_INVALID_HID; /* Dataspace ID */ hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) - H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, aapl_id); + H5TRACE7("i", "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, oapl_id, es_id); + + /* Set up request token pointer for asynchronous operation */ + if (H5ES_NONE != es_id) + token_ptr = &token; /* Point at token for VOL connector to set up */ + + /* Open the region asynchronously */ + if ((ret_value = H5R__open_region_api_common(ref_ptr, rapl_id, oapl_id, token_ptr, &vol_obj)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to synchronously open region") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, + H5ARG_TRACE7(FUNC, "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, oapl_id, es_id)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINSERT, H5I_INVALID_HID, "can't insert token into event set") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Ropen_region_async() */ + +/*------------------------------------------------------------------------- + * Function: H5R__open_attr_api_common + * + * Purpose: This is the common function for opening an attribute via a reference. + * + * Return: Valid ID on success / H5I_INVALID_HID on failure + * + *------------------------------------------------------------------------- + */ +static hid_t +H5R__open_attr_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr) +{ + hid_t loc_id; /* Reference location ID */ + H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */ + H5VL_object_t **vol_obj_ptr = + (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5O_token_t obj_token = {0}; /* Object token */ + H5I_type_t opened_type; /* Opened object type */ + void * opened_obj = NULL; /* Opened object */ + hid_t opened_obj_id = H5I_INVALID_HID; /* Opened object ID */ + void * opened_attr = NULL; /* Opened attribute */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_STATIC /* Check args */ if (ref_ptr == NULL) @@ -662,57 +803,108 @@ H5Ropen_attr(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id) if (H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get object token") - /* Get the VOL object */ - if (NULL == (vol_obj = H5VL_vol_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") - - /* Set location parameters */ - loc_params.type = H5VL_OBJECT_BY_TOKEN; - loc_params.loc_data.loc_by_token.token = &obj_token; - loc_params.obj_type = H5I_get_type(loc_id); + /* Set up arguments for object access by token */ + if (H5VL_setup_token_args(loc_id, ref_ptr, obj_token, vol_obj_ptr, &loc_params) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments") /* Open object by token */ - if (NULL == (opened_obj = H5VL_object_open(vol_obj, &loc_params, &opened_type, H5P_DATASET_XFER_DEFAULT, - H5_REQUEST_NULL))) + if (NULL == (opened_obj = H5VL_object_open(*vol_obj_ptr, &loc_params, &opened_type, H5P_DATASET_XFER_DEFAULT, token_ptr))) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object by token") /* Register object */ - if ((opened_obj_id = H5VL_register(opened_type, opened_obj, vol_obj->connector, FALSE)) < 0) + if ((opened_obj_id = H5VL_register(opened_type, opened_obj, (*vol_obj_ptr)->connector, FALSE)) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle") - /* Verify access property list and set up collective metadata if appropriate */ - if (H5CX_set_apl(&aapl_id, H5P_CLS_AACC, loc_id, FALSE) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") + /* Set up object access arguments */ + if (H5VL_setup_acc_args(opened_obj_id, H5P_CLS_AACC, FALSE, &aapl_id, vol_obj_ptr, &loc_params) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments") - /* Set location parameters */ - loc_params.type = H5VL_OBJECT_BY_SELF; + /* Reset object type */ loc_params.obj_type = opened_type; - /* Get VOL object object */ - if (NULL == (opened_obj = H5VL_vol_object(opened_obj_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") - /* Open the attribute */ - if (NULL == (opened_attr = H5VL_attr_open(opened_obj, &loc_params, - H5R_REF_ATTRNAME((const H5R_ref_priv_t *)ref_ptr), aapl_id, - H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open attribute: '%s'", - H5R_REF_ATTRNAME((const H5R_ref_priv_t *)ref_ptr)) + if (NULL == (opened_attr = H5VL_attr_open(opened_obj, &loc_params, H5R_REF_ATTRNAME((const H5R_ref_priv_t *)ref_ptr), aapl_id, H5P_DATASET_XFER_DEFAULT, token_ptr))) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open attribute: '%s'", H5R_REF_ATTRNAME((const H5R_ref_priv_t *)ref_ptr)) /* Register the attribute and get an ID for it */ - if ((ret_value = H5VL_register(H5I_ATTR, opened_attr, vol_obj->connector, TRUE)) < 0) + if ((ret_value = H5VL_register(H5I_ATTR, opened_attr, (*vol_obj_ptr)->connector, TRUE)) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize attribute handle") done: if ((opened_obj_id != H5I_INVALID_HID) && (H5I_dec_ref(opened_obj_id) < 0)) HDONE_ERROR(H5E_REFERENCE, H5E_CLOSEERROR, H5I_INVALID_HID, "can't close object") if (H5I_INVALID_HID == ret_value) /* Cleanup on failure */ - if (opened_attr && H5VL_attr_close(vol_obj, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if (opened_attr && H5VL_attr_close(*vol_obj_ptr, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) HDONE_ERROR(H5E_REFERENCE, H5E_CLOSEERROR, H5I_INVALID_HID, "can't close attribute") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__open_attr_api_common() */ + +/*------------------------------------------------------------------------- + * Function: H5Ropen_attr + * + * Purpose: Given a reference to some attribute, open that attribute and + * return an ID for that attribute. + * + * Return: Valid ID on success / H5I_INVALID_HID on failure + * + *------------------------------------------------------------------------- + */ +hid_t +H5Ropen_attr(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id) +{ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, aapl_id); + + /* Open the attribute synchronously */ + if ((ret_value = H5R__open_attr_api_common(ref_ptr, rapl_id, aapl_id, NULL, NULL)) < 0) + HDONE_ERROR(H5E_REFERENCE, H5E_OPENERROR, H5I_INVALID_HID, "can't open attribute") + +done: FUNC_LEAVE_API(ret_value) } /* end H5Ropen_attr() */ +/*-------------------------------------------------------------------------- + * Function: H5Ropen_attr_async + * + * Purpose: Asynchronous version of H5Ropen_attr + * + * Return: Success: An attribute ID + * Failure: H5I_INVALID_HID + * + *------------------------------------------------------------------------- + */ +hid_t +H5Ropen_attr_async(const char *app_file, const char *app_func, unsigned app_line, H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id, hid_t es_id) +{ + H5VL_object_t *vol_obj = NULL; /* Object for loc_id */ + void * token = NULL; /* Request token for async operation */ + void ** token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ + hid_t ret_value; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE7("i", "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, aapl_id, es_id); + + /* Set up request token pointer for asynchronous operation */ + if (H5ES_NONE != es_id) + token_ptr = &token; /* Point at token for VOL connector to set up */ + + /* Open the attribute asynchronously */ + if ((ret_value = H5R__open_attr_api_common(ref_ptr, rapl_id, aapl_id, token_ptr, &vol_obj)) < 0) + HDONE_ERROR(H5E_REFERENCE, H5E_OPENERROR, H5I_INVALID_HID, "can't open attribute") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, + H5ARG_TRACE7(FUNC, "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, aapl_id, es_id)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "can't insert token into event set") + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Ropen_attr_async() */ + /*------------------------------------------------------------------------- * Function: H5Rget_obj_type3 * diff --git a/src/H5Rpublic.h b/src/H5Rpublic.h index 6b30b854ff5..b693a98a1e9 100644 --- a/src/H5Rpublic.h +++ b/src/H5Rpublic.h @@ -113,8 +113,11 @@ H5_DLL herr_t H5Rcopy(const H5R_ref_t *src_ref_ptr, H5R_ref_t *dst_ref_ptr); /* Dereference */ H5_DLL hid_t H5Ropen_object(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id); +H5_DLL hid_t H5Ropen_object_async(const char *app_file, const char *app_func, unsigned app_line, H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, hid_t es_id); H5_DLL hid_t H5Ropen_region(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id); +H5_DLL hid_t H5Ropen_region_async(const char *app_file, const char *app_func, unsigned app_line, H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, hid_t es_id); H5_DLL hid_t H5Ropen_attr(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id); +H5_DLL hid_t H5Ropen_attr_async(const char *app_file, const char *app_func, unsigned app_line, H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id, hid_t es_id); /* Get type */ H5_DLL herr_t H5Rget_obj_type3(H5R_ref_t *ref_ptr, hid_t rapl_id, H5O_type_t *obj_type); diff --git a/src/H5T.c b/src/H5T.c index 156e5fafcc3..a73f3841c7d 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -32,6 +32,7 @@ #include "H5CXprivate.h" /* API Contexts */ #include "H5Dprivate.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ +#include "H5ESprivate.h" /* Event Sets */ #include "H5Fprivate.h" /* Files */ #include "H5FLprivate.h" /* Free Lists */ #include "H5FOprivate.h" /* File objects */ @@ -347,6 +348,7 @@ static herr_t H5T__unregister(H5T_pers_t pers, const char *name, H5T_t *src, H5T static htri_t H5T__compiler_conv(H5T_t *src, H5T_t *dst); static herr_t H5T__set_size(H5T_t *dt, size_t size); static herr_t H5T__close_cb(H5T_t *dt, void **request); +static hid_t H5T__copy_api_common(hid_t obj_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr); static H5T_path_t *H5T__path_find_real(const H5T_t *src, const H5T_t *dst, const char *name, H5T_conv_func_t *conv); static hbool_t H5T__detect_vlen_ref(const H5T_t *dt); @@ -1852,11 +1854,9 @@ H5Tcreate(H5T_class_t type, size_t size) } /* end H5Tcreate() */ /*------------------------------------------------------------------------- - * Function: H5Tcopy + * Function: H5T__copy_api_common * - * Purpose: Copies a datatype. The resulting datatype is not locked. - * The datatype should be closed when no longer needed by - * calling H5Tclose(). + * Purpose: This is the common function for opening a datatype * * Return: Success: The ID of a new datatype * @@ -1869,16 +1869,20 @@ H5Tcreate(H5T_class_t type, size_t size) * *------------------------------------------------------------------------- */ -hid_t -H5Tcopy(hid_t obj_id) +static hid_t +H5T__copy_api_common(hid_t obj_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr) { + H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */ + H5VL_object_t **vol_obj_ptr = + (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5T_t *dt = NULL; /* Pointer to the datatype to copy */ H5T_t *new_dt = NULL; /* Pointer to the new datatype */ hid_t dset_tid = H5I_INVALID_HID; /* Datatype ID from dataset */ hid_t ret_value = H5I_INVALID_HID; /* Return value */ - FUNC_ENTER_API(H5I_INVALID_HID) - H5TRACE1("i", "i", obj_id); + FUNC_ENTER_STATIC switch (H5I_get_type(obj_id)) { case H5I_DATATYPE: @@ -1888,16 +1892,14 @@ H5Tcopy(hid_t obj_id) break; case H5I_DATASET: { - H5VL_object_t *vol_obj = NULL; /* Dataset structure */ - /* The argument is a dataset handle */ - if (NULL == (vol_obj = (H5VL_object_t *)H5I_object_verify(obj_id, H5I_DATASET))) + if (NULL == (*vol_obj_ptr = (H5VL_object_t *)H5I_object_verify(obj_id, H5I_DATASET))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "type_id is not a dataset ID") /* Get the datatype from the dataset * NOTE: This will have to be closed after we're done with it. */ - if (H5VL_dataset_get(vol_obj, H5VL_DATASET_GET_TYPE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, + if (H5VL_dataset_get(*vol_obj_ptr, H5VL_DATASET_GET_TYPE, H5P_DATASET_XFER_DEFAULT, token_ptr, &dset_tid) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5I_INVALID_HID, "unable to get datatype from the dataset") @@ -1949,18 +1951,100 @@ H5Tcopy(hid_t obj_id) if (new_dt && H5T_close_real(new_dt) < 0) HDONE_ERROR(H5E_DATATYPE, H5E_CANTRELEASE, H5I_INVALID_HID, "unable to release datatype info") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__copy_api_common() */ + +/*------------------------------------------------------------------------- + * Function: H5Tcopy + * + * Purpose: Copies a datatype. The resulting datatype is not locked. + * The datatype should be closed when no longer needed by + * calling H5Tclose(). + * + * Return: Success: The ID of a new datatype + * + * Failure: H5I_INVALID_HID + * + * Note: The returned type is always transient and unlocked. If the + * TYPE_ID argument is a dataset instead of a datatype then + * this function returns a transient, modifiable datatype + * which is a copy of the dataset's datatype. + * + *------------------------------------------------------------------------- + */ +hid_t +H5Tcopy(hid_t obj_id) +{ + H5T_t *dt = NULL; /* Pointer to the datatype to copy */ + H5T_t *new_dt = NULL; /* Pointer to the new datatype */ + hid_t dset_tid = H5I_INVALID_HID; /* Datatype ID from dataset */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE1("i", "i", obj_id); + + /* Get the dataset's dataspace synchronously */ + if ((ret_value = H5T__copy_api_common(obj_id, NULL, NULL)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5I_INVALID_HID, "unable to synchronously get dataspace") + +done: FUNC_LEAVE_API(ret_value) } /* end H5Tcopy() */ +/*------------------------------------------------------------------------- + * Function: H5Tcopy_async + * + * Purpose: Asynchronous version of H5Tcopy. + * + * Return: Success: The ID of a new datatype + * + * Failure: H5I_INVALID_HID + * + * Note: The returned type is always transient and unlocked. If the + * TYPE_ID argument is a dataset instead of a datatype then + * this function returns a transient, modifiable datatype + * which is a copy of the dataset's datatype. + * + *------------------------------------------------------------------------- + */ +hid_t +H5Tcopy_async(const char *app_file, const char *app_func, unsigned app_line, hid_t obj_id, hid_t es_id) +{ + H5VL_object_t *vol_obj = NULL; /* Object for loc_id */ + void * token = NULL; /* Request token for async operation */ + void ** token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE5("i", "*s*sIuii", app_file, app_func, app_line, obj_id, es_id); + + /* Set up request token pointer for asynchronous operation */ + if (H5ES_NONE != es_id) + token_ptr = &token; /* Point at token for VOL connector to set up */ + + /* Copy the object's datatype asynchronously */ + if ((ret_value = H5T__copy_api_common(obj_id, token_ptr, &vol_obj)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5I_INVALID_HID, "unable to synchronously copy datatype") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, + H5ARG_TRACE5(FUNC, "*s*sIuii", app_file, app_func, app_line, obj_id, es_id)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, H5I_INVALID_HID, "can't insert token into event set") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Tcopy_async() */ + /*------------------------------------------------------------------------- * Function: H5Tclose * - * Purpose: Frees a datatype and all associated memory. + * Purpose: Frees a datatype and all associated memory. * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success/Negative on failure * - * Programmer: Robb Matzke - * Tuesday, December 9, 1997 + * Programmer: Robb Matzke + * Tuesday, December 9, 1997 *------------------------------------------------------------------------- */ herr_t @@ -1986,6 +2070,68 @@ H5Tclose(hid_t type_id) FUNC_LEAVE_API(ret_value) } /* end H5Tclose() */ +/*------------------------------------------------------------------------- + * Function: H5Tclose_async + * + * Purpose: Asynchronous version of H5Tclose. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Robb Matzke + * Tuesday, December 9, 1997 + *------------------------------------------------------------------------- + */ +herr_t +H5Tclose_async(const char *app_file, const char *app_func, unsigned app_line, hid_t type_id, hid_t es_id) +{ + H5T_t * dt; /* Pointer to datatype to close */ + void * token = NULL; /* Request token for async operation */ + void ** token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ + H5VL_object_t *vol_obj = NULL; /* VOL object of dset_id */ + H5VL_t * connector = NULL; /* VOL connector */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE5("e", "*s*sIuii", app_file, app_func, app_line, type_id, es_id); + + /* Check args */ + if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") + if (H5T_STATE_IMMUTABLE == dt->shared->state) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "immutable datatype") + + /* Get dataset object's connector */ + if (NULL == (vol_obj = H5VL_vol_object(type_id))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get VOL object for dataset") + + /* Prepare for possible asynchronous operation */ + if (H5ES_NONE != es_id) { + /* Increase connector's refcount, so it doesn't get closed if closing + * the dataset closes the file */ + connector = vol_obj->connector; + H5VL_conn_inc_rc(connector); + + /* Point at token for operation to set up */ + token_ptr = &token; + } /* end if */ + + /* When the reference count reaches zero the resources are freed */ + if (H5I_dec_app_ref(type_id) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "problem freeing id") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, + H5ARG_TRACE5(FUNC, "*s*sIuii", app_file, app_func, app_line, type_id, es_id)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "can't insert token into event set") + +done: + if (connector && H5VL_conn_dec_rc(connector) < 0) + HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "can't decrement ref count on connector") + + FUNC_LEAVE_API(ret_value) +} /* end H5Tclose_async() */ + /*------------------------------------------------------------------------- * Function: H5Tequal * diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c index 3eecfb36aad..7a91d512fa0 100644 --- a/src/H5Tcommit.c +++ b/src/H5Tcommit.c @@ -29,6 +29,7 @@ #include "H5ACprivate.h" /* Metadata cache */ #include "H5CXprivate.h" /* API Contexts */ #include "H5Eprivate.h" /* Error handling */ +#include "H5ESprivate.h" /* Event Sets */ #include "H5FLprivate.h" /* Free lists */ #include "H5FOprivate.h" /* File objects */ #include "H5Iprivate.h" /* IDs */ @@ -55,6 +56,11 @@ /* Local Prototypes */ /********************/ static H5T_t *H5T__open_oid(const H5G_loc_t *loc); +static herr_t H5T__commit_api_common(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, + hid_t tcpl_id, hid_t tapl_id, void **token_ptr, + H5VL_object_t **_vol_obj_ptr); +static hid_t H5T__open_api_common(hid_t loc_id, const char *name, hid_t tapl_id, void **token_ptr, + H5VL_object_t **_vol_obj_ptr); /*********************/ /* Public Variables */ @@ -79,7 +85,7 @@ H5FL_EXTERN(H5VL_t); H5FL_EXTERN(H5VL_object_t); /*------------------------------------------------------------------------- - * Function: H5Tcommit2 + * Function: H5T__commit_api_common * * Purpose: Save a transient datatype to a file and turn the type handle * into a "named", immutable type. @@ -91,18 +97,20 @@ H5FL_EXTERN(H5VL_object_t); * *------------------------------------------------------------------------- */ -herr_t -H5Tcommit2(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id) +static herr_t +H5T__commit_api_common(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, + hid_t tapl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr) { - void * data = NULL; /* VOL-managed datatype data */ - H5VL_object_t * new_obj = NULL; /* VOL object that holds the datatype object and the VOL info */ - H5T_t * dt = NULL; /* High level datatype object that wraps the VOL object */ - H5VL_object_t * vol_obj = NULL; /* object of loc_id */ - H5VL_loc_params_t loc_params; - herr_t ret_value = SUCCEED; /* Return value */ + void * data = NULL; /* VOL-managed datatype data */ + H5VL_object_t * new_obj = NULL; /* VOL object that holds the datatype object and the VOL info */ + H5T_t * dt = NULL; /* High level datatype object that wraps the VOL object */ + H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */ + H5VL_object_t **vol_obj_ptr = + (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_API(FAIL) - H5TRACE6("e", "i*siiii", loc_id, name, type_id, lcpl_id, tcpl_id, tapl_id); + FUNC_ENTER_STATIC /* Check arguments */ if (!name) @@ -129,37 +137,101 @@ H5Tcommit2(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, hid_t t /* Set the LCPL for the API context */ H5CX_set_lcpl(lcpl_id); - /* Verify access property list and set up collective metadata if appropriate */ - if (H5CX_set_apl(&tapl_id, H5P_CLS_TACC, loc_id, TRUE) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "can't set access property list info") - - /* Fill in location struct fields */ - loc_params.type = H5VL_OBJECT_BY_SELF; - loc_params.obj_type = H5I_get_type(loc_id); - - /* Get the object from the loc_id */ - if (NULL == (vol_obj = (H5VL_object_t *)H5I_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") + /* Set up object access arguments */ + if (H5VL_setup_acc_args(loc_id, H5P_CLS_TACC, TRUE, &tapl_id, vol_obj_ptr, &loc_params) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments") /* Commit the type */ - if (NULL == (data = H5VL_datatype_commit(vol_obj, &loc_params, name, type_id, lcpl_id, tcpl_id, tapl_id, - H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + if (NULL == (data = H5VL_datatype_commit(*vol_obj_ptr, &loc_params, name, type_id, lcpl_id, tcpl_id, + tapl_id, H5P_DATASET_XFER_DEFAULT, token_ptr))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to commit datatype") /* Set up VOL object */ if (NULL == (new_obj = H5FL_CALLOC(H5VL_object_t))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "can't allocate top object structure") - new_obj->connector = vol_obj->connector; + new_obj->connector = (*vol_obj_ptr)->connector; new_obj->connector->nrefs++; new_obj->data = data; /* Set the committed type object to the VOL connector pointer in the H5T_t struct */ dt->vol_obj = new_obj; +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__commit_api_common() */ + +/*------------------------------------------------------------------------- + * Function: H5Tcommit2 + * + * Purpose: Save a transient datatype to a file and turn the type handle + * into a "named", immutable type. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * April 5, 2007 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Tcommit2(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE6("e", "i*siiii", loc_id, name, type_id, lcpl_id, tcpl_id, tapl_id); + + /* Commit the dataset synchronously */ + if ((ret_value = H5T__commit_api_common(loc_id, name, type_id, lcpl_id, tcpl_id, tapl_id, NULL, NULL)) < + 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to synchronously commit datatype") + done: FUNC_LEAVE_API(ret_value) } /* end H5Tcommit2() */ +/*------------------------------------------------------------------------- + * Function: H5Tcommit_async + * + * Purpose: Asynchronous version of H5Tcommit2 + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5Tcommit_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, + hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id, hid_t es_id) +{ + H5VL_object_t *vol_obj = NULL; /* Object for loc_id */ + void * token = NULL; /* Request token for async operation */ + void ** token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE10("e", "*s*sIui*siiiii", app_file, app_func, app_line, loc_id, name, type_id, lcpl_id, tcpl_id, + tapl_id, es_id); + + /* Set up request token pointer for asynchronous operation */ + if (H5ES_NONE != es_id) + token_ptr = &token; + + /* Commit the datatype asynchronously */ + if ((ret_value = H5T__commit_api_common(loc_id, name, type_id, lcpl_id, tcpl_id, tapl_id, token_ptr, + &vol_obj)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to synchronously commit datatype") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, + H5ARG_TRACE10(FUNC, "*s*sIui*siiiii", app_file, app_func, app_line, loc_id, name, type_id, lcpl_id, tcpl_id, tapl_id, es_id)) < + 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "can't insert token into event set") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Tcommit_async() */ + /*------------------------------------------------------------------------- * Function: H5T__commit_named * @@ -545,7 +617,7 @@ H5T_link(const H5T_t *type, int adjust) } /* end H5T_link() */ /*------------------------------------------------------------------------- - * Function: H5Topen2 + * Function: H5T__open_api_common * * Purpose: Opens a named datatype using a Datatype Access Property * List. @@ -559,16 +631,18 @@ H5T_link(const H5T_t *type, int adjust) * *------------------------------------------------------------------------- */ -hid_t -H5Topen2(hid_t loc_id, const char *name, hid_t tapl_id) +static hid_t +H5T__open_api_common(hid_t loc_id, const char *name, hid_t tapl_id, void **token_ptr, + H5VL_object_t **_vol_obj_ptr) { - void * dt = NULL; /* datatype object created by VOL connector */ - H5VL_object_t * vol_obj = NULL; /* object of loc_id */ + void * dt = NULL; /* datatype object created by VOL connector */ + H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */ + H5VL_object_t **vol_obj_ptr = + (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ H5VL_loc_params_t loc_params; hid_t ret_value = H5I_INVALID_HID; /* Return value */ - FUNC_ENTER_API(H5I_INVALID_HID) - H5TRACE3("i", "i*si", loc_id, name, tapl_id); + FUNC_ENTER_STATIC /* Check args */ if (!name) @@ -576,36 +650,105 @@ H5Topen2(hid_t loc_id, const char *name, hid_t tapl_id) if (!*name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "name parameter cannot be an empty string") - /* Verify access property list and set up collective metadata if appropriate */ - if (H5CX_set_apl(&tapl_id, H5P_CLS_TACC, loc_id, FALSE) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "can't set access property list info") - - /* Fill in location struct fields */ - loc_params.type = H5VL_OBJECT_BY_SELF; - loc_params.obj_type = H5I_get_type(loc_id); - - /* get the location object */ - if (NULL == (vol_obj = (H5VL_object_t *)H5I_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid file identifier") + /* Set up object access arguments */ + if (H5VL_setup_acc_args(loc_id, H5P_CLS_TACC, FALSE, &tapl_id, vol_obj_ptr, &loc_params) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments") /* Open the datatype */ - if (NULL == (dt = H5VL_datatype_open(vol_obj, &loc_params, name, tapl_id, H5P_DATASET_XFER_DEFAULT, - H5_REQUEST_NULL))) + if (NULL == (dt = H5VL_datatype_open(*vol_obj_ptr, &loc_params, name, tapl_id, H5P_DATASET_XFER_DEFAULT, + token_ptr))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open named datatype") /* Register the type and return the ID */ - if ((ret_value = H5VL_register(H5I_DATATYPE, dt, vol_obj->connector, TRUE)) < 0) + if ((ret_value = H5VL_register(H5I_DATATYPE, dt, (*vol_obj_ptr)->connector, TRUE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register named datatype") done: /* Cleanup on error */ if (H5I_INVALID_HID == ret_value) - if (dt && H5VL_datatype_close(vol_obj, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if (dt && H5VL_datatype_close(*vol_obj_ptr, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) HDONE_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, H5I_INVALID_HID, "unable to release datatype") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__open_api_common() */ + +/*------------------------------------------------------------------------- + * Function: H5Topen2 + * + * Purpose: Opens a named datatype using a Datatype Access Property + * List. + * + * Return: Success: Object ID of the named datatype + * + * Failure: H5I_INVALID_HID + * + * Programmer: James Laird + * Thursday July 27, 2006 + * + *------------------------------------------------------------------------- + */ +hid_t +H5Topen2(hid_t loc_id, const char *name, hid_t tapl_id) +{ + void * dt = NULL; /* datatype object created by VOL connector */ + H5VL_object_t * vol_obj = NULL; /* object of loc_id */ + H5VL_loc_params_t loc_params; + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE3("i", "i*si", loc_id, name, tapl_id); + + /* Open the datatype synchronously */ + if ((ret_value = H5T__open_api_common(loc_id, name, tapl_id, NULL, NULL)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to synchronously open dataset") + +done: FUNC_LEAVE_API(ret_value) } /* end H5Topen2() */ +/*------------------------------------------------------------------------- + * Function: H5Topen_async + * + * Purpose: Asynchronous version of H5Topen2. + * + * Return: Success: Object ID of the named datatype + * + * Failure: H5I_INVALID_HID + * + * Programmer: James Laird + * Thursday July 27, 2006 + * + *------------------------------------------------------------------------- + */ +hid_t +H5Topen_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, hid_t tapl_id, hid_t es_id) +{ + H5VL_object_t *vol_obj = NULL; /* Object for loc_id */ + void * token = NULL; /* Request token for async operation */ + void **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE7("i", "*s*sIui*sii", app_file, app_func, app_line, loc_id, name, tapl_id, es_id); + + /* Set up request token pointer for asynchronous operation */ + if (H5ES_NONE != es_id) + token_ptr = &token; /* Point at token for VOL connector to set up */ + + /* Open the datatype synchronously */ + if ((ret_value = H5T__open_api_common(loc_id, name, tapl_id, NULL, NULL)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to synchronously open dataset") + + /* If a token was created, add the token to the event set */ + if (NULL != token) + if (H5ES_insert(es_id, vol_obj->connector, token, + H5ARG_TRACE7(FUNC, "*s*sIui*sii", app_file, app_func, app_line, loc_id, name, tapl_id, es_id)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, H5I_INVALID_HID, "can't insert token into event set") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Topen_async() */ + /*------------------------------------------------------------------------- * Function: H5Tget_create_plist * diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index 73a00b68b7f..ac11ce03998 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -501,12 +501,15 @@ H5_DLLVAR hid_t H5T_NATIVE_UINT_FAST64_g; /* Operations defined on all datatypes */ H5_DLL hid_t H5Tcreate(H5T_class_t type, size_t size); H5_DLL hid_t H5Tcopy(hid_t type_id); +H5_DLL hid_t H5Tcopy_async(const char *app_file, const char *app_func, unsigned app_line, hid_t obj_id, hid_t es_id); H5_DLL herr_t H5Tclose(hid_t type_id); +H5_DLL herr_t H5Tclose_async(const char *app_file, const char *app_func, unsigned app_line, hid_t type_id, hid_t es_id); H5_DLL htri_t H5Tequal(hid_t type1_id, hid_t type2_id); H5_DLL herr_t H5Tlock(hid_t type_id); -H5_DLL herr_t H5Tcommit2(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, - hid_t tapl_id); +H5_DLL herr_t H5Tcommit2(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id); +H5_DLL herr_t H5Tcommit_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id, hid_t es_id); H5_DLL hid_t H5Topen2(hid_t loc_id, const char *name, hid_t tapl_id); +H5_DLL hid_t H5Topen_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, hid_t tapl_id, hid_t es_id); H5_DLL herr_t H5Tcommit_anon(hid_t loc_id, hid_t type_id, hid_t tcpl_id, hid_t tapl_id); H5_DLL hid_t H5Tget_create_plist(hid_t type_id); H5_DLL htri_t H5Tcommitted(hid_t type_id); diff --git a/src/H5VLint.c b/src/H5VLint.c index 33ee7cd9f57..4a5f6835071 100644 --- a/src/H5VLint.c +++ b/src/H5VLint.c @@ -2397,7 +2397,7 @@ H5VL_wrap_register(H5I_type_t type, void *obj, hbool_t app_ref) herr_t H5VL_setup_args(hid_t loc_id, H5I_type_t id_type, H5VL_object_t **vol_obj) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -2426,10 +2426,9 @@ H5VL_setup_args(hid_t loc_id, H5I_type_t id_type, H5VL_object_t **vol_obj) *------------------------------------------------------------------------- */ herr_t -H5VL_setup_loc_args(hid_t loc_id, H5VL_object_t **vol_obj, - H5VL_loc_params_t *loc_params) +H5VL_setup_loc_args(hid_t loc_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -2463,10 +2462,10 @@ H5VL_setup_loc_args(hid_t loc_id, H5VL_object_t **vol_obj, *------------------------------------------------------------------------- */ herr_t -H5VL_setup_acc_args(hid_t loc_id, const H5P_libclass_t *libclass, hbool_t is_collective, - hid_t *acspl_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params) +H5VL_setup_acc_args(hid_t loc_id, const H5P_libclass_t *libclass, hbool_t is_collective, hid_t *acspl_id, + H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -2504,7 +2503,7 @@ H5VL_setup_acc_args(hid_t loc_id, const H5P_libclass_t *libclass, hbool_t is_col herr_t H5VL_setup_self_args(hid_t loc_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -2534,11 +2533,10 @@ H5VL_setup_self_args(hid_t loc_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *l *------------------------------------------------------------------------- */ herr_t -H5VL_setup_name_args(hid_t loc_id, const char *name, const H5P_libclass_t *libclass, - hbool_t is_collective, - hid_t acspl_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params) +H5VL_setup_name_args(hid_t loc_id, const char *name, const H5P_libclass_t *libclass, hbool_t is_collective, + hid_t acspl_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -2547,13 +2545,13 @@ H5VL_setup_name_args(hid_t loc_id, const char *name, const H5P_libclass_t *libcl HDassert(loc_params); /* Check args */ - if(!name) + if (!name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "name parameter cannot be NULL") - if(!*name) + if (!*name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "name parameter cannot be an empty string") /* Verify access property list and set up collective metadata if appropriate */ - if(H5CX_set_apl(&acspl_id, libclass, loc_id, is_collective) < 0) + if (H5CX_set_apl(&acspl_id, libclass, loc_id, is_collective) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set access property list info") /* Get the location object */ @@ -2561,10 +2559,10 @@ H5VL_setup_name_args(hid_t loc_id, const char *name, const H5P_libclass_t *libcl HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") /* Set up location parameters */ - loc_params->type = H5VL_OBJECT_BY_NAME; - loc_params->loc_data.loc_by_name.name = name; - loc_params->loc_data.loc_by_name.lapl_id = acspl_id; - loc_params->obj_type = H5I_get_type(loc_id); + loc_params->type = H5VL_OBJECT_BY_NAME; + loc_params->loc_data.loc_by_name.name = name; + loc_params->loc_data.loc_by_name.lapl_id = acspl_id; + loc_params->obj_type = H5I_get_type(loc_id); done: FUNC_LEAVE_NOAPI(ret_value) @@ -2580,11 +2578,11 @@ H5VL_setup_name_args(hid_t loc_id, const char *name, const H5P_libclass_t *libcl *------------------------------------------------------------------------- */ herr_t -H5VL_setup_idx_args(hid_t loc_id, const char *name, H5_index_t idx_type, H5_iter_order_t order, - hsize_t n, const H5P_libclass_t *libclass, hbool_t is_collective, - hid_t acspl_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params) +H5VL_setup_idx_args(hid_t loc_id, const char *name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, + const H5P_libclass_t *libclass, hbool_t is_collective, hid_t acspl_id, + H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -2593,17 +2591,17 @@ H5VL_setup_idx_args(hid_t loc_id, const char *name, H5_index_t idx_type, H5_iter HDassert(loc_params); /* Check args */ - if(!name) + if (!name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "name parameter cannot be NULL") - if(!name) + if (!name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "name parameter cannot be an empty string") - if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N) + if (idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index type specified") - if(order <= H5_ITER_UNKNOWN || order >= H5_ITER_N) + if (order <= H5_ITER_UNKNOWN || order >= H5_ITER_N) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid iteration order specified") /* Verify access property list and set up collective metadata if appropriate */ - if(H5CX_set_apl(&acspl_id, libclass, loc_id, is_collective) < 0) + if (H5CX_set_apl(&acspl_id, libclass, loc_id, is_collective) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set access property list info") /* Get the location object */ @@ -2623,3 +2621,42 @@ H5VL_setup_idx_args(hid_t loc_id, const char *name, H5_index_t idx_type, H5_iter FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_setup_idx_args() */ +/*------------------------------------------------------------------------- + * Function: H5VL_setup_token_args + * + * Purpose: Set up arguments to access an object by token + * + * Return: SUCCEED / FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_setup_token_args(hid_t loc_id, H5R_ref_t *ref_ptr, H5O_token_t obj_token, + H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity check */ + HDassert(vol_obj); + HDassert(loc_params); + + /* Get object token */ + /* This caused the need to include H5Rpkg.h, which is not allowed. Right? + if (H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, H5I_INVALID_HID, "unable to get object token") + */ + + /* Get the location object */ + if (NULL == (*vol_obj = (H5VL_object_t *)H5VL_vol_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Set location parameters */ + loc_params->type = H5VL_OBJECT_BY_TOKEN; + loc_params->loc_data.loc_by_token.token = &obj_token; + loc_params->obj_type = H5I_get_type(loc_id); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_setup_token_args() */ diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index d96ba860612..e920cd58555 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -120,17 +120,18 @@ H5_DLL herr_t H5VL_register_using_existing_id(H5I_type_t type, void *object, H5V /* Object access functions */ struct H5P_libclass_t; H5_DLL herr_t H5VL_setup_args(hid_t loc_id, H5I_type_t id_type, H5VL_object_t **vol_obj); -H5_DLL herr_t H5VL_setup_loc_args(hid_t loc_id, H5VL_object_t **vol_obj, - H5VL_loc_params_t *loc_params); -H5_DLL herr_t H5VL_setup_acc_args(hid_t loc_id, const struct H5P_libclass_t *libclass, - hbool_t is_collective, hid_t *acspl_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params); +H5_DLL herr_t H5VL_setup_loc_args(hid_t loc_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params); +H5_DLL herr_t H5VL_setup_acc_args(hid_t loc_id, const struct H5P_libclass_t *libclass, hbool_t is_collective, + hid_t *acspl_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params); H5_DLL herr_t H5VL_setup_self_args(hid_t loc_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params); H5_DLL herr_t H5VL_setup_name_args(hid_t loc_id, const char *name, const struct H5P_libclass_t *libclass, - hbool_t is_collective, hid_t acspl_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params); + hbool_t is_collective, hid_t acspl_id, H5VL_object_t **vol_obj, + H5VL_loc_params_t *loc_params); H5_DLL herr_t H5VL_setup_idx_args(hid_t loc_id, const char *name, H5_index_t idx_type, H5_iter_order_t order, - hsize_t n, const struct H5P_libclass_t *libclass, hbool_t is_collective, - hid_t acspl_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params); - + hsize_t n, const struct H5P_libclass_t *libclass, hbool_t is_collective, + hid_t acspl_id, H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params); +H5_DLL herr_t H5VL_setup_token_args(hid_t loc_id, H5R_ref_t *ref_ptr, H5O_token_t obj_token, + H5VL_object_t **vol_obj, H5VL_loc_params_t *loc_params); /********************************** * VOL connector callback wrappers