summaryrefslogtreecommitdiffstats
path: root/src/H5VLint.c
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2018-10-17 09:06:28 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2018-10-17 09:06:28 (GMT)
commit2d6d5cad0cc426cd53b9d4fda15e53d8021e4c7b (patch)
tree40d72b402a0af13b09e431aeb031b1c22a2f02c5 /src/H5VLint.c
parent1e8ef703cdc057211b3587be776a6e9f62e8f76f (diff)
downloadhdf5-2d6d5cad0cc426cd53b9d4fda15e53d8021e4c7b.zip
hdf5-2d6d5cad0cc426cd53b9d4fda15e53d8021e4c7b.tar.gz
hdf5-2d6d5cad0cc426cd53b9d4fda15e53d8021e4c7b.tar.bz2
Updates to the VOL ID and object API calls.
This brings the H5VL code in line with the H5I code regarding naming, parameter order, etc. Several public API calls were affected by this change. These changed names to reflect their use with VOL drivers: H5VLregister() --> H5VLregister_driver() H5VLregister_by_name() --> H5VLregister_driver_by_name() H5VLunregister() --> H5VLunregister_driver() H5VLis_registered() --> H5VLis_driver_registered() This call was renamed to match H5Iregister(). The order of the first two parameters also reversed and the object pointer is now const. H5VLobject_register() --> H5VLregister()
Diffstat (limited to 'src/H5VLint.c')
-rw-r--r--src/H5VLint.c204
1 files changed, 140 insertions, 64 deletions
diff --git a/src/H5VLint.c b/src/H5VLint.c
index 78ba6d9..e246989 100644
--- a/src/H5VLint.c
+++ b/src/H5VLint.c
@@ -213,20 +213,21 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5VL_register_id
+ * Function: H5VL_register
*
- * Purpose: Wrapper to register an object ID with a VOL aux struct
- * and increment ref count on VOL driver ID
+ * Purpose: VOL-aware version of H5I_register. Constructs an H5VL_object_t
+ * from the passed-in object and registers that. Does the right
+ * thing with datatypes, which are complicated under the VOL.
*
- * Return: Success: A valid HDF5 ID
+ * Return: Success: A valid HDF5 ID
* Failure: H5I_INVALID_HID
*
*-------------------------------------------------------------------------
*/
hid_t
-H5VL_register_id(H5I_type_t type, void *object, H5VL_t *vol_driver, hbool_t app_ref)
+H5VL_register(H5I_type_t type, const void *object, H5VL_t *vol_driver, hbool_t app_ref)
{
- H5VL_object_t *new_obj = NULL;
+ H5VL_object_t *vol_obj = NULL;
hid_t ret_value = H5I_INVALID_HID;
FUNC_ENTER_NOAPI(H5I_INVALID_HID)
@@ -235,32 +236,135 @@ H5VL_register_id(H5I_type_t type, void *object, H5VL_t *vol_driver, hbool_t app_
HDassert(object);
HDassert(vol_driver);
- /* setup VOL object */
- if (NULL == (new_obj = H5FL_CALLOC(H5VL_object_t)))
+ /* Set up VOL object to wrap the passed-in data */
+ if (NULL == (vol_obj = H5FL_CALLOC(H5VL_object_t)))
HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, H5I_INVALID_HID, "can't allocate top object structure");
- new_obj->driver = vol_driver;
- new_obj->data = object;
+ vol_obj->driver = vol_driver;
+ vol_obj->data = object;
vol_driver->nrefs++;
+ /* Datatypes need special handling under the VOL, since they have a non-VOL aspect */
if (H5I_DATATYPE == type) {
H5T_t *dt = NULL;
- if (NULL == (dt = H5T_construct_datatype(new_obj)))
+ if (NULL == (dt = H5T_construct_datatype(vol_obj)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5I_INVALID_HID, "can't construct datatype object");
if ((ret_value = H5I_register(type, dt, app_ref)) < 0)
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize handle");
}
else {
- if ((ret_value = H5I_register(type, new_obj, app_ref)) < 0)
+ if ((ret_value = H5I_register(type, vol_obj, app_ref)) < 0)
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize handle");
}
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5VL_register_id() */
+} /* end H5VL_register() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5VL_register_using_existing_id
+ *
+ * Purpose: Registers an OBJECT in a TYPE with the supplied ID for it.
+ * This routine will check to ensure the supplied ID is not already
+ * in use, and ensure that it is a valid ID for the given type,
+ * but will NOT check to ensure the OBJECT is not already
+ * registered (thus, it is possible to register one object under
+ * multiple IDs).
+ *
+ * NOTE: Intended for use in refresh calls, where we have to close
+ * and re-open the underlying data, then hook the VOL object back
+ * up to the original ID.
+ *
+ * Return: SUCCEED/FAIL
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5VL_register_using_existing_id(H5I_type_t type, void *object, H5VL_t *vol_driver, hbool_t app_ref, hid_t existing_id)
+{
+ H5VL_object_t *new_vol_obj = NULL; /* Pointer to new VOL object */
+ void *stored_obj = NULL; /* Pointer to the object that will be stored */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(FAIL)
+
+ /* Check arguments */
+ HDassert(object);
+ HDassert(vol_driver);
+
+ /* Make sure type number is valid */
+ if(type != H5I_ATTR && type != H5I_DATASET && type != H5I_DATATYPE && type != H5I_FILE && type != H5I_GROUP)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid type number")
+
+ /* Set up the new VOL object */
+ if(NULL == (new_vol_obj = H5FL_CALLOC(H5VL_object_t)))
+ HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, FAIL, "can't allocate memory for VOL object");
+ new_vol_obj->driver = vol_driver;
+ new_vol_obj->data = object;
+
+ /* Bump the reference count on the VOL driver */
+ vol_driver->nrefs++;
+
+ /* If this is a datatype, we have to hide the VOL object under the H5T_t pointer */
+ if(H5I_DATATYPE == type) {
+ if(NULL == (stored_obj = (void *)H5T_construct_datatype(new_vol_obj)))
+ HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't construct datatype object");
+ }
+ else
+ stored_obj = (void *)new_vol_obj;
+
+ /* Call the underlying H5I function to complete the registration */
+ if(H5I_register_using_existing_id(type, stored_obj, app_ref, existing_id) < 0)
+ HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, FAIL, "can't register object under existing ID")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5VL_register_using_existing_id() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5VL_register_using_vol_id
+ *
+ * Purpose: Utility function to create a user ID for an object created
+ * or opened through the VOL. Uses the VOL driver's ID to
+ * get the driver information instead of it being passed in.
+ *
+ * Return: Success: A valid HDF5 ID
+ * Failure: H5I_INVALID_HID
+ *
+ *-------------------------------------------------------------------------
+ */
+hid_t
+H5VL_register_using_vol_id(H5I_type_t type, const void *obj, hid_t driver_id, hbool_t app_ref)
+{
+ H5VL_class_t *cls = NULL;
+ H5VL_t *driver = NULL; /* VOL driver struct */
+ hid_t ret_value = H5I_INVALID_HID;
+
+ FUNC_ENTER_NOAPI(FAIL)
+
+ if (NULL == (cls = (H5VL_class_t *)H5I_object_verify(driver_id, H5I_VOL)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a VOL driver ID");
+
+ /* Setup VOL info struct */
+ if (NULL == (driver = H5FL_CALLOC(H5VL_t)))
+ HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, H5I_INVALID_HID, "can't allocate VOL info struct");
+ driver->cls = cls;
+ driver->id = driver_id;
+ if (H5I_inc_ref(driver->id, FALSE) < 0)
+ HGOTO_ERROR(H5E_ATOM, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL driver");
+
+ /* Get an ID for the VOL object */
+ if ((ret_value = H5VL_register(type, obj, driver, app_ref)) < 0)
+ HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle");
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5VL_register_using_vol_id() */
/*-------------------------------------------------------------------------
@@ -299,7 +403,7 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5VL_register
+ * Function: H5VL_register_driver
*
* Purpose: Registers a new VOL driver as a member of the virtual object
* layer class.
@@ -312,7 +416,7 @@ done:
*-------------------------------------------------------------------------
*/
hid_t
-H5VL_register(const void *_cls, size_t size, hbool_t app_ref)
+H5VL_register_driver(const void *_cls, size_t size, hbool_t app_ref)
{
const H5VL_class_t *cls = (const H5VL_class_t *)_cls;
H5VL_class_t *saved = NULL;
@@ -338,47 +442,7 @@ done:
H5MM_xfree(saved);
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5VL_register() */
-
-
-/*-------------------------------------------------------------------------
- * Function: H5VL_object_register
- *
- * Purpose: Utility function to create a user ID for an object created
- * or opened through the VOL
- *
- * Return: Success: A valid HDF5 ID
- * Failure: H5I_INVALID_HID
- *
- *-------------------------------------------------------------------------
- */
-hid_t
-H5VL_object_register(void *obj, H5I_type_t obj_type, hid_t driver_id, hbool_t app_ref)
-{
- H5VL_class_t *cls = NULL;
- H5VL_t *driver = NULL; /* VOL driver struct */
- hid_t ret_value = H5I_INVALID_HID;
-
- FUNC_ENTER_NOAPI(FAIL)
-
- if (NULL == (cls = (H5VL_class_t *)H5I_object_verify(driver_id, H5I_VOL)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a VOL driver ID");
-
- /* Setup VOL info struct */
- if (NULL == (driver = H5FL_CALLOC(H5VL_t)))
- HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, H5I_INVALID_HID, "can't allocate VOL info struct");
- driver->cls = cls;
- driver->id = driver_id;
- if (H5I_inc_ref(driver->id, FALSE) < 0)
- HGOTO_ERROR(H5E_ATOM, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL driver");
-
- /* Get an ID for the VOL object */
- if ((ret_value = H5VL_register_id(obj_type, obj, driver, app_ref)) < 0)
- HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle");
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5VL_object_register() */
+} /* end H5VL_register_driver() */
/*-------------------------------------------------------------------------
@@ -402,7 +466,7 @@ H5VL_get_driver_name(hid_t id, char *name /*out*/, size_t size)
FUNC_ENTER_NOAPI(FAIL)
/* get the object pointer */
- if (NULL == (vol_obj = H5VL_get_object(id)))
+ if (NULL == (vol_obj = H5VL_vol_object(id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier");
cls = vol_obj->driver->cls;
@@ -423,7 +487,7 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5VL_get_object
+ * Function: H5VL_vol_object
*
* Purpose: Utility function to return the object pointer associated with
* a hid_t. This routine is the same as H5I_object for all types
@@ -436,7 +500,7 @@ done:
*-------------------------------------------------------------------------
*/
H5VL_object_t *
-H5VL_get_object(hid_t id)
+H5VL_vol_object(hid_t id)
{
void *obj = NULL;
H5I_type_t obj_type = H5I_get_type(id);
@@ -463,7 +527,7 @@ H5VL_get_object(hid_t id)
ret_value = (H5VL_object_t *)obj;
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5VL_get_object() */
+} /* end H5VL_vol_object() */
/*-------------------------------------------------------------------------
@@ -597,15 +661,27 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_object_verify() */
-
-/* XXX (VOL MERGE): This could be a macro like in H5F */
+
+/*-------------------------------------------------------------------------
+ * Function: H5VL_driver_data
+ *
+ * Purpose: Get the VOL-specific data stored in a VOL object
+ *
+ * Return: Success: Pointer to the data
+ *
+ * Failure: NULL (technically can't fail)
+ *
+ *-------------------------------------------------------------------------
+ */
void *
-H5VL_driver_object(H5VL_object_t *vol_obj)
+H5VL_driver_data(H5VL_object_t *vol_obj)
{
FUNC_ENTER_NOAPI_NOINIT_NOERR
+ HDassert(vol_obj);
+
FUNC_LEAVE_NOAPI(vol_obj->data)
-} /* end H5VL_driver_object() */
+} /* end H5VL_driver_data() */
/*-------------------------------------------------------------------------