From a510f4e8a24efcbdef7b93e5934bc0e2c965a3fe Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Fri, 24 Oct 2003 14:40:23 -0500 Subject: [svn-r7726] Purpose: Code cleanup Description: Refactored handlier of VFL drivers in file access and data transfer property lists in order to simplify and unify the code dealing with them. Platforms tested: FreeBSD 4.9 (sleipnir) too minor to require h5committest --- src/H5D.c | 50 ++++++---- src/H5F.c | 123 +++++++++++------------ src/H5FD.c | 284 ++++++++++++++++++++++++++++++++++++++++-------------- src/H5FDprivate.h | 8 +- src/H5Pfapl.c | 60 ++++-------- 5 files changed, 316 insertions(+), 209 deletions(-) diff --git a/src/H5D.c b/src/H5D.c index 8563a30..bffa6b4 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -605,23 +605,15 @@ H5D_xfer_create(hid_t dxpl_id, void UNUSED *create_data) /* Get the driver information */ if(H5P_get(plist, H5D_XFER_VFL_ID_NAME, &driver_id)<0) - HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Can't retrieve VFL driver ID"); + HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "can't retrieve VFL driver ID"); if(H5P_get(plist, H5D_XFER_VFL_INFO_NAME, &driver_info)<0) - HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Can't retrieve VFL driver info"); + HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "can't retrieve VFL driver info"); /* Check if we have a valid driver ID */ if(driver_id>0) { - /* Increment the reference count on the driver and copy the driver info */ - if(H5I_inc_ref(driver_id)<0) - HGOTO_ERROR (H5E_DATASET, H5E_CANTINC, FAIL, "Can't increment VFL driver ID"); - if(H5FD_dxpl_copy(driver_id, driver_info, &driver_info)<0) - HGOTO_ERROR (H5E_DATASET, H5E_CANTCOPY, FAIL, "Can't copy VFL driver"); - - /* Set the driver information for the new property list */ - if(H5P_set(plist, H5D_XFER_VFL_ID_NAME, &driver_id)<0) - HGOTO_ERROR (H5E_PLIST, H5E_CANTSET, FAIL, "Can't set VFL driver ID"); - if(H5P_set(plist, H5D_XFER_VFL_INFO_NAME, &driver_info)<0) - HGOTO_ERROR (H5E_PLIST, H5E_CANTSET, FAIL, "Can't set VFL driver info"); + /* Set the driver for the property list */ + if(H5FD_dxpl_open(plist, driver_id, driver_info)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set driver") } /* end if */ done: @@ -648,15 +640,32 @@ done: *------------------------------------------------------------------------- */ herr_t -H5D_xfer_copy(hid_t new_plist_id, hid_t UNUSED old_plist_id, - void *copy_data) +H5D_xfer_copy(hid_t new_dxpl_id, hid_t old_dxpl_id, void UNUSED *copy_data) { + hid_t driver_id; + void* driver_info; + H5P_genplist_t *new_plist; /* New property list */ + H5P_genplist_t *old_plist; /* Old property list */ herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5D_xfer_copy, FAIL); - if(H5D_xfer_create(new_plist_id, copy_data) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "can't copy property list"); + if(NULL == (new_plist = H5I_object(new_dxpl_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get property list") + if(NULL == (old_plist = H5I_object(old_dxpl_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get property list") + + /* Get values from old property list */ + if(H5P_get(old_plist, H5D_XFER_VFL_ID_NAME, &driver_id)<0) + HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "can't retrieve VFL driver ID") + if(H5P_get(old_plist, H5D_XFER_VFL_INFO_NAME, &driver_info)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get drver info") + + if(driver_id > 0) { + /* Set the driver for the property list */ + if(H5FD_dxpl_open(new_plist, driver_id, driver_info)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set driver") + } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value); @@ -702,10 +711,9 @@ H5D_xfer_close(hid_t dxpl_id, void UNUSED *close_data) if(H5P_get(plist, H5D_XFER_VFL_INFO_NAME, &driver_info)<0) HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Can't retrieve VFL driver info"); if(driver_id>0) { - if(H5FD_dxpl_free(driver_id, driver_info)<0) - HGOTO_ERROR (H5E_DATASET, H5E_CANTFREE, FAIL, "Can't free VFL driver"); - if(H5I_dec_ref(driver_id)<0) - HGOTO_ERROR (H5E_DATASET, H5E_CANTFREE, FAIL, "Can't decrement VFL driver ID"); + /* Close the driver for the property list */ + if(H5FD_dxpl_close(driver_id, driver_info)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't reset driver") } /* end if */ done: diff --git a/src/H5F.c b/src/H5F.c index 279ff19..63d6408 100644 --- a/src/H5F.c +++ b/src/H5F.c @@ -531,15 +531,9 @@ H5F_acs_create(hid_t fapl_id, void UNUSED *copy_data) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get drver info"); if(driver_id > 0) { - /* Increment the reference count on driver and copy driver info */ - H5I_inc_ref(driver_id); - driver_info = H5FD_fapl_copy(driver_id, driver_info); - - /* Set the driver properties for the list */ - if(H5P_set(plist, H5F_ACS_FILE_DRV_ID_NAME, &driver_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set drver ID"); - if(H5P_set(plist, H5F_ACS_FILE_DRV_INFO_NAME, &driver_info) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set drver info"); + /* Set the driver for the property list */ + if(H5FD_fapl_open(plist, driver_id, driver_info)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set driver") } /* end if */ done: @@ -548,60 +542,6 @@ done: /*-------------------------------------------------------------------------- - * Function: H5F_acs_close - * - * Purpose: Callback routine which is called whenever a file access - * property list is closed. This routine performs any generic - * cleanup needed on the properties. - * - * Return: Success: Non-negative - * - * Failure: Negative - * - * Programmer: Raymond Lu - * Tuesday, Oct 23, 2001 - * - * Modifications: - * - *--------------------------------------------------------------------------- - */ -herr_t -H5F_acs_close(hid_t fapl_id, void UNUSED *close_data) -{ - hid_t driver_id; - void *driver_info; - H5P_genplist_t *plist; /* Property list */ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_NOAPI(H5F_acs_close, FAIL); - - /* Check argument */ - if(NULL == (plist = H5I_object(fapl_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list"); - - if(H5P_get(plist, H5F_ACS_FILE_DRV_ID_NAME, &driver_id) < 0) - HGOTO_DONE(FAIL); /* Can't return errors when library is shutting down */ - if(H5P_get(plist, H5F_ACS_FILE_DRV_INFO_NAME, &driver_info) < 0) - HGOTO_DONE(FAIL); /* Can't return errors when library is shutting down */ - - if(driver_id > 0) { - /* Free memory for driver info and decrement reference count for driver */ - H5FD_fapl_free(driver_id, driver_info); - H5I_dec_ref(driver_id); - driver_info = NULL; - driver_id = -1; - if(H5P_set(plist, H5F_ACS_FILE_DRV_ID_NAME, &driver_id) < 0) - HGOTO_DONE(FAIL); /* Can't return errors when library is shutting down */ - if(H5P_set(plist, H5F_ACS_FILE_DRV_INFO_NAME, &driver_info) < 0) - HGOTO_DONE(FAIL); /* Can't return errors when library is shutting down */ - } - -done: - FUNC_LEAVE_NOAPI(ret_value); -} - - -/*-------------------------------------------------------------------------- * Function: H5F_acs_copy * * Purpose: Callback routine which is called whenever a file access @@ -640,18 +580,63 @@ H5F_acs_copy(hid_t new_fapl_id, hid_t old_fapl_id, void UNUSED *copy_data) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get drver info"); if(driver_id > 0) { - H5I_inc_ref(driver_id); - driver_info = H5FD_fapl_copy(driver_id, driver_info); - if(H5P_set(new_plist, H5F_ACS_FILE_DRV_ID_NAME, &driver_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set drver ID"); - if(H5P_set(new_plist, H5F_ACS_FILE_DRV_INFO_NAME, &driver_info) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set drver info"); + /* Set the driver for the property list */ + if(H5FD_fapl_open(new_plist, driver_id, driver_info)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set driver") } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value); } + +/*-------------------------------------------------------------------------- + * Function: H5F_acs_close + * + * Purpose: Callback routine which is called whenever a file access + * property list is closed. This routine performs any generic + * cleanup needed on the properties. + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Raymond Lu + * Tuesday, Oct 23, 2001 + * + * Modifications: + * + *--------------------------------------------------------------------------- + */ +herr_t +H5F_acs_close(hid_t fapl_id, void UNUSED *close_data) +{ + hid_t driver_id; + void *driver_info; + H5P_genplist_t *plist; /* Property list */ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(H5F_acs_close, FAIL); + + /* Check argument */ + if(NULL == (plist = H5I_object(fapl_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list"); + + if(H5P_get(plist, H5F_ACS_FILE_DRV_ID_NAME, &driver_id) < 0) + HGOTO_DONE(FAIL); /* Can't return errors when library is shutting down */ + if(H5P_get(plist, H5F_ACS_FILE_DRV_INFO_NAME, &driver_info) < 0) + HGOTO_DONE(FAIL); /* Can't return errors when library is shutting down */ + + if(driver_id > 0) { + /* Close the driver for the property list */ + if(H5FD_fapl_close(driver_id, driver_info)<0) + HGOTO_DONE(FAIL) /* Can't return errors when library is shutting down */ + } + +done: + FUNC_LEAVE_NOAPI(ret_value); +} + #ifdef NOT_YET /*------------------------------------------------------------------------- diff --git a/src/H5FD.c b/src/H5FD.c index b2d41e8..60807a9 100644 --- a/src/H5FD.c +++ b/src/H5FD.c @@ -48,6 +48,10 @@ static int interface_initialize_g = 0; /* static prototypes */ static herr_t H5FD_init_interface(void); +static herr_t H5FD_pl_copy(void *(*copy_func)(const void *), size_t pl_size, + const void *old_pl, void **copied_pl); +static herr_t H5FD_pl_close(hid_t driver_id, herr_t (*free_func)(void *), + void *pl); static herr_t H5FD_free_cls(H5FD_class_t *cls); static haddr_t H5FD_alloc_from_free_list(H5FD_t *file, H5FD_mem_t type, H5FD_mem_t mapped_type, hsize_t size); @@ -466,6 +470,92 @@ done: /*------------------------------------------------------------------------- + * Function: H5FD_pl_copy + * + * Purpose: Copies the driver-specific part of the a property list. + * This is common code, used by both the dataset transfer and + * file access property list routines. + * + * Return: Success: non-negative + * + * Failure: negative + * + * Programmer: Quincey Koziol + * Thursday, October 23, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD_pl_copy(void *(*copy_func)(const void *), size_t pl_size, const void *old_pl, void **copied_pl) +{ + void *new_pl = NULL; /* Copy of property list */ + herr_t ret_value=SUCCEED; /* Return value */ + + FUNC_ENTER_NOINIT(H5FD_pl_copy) + + /* Copy old pl, if one exists */ + if (old_pl) { + /* Allow the driver to copy or do it ourselves */ + if (copy_func) { + new_pl = (copy_func)(old_pl); + } else if (pl_size>0) { + if((new_pl = H5MM_malloc(pl_size))==NULL) + HGOTO_ERROR(H5E_VFL, H5E_NOSPACE, FAIL, "property list allocation failed") + HDmemcpy(new_pl, old_pl, pl_size); + } else + HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "no way to copy driver property list") + } /* end if */ + + /* Set copied value */ + *copied_pl=new_pl; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD_pl_copy() */ + + +/*------------------------------------------------------------------------- + * Function: H5FD_pl_close + * + * Purpose: Closes a driver for a property list + * This is common code, used by both the dataset transfer and + * file access property list routines. + * + * Return: Success: non-negative + * Failure: negative + * + * Programmer: Quincey Koziol + * Thursday, October 23, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD_pl_close(hid_t driver_id, herr_t (*free_func)(void *), void *pl) +{ + herr_t ret_value=SUCCEED; /* Return value */ + + FUNC_ENTER_NOINIT(H5FD_pl_close) + + /* Allow driver to free or do it ourselves */ + if (pl && free_func) { + if ((free_func)(pl)<0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "driver free request failed") + } else + H5MM_xfree(pl); + + /* Decrement reference count for driver */ + H5I_dec_ref(driver_id); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD_pl_close() */ + + +/*------------------------------------------------------------------------- * Function: H5FD_fapl_get * * Purpose: Gets the file access property list associated with a file. @@ -509,17 +599,55 @@ done: /*------------------------------------------------------------------------- + * Function: H5FD_fapl_open + * + * Purpose: Mark a driver as used by a file access property list + * + * Return: Success: non-negative + * + * Failure: negative + * + * Programmer: Quincey Koziol + * Thursday, October 23, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5FD_fapl_open(H5P_genplist_t *plist, hid_t driver_id, void *driver_info) +{ + void *copied_driver_info; /* Temporary VFL driver info */ + herr_t ret_value=SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(H5FD_fapl_open, FAIL) + + /* Increment the reference count on driver and copy driver info */ + if(H5I_inc_ref(driver_id)<0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINC, FAIL, "unable to increment ref count on VFL driver") + if(H5FD_fapl_copy(driver_id, driver_info, &copied_driver_info)<0) + HGOTO_ERROR (H5E_PLIST, H5E_CANTCOPY, FAIL, "can't copy VFL driver info") + + /* Set the driver properties for the list */ + if(H5P_set(plist, H5F_ACS_FILE_DRV_ID_NAME, &driver_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set driver ID") + if(H5P_set(plist, H5F_ACS_FILE_DRV_INFO_NAME, &copied_driver_info) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set driver info") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD_fapl_open() */ + + +/*------------------------------------------------------------------------- * Function: H5FD_fapl_copy * * Purpose: Copies the driver-specific part of the file access property * list. * - * Return: Success: Pointer to new driver-specific file access - * properties. + * Return: Success: non-negative * - * Failure: NULL, but also returns null with no error - * pushed onto the error stack if the OLD_FAPL - * is null. + * Failure: negative * * Programmer: Robb Matzke * Tuesday, August 3, 1999 @@ -528,32 +656,21 @@ done: * *------------------------------------------------------------------------- */ -void * -H5FD_fapl_copy(hid_t driver_id, const void *old_fapl) +herr_t +H5FD_fapl_copy(hid_t driver_id, const void *old_fapl, void **copied_fapl) { - void *new_fapl = NULL; H5FD_class_t *driver=NULL; - void *ret_value; /* Return value */ + herr_t ret_value=SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5FD_fapl_copy, NULL); + FUNC_ENTER_NOAPI(H5FD_fapl_copy, FAIL); /* Check args */ if (NULL==(driver=H5I_object(driver_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a driver ID"); - if (!old_fapl) - HGOTO_DONE(NULL); /*but no error*/ - - /* Allow the driver to copy or do it ourselves */ - if (driver->fapl_copy) { - new_fapl = (driver->fapl_copy)(old_fapl); - } else if (driver->fapl_size>0) { - new_fapl = H5MM_malloc(driver->fapl_size); - HDmemcpy(new_fapl, old_fapl, driver->fapl_size); - } else - HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, NULL, "no way to copy driver file access property list"); + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a driver ID") - /* Set return value */ - ret_value=new_fapl; + /* Copy the file access property list */ + if(H5FD_pl_copy(driver->fapl_copy,driver->fapl_size,old_fapl,copied_fapl)<0) + HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "can't copy driver file access property list") done: FUNC_LEAVE_NOAPI(ret_value); @@ -561,9 +678,9 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_fapl_free + * Function: H5FD_fapl_close * - * Purpose: Frees the driver-specific file access property list. + * Purpose: Closes a driver for a dataset transfer property list * * Return: Success: non-negative * @@ -577,24 +694,22 @@ done: *------------------------------------------------------------------------- */ herr_t -H5FD_fapl_free(hid_t driver_id, void *fapl) +H5FD_fapl_close(hid_t driver_id, void *fapl) { H5FD_class_t *driver=NULL; herr_t ret_value=SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5FD_fapl_free, FAIL); + FUNC_ENTER_NOAPI(H5FD_fapl_close, FAIL) /* Check args */ - if (NULL==(driver=H5I_object(driver_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a driver ID"); - - /* Allow driver to free or do it ourselves */ - if (fapl && driver->fapl_free) { - if ((driver->fapl_free)(fapl)<0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "driver fapl_free request failed"); - } else { - H5MM_xfree(fapl); - } + if(driver_id>0) { + if (NULL==(driver=H5I_object(driver_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a driver ID") + + /* Close the driver for the property list */ + if(H5FD_pl_close(driver_id,driver->fapl_free,fapl)<0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "driver fapl_free request failed") + } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value); @@ -602,17 +717,55 @@ done: /*------------------------------------------------------------------------- + * Function: H5FD_dxpl_open + * + * Purpose: Mark a driver as used by a data transfer property list + * + * Return: Success: non-negative + * + * Failure: negative + * + * Programmer: Quincey Koziol + * Thursday, October 23, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5FD_dxpl_open(H5P_genplist_t *plist, hid_t driver_id, void *driver_info) +{ + void *copied_driver_info; /* Temporary VFL driver info */ + herr_t ret_value=SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(H5FD_dxpl_open, FAIL) + + /* Increment the reference count on the driver and copy the driver info */ + if(H5I_inc_ref(driver_id)<0) + HGOTO_ERROR (H5E_DATASET, H5E_CANTINC, FAIL, "can't increment VFL driver ID") + if(H5FD_dxpl_copy(driver_id, driver_info, &copied_driver_info)<0) + HGOTO_ERROR (H5E_DATASET, H5E_CANTCOPY, FAIL, "can't copy VFL driver") + + /* Set the driver information for the new property list */ + if(H5P_set(plist, H5D_XFER_VFL_ID_NAME, &driver_id)<0) + HGOTO_ERROR (H5E_PLIST, H5E_CANTSET, FAIL, "can't set VFL driver ID") + if(H5P_set(plist, H5D_XFER_VFL_INFO_NAME, &copied_driver_info)<0) + HGOTO_ERROR (H5E_PLIST, H5E_CANTSET, FAIL, "can't set VFL driver info") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD_dxpl_open() */ + + +/*------------------------------------------------------------------------- * Function: H5FD_dxpl_copy * * Purpose: Copies the driver-specific part of the data transfer property * list. * - * Return: Success: Pointer to new driver-specific data transfer - * properties. + * Return: Success: non-negative * - * Failure: NULL, but also returns null with no error - * pushed onto the error stack if the OLD_DXPL - * is null. + * Failure: negative * * Programmer: Robb Matzke * Tuesday, August 3, 1999 @@ -624,7 +777,6 @@ done: herr_t H5FD_dxpl_copy(hid_t driver_id, const void *old_dxpl, void **copied_dxpl) { - void *new_dxpl = NULL; H5FD_class_t *driver=NULL; herr_t ret_value=SUCCEED; /* Return value */ @@ -634,21 +786,9 @@ H5FD_dxpl_copy(hid_t driver_id, const void *old_dxpl, void **copied_dxpl) if (NULL==(driver=H5I_object(driver_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a driver ID"); - /* Copy old dxpl, if one exists */ - if (old_dxpl) { - /* Allow the driver to copy or do it ourselves */ - if (driver->dxpl_copy) { - new_dxpl = (driver->dxpl_copy)(old_dxpl); - } else if (driver->dxpl_size>0) { - new_dxpl = H5MM_malloc(driver->dxpl_size); - assert(new_dxpl); - HDmemcpy(new_dxpl, old_dxpl, driver->dxpl_size); - } else - HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "no way to copy driver file access property list"); - } /* end if */ - - /* Set copied value */ - *copied_dxpl=new_dxpl; + /* Copy the file access property list */ + if(H5FD_pl_copy(driver->dxpl_copy,driver->dxpl_size,old_dxpl,copied_dxpl)<0) + HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "can't copy driver data transfer property list") done: FUNC_LEAVE_NOAPI(ret_value); @@ -656,9 +796,9 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_dxpl_free + * Function: H5FD_dxpl_close * - * Purpose: Frees the driver-specific data transfer property list. + * Purpose: Closes a driver for a dataset transfer property list * * Return: Success: non-negative * @@ -672,24 +812,22 @@ done: *------------------------------------------------------------------------- */ herr_t -H5FD_dxpl_free(hid_t driver_id, void *dxpl) +H5FD_dxpl_close(hid_t driver_id, void *dxpl) { H5FD_class_t *driver=NULL; herr_t ret_value=SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5FD_dxpl_free, FAIL); + FUNC_ENTER_NOAPI(H5FD_dxpl_close, FAIL) /* Check args */ - if (NULL==(driver=H5I_object(driver_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a driver ID"); - - /* Allow driver to free or do it ourselves */ - if (dxpl && driver->dxpl_free) { - if ((driver->dxpl_free)(dxpl)<0) - HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "driver dxpl_free request failed"); - } else { - H5MM_xfree(dxpl); - } + if(driver_id>0) { + if (NULL==(driver=H5I_object(driver_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a driver ID") + + /* Close the driver for the property list */ + if(H5FD_pl_close(driver_id,driver->dxpl_free,dxpl)<0) + HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "driver fapl_free request failed") + } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value); diff --git a/src/H5FDprivate.h b/src/H5FDprivate.h index d02ba35..a53bbd3 100644 --- a/src/H5FDprivate.h +++ b/src/H5FDprivate.h @@ -27,10 +27,12 @@ H5_DLL hsize_t H5FD_sb_size(H5FD_t *file); H5_DLL herr_t H5FD_sb_encode(H5FD_t *file, char *name/*out*/, uint8_t *buf); H5_DLL herr_t H5FD_sb_decode(H5FD_t *file, const char *name, const uint8_t *buf); H5_DLL void *H5FD_fapl_get(H5FD_t *file); -H5_DLL void *H5FD_fapl_copy(hid_t driver_id, const void *fapl); -H5_DLL herr_t H5FD_fapl_free(hid_t driver_id, void *fapl); +H5_DLL herr_t H5FD_fapl_open(struct H5P_genplist_t *plist, hid_t driver_id, void *driver_info); +H5_DLL herr_t H5FD_fapl_copy(hid_t driver_id, const void *fapl, void **copied_fapl); +H5_DLL herr_t H5FD_fapl_close(hid_t driver_id, void *fapl); +H5_DLL herr_t H5FD_dxpl_open(struct H5P_genplist_t *plist, hid_t driver_id, void *driver_info); H5_DLL herr_t H5FD_dxpl_copy(hid_t driver_id, const void *dxpl, void **copied_dxpl); -H5_DLL herr_t H5FD_dxpl_free(hid_t driver_id, void *dxpl); +H5_DLL herr_t H5FD_dxpl_close(hid_t driver_id, void *dxpl); H5_DLL H5FD_t *H5FD_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr); H5_DLL herr_t H5FD_close(H5FD_t *file); diff --git a/src/H5Pfapl.c b/src/H5Pfapl.c index d3f5d6a..0d4a884 100644 --- a/src/H5Pfapl.c +++ b/src/H5Pfapl.c @@ -182,7 +182,6 @@ H5P_set_driver(H5P_genplist_t *plist, hid_t new_driver_id, const void *new_drive { hid_t driver_id; /* VFL driver ID */ void *driver_info; /* VFL driver info */ - void *copied_driver_info; /* Temporary VFL driver info */ herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5P_set_driver, FAIL); @@ -191,58 +190,33 @@ H5P_set_driver(H5P_genplist_t *plist, hid_t new_driver_id, const void *new_drive HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file driver ID"); if( TRUE == H5P_isa_class(plist->plist_id, H5P_FILE_ACCESS) ) { - /* Remove old driver */ + /* Get the current driver information */ if(H5P_get(plist, H5F_ACS_FILE_DRV_ID_NAME, &driver_id) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get driver ID"); if(H5P_get(plist, H5F_ACS_FILE_DRV_INFO_NAME, &driver_info) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET,FAIL,"can't get driver info"); - assert(driver_id>=0); - H5FD_fapl_free(driver_id, driver_info); - H5I_dec_ref(driver_id); - - /* Add new driver */ - H5I_inc_ref(new_driver_id); - driver_id = new_driver_id; - driver_info = H5FD_fapl_copy(new_driver_id, new_driver_info); - - if(H5P_set(plist, H5F_ACS_FILE_DRV_ID_NAME, &driver_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set driver ID"); - if(H5P_set(plist, H5F_ACS_FILE_DRV_INFO_NAME, &driver_info) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTSET,FAIL,"can't set driver info"); - + + /* Close the driver for the property list */ + if(H5FD_fapl_close(driver_id, driver_info)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't reset driver") + + /* Set the driver for the property list */ + if(H5FD_fapl_open(plist, new_driver_id, new_driver_info)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set driver") } else if( TRUE == H5P_isa_class(plist->plist_id, H5P_DATASET_XFER) ) { /* Get the current driver information */ if(H5P_get(plist, H5D_XFER_VFL_ID_NAME, &driver_id)<0) - HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Can't retrieve VFL driver ID"); + HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "can't retrieve VFL driver ID"); if(H5P_get(plist, H5D_XFER_VFL_INFO_NAME, &driver_info)<0) - HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Can't retrieve VFL driver info"); - - /* Remove old driver */ - - /* Double-check value... */ - assert(driver_id>=0); - - /* Free any driver information stored */ - H5FD_dxpl_free(driver_id, driver_info); - - /* Decrement reference count for old driver */ - H5I_dec_ref(driver_id); - - /* Add new driver */ - - /* Increment reference count for new driver */ - H5I_inc_ref(new_driver_id); + HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "can't retrieve VFL driver info"); - /* Make a copy of the driver information */ - if(H5FD_dxpl_copy(new_driver_id, new_driver_info, &copied_driver_info)<0) - HGOTO_ERROR (H5E_DATASET, H5E_CANTCOPY, FAIL, "Can't copy VFL driver"); + /* Close the driver for the property list */ + if(H5FD_dxpl_close(driver_id, driver_info)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't reset driver") - /* Set the driver info for the property list */ - if(H5P_set(plist, H5D_XFER_VFL_ID_NAME, &new_driver_id)<0) - HGOTO_ERROR (H5E_PLIST, H5E_CANTSET, FAIL, "Can't set VFL driver ID"); - if(H5P_set(plist, H5D_XFER_VFL_INFO_NAME, &copied_driver_info) < 0) - HGOTO_ERROR (H5E_PLIST, H5E_CANTSET, FAIL, "Can't set VFL driver info"); - + /* Set the driver for the property list */ + if(H5FD_dxpl_open(plist, new_driver_id, new_driver_info)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set driver") } else { HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access or data transfer property list"); } -- cgit v0.12