Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VOL refactor and cleanup #4856

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open

Conversation

qkoziol
Copy link
Contributor

@qkoziol qkoziol commented Sep 18, 2024

Cleanup and prepare for thread-safety changes.

Big ideas:

  • Wrap H5VL_class_t with H5VL_connector_t, so use of the class can be refcounted within the H5VL package, instead of relying on storing an ID within the H5VL_t struct and incrementing & decrementing the ID's refcount.
  • Register H5VL_connector_t* for VOL connector IDs, instead of the H5VL_class_t*
  • Stop other packages from rummaging around inside H5VL_connector_t and H5VL_object_t data structures, so that the H5VL package can change implementation details without coupled changes throughout the library

Small things:

  • Simplified the coding for creating links
  • Moved some routines into more logical locations

qkoziol and others added 12 commits September 6, 2024 17:47
Signed-off-by: Quincey Koziol <quincey@koziol.cc>
Signed-off-by: Quincey Koziol <quincey@koziol.cc>
So they don't sound like they are operating on connectors.

Signed-off-by: Quincey Koziol <quincey@koziol.cc>
Signed-off-by: Quincey Koziol <quincey@koziol.cc>
Also, small code tidying

Signed-off-by: Quincey Koziol <quincey@koziol.cc>
Signed-off-by: Quincey Koziol <quincey@koziol.cc>
Signed-off-by: Quincey Koziol <quincey@koziol.cc>
Also simplify and enforce some modularity boundaries around them, so that
other packages can't modify VOL data structures.

Signed-off-by: Quincey Koziol <quincey@koziol.cc>
Signed-off-by: Quincey Koziol <quincey@koziol.cc>
Signed-off-by: Quincey Koziol <quincey@koziol.cc>
!!
!! See C API: @ref H5VLcmp_connector_cls()
!!
SUBROUTINE H5VLcmp_connector_cls_f(are_same, conn_id1, conn_id2, hdferr)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This routine is necessary because it's possible to have VOL connector IDs that are different, but point to the same underlying VOL connector class.


f_ptr = C_NULL_PTR
CALL H5Pset_vol_f(fapl_id, vol_id, error, f_ptr)
CALL check("H5Pset_vol_f",error,total_error)

CALL H5Pget_vol_id_f(fapl_id, vol_id_out, error)
CALL check("H5Pget_vol_id_f",error,total_error)
CALL VERIFY("H5Pget_vol_id_f", vol_id_out, vol_id, total_error)
are_same = .FALSE.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use new routine instead of directly comparing IDs.

/**
* @ingroup JH5VL
*
* H5VLcmp_connector_cls Determines whether two connector identifiers refer to the same connector.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This routine is necessary because it's possible to have VOL connector IDs that are different, but point to the same underlying VOL connector class.

@@ -98,7 +98,8 @@ public void testH5VLget_connector_id()
*/
String connector = System.getenv("HDF5_VOL_CONNECTOR");
if (connector == null)
assertEquals(HDF5Constants.H5VL_NATIVE, native_id);
assertTrue("H5.H5VLcmp_connector_cls(H5VL_NATIVE_NAME, native_id)",
H5.H5VLcmp_connector_cls(HDF5Constants.H5VL_NATIVE, native_id));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use new routine instead of directly comparing IDs.

@@ -125,7 +125,7 @@ H5A__create_common(H5VL_object_t *vol_obj, H5VL_loc_params_t *loc_params, const
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5I_INVALID_HID, "unable to create attribute");

/* Register the new attribute and get an ID for it */
if ((ret_value = H5VL_register(H5I_ATTR, attr, vol_obj->connector, true)) < 0)
if ((ret_value = H5VL_register(H5I_ATTR, attr, H5VL_OBJ_CONNECTOR(vol_obj), true)) < 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes, and similar ones in non-H5VL packages, are to remove the code coupling to the H5VL package, allowing it to change implementation of H5VL data structures without rippling through the library.

@@ -931,33 +931,27 @@ H5CX_retrieve_state(H5CX_state_t **api_state)
} /* end if */

/* Keep a copy of the VOL connector property, if there is one */
if ((*head)->ctx.vol_connector_prop_valid && (*head)->ctx.vol_connector_prop.connector_id > 0) {
if ((*head)->ctx.vol_connector_prop_valid && (*head)->ctx.vol_connector_prop.connector) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VOL connector property stores a pointer to the connector struct now, instead of nesting an ID inside the property list.

@@ -88,12 +88,6 @@ static herr_t H5F__flush_api_common(hid_t object_id, H5F_scope_t scope, void **t
/* Local Variables */
/*******************/

/* Declare a free list to manage the H5VL_t struct */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused (and should not be used outside the H5VL package)

@@ -25,9 +25,6 @@
/* Public Macros */
/*****************/

/* Identifier for the native VOL connector */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move private pieces to private header

@@ -36,37 +36,51 @@
/* Package Private Typedefs */
/****************************/

/* Internal struct to track VOL connectors */
struct H5VL_connector_t {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One connector object per VOL connector class registered with the library

@@ -27,28 +27,33 @@
/* Library Private Macros */
/**************************/

/* If the module using this macro is allowed access to the private variables, access them directly */
#ifdef H5VL_MODULE
#define H5VL_OBJ_RC(VOL_OBJ) ((VOL_OBJ)->rc)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getters, for the rest of the library packages. (Similar idiom as in H5Fprivate.h)

@@ -395,7 +396,12 @@ test_es_get_requests(void)
TEST_ERROR;
if (count != 1)
TEST_ERROR;
if (connector_ids[0] != connector_ids_g[0])
cmp_value = 0;
if (H5VLcmp_connector_cls(&cmp_value, connector_ids[0], connector_ids_g[0]) < 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use new comparison routine in tests.

@qkoziol
Copy link
Contributor Author

qkoziol commented Sep 18, 2024

@mattjala - this is the PR that we talked about a week and a half ago. Should replace #4635 and fix #4634

@byrnHDF byrnHDF added Component - C Library Core C library issues (usually in the src directory) Component - Tools Command-line tools like h5dump, includes high-level tools Component - Java Java wrappers Component - Fortran Fortran wrappers Component - Testing Code in test or testpar directories, GitHub workflows Type - Improvement Improvements that don't add a new feature or functionality labels Sep 19, 2024
src/H5ES.c Show resolved Hide resolved
@derobins derobins added Merge - Develop Only This cannot be merged to previous versions of HDF5 (file format or breaking API changes) Priority - 1. High 🔼 These are important issues that should be resolved in the next release labels Sep 19, 2024
src/H5L.c Show resolved Hide resolved
HGOTO_ERROR(H5E_LINK, H5E_CANTCREATE, FAIL, "unable to create hard link");

/* Set the connector to use for async operations */
if (connector)
*connector = (link_vol_obj ? H5VL_OBJ_CONNECTOR(link_vol_obj) : H5VL_OBJ_CONNECTOR(curr_vol_obj));
Copy link
Contributor

@mattjala mattjala Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this returns a pointer to the connector, I think it should increment the ref count and require the caller to release it after it's done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strictly local within the source module and only used in one spot, so I don't think that is necessary here.

src/H5VL.c Show resolved Hide resolved
src/H5VL.c Show resolved Hide resolved
src/H5VL.c Show resolved Hide resolved
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL connector ID");

/* Bypass the H5VLint layer, calling the VOL callback directly */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the original reason to bypass the H5VLint layer here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not certain 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to have it be consistent, in the long term

Signed-off-by: Quincey Koziol <quincey@koziol.cc>
src/H5VLint.c Outdated Show resolved Hide resolved
Signed-off-by: Quincey Koziol <quincey@koziol.cc>
@@ -671,12 +671,8 @@ h5tools_set_fapl_vol(hid_t fapl_id, h5tools_vol_info_t *vol_info)
/* Check for VOL connectors that ship with the library, then try
* registering by name if that fails.
*/
if (!strcmp(vol_info->u.name, H5VL_NATIVE_NAME)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it would cause problems when trying to use h5tools with the native VOL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tools use the native connector by default; no command-line option is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - C Library Core C library issues (usually in the src directory) Component - Fortran Fortran wrappers Component - Java Java wrappers Component - Testing Code in test or testpar directories, GitHub workflows Component - Tools Command-line tools like h5dump, includes high-level tools Merge - Develop Only This cannot be merged to previous versions of HDF5 (file format or breaking API changes) Priority - 1. High 🔼 These are important issues that should be resolved in the next release Type - Improvement Improvements that don't add a new feature or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants