From 0afb76228e16e63d72a7dbacdbb894d34fe29722 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 24 May 2019 13:39:45 -0700 Subject: Added code that disallows unregistering the native VOL connector. --- src/H5VL.c | 81 ++++++++++++++++++++++++++++++++++++-------------------------- test/vol.c | 24 ++++++++++++++----- 2 files changed, 65 insertions(+), 40 deletions(-) diff --git a/src/H5VL.c b/src/H5VL.c index fd45bf8..d4c0ff2 100644 --- a/src/H5VL.c +++ b/src/H5VL.c @@ -33,6 +33,8 @@ #include "H5Iprivate.h" /* IDs */ #include "H5VLpkg.h" /* Virtual Object Layer */ +/* VOL connectors */ +#include "H5VLnative.h" /* Native VOL connector */ /****************/ /* Local Macros */ @@ -321,6 +323,7 @@ done: herr_t H5VLunregister_connector(hid_t vol_id) { + hid_t native_id = H5I_INVALID_HID; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) @@ -328,13 +331,23 @@ H5VLunregister_connector(hid_t vol_id) /* Check arguments */ if(NULL == H5I_object_verify(vol_id, H5I_VOL)) - HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, FAIL, "not a VOL connector") + HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, FAIL, "not a VOL connector ID") + + /* For the time being, we disallow unregistering the native VOL connector */ + if(H5I_INVALID_HID == (native_id = H5VL__get_connector_id(H5VL_NATIVE_NAME, FALSE))) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "unable to find the native VOL connector ID") + if(vol_id == native_id) + HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, FAIL, "unregistering the native VOL connector is not allowed") /* The H5VL_class_t struct will be freed by this function */ - if (H5I_dec_app_ref(vol_id) < 0) + if(H5I_dec_app_ref(vol_id) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to unregister VOL connector") done: + if(native_id != H5I_INVALID_HID) + if(H5I_dec_ref(native_id) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement count on native_id") + FUNC_LEAVE_API(ret_value) } /* end H5VLunregister_connector() */ @@ -344,8 +357,8 @@ done: * * Purpose: Compares two connector classes (based on their value field) * - * Note: This routine is _only_ for HDF5 VOL connector authors! It is - * _not_ part of the public API for HDF5 application developers. + * Note: This routine is _only_ for HDF5 VOL connector authors! It is + * _not_ part of the public API for HDF5 application developers. * * Return: Success: Non-negative, *cmp set to a value like strcmp * @@ -381,11 +394,11 @@ done: * Function: H5VLwrap_register * * Purpose: Wrap an internal object with a "wrap context" and register an - * hid_t for the resulting object. + * hid_t for the resulting object. * - * Note: This routine is mainly targeted toward wrapping objects for - * iteration routine callbacks (i.e. the callbacks from H5Aiterate*, - * H5Literate* / H5Lvisit*, and H5Ovisit* ). + * Note: This routine is mainly targeted toward wrapping objects for + * iteration routine callbacks (i.e. the callbacks from H5Aiterate*, + * H5Literate* / H5Lvisit*, and H5Ovisit* ). * * Return: Success: Non-negative hid_t for the object. * Failure: Negative (H5I_INVALID_HID) @@ -420,10 +433,10 @@ done: * Function: H5VLobject * * Purpose: Retrieve the object pointer associated with an hid_t for a. - * VOL object. + * VOL object. * - * Note: This routine is mainly targeted toward unwrapping objects for - * testing. + * Note: This routine is mainly targeted toward unwrapping objects for + * testing. * * Return: Success: Object pointer * Failure: NULL @@ -451,16 +464,16 @@ done: * Function: H5VLretrieve_lib_state * * Purpose: Retrieves a copy of the internal state of the HDF5 library, - * so that it can be restored later. + * so that it can be restored later. * - * Note: This routine is _only_ for HDF5 VOL connector authors! It is - * _not_ part of the public API for HDF5 application developers. + * Note: This routine is _only_ for HDF5 VOL connector authors! It is + * _not_ part of the public API for HDF5 application developers. * * Return: Success: Non-negative, *state set * Failure: Negative, *state unset * - * Programmer: Quincey Koziol - * Thursday, January 10, 2019 + * Programmer: Quincey Koziol + * Thursday, January 10, 2019 * *--------------------------------------------------------------------------- */ @@ -491,14 +504,14 @@ done: * * Purpose: Restores the internal state of the HDF5 library. * - * Note: This routine is _only_ for HDF5 VOL connector authors! It is - * _not_ part of the public API for HDF5 application developers. + * Note: This routine is _only_ for HDF5 VOL connector authors! It is + * _not_ part of the public API for HDF5 application developers. * * Return: Success: Non-negative * Failure: Negative * - * Programmer: Quincey Koziol - * Thursday, January 10, 2019 + * Programmer: Quincey Koziol + * Thursday, January 10, 2019 * *--------------------------------------------------------------------------- */ @@ -528,20 +541,20 @@ done: * Function: H5VLreset_lib_state * * Purpose: Resets the internal state of the HDF5 library, undoing the - * affects of H5VLrestore_lib_state. + * affects of H5VLrestore_lib_state. * - * Note: This routine is _only_ for HDF5 VOL connector authors! It is - * _not_ part of the public API for HDF5 application developers. + * Note: This routine is _only_ for HDF5 VOL connector authors! It is + * _not_ part of the public API for HDF5 application developers. * - * Note: This routine must be called as a "pair" with - * H5VLrestore_lib_state. It can be called before / after / - * independently of H5VLfree_lib_state. + * Note: This routine must be called as a "pair" with + * H5VLrestore_lib_state. It can be called before / after / + * independently of H5VLfree_lib_state. * * Return: Success: Non-negative * Failure: Negative * - * Programmer: Quincey Koziol - * Saturday, February 23, 2019 + * Programmer: Quincey Koziol + * Saturday, February 23, 2019 * *--------------------------------------------------------------------------- */ @@ -568,17 +581,17 @@ done: * * Purpose: Free a retrieved library state. * - * Note: This routine is _only_ for HDF5 VOL connector authors! It is - * _not_ part of the public API for HDF5 application developers. + * Note: This routine is _only_ for HDF5 VOL connector authors! It is + * _not_ part of the public API for HDF5 application developers. * - * Note: This routine must be called as a "pair" with - * H5VLretrieve_lib_state. + * Note: This routine must be called as a "pair" with + * H5VLretrieve_lib_state. * * Return: Success: Non-negative * Failure: Negative * - * Programmer: Quincey Koziol - * Thursday, January 10, 2019 + * Programmer: Quincey Koziol + * Thursday, January 10, 2019 * *--------------------------------------------------------------------------- */ diff --git a/test/vol.c b/test/vol.c index 3f6afaa..e5b8243 100644 --- a/test/vol.c +++ b/test/vol.c @@ -148,8 +148,11 @@ static const H5VL_class_t fake_vol_g = { static herr_t test_vol_registration(void) { - htri_t is_registered; - hid_t vol_id = -1, vol_id2 = -1; + hid_t native_id = H5I_INVALID_HID; + herr_t ret = SUCCEED; + htri_t is_registered = FAIL; + hid_t vol_id = H5I_INVALID_HID; + hid_t vol_id2 = H5I_INVALID_HID; TESTING("VOL registration"); @@ -157,7 +160,7 @@ test_vol_registration(void) if ((is_registered = H5VLis_connector_registered(FAKE_VOL_NAME)) < 0) FAIL_STACK_ERROR; if (is_registered > 0) - FAIL_PUTS_ERROR("native VOL connector is inappropriately registered"); + FAIL_PUTS_ERROR("VOL connector is inappropriately registered"); /* Load a VOL interface */ if ((vol_id = H5VLregister_connector(&fake_vol_g, H5P_DEFAULT)) < 0) @@ -167,7 +170,7 @@ test_vol_registration(void) if ((is_registered = H5VLis_connector_registered(FAKE_VOL_NAME)) < 0) FAIL_STACK_ERROR; if (0 == is_registered) - FAIL_PUTS_ERROR("native VOL connector is un-registered"); + FAIL_PUTS_ERROR("VOL connector is un-registered"); /* Re-register a VOL connector */ if ((vol_id2 = H5VLregister_connector(&fake_vol_g, H5P_DEFAULT)) < 0) @@ -177,7 +180,7 @@ test_vol_registration(void) if ((is_registered = H5VLis_connector_registered(FAKE_VOL_NAME)) < 0) FAIL_STACK_ERROR; if (0 == is_registered) - FAIL_PUTS_ERROR("native VOL connector is un-registered"); + FAIL_PUTS_ERROR("VOL connector is un-registered"); /* Unregister the second test/fake VOL ID */ if (H5VLunregister_connector(vol_id2) < 0) @@ -187,12 +190,21 @@ test_vol_registration(void) if ((is_registered = H5VLis_connector_registered(FAKE_VOL_NAME)) < 0) FAIL_STACK_ERROR; if (0 == is_registered) - FAIL_PUTS_ERROR("native VOL connector is un-registered"); + FAIL_PUTS_ERROR("VOL connector is un-registered"); /* Unregister the original test/fake VOL ID */ if (H5VLunregister_connector(vol_id) < 0) FAIL_STACK_ERROR; + /* Try to unregister the native VOL connector (should fail) */ + if (H5I_INVALID_HID == (native_id = H5VLget_connector_id(H5VL_NATIVE_NAME))) + FAIL_STACK_ERROR; + H5E_BEGIN_TRY { + ret = H5VLunregister_connector(native_id); + } H5E_END_TRY; + if (FAIL != ret) + FAIL_PUTS_ERROR("should not be able to unregister the native VOL connector"); + PASSED(); return SUCCEED; -- cgit v0.12