diff options
author | Mohamad Chaarawi <chaarawi@hdfgroup.org> | 2014-09-05 21:36:55 (GMT) |
---|---|---|
committer | Mohamad Chaarawi <chaarawi@hdfgroup.org> | 2014-09-05 21:36:55 (GMT) |
commit | 05d51c036140f94a07efb75aab9675b3b4bd5ef0 (patch) | |
tree | 5fe046db1c355df5c771077164ba6d6c1f272866 /src/H5Tcommit.c | |
parent | f2e6cec0728a75f5982e3b6d91f0ce823d1206a6 (diff) | |
download | hdf5-05d51c036140f94a07efb75aab9675b3b4bd5ef0.zip hdf5-05d51c036140f94a07efb75aab9675b3b4bd5ef0.tar.gz hdf5-05d51c036140f94a07efb75aab9675b3b4bd5ef0.tar.bz2 |
[svn-r25575] cleanup H5I usage in VOL by removing the use of the aux pointer and
make a higher level wrapper object around all VOL objects that
includes the VOL information.
Diffstat (limited to 'src/H5Tcommit.c')
-rw-r--r-- | src/H5Tcommit.c | 271 |
1 files changed, 119 insertions, 152 deletions
diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c index ed4d37b..315920e 100644 --- a/src/H5Tcommit.c +++ b/src/H5Tcommit.c @@ -82,6 +82,10 @@ static H5T_t *H5T_open_oid(const H5G_loc_t *loc, hid_t dxpl_id); /* Local Variables */ /*******************/ +/* Declare a free list to manage the H5VL_t struct */ +H5FL_EXTERN(H5VL_t); +/* Declare a free list to manage the H5VL_object_t struct */ +H5FL_EXTERN(H5VL_object_t); /*-------------------------------------------------------------------------- @@ -123,12 +127,12 @@ 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) { - void *dt = NULL; - H5T_t *type = NULL; - void *obj = NULL; /* object token of loc_id */ - H5VL_t *vol_plugin; /* VOL plugin information */ + void *dt = NULL; /* datatype object created by VOL plugin */ + H5VL_object_t *new_obj = NULL; /* VOL object that holds the datatype object and the VOL info */ + H5T_t *type = NULL; /* high level datatype object that wraps the VOL object */ + H5VL_object_t *obj = NULL; /* object token of loc_id */ H5VL_loc_params_t loc_params; - herr_t ret_value = SUCCEED; /* Return value */ + 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); @@ -138,7 +142,7 @@ H5Tcommit2(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name") if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") - if(H5T_committed(type)) + if(H5T_is_named(type)) HGOTO_ERROR(H5E_ARGS, H5E_CANTSET, FAIL, "datatype is already committed") /* Get correct property list */ @@ -166,29 +170,24 @@ H5Tcommit2(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, loc_params.obj_type = H5I_get_type(loc_id); /* get the object from the loc_id */ - if(NULL == (obj = (void *)H5I_object(loc_id))) + if(NULL == (obj = (H5VL_object_t *)H5I_object(loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - /* get the plugin pointer */ - if (NULL == (vol_plugin = (H5VL_t *)H5I_get_aux(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "ID does not contain VOL information") /* commit the datatype through the VOL */ - if (NULL == (dt = H5VL_datatype_commit(obj, loc_params, vol_plugin->cls, name, type_id, lcpl_id, - tcpl_id, tapl_id, H5AC_dxpl_id, H5_REQUEST_NULL))) + if (NULL == (dt = H5VL_datatype_commit(obj->vol_obj, loc_params, obj->vol_info->vol_cls, + name, type_id, lcpl_id, tcpl_id, tapl_id, + H5AC_dxpl_id, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to commit datatype") - /* attach the vol object created using the commit call to the - library datatype structure */ - /* set the committed type object to the VOL pluging pointer in the H5T_t struct */ - type->vol_obj = dt; - - /* attach VOL information to the ID */ - if (H5I_register_aux(type_id, vol_plugin) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") + /* setup VOL object */ + if(NULL == (new_obj = H5FL_CALLOC(H5VL_object_t))) + HGOTO_ERROR(H5E_VOL, H5E_NOSPACE, FAIL, "can't allocate top object structure") + new_obj->vol_info = obj->vol_info; + new_obj->vol_info->nrefs ++; + new_obj->vol_obj = dt; - vol_plugin->nrefs ++; - if(H5I_inc_ref(vol_plugin->id, FALSE) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINC, FAIL, "unable to increment ref count on VOL plugin") + /* set the committed type object to the VOL pluging pointer in the H5T_t struct */ + type->vol_obj = new_obj; done: FUNC_LEAVE_API(ret_value) @@ -299,12 +298,12 @@ done: herr_t H5Tcommit_anon(hid_t loc_id, hid_t type_id, hid_t tcpl_id, hid_t tapl_id) { - void *dt = NULL; - H5T_t *type = NULL; - void *obj = NULL; /* object token of loc_id */ - H5VL_t *vol_plugin; /* VOL plugin information */ + void *dt = NULL; /* datatype object created by VOL plugin */ + H5VL_object_t *new_obj = NULL; /* VOL object that holds the datatype object and the VOL info */ + H5T_t *type = NULL; /* high level datatype object that wraps the VOL object */ + H5VL_object_t *obj = NULL; /* object token of loc_id */ H5VL_loc_params_t loc_params; - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE4("e", "iiii", loc_id, type_id, tcpl_id, tapl_id); @@ -312,7 +311,7 @@ H5Tcommit_anon(hid_t loc_id, hid_t type_id, hid_t tcpl_id, hid_t tapl_id) /* check args */ if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") - if(H5T_committed(type)) + if(H5T_is_named(type)) HGOTO_ERROR(H5E_ARGS, H5E_CANTSET, FAIL, "datatype is already committed") /* Get correct property list */ @@ -333,27 +332,24 @@ H5Tcommit_anon(hid_t loc_id, hid_t type_id, hid_t tcpl_id, hid_t tapl_id) loc_params.obj_type = H5I_get_type(loc_id); /* get the file object */ - if(NULL == (obj = (void *)H5I_object(loc_id))) + if(NULL == (obj = (H5VL_object_t *)H5I_object(loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") - /* get the plugin pointer */ - if (NULL == (vol_plugin = (H5VL_t *)H5I_get_aux(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "ID does not contain VOL information") /* commite the datatype through the VOL */ - if (NULL == (dt = H5VL_datatype_commit(obj, loc_params, vol_plugin->cls, NULL, type_id, H5P_DEFAULT, - tcpl_id, tapl_id, H5AC_dxpl_id, H5_REQUEST_NULL))) + if (NULL == (dt = H5VL_datatype_commit(obj->vol_obj, loc_params, obj->vol_info->vol_cls, + NULL, type_id, H5P_DEFAULT, tcpl_id, tapl_id, + H5AC_dxpl_id, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to commit datatype") - /* set the committed type object to the VOL pluging pointer in the H5T_t struct */ - type->vol_obj = dt; + /* setup VOL object */ + if(NULL == (new_obj = H5FL_CALLOC(H5VL_object_t))) + HGOTO_ERROR(H5E_VOL, H5E_NOSPACE, FAIL, "can't allocate top object structure") + new_obj->vol_info = obj->vol_info; + new_obj->vol_info->nrefs ++; + new_obj->vol_obj = dt; - /* attach VOL information to the ID */ - if (H5I_register_aux(type_id, vol_plugin) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - - vol_plugin->nrefs ++; - if(H5I_inc_ref(vol_plugin->id, FALSE) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINC, FAIL, "unable to increment ref count on VOL plugin") + /* set the committed type object to the VOL pluging pointer in the H5T_t struct */ + type->vol_obj = new_obj; done: FUNC_LEAVE_API(ret_value) @@ -510,7 +506,7 @@ H5Tcommitted(hid_t type_id) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") /* Set return value */ - ret_value = H5T_committed(type); + ret_value = H5T_is_named(type); done: FUNC_LEAVE_API(ret_value) @@ -518,36 +514,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5T_committed - * - * Purpose: Determines if a datatype is committed or not. - * - * Return: Success: TRUE if committed, FALSE otherwise. - * - * Programmer: Quincey Koziol - * Wednesday, September 24, 2003 - * - *------------------------------------------------------------------------- - */ -htri_t -H5T_committed(const H5T_t *type) -{ - htri_t ret_value; - - FUNC_ENTER_NOAPI_NOINIT_NOERR - - HDassert(type); - - if(type->vol_obj) - ret_value = TRUE; - else - ret_value = (H5T_STATE_OPEN == type->shared->state || H5T_STATE_NAMED == type->shared->state); - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_committed() */ - - -/*------------------------------------------------------------------------- * Function: H5T_link * * Purpose: Adjust the link count for an object header by adding @@ -597,11 +563,10 @@ done: hid_t H5Topen2(hid_t loc_id, const char *name, hid_t tapl_id) { - void *dt = NULL; /* datatype token from VOL plugin */ - void *obj = NULL; /* object token of loc_id */ - H5VL_t *vol_plugin; /* VOL plugin information */ + void *vol_dt = NULL; /* datatype token created by VOL plugin */ + H5VL_object_t *obj = NULL; /* object token of loc_id */ H5VL_loc_params_t loc_params; - hid_t ret_value = FAIL; /* Return value */ + hid_t ret_value = FAIL; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE3("i", "i*si", loc_id, name, tapl_id); @@ -620,26 +585,23 @@ H5Topen2(hid_t loc_id, const char *name, hid_t tapl_id) loc_params.type = H5VL_OBJECT_BY_SELF; loc_params.obj_type = H5I_get_type(loc_id); - /* get the file object */ - if(NULL == (obj = (void *)H5I_object(loc_id))) + /* get the location object */ + if(NULL == (obj = (H5VL_object_t *)H5I_object(loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") - /* get the plugin pointer */ - if (NULL == (vol_plugin = (H5VL_t *)H5I_get_aux(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "ID does not contain VOL information") /* Create the datatype through the VOL */ - if(NULL == (dt = H5VL_datatype_open(obj, loc_params, vol_plugin->cls, name, tapl_id, - H5AC_dxpl_id, H5_REQUEST_NULL))) + if(NULL == (vol_dt = H5VL_datatype_open(obj->vol_obj, loc_params, obj->vol_info->vol_cls, + name, tapl_id, H5AC_dxpl_id, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open datatype") /* Get an atom for the datatype */ - if ((ret_value = H5VL_create_datatype(dt, vol_plugin, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize datatype handle") + if((ret_value = H5VL_register_id(H5I_DATATYPE, vol_dt, obj->vol_info, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize datatype handle") done: - if (ret_value < 0 && dt) - if(H5VL_datatype_close (dt, vol_plugin->cls, H5AC_dxpl_id, H5_REQUEST_NULL) < 0) - HDONE_ERROR(H5E_SYM, H5E_CLOSEERROR, FAIL, "unable to release dataset") + if (ret_value < 0 && vol_dt) + if(H5VL_datatype_close (vol_dt, obj->vol_info->vol_cls, H5AC_dxpl_id, H5_REQUEST_NULL) < 0) + HDONE_ERROR(H5E_SYM, H5E_CLOSEERROR, FAIL, "unable to release datatype") FUNC_LEAVE_API(ret_value) } /* end H5Topen2() */ @@ -676,7 +638,7 @@ H5Tget_create_plist(hid_t dtype_id) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") /* Check if the datatype is committed */ - if((status = H5T_committed(type)) < 0) + if((status = H5T_is_named(type)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't check whether datatype is committed") /* If the datatype is not committed, just copy the default @@ -691,18 +653,10 @@ H5Tget_create_plist(hid_t dtype_id) /* If the datatype is committed, let the VOL create the creation property list ID. */ else if(TRUE == status) { - H5VL_t *vol_plugin; /* VOL plugin information */ - - /* get the plugin pointer */ - if (NULL == (vol_plugin = (H5VL_t *)H5I_get_aux(dtype_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "ID does not contain VOL information") - - /* get the named datatype object */ - if(NULL == (type = (H5T_t *)H5VL_get_object(dtype_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") + H5VL_object_t *vol_dt = type->vol_obj; /* get the rest of the plist through the VOL */ - if(H5VL_datatype_get(type, vol_plugin->cls, H5VL_DATATYPE_GET_TCPL, + if(H5VL_datatype_get(vol_dt->vol_obj, vol_dt->vol_info->vol_cls, H5VL_DATATYPE_GET_TCPL, H5AC_ind_dxpl_id, H5_REQUEST_NULL, &ret_value) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get datatype") } /* end if */ @@ -916,8 +870,7 @@ H5T_update_shared(H5T_t *dt) /*------------------------------------------------------------------------- * Function: H5T_get_named_type * - * Purpose: returns the VOL object or the named datatype structure - * if it exists + * Purpose: returns the VOL object for the named datatype if it exists * * Return: Success: Pointer to the VOL Datatype object * @@ -928,10 +881,10 @@ H5T_update_shared(H5T_t *dt) * *------------------------------------------------------------------------- */ -void * +H5VL_object_t * H5T_get_named_type(const H5T_t *dt) { - void *ret_value = NULL; /* Return value */ + H5VL_object_t *ret_value = NULL; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -943,7 +896,40 @@ H5T_get_named_type(const H5T_t *dt) /*------------------------------------------------------------------------- - * Function: H5VL_create_datatype + * Function: H5T_get_actual_type + * + * Purpose: returns underlying native datatype created by native plugin + * if datatype is committed, otherwise return the datatype + * object associate with the ID. + * + * Return: Success: Pointer to the VOL Datatype object + * + * Failure: NULL + * + * Programmer: Mohamad Chaarawi + * September 2014 + * + *------------------------------------------------------------------------- + */ +H5T_t * +H5T_get_actual_type(const H5T_t *dt) +{ + H5T_t *ret_value = NULL; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT_NOERR + + /* Check if the datatype is committed */ + if(NULL == dt->vol_obj) + ret_value = dt; + else + ret_value = (H5T_t *)dt->vol_obj->vol_obj; + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T_get_actual_type() */ + + +/*------------------------------------------------------------------------- + * Function: H5T_construct_datatype * * Purpose: Create a Library datatype with a plugin specific datatype object * @@ -956,43 +942,42 @@ H5T_get_named_type(const H5T_t *dt) * *------------------------------------------------------------------------- */ -hid_t -H5VL_create_datatype(void *dt_obj, H5VL_t *vol_plugin, hbool_t app_ref) +H5T_t * +H5T_construct_datatype(H5VL_object_t *dt_obj) { ssize_t nalloc; void *buf = NULL; H5T_t *dt = NULL; /* datatype token from VOL plugin */ - hid_t ret_value = FAIL; + H5T_t *ret_value = NULL; - FUNC_ENTER_NOAPI(FAIL) + FUNC_ENTER_NOAPI(NULL) /* get required buf size for encoding the datatype */ - if(H5VL_datatype_get(dt_obj, vol_plugin->cls, H5VL_DATATYPE_GET_BINARY, + if(H5VL_datatype_get(dt_obj->vol_obj, dt_obj->vol_info->vol_cls, H5VL_DATATYPE_GET_BINARY, H5AC_dxpl_id, H5_REQUEST_NULL, &nalloc, NULL, 0) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to get datatype serialized size") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to get datatype serialized size") /* allocate buffer to store binary description of the datatype */ if (NULL == (buf = (void *) H5MM_malloc ((size_t)nalloc))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate space for datatype") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't allocate space for datatype") /* get binary description of the datatype */ - if(H5VL_datatype_get(dt_obj, vol_plugin->cls, H5VL_DATATYPE_GET_BINARY, + if(H5VL_datatype_get(dt_obj->vol_obj, dt_obj->vol_info->vol_cls, H5VL_DATATYPE_GET_BINARY, H5AC_dxpl_id, H5_REQUEST_NULL, &nalloc, buf, (size_t)nalloc) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to get serialized datatype") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to get serialized datatype") + + if(NULL == (dt = H5T_decode((const unsigned char *)buf))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "can't decode datatype") - if(NULL == (dt = H5T_decode((const unsigned char *)buf))) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "can't decode datatype") dt->vol_obj = dt_obj; H5MM_free(buf); - /* Get an atom for the datatype with the VOL information as the auxilary struct*/ - if((ret_value = H5VL_register_id(H5I_DATATYPE, dt, vol_plugin, app_ref)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize datatype handle") + ret_value = dt; done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_create_datatype() */ +} /* end H5T_construct_datatype() */ /*------------------------------------------------------------------------- @@ -1010,47 +995,29 @@ done: *------------------------------------------------------------------------- */ herr_t -H5T_close_datatype(void *type, H5VL_t *vol_plugin) +H5T_close_datatype(void *type) { H5T_t *dt = (H5T_t *)type; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - /* Close the datatype through the VOL*/ if (NULL != dt->vol_obj) { - if((ret_value = H5VL_datatype_close(dt->vol_obj, vol_plugin->cls, H5AC_dxpl_id, H5_REQUEST_NULL)) < 0) + H5VL_object_t *vol_dt = dt->vol_obj; + + /* Close the datatype through the VOL*/ + if((ret_value = H5VL_datatype_close(vol_dt->vol_obj, vol_dt->vol_info->vol_cls, + H5AC_dxpl_id, H5_REQUEST_NULL)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to close datatype") - /* decrement ref count on VOL ID */ - if(H5VL_free_id(vol_plugin) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement ref count on VOL plugin") + /* free attribute */ + if(H5VL_free_object(vol_dt) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTDEC, FAIL, "unable to free VOL object") } + if((ret_value = H5T_close(dt)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to close datatype") + done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T_close_datatype() */ - - -/*------------------------------------------------------------------------- - * Function: H5T_set_vol_object - * - * Purpose: Set the vol_object in the H5T_t struct. - * Called from outside the H5T package - * - * Return: Succeed - * - * Programmer: Mohamad Chaarawi - * June 2012 - * - *------------------------------------------------------------------------- - */ -herr_t -H5T_set_vol_object(H5T_t *type, void *vol_obj) -{ - FUNC_ENTER_NOAPI_NOINIT_NOERR - - type->vol_obj = vol_obj; - - FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5T_set_vol_object() */ |