diff options
Diffstat (limited to 'src/H5Pfapl.c')
-rw-r--r-- | src/H5Pfapl.c | 564 |
1 files changed, 564 insertions, 0 deletions
diff --git a/src/H5Pfapl.c b/src/H5Pfapl.c index 319dc77..e32a077 100644 --- a/src/H5Pfapl.c +++ b/src/H5Pfapl.c @@ -40,6 +40,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* Files */ #include "H5FDprivate.h" /* File drivers */ +#include "H5VLprivate.h" /* VOL plugins */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory Management */ #include "H5Ppkg.h" /* Property lists */ @@ -47,6 +48,10 @@ /* Includes needed to set as default file driver */ #include "H5FDsec2.h" /* Posix unbuffered I/O file driver */ #include "H5FDstdio.h" /* Standard C buffered I/O */ + +/* Includes needed to set as default VOL driver */ +#include "H5VLnative.h" /* Native H5 VOL plugin */ + #ifdef H5_HAVE_WINDOWS #include "H5FDwindows.h" /* Windows buffered I/O */ #endif @@ -159,6 +164,19 @@ #define H5F_ACS_EFC_SIZE_DEF 0 #define H5F_ACS_EFC_SIZE_ENC H5P__encode_unsigned #define H5F_ACS_EFC_SIZE_DEC H5P__decode_unsigned + +/* Definition for file VOL plugin ID & info */ +#define H5F_ACS_VOL_SIZE sizeof(H5VL_plugin_prop_t) +#define H5F_ACS_VOL_DEF {H5_DEFAULT_VOL, NULL} +#define H5F_ACS_VOL_CRT H5P__facc_vol_create +#define H5F_ACS_VOL_SET H5P__facc_vol_set +#define H5F_ACS_VOL_GET H5P__facc_vol_get +#define H5F_ACS_VOL_DEL H5P__facc_vol_del +#define H5F_ACS_VOL_COPY H5P__facc_vol_copy +#define H5F_ACS_VOL_CMP H5P__facc_vol_cmp +#define H5F_ACS_VOL_CLOSE H5P__facc_vol_close + + /* Definition of pointer to initial file image info */ #define H5F_ACS_FILE_IMAGE_INFO_SIZE sizeof(H5FD_file_image_info_t) #define H5F_ACS_FILE_IMAGE_INFO_DEF H5FD_DEFAULT_FILE_IMAGE_INFO @@ -205,6 +223,15 @@ static herr_t H5P__facc_file_driver_copy(const char *name, size_t size, void *va static int H5P__facc_file_driver_cmp(const void *value1, const void *value2, size_t size); static herr_t H5P__facc_file_driver_close(const char *name, size_t size, void *value); +/* File vol plugin ID & info property callbacks */ +static herr_t H5P__facc_vol_create(const char *name, size_t size, void *value); +static herr_t H5P__facc_vol_set(hid_t prop_id, const char *name, size_t size, void *value); +static herr_t H5P__facc_vol_get(hid_t prop_id, const char *name, size_t size, void *value); +static herr_t H5P__facc_vol_del(hid_t prop_id, const char *name, size_t size, void *value); +static herr_t H5P__facc_vol_copy(const char *name, size_t size, void *value); +static int H5P__facc_vol_cmp(const void *value1, const void *value2, size_t size); +static herr_t H5P__facc_vol_close(const char *name, size_t size, void *value); + /* File image info property callbacks */ static herr_t H5P__file_image_info_copy(void *value); static herr_t H5P__file_image_info_free(void *value); @@ -298,6 +325,8 @@ static herr_t H5P__facc_reg_prop(H5P_genclass_t *pclass) { const H5FD_driver_prop_t def_driver_prop = H5F_ACS_FILE_DRV_DEF; /* Default VFL driver ID & info (initialized from a variable) */ + const H5VL_plugin_prop_t def_vol_prop = H5F_ACS_VOL_DEF; /* Default VOL plugin ID & info (initialized from a variable) */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -369,6 +398,13 @@ H5P__facc_reg_prop(H5P_genclass_t *pclass) H5F_ACS_FILE_DRV_DEL, H5F_ACS_FILE_DRV_COPY, H5F_ACS_FILE_DRV_CMP, H5F_ACS_FILE_DRV_CLOSE) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") + /* Register the file VOL plugin ID & info */ + /* (Note: this property should not have an encode/decode callback -QAK) */ + if(H5P_register_real(pclass, H5F_ACS_VOL_NAME, H5F_ACS_VOL_SIZE, &def_vol_prop, + H5F_ACS_VOL_CRT, H5F_ACS_VOL_SET, H5F_ACS_VOL_GET, NULL, NULL, + H5F_ACS_VOL_DEL, H5F_ACS_VOL_COPY, H5F_ACS_VOL_CMP, H5F_ACS_VOL_CLOSE) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") + /* Register the file close degree */ if(H5P_register_real(pclass, H5F_ACS_CLOSE_DEGREE_NAME, H5F_CLOSE_DEGREE_SIZE, &H5F_def_close_degree_g, NULL, NULL, NULL, H5F_CLOSE_DEGREE_ENC, H5F_CLOSE_DEGREE_DEC, @@ -2200,6 +2236,534 @@ done: /*------------------------------------------------------------------------- + * Function: H5P_set_vol + * + * Purpose: Set the vol plugin for a file access property list + * (PLIST_ID). The vol properties will + * be copied into the property list and the reference count on + * the vol will be incremented. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * January, 2012 + * + *------------------------------------------------------------------------- + */ +herr_t +H5P_set_vol(H5P_genplist_t *plist, hid_t vol_id, const void *vol_info) +{ + herr_t ret_value=SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + if(NULL == H5I_object_verify(vol_id, H5I_VOL)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL plugin ID") + + if(TRUE == H5P_isa_class(plist->plist_id, H5P_FILE_ACCESS)) { + H5VL_plugin_prop_t vol_prop; /* Property for VOL ID & info */ + + /* Prepare the vol plugin property */ + vol_prop.plugin_id = vol_id; + vol_prop.plugin_info = vol_info; + + /* Set the driver ID & info property */ + if(H5P_set(plist, H5F_ACS_VOL_NAME, &vol_prop) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set VOL plugin ID & info") + } + else + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list"); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P_set_vol() */ + + +/*------------------------------------------------------------------------- + * Function: H5Pset_vol + * + * Purpose: Set the file vol plugin (VOL_ID) for a file access + * property list (PLIST_ID) + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * April, 2012 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Pset_vol(hid_t plist_id, hid_t new_vol_id, const void *new_vol_info) +{ + H5P_genplist_t *plist; /* Property list pointer */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE3("e", "ii*x", plist_id, new_vol_id, new_vol_info); + + /* Check arguments */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object_verify(plist_id, H5I_GENPROP_LST))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") + if(NULL == H5I_object_verify(new_vol_id, H5I_VOL)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file vol ID") + + /* Set the vol */ + if(H5P_set_vol(plist, new_vol_id, new_vol_info) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set vol") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Pset_vol() */ + + +/*------------------------------------------------------------------------- + * Function: H5P_get_vol_info + * + * Purpose: Returns a pointer directly to the file vol-specific + * information of a file access property list. + * + * Return: Success: Ptr to *uncopied* vol specific data + * structure if any. + * + * Failure: NULL. Null is also returned if the vol has + * not registered any vol-specific properties + * although no error is pushed on the stack in + * this case. + * + * Programmer: Mohamad Chaarawi + * July, 2012 + * + *------------------------------------------------------------------------- + */ +void * +H5P_get_vol_info(H5P_genplist_t *plist) +{ + void *ret_value=NULL; + + FUNC_ENTER_NOAPI(NULL) + + /* Get the current vol info */ + if( TRUE == H5P_isa_class(plist->plist_id, H5P_FILE_ACCESS) ) { + H5VL_plugin_prop_t plugin_prop; /* Property for vol plugin ID & info */ + + if(H5P_peek(plist, H5F_ACS_VOL_NAME, &plugin_prop) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get vol plugin info") + ret_value = (void *)plugin_prop.plugin_info; + } else + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P_get_vol_info() */ + + +/*------------------------------------------------------------------------- + * Function: H5Pget_vol_info + * + * Purpose: Returns a pointer directly to the file vol-specific + * information of a file access property list. + * + * Return: Success: Ptr to *uncopied* vol specific data + * structure if any. + * + * Failure: NULL. Null is also returned if the vol has + * not registered any vol-specific properties + * although no error is pushed on the stack in + * this case. + * + * Programmer: Mohamad Chaarawi + * July 2012 + * + *------------------------------------------------------------------------- + */ +void * +H5Pget_vol_info(hid_t plist_id) +{ + H5P_genplist_t *plist; /* Property list pointer */ + void *ret_value; /* Return value */ + + FUNC_ENTER_API(NULL) + H5TRACE1("*x", "i", plist_id); + + if(NULL == (plist = (H5P_genplist_t *)H5I_object_verify(plist_id, H5I_GENPROP_LST))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a property list") + + if(NULL == (ret_value = H5P_get_vol_info(plist))) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get vol info") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Pget_vol_info() */ + + +/*------------------------------------------------------------------------- + * Function: H5P__vol_copy + * + * Purpose: Copy vol plugin ID & info. + * + * Note: This is an "in-place" copy, since this routine gets called + * after the top-level copy has been performed and this routine + * finishes the "deep" part of the copy. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * October, 2015 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5P__vol_copy(void *value) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + if(value) { + H5VL_plugin_prop_t *info = (H5VL_plugin_prop_t *)value; /* Plugin ID & info struct */ + + /* Copy the plugin & info, if there is one */ + if(info->plugin_id > 0) { + /* Increment the reference count on plugin and copy plugin info */ + if(H5I_inc_ref(info->plugin_id, FALSE) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTINC, FAIL, "unable to increment ref count on VFL plugin") + + /* Copy plugin info, if it exists */ + if(info->plugin_info) { + H5VL_class_t *plugin; /* Pointer to plugin */ + void *new_pl; /* Copy of plugin info */ + + /* Retrieve the plugin for the ID */ + if(NULL == (plugin = (H5VL_class_t *)H5I_object(info->plugin_id))) + HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a plugin ID") + + /* Allow the plugin to copy or do it ourselves */ + if(plugin->fapl_copy) { + if(NULL == (new_pl = (plugin->fapl_copy)(info->plugin_info))) + HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "plugin info copy failed") + } /* end if */ + else if(plugin->fapl_size > 0) { + if(NULL == (new_pl = H5MM_malloc(plugin->fapl_size))) + HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "plugin info allocation failed") + HDmemcpy(new_pl, info->plugin_info, plugin->fapl_size); + } /* end else-if */ + else + HGOTO_ERROR(H5E_PLIST, H5E_UNSUPPORTED, FAIL, "no way to copy plugin info") + + /* Set the plugin info for the copy */ + info->plugin_info = new_pl; + } /* end if */ + } /* end if */ + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P__vol_copy() */ + + +/*------------------------------------------------------------------------- + * Function: H5P__vol_free + * + * Purpose: Free vol plugin ID & info. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * October, 2015 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5P__vol_free(void *value) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + if(value) { + H5VL_plugin_prop_t *info = (H5VL_plugin_prop_t *)value; /* Plugin ID & info struct */ + + /* Copy the plugin & info, if there is one */ + if(info->plugin_id > 0) { + if(info->plugin_info) { + H5VL_class_t *plugin; /* Pointer to plugin */ + + /* Retrieve the plugin for the ID */ + if(NULL == (plugin = (H5VL_class_t *)H5I_object(info->plugin_id))) + HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a plugin ID") + + /* Allow plugin to free info or do it ourselves */ + if(plugin->fapl_free) { + if((plugin->fapl_free)((void *)info->plugin_info) < 0) /* Casting away const OK -QAK */ + HGOTO_ERROR(H5E_PLIST, H5E_CANTFREE, FAIL, "plugin info free request failed") + } /* end if */ + else + H5MM_xfree((void *)info->plugin_info); /* Casting away const OK -QAK */ + } /* end if */ + + /* Decrement reference count for plugin */ + if(H5I_dec_ref(info->plugin_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTDEC, FAIL, "can't decrement reference count for plugin ID") + } /* end if */ + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P__vol_free() */ + + +/*------------------------------------------------------------------------- + * Function: H5P__facc_vol_create + * + * Purpose: Create callback for the vol plugin ID & info property. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * October, 2015 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5P__facc_vol_create(const char H5_ATTR_UNUSED *name, size_t H5_ATTR_UNUSED size, void *value) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Make copy of file plugin */ + if(H5P__vol_copy(value) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "can't copy vol plugin") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P__facc_vol_create() */ + + +/*------------------------------------------------------------------------- + * Function: H5P__facc_vol_set + * + * Purpose: Copies a vol plugin property when it's set for a property list + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * Monday, Sept 7, 2015 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5P__facc_vol_set(hid_t H5_ATTR_UNUSED prop_id, const char H5_ATTR_UNUSED *name, + size_t H5_ATTR_UNUSED size, void *value) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(value); + + /* Make copy of vol plugin ID & info */ + if(H5P__vol_copy(value) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "can't copy vol plugin") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P__facc_vol_set() */ + + +/*------------------------------------------------------------------------- + * Function: H5P__facc_vol_get + * + * Purpose: Copies a vol plugin property when it's retrieved from a property list + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * Monday, Sept 7, 2015 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5P__facc_vol_get(hid_t H5_ATTR_UNUSED prop_id, const char H5_ATTR_UNUSED *name, + size_t H5_ATTR_UNUSED size, void *value) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(value); + + /* Make copy of vol plugin */ + if(H5P__vol_copy(value) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "can't copy vol plugin") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P__facc_vol_get() */ + + +/*------------------------------------------------------------------------- + * Function: H5P__facc_vol_del + * + * Purpose: Frees memory used to store the plugin ID & info property + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * October, 2015 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5P__facc_vol_del(hid_t H5_ATTR_UNUSED prop_id, const char H5_ATTR_UNUSED *name, size_t H5_ATTR_UNUSED size, void *value) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Free the vol plugin ID & info */ + if(H5P__vol_free(value) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTRELEASE, FAIL, "can't release vol plugin") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P__facc_vol_del() */ + + +/*------------------------------------------------------------------------- + * Function: H5P__facc_vol_copy + * + * Purpose: Copy callback for the vol plugin ID & info property. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * October, 2015 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5P__facc_vol_copy(const char H5_ATTR_UNUSED *name, size_t H5_ATTR_UNUSED size, void *value) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Make copy of vol plugin */ + if(H5P__vol_copy(value) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "can't copy vol plugin") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P__facc_vol_copy() */ + + +/*------------------------------------------------------------------------- + * Function: H5P__facc_vol_cmp + * + * Purpose: Callback routine which is called whenever the vol plugin ID & info + * property in the file access property list is compared. + * + * Return: positive if VALUE1 is greater than VALUE2, negative if + * VALUE2 is greater than VALUE1 and zero if VALUE1 and + * VALUE2 are equal. + * + * Programmer: Mohamad Chaarawi + * October, 2015 + * + *------------------------------------------------------------------------- + */ +static int +H5P__facc_vol_cmp(const void *_info1, const void *_info2, + size_t H5_ATTR_UNUSED size) +{ + const H5VL_plugin_prop_t *info1 = (const H5VL_plugin_prop_t *)_info1, /* Create local aliases for values */ + *info2 = (const H5VL_plugin_prop_t *)_info2; + H5VL_class_t *cls1, *cls2; /* Plugin class for each property */ + int cmp_value; /* Value from comparison */ + herr_t ret_value = 0; /* Return value */ + + FUNC_ENTER_STATIC_NOERR + + /* Sanity check */ + HDassert(info1); + HDassert(info2); + HDassert(size == sizeof(H5VL_plugin_prop_t)); + + /* Compare plugins */ + if(NULL == (cls1 = (H5VL_class_t *)H5I_object(info1->plugin_id))) + HGOTO_DONE(-1) + if(NULL == (cls2 = (H5VL_class_t *)H5I_object(info2->plugin_id))) + HGOTO_DONE(1) + if(cls1->name == NULL && cls2->name != NULL) HGOTO_DONE(-1); + if(cls1->name != NULL && cls2->name == NULL) HGOTO_DONE(1); + if(0 != (cmp_value = HDstrcmp(cls1->name, cls2->name))) + HGOTO_DONE(cmp_value); + + if(cls1->value > cls2->value) HGOTO_DONE(1); + if(cls2->value > cls1->value) HGOTO_DONE(1); + HDassert(cls1->value == cls2->value); + + /* Compare plugin infos */ + if(cls1->fapl_size < cls2->fapl_size) HGOTO_DONE(-1) + if(cls1->fapl_size > cls2->fapl_size) HGOTO_DONE(1) + HDassert(cls1->fapl_size == cls2->fapl_size); + + if(info1->plugin_info == NULL && info2->plugin_info != NULL) HGOTO_DONE(-1); + if(info1->plugin_info != NULL && info2->plugin_info == NULL) HGOTO_DONE(1); + if(info1->plugin_info) { + HDassert(cls1->fapl_size > 0); + if(0 != (cmp_value = HDmemcmp(info1->plugin_info, info2->plugin_info, cls1->fapl_size))) + HGOTO_DONE(cmp_value); + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P__facc_vol_cmp() */ + + +/*------------------------------------------------------------------------- + * Function: H5P__facc_vol_close + * + * Purpose: Close callback for the vol plugin ID & info property. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * October, 2015 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5P__facc_vol_close(const char H5_ATTR_UNUSED *name, size_t H5_ATTR_UNUSED size, void *value) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Free the vol plugin */ + if(H5P__vol_free(value) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTRELEASE, FAIL, "can't release vol plugin") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P__facc_vol_close() */ + + +/*------------------------------------------------------------------------- * Function: H5Pset_file_image * * Purpose: Sets the initial file image. Some file drivers can initialize |