From f9c3aeff1271697fdc7842ecb83ade5c6837a99c Mon Sep 17 00:00:00 2001 From: Mohamad Chaarawi Date: Mon, 25 Aug 2014 12:12:45 -0500 Subject: [svn-r25549] Implement 4 new routines: H5VLinitialize, H5VLterminate, H5VLget_plugin_id, H5VLclose Add simple tests in external log plugin. Fix some bugs with terminating Native plugin. --- examples/h5_vol_external_log_native.c | 28 ++++++- src/H5VL.c | 147 ++++++++++++++++++++++++++++++++-- src/H5VLint.c | 30 ------- src/H5VLnative.c | 8 +- src/H5VLprivate.h | 1 - src/H5VLpublic.h | 12 +-- 6 files changed, 173 insertions(+), 53 deletions(-) diff --git a/examples/h5_vol_external_log_native.c b/examples/h5_vol_external_log_native.c index 625403f..d563441 100644 --- a/examples/h5_vol_external_log_native.c +++ b/examples/h5_vol_external_log_native.c @@ -6,6 +6,9 @@ #define LOG 502 +static herr_t H5VL_log_init(hid_t vipl_id); +static herr_t H5VL_log_term(hid_t vtpl_id); + /* Datatype callbacks */ static void *H5VL_log_datatype_commit(void *obj, H5VL_loc_params_t loc_params, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id, hid_t dxpl_id, void **req); static void *H5VL_log_datatype_open(void *obj, H5VL_loc_params_t loc_params, const char *name, hid_t tapl_id, hid_t dxpl_id, void **req); @@ -40,8 +43,8 @@ static herr_t H5VL_log_object_specific(void *obj, H5VL_loc_params_t loc_params, static const H5VL_class_t H5VL_log_g = { LOG, "log", /* name */ - NULL, /* initialize */ - NULL, /* terminate */ + H5VL_log_init, /* initialize */ + H5VL_log_term, /* terminate */ sizeof(hid_t), NULL, NULL, @@ -147,7 +150,7 @@ int main(int argc, char **argv) { hid_t datasetId; hid_t acc_tpl; hid_t under_fapl; - hid_t vol_id; + hid_t vol_id, vol_id2; hid_t int_id; hid_t attr; hid_t space; @@ -164,6 +167,10 @@ int main(int argc, char **argv) { vol_id = H5VLregister (&H5VL_log_g); assert(H5VLis_registered(&H5VL_log_g) == 1); + vol_id2 = H5VLget_plugin_id(&H5VL_log_g); + H5VLinitialize(vol_id2, H5P_DEFAULT); + H5VLclose(vol_id2); + acc_tpl = H5Pcreate (H5P_FILE_ACCESS); H5Pset_vol(acc_tpl, vol_id, &under_fapl); @@ -240,12 +247,25 @@ int main(int argc, char **argv) { H5Fclose(file_id); H5Pclose(acc_tpl); H5Pclose(under_fapl); - + + H5VLterminate(vol_id, H5P_DEFAULT); H5VLunregister (vol_id); assert(H5VLis_registered(&H5VL_log_g) == 0); return 0; } +static herr_t H5VL_log_init(hid_t vipl_id) +{ + printf("------- LOG INIT\n"); + return 0; +} + +static herr_t H5VL_log_term(hid_t vtpl_id) +{ + printf("------- LOG TERM\n"); + return 0; +} + static void * H5VL_log_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, hid_t dxpl_id, void **req) { diff --git a/src/H5VL.c b/src/H5VL.c index 8d88e9a..485bc57 100644 --- a/src/H5VL.c +++ b/src/H5VL.c @@ -194,19 +194,14 @@ H5VL_term_interface(void) static herr_t H5VL_free_cls(H5VL_class_t *cls) { - herr_t ret_value = SUCCEED; - - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_NOAPI_NOINIT_NOERR /* Sanity check */ HDassert(cls); - if(cls->terminate && cls->terminate() < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTCLOSEOBJ, FAIL, "vol plugin '%s' did not terminate cleanly", cls->name) - H5MM_free(cls); -done: - FUNC_LEAVE_NOAPI(ret_value) + + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5VL_free_cls() */ @@ -293,6 +288,70 @@ done: /*------------------------------------------------------------------------- + * Function: H5VLinitialize + * + * Purpose: Calls the plugin specific callback to init the plugin. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Mohamad Chaarawi + * August 2014 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VLinitialize(hid_t plugin_id, hid_t vipl_id) +{ + H5VL_class_t *cls = NULL; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + + /* Check args */ + if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(plugin_id, H5I_VOL))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL plugin ID") + + if(cls->initialize && cls->initialize(vipl_id) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTCLOSEOBJ, FAIL, "VOL plugin did not initialize") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5VLinitialize() */ + + +/*------------------------------------------------------------------------- + * Function: H5VLterminate + * + * Purpose: + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Mohamad Chaarawi + * August 2014 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VLterminate(hid_t plugin_id, hid_t vtpl_id) +{ + H5VL_class_t *cls = NULL; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + + /* Check args */ + if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(plugin_id, H5I_VOL))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL plugin ID") + + if(cls->terminate && cls->terminate(vtpl_id) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTCLOSEOBJ, FAIL, "VOL plugin did not terminate cleanly") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5VLterminate() */ + + +/*------------------------------------------------------------------------- * Function: H5VL__is_registered_cb * * Purpose: Callback routine to search through registered VLs @@ -364,6 +423,46 @@ done: /*------------------------------------------------------------------------- + * Function: H5VLget_plugin_id + * + * Purpose: Retrieves the registered plugin ID for a VOL. + * + * Return: Positive if the VOL class has been registered + * Negative on error (if the class is not a valid class or not registered) + * + * Programmer: Mohamad Chaarawi + * August 2014 + * + *------------------------------------------------------------------------- + */ +hid_t +H5VLget_plugin_id(const H5VL_class_t *cls) +{ + H5VL_is_registered_ud_t op_data; + hid_t ret_value = FAIL; /* Return value */ + + FUNC_ENTER_API(FAIL) + + op_data.ret_id = FAIL; + op_data.vol_cls = cls; + + /* Check arguments */ + if(H5I_iterate(H5I_VOL, H5VL__is_registered_cb, &op_data, TRUE) < 0) + HGOTO_ERROR(H5E_VOL, H5E_BADITER,FAIL, "can't iterate over VOL ids") + + if(op_data.ret_id != FAIL) { + if(H5I_inc_ref(op_data.ret_id, TRUE) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINC, FAIL, "unable to increment ref count on VOL plugin") + + ret_value = op_data.ret_id; + } + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5VLget_plugin_id() */ + + +/*------------------------------------------------------------------------- * Function: H5VLget_plugin_name * * Purpose: Returns the plugin name for the VOL associated with the @@ -393,6 +492,38 @@ done: } /* end H5VLget_plugin_name() */ +/*------------------------------------------------------------------------- + * Function: H5VLclose + * + * Purpose: Closes the specified VOL plugin. The VOL ID will no longer be + * valid for accessing the VOL. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Mohamad Chaarawi + * August 2014 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VLclose(hid_t vol_id) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + + /* Check args */ + if(NULL == H5I_object_verify(vol_id,H5I_VOL)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL plugin ID") + + if(H5I_dec_app_ref(vol_id) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to close VOL plugin ID") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5VLclose() */ + + /*--------------------------------------------------------------------------- * Function: H5VLobject_register * diff --git a/src/H5VLint.c b/src/H5VLint.c index 01d4bbb..bfdd35e 100644 --- a/src/H5VLint.c +++ b/src/H5VLint.c @@ -256,36 +256,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5VL_close - * - * Purpose: decrements the ref count on the number of references - * outstanding for a VOL plugin - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Mohamad Chaarawi - * May, 2012 - * - *------------------------------------------------------------------------- - */ -herr_t -H5VL_close(H5VL_class_t *cls) -{ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_NOAPI(FAIL) - - if(cls->terminate && cls->terminate() < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTCLOSEOBJ, FAIL, "VOL plugin did not terminate cleanly") - - H5MM_xfree(cls); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_close() */ - - -/*------------------------------------------------------------------------- * Function: H5VL_get_plugin_name * * Purpose: Private version of H5VLget_plugin_name diff --git a/src/H5VLnative.c b/src/H5VLnative.c index 1dc6bcc..295f146 100644 --- a/src/H5VLnative.c +++ b/src/H5VLnative.c @@ -61,8 +61,6 @@ static hid_t H5VL_NATIVE_g = 0; /* Prototypes */ static H5F_t *H5VL_native_get_file(void *obj, H5I_type_t type); -static herr_t H5VL_native_term(void); - /* Atrribute callbacks */ static void *H5VL_native_attr_create(void *obj, H5VL_loc_params_t loc_params, const char *attr_name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); static void *H5VL_native_attr_open(void *obj, H5VL_loc_params_t loc_params, const char *attr_name, hid_t aapl_id, hid_t dxpl_id, void **req); @@ -128,7 +126,7 @@ static H5VL_class_t H5VL_native_g = { NATIVE, "native", /* name */ NULL, /* initialize */ - H5VL_native_term, /* terminate */ + NULL, /* terminate */ 0, /* fapl_size */ NULL, /* fapl_copy */ NULL, /* fapl_free */ @@ -244,7 +242,7 @@ H5VL_native_init(void) FUNC_ENTER_NOAPI(FAIL) /* Register the Native VOL, if it isn't already */ - if(H5I_VOL != H5I_get_type(H5VL_NATIVE_g)) { + if(NULL == H5I_object_verify(H5VL_NATIVE_g, H5I_VOL)) { if((H5VL_NATIVE_g = H5VL_register((const H5VL_class_t *)&H5VL_native_g, sizeof(H5VL_class_t), FALSE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTINSERT, FAIL, "can't create ID for native plugin") @@ -257,6 +255,7 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_native_init() */ +#if 0 /*--------------------------------------------------------------------------- * Function: H5VL_native_term @@ -277,6 +276,7 @@ H5VL_native_term(void) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5VL_native_term() */ +#endif /*--------------------------------------------------------------------------- diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index 005e362..0509a47 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -50,7 +50,6 @@ H5_DLL hid_t H5VL_register(const void *cls, size_t size, hbool_t app_ref); H5_DLL hid_t H5VL_object_register(void *obj, H5I_type_t obj_type, H5VL_t *vol_plugin, hbool_t app_ref); H5_DLL ssize_t H5VL_get_plugin_name(hid_t id, char *name/*out*/, size_t size); H5_DLL void *H5VL_get_object(hid_t id); -H5_DLL herr_t H5VL_close(H5VL_class_t *vol_plugin); H5_DLL void *H5VL_attr_create(void *obj, H5VL_loc_params_t loc_params, H5VL_t *vol_plugin, const char *attr_name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); H5_DLL void *H5VL_attr_open(void *obj, H5VL_loc_params_t loc_params, H5VL_t *vol_plugin, const char *name, hid_t aapl_id, hid_t dxpl_id, void **req); diff --git a/src/H5VLpublic.h b/src/H5VLpublic.h index d0598d3..77b935b 100644 --- a/src/H5VLpublic.h +++ b/src/H5VLpublic.h @@ -327,8 +327,8 @@ typedef enum H5VL_class_value_t { typedef struct H5VL_class_t { H5VL_class_value_t value; const char *name; - herr_t (*initialize)(void); - herr_t (*terminate)(void); + herr_t (*initialize)(hid_t vipl_id); + herr_t (*terminate)(hid_t vtpl_id); size_t fapl_size; void * (*fapl_copy)(const void *info); herr_t (*fapl_free)(void *info); @@ -426,6 +426,10 @@ H5_DLL herr_t H5VLrequest_test(void **req, H5VL_t *vol_plugin, H5ES_status_t *st H5_DLL herr_t H5VLrequest_wait(void **req, H5VL_t *vol_plugin, H5ES_status_t *status); /* Function prototypes */ +H5_DLL herr_t H5VLinitialize(hid_t plugin_id, hid_t vipl_id); +H5_DLL herr_t H5VLterminate(hid_t plugin_id, hid_t vtpl_id); +H5_DLL hid_t H5VLget_plugin_id(const H5VL_class_t *cls); +H5_DLL herr_t H5VLclose(hid_t plugin_id); H5_DLL hid_t H5VLregister(const H5VL_class_t *cls); H5_DLL herr_t H5VLunregister(hid_t plugin_id); H5_DLL htri_t H5VLis_registered(const H5VL_class_t *cls); @@ -434,10 +438,6 @@ H5_DLL hid_t H5VLobject_register(void *obj, H5I_type_t obj_type, const H5VL_clas H5_DLL herr_t H5VLget_object(hid_t obj_id, void **obj, H5VL_t **vol_plugin); #if 0 H5_DLL hid_t H5VLregister_by_name(const char *plugin_name); - H5_DLL herr_t H5VLinitialize(hid_t plugin_id, hid_t vipl_id); - H5_DLL herr_t H5VLterminate(hid_t plugin_id, hid_t vtpl_id); - H5_DLL hid_t H5VLget_plugin_id(H5VL_class_value_t or char *); - H5_DLL herr_t H5VLclose(hid_t plugin_id); H5_DLL herr_t H5VLioctl(hid_t loc_id or vol_id, , ...); #endif -- cgit v0.12