From f3686baaf0de37c2a4db6c3ec68d3a1be7c600e5 Mon Sep 17 00:00:00 2001 From: Vailin Choi Date: Thu, 5 Dec 2019 16:09:49 -0600 Subject: Verify the decoded version for hyperslab selection. --- src/H5Shyper.c | 3 +++ src/H5Spkg.h | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 5147289..e9a7133 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -4250,6 +4250,9 @@ H5S__hyper_deserialize(H5S_t **space, const uint8_t **p) /* Decode version */ UINT32DECODE(pp, version); + if(version < H5S_HYPER_VERSION_1 || version > H5S_HYPER_VERSION_LATEST) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "bad version number for hyperslab selection") + if(version >= (uint32_t)H5S_HYPER_VERSION_2) { /* Decode flags */ flags = *(pp)++; diff --git a/src/H5Spkg.h b/src/H5Spkg.h index 278f08d..6a78e52 100644 --- a/src/H5Spkg.h +++ b/src/H5Spkg.h @@ -41,9 +41,10 @@ #define H5S_SELECT_FLAG_BITS (H5S_HYPER_REGULAR) /* Versions for H5S_SEL_HYPER selection info */ -#define H5S_HYPER_VERSION_1 1 -#define H5S_HYPER_VERSION_2 2 -#define H5S_HYPER_VERSION_3 3 +#define H5S_HYPER_VERSION_1 1 +#define H5S_HYPER_VERSION_2 2 +#define H5S_HYPER_VERSION_3 3 +#define H5S_HYPER_VERSION_LATEST H5S_HYPER_VERSION_3 /* Versions for H5S_SEL_POINTS selection info */ #define H5S_POINT_VERSION_1 1 -- cgit v0.12 From a7a70824e43e7ff722bbbd39866ac3eff9faa961 Mon Sep 17 00:00:00 2001 From: Jordan Henderson Date: Mon, 2 Dec 2019 12:43:49 -0600 Subject: Add OAPL parameter to H5Rcreate_ APIs --- examples/h5_ref_extern.c | 2 +- src/H5R.c | 42 ++++++++++++++++++++++++---- src/H5Rdeprec.c | 1 + src/H5Rpublic.h | 6 ++-- test/objcopy_ref.c | 12 ++++---- test/trefer.c | 72 ++++++++++++++++++++++++------------------------ 6 files changed, 83 insertions(+), 52 deletions(-) diff --git a/examples/h5_ref_extern.c b/examples/h5_ref_extern.c index 4327a06..17082ba 100644 --- a/examples/h5_ref_extern.c +++ b/examples/h5_ref_extern.c @@ -56,7 +56,7 @@ main(void) { /* Create reference to dataset1 in "refer_extern1.h5" */ file1 = H5Fopen(H5FILE_NAME1, H5F_ACC_RDONLY, H5P_DEFAULT); - H5Rcreate_object(file1, "dataset1", &ref_buf[0]); + H5Rcreate_object(file1, "dataset1", H5P_DEFAULT, &ref_buf[0]); H5Fclose(file1); /* Store reference in dataset in separate file "refer_extern2.h5" */ diff --git a/src/H5R.c b/src/H5R.c index 11b75ca..162bd8c 100644 --- a/src/H5R.c +++ b/src/H5R.c @@ -74,7 +74,7 @@ *------------------------------------------------------------------------- */ herr_t -H5Rcreate_object(hid_t loc_id, const char *name, H5R_ref_t *ref_ptr) +H5Rcreate_object(hid_t loc_id, const char *name, hid_t oapl_id, H5R_ref_t *ref_ptr) { H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ H5I_type_t obj_type; /* Object type of loc_id */ @@ -86,13 +86,22 @@ H5Rcreate_object(hid_t loc_id, const char *name, H5R_ref_t *ref_ptr) herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) - H5TRACE3("e", "i*s*Rr", loc_id, name, ref_ptr); + H5TRACE4("e", "i*si*Rr", loc_id, name, oapl_id, ref_ptr); /* Check args */ if(ref_ptr == NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer") if(!name || !*name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given") + if(oapl_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") + + /* Get object access property list */ + if(H5P_DEFAULT == oapl_id) + oapl_id = H5P_LINK_ACCESS_DEFAULT; + else + if(TRUE != H5P_isa_class(oapl_id, H5P_LINK_ACCESS)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "oapl_id is not a link access property list ID") /* Get the VOL object */ if(NULL == (vol_obj = H5VL_vol_object(loc_id))) @@ -117,6 +126,7 @@ H5Rcreate_object(hid_t loc_id, const char *name, H5R_ref_t *ref_ptr) /* Set location parameters */ loc_params.type = H5VL_OBJECT_BY_NAME; loc_params.loc_data.loc_by_name.name = name; + loc_params.loc_data.loc_by_name.lapl_id = oapl_id; loc_params.obj_type = obj_type; /* Get the object token */ @@ -152,7 +162,7 @@ done: */ herr_t H5Rcreate_region(hid_t loc_id, const char *name, hid_t space_id, - H5R_ref_t *ref_ptr) + hid_t oapl_id, H5R_ref_t *ref_ptr) { H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ H5I_type_t obj_type; /* Object type of loc_id */ @@ -165,7 +175,7 @@ H5Rcreate_region(hid_t loc_id, const char *name, hid_t space_id, herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) - H5TRACE4("e", "i*si*Rr", loc_id, name, space_id, ref_ptr); + H5TRACE5("e", "i*sii*Rr", loc_id, name, space_id, oapl_id, ref_ptr); /* Check args */ if(ref_ptr == NULL) @@ -176,6 +186,15 @@ H5Rcreate_region(hid_t loc_id, const char *name, hid_t space_id, HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "reference region dataspace id must be valid") if(NULL == (space = (struct H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") + if(oapl_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") + + /* Get object access property list */ + if(H5P_DEFAULT == oapl_id) + oapl_id = H5P_LINK_ACCESS_DEFAULT; + else + if(TRUE != H5P_isa_class(oapl_id, H5P_LINK_ACCESS)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "oapl_id is not a link access property list ID") /* Get the VOL object */ if(NULL == (vol_obj = H5VL_vol_object(loc_id))) @@ -200,6 +219,7 @@ H5Rcreate_region(hid_t loc_id, const char *name, hid_t space_id, /* Set location parameters */ loc_params.type = H5VL_OBJECT_BY_NAME; loc_params.loc_data.loc_by_name.name = name; + loc_params.loc_data.loc_by_name.lapl_id = oapl_id; loc_params.obj_type = obj_type; /* Get the object token */ @@ -234,7 +254,7 @@ done: */ herr_t H5Rcreate_attr(hid_t loc_id, const char *name, const char *attr_name, - H5R_ref_t *ref_ptr) + hid_t oapl_id, H5R_ref_t *ref_ptr) { H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ H5I_type_t obj_type; /* Object type of loc_id */ @@ -246,7 +266,7 @@ H5Rcreate_attr(hid_t loc_id, const char *name, const char *attr_name, herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) - H5TRACE4("e", "i*s*s*Rr", loc_id, name, attr_name, ref_ptr); + H5TRACE5("e", "i*s*si*Rr", loc_id, name, attr_name, oapl_id, ref_ptr); /* Check args */ if(ref_ptr == NULL) @@ -255,6 +275,15 @@ H5Rcreate_attr(hid_t loc_id, const char *name, const char *attr_name, HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given") if(!attr_name || !*attr_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name given") + if(oapl_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") + + /* Get object access property list */ + if(H5P_DEFAULT == oapl_id) + oapl_id = H5P_LINK_ACCESS_DEFAULT; + else + if(TRUE != H5P_isa_class(oapl_id, H5P_LINK_ACCESS)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "oapl_id is not a link access property list ID") /* Get the VOL object */ if(NULL == (vol_obj = H5VL_vol_object(loc_id))) @@ -279,6 +308,7 @@ H5Rcreate_attr(hid_t loc_id, const char *name, const char *attr_name, /* Set location parameters */ loc_params.type = H5VL_OBJECT_BY_NAME; loc_params.loc_data.loc_by_name.name = name; + loc_params.loc_data.loc_by_name.lapl_id = oapl_id; loc_params.obj_type = obj_type; /* Get the object token */ diff --git a/src/H5Rdeprec.c b/src/H5Rdeprec.c index b9bdffa..f0dc503 100644 --- a/src/H5Rdeprec.c +++ b/src/H5Rdeprec.c @@ -258,6 +258,7 @@ H5Rcreate(void *ref, hid_t loc_id, const char *name, H5R_type_t ref_type, /* Set location parameters */ loc_params.type = H5VL_OBJECT_BY_NAME; loc_params.loc_data.loc_by_name.name = name; + loc_params.loc_data.loc_by_name.lapl_id = H5P_LINK_ACCESS_DEFAULT; loc_params.obj_type = vol_obj_type; /* Get the object token */ diff --git a/src/H5Rpublic.h b/src/H5Rpublic.h index ce54ac4..585cb85 100644 --- a/src/H5Rpublic.h +++ b/src/H5Rpublic.h @@ -93,9 +93,9 @@ extern "C" { #endif /* Constructors */ -H5_DLL herr_t H5Rcreate_object(hid_t loc_id, const char *name, H5R_ref_t *ref_ptr); -H5_DLL herr_t H5Rcreate_region(hid_t loc_id, const char *name, hid_t space_id, H5R_ref_t *ref_ptr); -H5_DLL herr_t H5Rcreate_attr(hid_t loc_id, const char *name, const char *attr_name, H5R_ref_t *ref_ptr); +H5_DLL herr_t H5Rcreate_object(hid_t loc_id, const char *name, hid_t oapl_id, H5R_ref_t *ref_ptr); +H5_DLL herr_t H5Rcreate_region(hid_t loc_id, const char *name, hid_t space_id, hid_t oapl_id, H5R_ref_t *ref_ptr); +H5_DLL herr_t H5Rcreate_attr(hid_t loc_id, const char *name, const char *attr_name, hid_t oapl_id, H5R_ref_t *ref_ptr); H5_DLL herr_t H5Rdestroy(H5R_ref_t *ref_ptr); /* Info */ diff --git a/test/objcopy_ref.c b/test/objcopy_ref.c index 721a7c6..a73e569 100644 --- a/test/objcopy_ref.c +++ b/test/objcopy_ref.c @@ -247,8 +247,8 @@ attach_ref_attr(hid_t file_id, hid_t loc_id) if(H5Dwrite(did2, H5T_NATIVE_INT, H5S_ALL , H5S_ALL, H5P_DEFAULT,data2) < 0) TEST_ERROR /* create an attribute with two object references */ - if(H5Rcreate_object(file_id, dsetname1, &ref[0]) < 0) TEST_ERROR - if(H5Rcreate_object(file_id, dsetname2, &ref[1]) < 0) TEST_ERROR + if(H5Rcreate_object(file_id, dsetname1, H5P_DEFAULT, &ref[0]) < 0) TEST_ERROR + if(H5Rcreate_object(file_id, dsetname2, H5P_DEFAULT, &ref[1]) < 0) TEST_ERROR if((aid = H5Acreate2(loc_id, "obj_ref_attr", H5T_STD_REF, sid_ref, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR if(H5Awrite(aid, H5T_STD_REF, ref) < 0) TEST_ERROR @@ -315,12 +315,12 @@ attach_reg_ref_attr(hid_t file_id, hid_t loc_id) /* create reg_ref of block selection */ if(H5Sselect_hyperslab(space_id,H5S_SELECT_SET,start,NULL,count,NULL) < 0) TEST_ERROR - if(H5Rcreate_region(file_id, dsetnamev, space_id, &ref[0]) < 0) TEST_ERROR + if(H5Rcreate_region(file_id, dsetnamev, space_id, H5P_DEFAULT, &ref[0]) < 0) TEST_ERROR /* create reg_ref of point selection */ if(H5Sselect_none(space_id) < 0) TEST_ERROR if(H5Sselect_elements(space_id, H5S_SELECT_SET, num_points, (const hsize_t *)coord) < 0) TEST_ERROR - if(H5Rcreate_region(file_id, dsetnamev, space_id, &ref[1]) < 0) TEST_ERROR + if(H5Rcreate_region(file_id, dsetnamev, space_id, H5P_DEFAULT, &ref[1]) < 0) TEST_ERROR /* create reg_ref attribute */ if((aid = H5Acreate2(loc_id, "reg_ref_attr", H5T_STD_REF, spacer_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR @@ -402,10 +402,10 @@ create_reg_ref_dataset(hid_t file_id, hid_t loc_id) count[0] = 2; count[1] = 3; if(H5Sselect_hyperslab(space_id,H5S_SELECT_SET,start,NULL,count,NULL) < 0) TEST_ERROR - if(H5Rcreate_region(file_id, dsetnamev, space_id, &ref[0]) < 0) TEST_ERROR + if(H5Rcreate_region(file_id, dsetnamev, space_id, H5P_DEFAULT, &ref[0]) < 0) TEST_ERROR if(H5Sselect_none(space_id) < 0) TEST_ERROR if(H5Sselect_elements(space_id, H5S_SELECT_SET, num_points, (const hsize_t *)coord) < 0) TEST_ERROR - if(H5Rcreate_region(file_id, dsetnamev, space_id, &ref[1]) < 0) TEST_ERROR + if(H5Rcreate_region(file_id, dsetnamev, space_id, H5P_DEFAULT, &ref[1]) < 0) TEST_ERROR if(H5Dwrite(dsetr_id, H5T_STD_REF, H5S_ALL, H5S_ALL, H5P_DEFAULT,ref) < 0) TEST_ERROR if(H5Dclose(dsetr_id) < 0) TEST_ERROR diff --git a/test/trefer.c b/test/trefer.c index 7d87ea9..7ab3bd4 100644 --- a/test/trefer.c +++ b/test/trefer.c @@ -195,33 +195,33 @@ test_reference_params(void) CHECK(ret, H5I_INVALID_HID, "H5Dcreate2"); /* Test parameters to H5Rcreate_object */ - ret = H5Rcreate_object(fid1, "/Group1/Dataset1", NULL); + ret = H5Rcreate_object(fid1, "/Group1/Dataset1", H5P_DEFAULT, NULL); VERIFY(ret, FAIL, "H5Rcreate_object ref"); - ret = H5Rcreate_object(H5I_INVALID_HID, "/Group1/Dataset1", &wbuf[0]); + ret = H5Rcreate_object(H5I_INVALID_HID, "/Group1/Dataset1", H5P_DEFAULT, &wbuf[0]); VERIFY(ret, FAIL, "H5Rcreate_object loc_id"); - ret = H5Rcreate_object(fid1, NULL, &wbuf[0]); + ret = H5Rcreate_object(fid1, NULL, H5P_DEFAULT, &wbuf[0]); VERIFY(ret, FAIL, "H5Rcreate_object name"); - ret = H5Rcreate_object(fid1, "", &wbuf[0]); + ret = H5Rcreate_object(fid1, "", H5P_DEFAULT, &wbuf[0]); VERIFY(ret, FAIL, "H5Rcreate_object null name"); /* Test parameters to H5Rcreate_region */ - ret = H5Rcreate_region(fid1, "/Group1/Dataset1", sid1, NULL); + ret = H5Rcreate_region(fid1, "/Group1/Dataset1", sid1, H5P_DEFAULT, NULL); VERIFY(ret, FAIL, "H5Rcreate_region ref"); - ret = H5Rcreate_region(H5I_INVALID_HID, "/Group1/Dataset1", sid1, &wbuf[0]); + ret = H5Rcreate_region(H5I_INVALID_HID, "/Group1/Dataset1", sid1, H5P_DEFAULT, &wbuf[0]); VERIFY(ret, FAIL, "H5Rcreate_region loc_id"); - ret = H5Rcreate_region(fid1, NULL, sid1, &wbuf[0]); + ret = H5Rcreate_region(fid1, NULL, sid1, H5P_DEFAULT, &wbuf[0]); VERIFY(ret, FAIL, "H5Rcreate_region name"); - ret = H5Rcreate_region(fid1, "/Group1/Dataset1", H5I_INVALID_HID, &wbuf[0]); + ret = H5Rcreate_region(fid1, "/Group1/Dataset1", H5I_INVALID_HID, H5P_DEFAULT, &wbuf[0]); VERIFY(ret, FAIL, "H5Rcreate_region dataspace"); /* Test parameters to H5Rcreate_attr */ - ret = H5Rcreate_attr(fid1, "/Group1/Dataset2", "Attr", NULL); + ret = H5Rcreate_attr(fid1, "/Group1/Dataset2", "Attr", H5P_DEFAULT, NULL); VERIFY(ret, FAIL, "H5Rcreate_attr ref"); - ret = H5Rcreate_attr(H5I_INVALID_HID, "/Group1/Dataset2", "Attr", &wbuf[0]); + ret = H5Rcreate_attr(H5I_INVALID_HID, "/Group1/Dataset2", "Attr", H5P_DEFAULT, &wbuf[0]); VERIFY(ret, FAIL, "H5Rcreate_attr loc_id"); - ret = H5Rcreate_attr(fid1, NULL, "Attr", &wbuf[0]); + ret = H5Rcreate_attr(fid1, NULL, "Attr", H5P_DEFAULT, &wbuf[0]); VERIFY(ret, FAIL, "H5Rcreate_attr name"); - ret = H5Rcreate_attr(fid1, "/Group1/Dataset2", NULL, &wbuf[0]); + ret = H5Rcreate_attr(fid1, "/Group1/Dataset2", NULL, H5P_DEFAULT, &wbuf[0]); VERIFY(ret, FAIL, "H5Rcreate_attr attr_name"); /* Test parameters to H5Rdestroy */ @@ -403,28 +403,28 @@ test_reference_obj(void) CHECK(dataset, H5I_INVALID_HID, "H5Dcreate2"); /* Create reference to dataset */ - ret = H5Rcreate_object(fid1, "/Group1/Dataset1", &wbuf[0]); + ret = H5Rcreate_object(fid1, "/Group1/Dataset1", H5P_DEFAULT, &wbuf[0]); CHECK(ret, FAIL, "H5Rcreate_object"); ret = H5Rget_obj_type3((const H5R_ref_t *)&wbuf[0], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); VERIFY(obj_type, H5O_TYPE_DATASET, "H5Rget_obj_type3"); /* Create reference to dataset */ - ret = H5Rcreate_object(fid1, "/Group1/Dataset2", &wbuf[1]); + ret = H5Rcreate_object(fid1, "/Group1/Dataset2", H5P_DEFAULT, &wbuf[1]); CHECK(ret, FAIL, "H5Rcreate_object"); ret = H5Rget_obj_type3((const H5R_ref_t *)&wbuf[1], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); VERIFY(obj_type, H5O_TYPE_DATASET, "H5Rget_obj_type3"); /* Create reference to group */ - ret = H5Rcreate_object(fid1, "/Group1", &wbuf[2]); + ret = H5Rcreate_object(fid1, "/Group1", H5P_DEFAULT, &wbuf[2]); CHECK(ret, FAIL, "H5Rcreate_object"); ret = H5Rget_obj_type3((const H5R_ref_t *)&wbuf[2], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); VERIFY(obj_type, H5O_TYPE_GROUP, "H5Rget_obj_type3"); /* Create reference to named datatype */ - ret = H5Rcreate_object(fid1, "/Group1/Datatype1", &wbuf[3]); + ret = H5Rcreate_object(fid1, "/Group1/Datatype1", H5P_DEFAULT, &wbuf[3]); CHECK(ret, FAIL, "H5Rcreate_object"); ret = H5Rget_obj_type3((const H5R_ref_t *)&wbuf[3], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); @@ -645,7 +645,7 @@ test_reference_region(H5F_libver_t libver_low, H5F_libver_t libver_high) VERIFY(ret, 36, "H5Sget_select_npoints"); /* Store first dataset region */ - ret = H5Rcreate_region(fid1, "/Dataset2", sid2, &wbuf[0]); + ret = H5Rcreate_region(fid1, "/Dataset2", sid2, H5P_DEFAULT, &wbuf[0]); CHECK(ret, FAIL, "H5Rcreate_region"); ret = H5Rget_obj_type3((const H5R_ref_t *)&wbuf[0], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); @@ -669,7 +669,7 @@ test_reference_region(H5F_libver_t libver_low, H5F_libver_t libver_high) VERIFY(ret, SPACE2_DIM2, "H5Sget_select_npoints"); /* Store second dataset region */ - ret = H5Rcreate_region(fid1, "/Dataset2", sid2, &wbuf[1]); + ret = H5Rcreate_region(fid1, "/Dataset2", sid2, H5P_DEFAULT, &wbuf[1]); CHECK(ret, FAIL, "H5Rcreate_region"); /* Select unlimited hyperslab for third reference */ @@ -688,7 +688,7 @@ test_reference_region(H5F_libver_t libver_low, H5F_libver_t libver_high) VERIFY(hssize_ret, (hssize_t)H5S_UNLIMITED, "H5Sget_select_npoints"); /* Store third dataset region */ - ret = H5Rcreate_region(fid1, "/Dataset2", sid2, &wbuf[2]); + ret = H5Rcreate_region(fid1, "/Dataset2", sid2, H5P_DEFAULT, &wbuf[2]); CHECK(ret, FAIL, "H5Rcreate_region"); ret = H5Rget_obj_type3((const H5R_ref_t *)&wbuf[2], H5P_DEFAULT, &obj_type); @@ -696,7 +696,7 @@ test_reference_region(H5F_libver_t libver_low, H5F_libver_t libver_high) VERIFY(obj_type, H5O_TYPE_DATASET, "H5Rget_obj_type3"); /* Store fourth dataset region */ - ret = H5Rcreate_region(fid1, "/Dataset2", sid2, &wbuf[3]); + ret = H5Rcreate_region(fid1, "/Dataset2", sid2, H5P_DEFAULT, &wbuf[3]); CHECK(ret, FAIL, "H5Rcreate_region"); /* Write selection to disk */ @@ -1068,7 +1068,7 @@ test_reference_region_1D(H5F_libver_t libver_low, H5F_libver_t libver_high) VERIFY(ret, (block[0] * count[0]), "H5Sget_select_npoints"); /* Store first dataset region */ - ret = H5Rcreate_region(fid1, "/Dataset2", sid3, &wbuf[0]); + ret = H5Rcreate_region(fid1, "/Dataset2", sid3, H5P_DEFAULT, &wbuf[0]); CHECK(ret, FAIL, "H5Rcreate_region"); ret = H5Rget_obj_type3((const H5R_ref_t *)&wbuf[0], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); @@ -1092,7 +1092,7 @@ test_reference_region_1D(H5F_libver_t libver_low, H5F_libver_t libver_high) VERIFY(ret, POINT1_NPOINTS, "H5Sget_select_npoints"); /* Store second dataset region */ - ret = H5Rcreate_region(fid1, "/Dataset2", sid3, &wbuf[1]); + ret = H5Rcreate_region(fid1, "/Dataset2", sid3, H5P_DEFAULT, &wbuf[1]); CHECK(ret, FAIL, "H5Rcreate_region"); /* Write selection to disk */ @@ -1311,7 +1311,7 @@ test_reference_obj_deleted(void) CHECK(dataset, H5I_INVALID_HID, "H5Dcreate2"); /* Create reference to dataset */ - ret = H5Rcreate_object(fid1, "/Dataset1", &oref); + ret = H5Rcreate_object(fid1, "/Dataset1", H5P_DEFAULT, &oref); CHECK(ret, FAIL, "H5Rcreate_object"); ret = H5Rget_obj_type3((const H5R_ref_t *)&oref, H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); @@ -1469,7 +1469,7 @@ test_reference_group(void) CHECK(did, H5I_INVALID_HID, "H5Dcreate2"); /* Create reference to group */ - ret = H5Rcreate_object(fid, GROUPNAME, &wref); + ret = H5Rcreate_object(fid, GROUPNAME, H5P_DEFAULT, &wref); CHECK(ret, FAIL, "H5Rcreate_object"); /* Write reference to disk */ @@ -1678,28 +1678,28 @@ test_reference_attr(void) CHECK(dataset, H5I_INVALID_HID, "H5Dcreate2"); /* Create reference to dataset1 attribute */ - ret = H5Rcreate_attr(fid, "/Group1/Dataset1", "Attr1", &ref_wbuf[0]); + ret = H5Rcreate_attr(fid, "/Group1/Dataset1", "Attr1", H5P_DEFAULT, &ref_wbuf[0]); CHECK(ret, FAIL, "H5Rcreate_attr"); ret = H5Rget_obj_type3((const H5R_ref_t *)&ref_wbuf[0], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); VERIFY(obj_type, H5O_TYPE_DATASET, "H5Rget_obj_type3"); /* Create reference to dataset2 attribute */ - ret = H5Rcreate_attr(fid, "/Group1/Dataset2", "Attr1", &ref_wbuf[1]); + ret = H5Rcreate_attr(fid, "/Group1/Dataset2", "Attr1", H5P_DEFAULT, &ref_wbuf[1]); CHECK(ret, FAIL, "H5Rcreate_attr"); ret = H5Rget_obj_type3((const H5R_ref_t *)&ref_wbuf[1], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); VERIFY(obj_type, H5O_TYPE_DATASET, "H5Rget_obj_type3"); /* Create reference to group attribute */ - ret = H5Rcreate_attr(fid, "/Group1", "Attr2", &ref_wbuf[2]); + ret = H5Rcreate_attr(fid, "/Group1", "Attr2", H5P_DEFAULT, &ref_wbuf[2]); CHECK(ret, FAIL, "H5Rcreate_attr"); ret = H5Rget_obj_type3((const H5R_ref_t *)&ref_wbuf[2], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); VERIFY(obj_type, H5O_TYPE_GROUP, "H5Rget_obj_type3"); /* Create reference to named datatype attribute */ - ret = H5Rcreate_attr(fid, "/Group1/Datatype1", "Attr3", &ref_wbuf[3]); + ret = H5Rcreate_attr(fid, "/Group1/Datatype1", "Attr3", H5P_DEFAULT, &ref_wbuf[3]); CHECK(ret, FAIL, "H5Rcreate_attr"); ret = H5Rget_obj_type3((const H5R_ref_t *)&ref_wbuf[3], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); @@ -1938,28 +1938,28 @@ test_reference_external(void) CHECK(ret, FAIL, "H5Gclose"); /* Create reference to dataset1 attribute */ - ret = H5Rcreate_attr(fid1, "/Group1/Dataset1", "Attr1", &ref_wbuf[0]); + ret = H5Rcreate_attr(fid1, "/Group1/Dataset1", "Attr1", H5P_DEFAULT, &ref_wbuf[0]); CHECK(ret, FAIL, "H5Rcreate_attr"); ret = H5Rget_obj_type3((const H5R_ref_t *)&ref_wbuf[0], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); VERIFY(obj_type, H5O_TYPE_DATASET, "H5Rget_obj_type3"); /* Create reference to dataset2 attribute */ - ret = H5Rcreate_attr(fid1, "/Group1/Dataset2", "Attr1", &ref_wbuf[1]); + ret = H5Rcreate_attr(fid1, "/Group1/Dataset2", "Attr1", H5P_DEFAULT, &ref_wbuf[1]); CHECK(ret, FAIL, "H5Rcreate_attr"); ret = H5Rget_obj_type3((const H5R_ref_t *)&ref_wbuf[1], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); VERIFY(obj_type, H5O_TYPE_DATASET, "H5Rget_obj_type3"); /* Create reference to group attribute */ - ret = H5Rcreate_attr(fid1, "/Group1", "Attr2", &ref_wbuf[2]); + ret = H5Rcreate_attr(fid1, "/Group1", "Attr2", H5P_DEFAULT, &ref_wbuf[2]); CHECK(ret, FAIL, "H5Rcreate_attr"); ret = H5Rget_obj_type3((const H5R_ref_t *)&ref_wbuf[2], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); VERIFY(obj_type, H5O_TYPE_GROUP, "H5Rget_obj_type3"); /* Create reference to named datatype attribute */ - ret = H5Rcreate_attr(fid1, "/Group1/Datatype1", "Attr3", &ref_wbuf[3]); + ret = H5Rcreate_attr(fid1, "/Group1/Datatype1", "Attr3", H5P_DEFAULT, &ref_wbuf[3]); CHECK(ret, FAIL, "H5Rcreate_attr"); ret = H5Rget_obj_type3((const H5R_ref_t *)&ref_wbuf[3], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); @@ -2506,7 +2506,7 @@ test_reference_perf(void) t = 0; for(i = 0; i < MAX_ITER_CREATE; i++) { t1 = H5_get_time(); - ret = H5Rcreate_object(fid1, "/Group1/Dataset1", &wbuf[0]); + ret = H5Rcreate_object(fid1, "/Group1/Dataset1", H5P_DEFAULT, &wbuf[0]); CHECK(ret, FAIL, "H5Rcreate_object"); t2 = H5_get_time(); t += t2 - t1; @@ -2516,7 +2516,7 @@ test_reference_perf(void) HDprintf("--- Object reference create time: %lfs\n", t / MAX_ITER_CREATE); /* Create reference to dataset */ - ret = H5Rcreate_object(fid1, "/Group1/Dataset1", &wbuf[0]); + ret = H5Rcreate_object(fid1, "/Group1/Dataset1", H5P_DEFAULT, &wbuf[0]); CHECK(ret, FAIL, "H5Rcreate_object"); ret = H5Rget_obj_type3((const H5R_ref_t *)&wbuf[0], H5P_DEFAULT, &obj_type); CHECK(ret, FAIL, "H5Rget_obj_type3"); @@ -2578,7 +2578,7 @@ test_reference_perf(void) for(i = 0; i < MAX_ITER_CREATE; i++) { t1 = H5_get_time(); /* Store first dataset region */ - ret = H5Rcreate_region(fid1, "/Group1/Dataset1", sid1, &wbuf_reg[0]); + ret = H5Rcreate_region(fid1, "/Group1/Dataset1", sid1, H5P_DEFAULT, &wbuf_reg[0]); CHECK(ret, FAIL, "H5Rcreate_region"); t2 = H5_get_time(); t += t2 - t1; @@ -2588,7 +2588,7 @@ test_reference_perf(void) HDprintf("--- Region reference create time: %lfs\n", t / MAX_ITER_CREATE); /* Store first dataset region */ - ret = H5Rcreate_region(fid1, "/Group1/Dataset1", sid1, &wbuf_reg[0]); + ret = H5Rcreate_region(fid1, "/Group1/Dataset1", sid1, H5P_DEFAULT, &wbuf_reg[0]); CHECK(ret, FAIL, "H5Rcreate_region"); t = 0; -- cgit v0.12 From 0f1be317c37ca04db263680e6f1fe4d97b937b39 Mon Sep 17 00:00:00 2001 From: Vailin Choi Date: Fri, 6 Dec 2019 12:17:30 -0600 Subject: More fixes for the PR: (1) Set the version for reference datatype message to H5O_DTYPE_VERSION_4. (2) The tests for the new reference types should work for V112 and beyond. --- src/H5T.c | 1 + test/trefer.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/H5T.c b/src/H5T.c index 43dfef8..f2d6c70 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -254,6 +254,7 @@ dt->shared->u.atomic.u.r.rtype = H5R_OBJECT2; \ dt->shared->u.atomic.u.r.opaque = TRUE; \ dt->shared->u.atomic.u.r.version = H5R_ENCODE_VERSION; \ + dt->shared->version = H5O_DTYPE_VERSION_4; \ } /* Define the code templates for the "SIZE_TMPL" in the H5T_INIT_TYPE macro */ diff --git a/test/trefer.c b/test/trefer.c index 7d87ea9..580ebe1 100644 --- a/test/trefer.c +++ b/test/trefer.c @@ -2811,7 +2811,7 @@ test_reference(void) for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { /* Invalid combinations, just continue */ - if(high == H5F_LIBVER_EARLIEST || high < low) + if(high <= H5F_LIBVER_V110 || high < low) continue; test_reference_region(low, high); /* Test basic H5R dataset region reference code */ -- cgit v0.12 From 63282c122955dad755e9e2500c7159fdc29abf5d Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Tue, 29 Oct 2019 14:38:50 -0500 Subject: Implement H5VLget_file_type() to return a copy of a datatype with the location set to be in a file. Only meant to be used by VOL connectors. Implement H5VLpeek_connector_id() to support connectors querying their own IDs. Fix app_ref with connector IDs in a couple places (external VOLs registered as default through ENV should be visible to the application). Modify vlen and reference interfaces to work with arbitrary VOL connectors. Implement file "post open" specific callback, to enable connectors to update their file structs after a wrap context has been set. --- src/H5Aint.c | 4 +- src/H5Dchunk.c | 2 +- src/H5Dcompact.c | 2 +- src/H5Dcontig.c | 2 +- src/H5Dint.c | 4 +- src/H5Dio.c | 2 +- src/H5F.c | 26 +++++ src/H5Fefc.c | 12 +++ src/H5Fint.c | 42 +++++++- src/H5Fpkg.h | 2 + src/H5Fprivate.h | 5 +- src/H5Fquery.c | 20 ++++ src/H5Oattr.c | 2 +- src/H5Oattribute.c | 4 +- src/H5Ocopy_ref.c | 2 +- src/H5Odtype.c | 4 +- src/H5T.c | 76 +++++++++++--- src/H5Tcommit.c | 6 +- src/H5Tconv.c | 30 +++--- src/H5Tpkg.h | 28 +++--- src/H5Tprivate.h | 5 +- src/H5Tref.c | 235 +++++++++++++++++++++++++++---------------- src/H5Tvlen.c | 176 ++++++++++++-------------------- src/H5VL.c | 101 +++++++++++++++++++ src/H5VLcallback.c | 14 +-- src/H5VLconnector.h | 6 +- src/H5VLconnector_passthru.h | 2 +- src/H5VLint.c | 101 +++++++++++++++++-- src/H5VLnative_blob.c | 11 +- src/H5VLnative_file.c | 9 ++ src/H5VLnative_private.h | 2 +- src/H5VLpassthru.c | 4 +- src/H5VLpkg.h | 1 + src/H5VLprivate.h | 3 +- 34 files changed, 656 insertions(+), 289 deletions(-) diff --git a/src/H5Aint.c b/src/H5Aint.c index f9ae009..67f914f 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -207,7 +207,7 @@ H5A__create(const H5G_loc_t *loc, const char *attr_name, const H5T_t *type, HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "can't get shared datatype info") /* Mark datatype as being on disk now */ - if(H5T_set_loc(attr->shared->dt, loc->oloc->file, H5T_LOC_DISK) < 0) + if(H5T_set_loc(attr->shared->dt, H5F_VOL_OBJ(loc->oloc->file), H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid datatype location") /* Set the version for datatype */ @@ -2114,7 +2114,7 @@ H5A__attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_s HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "cannot copy datatype") /* Set the location of the destination datatype */ - if(H5T_set_loc(attr_dst->shared->dt, file_dst, H5T_LOC_DISK) < 0) + if(H5T_set_loc(attr_dst->shared->dt, H5F_VOL_OBJ(file_dst), H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "cannot mark datatype on disk") if(!H5T_is_named(attr_src->shared->dt)) { diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index 53ca7d1..d605ef9 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -6279,7 +6279,7 @@ H5D__chunk_copy(H5F_t *f_src, H5O_storage_chunk_t *storage_src, /* create variable-length datatype at the destinaton file */ if(NULL == (dt_dst = H5T_copy(dt_src, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy") - if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0) { + if(H5T_set_loc(dt_dst, H5F_VOL_OBJ(f_dst), H5T_LOC_DISK) < 0) { (void)H5T_close_real(dt_dst); HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype on disk") } /* end if */ diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c index edad3c5..809cdfc 100644 --- a/src/H5Dcompact.c +++ b/src/H5Dcompact.c @@ -476,7 +476,7 @@ H5D__compact_copy(H5F_t *f_src, H5O_storage_compact_t *_storage_src, H5F_t *f_ds /* create variable-length datatype at the destinaton file */ if(NULL == (dt_dst = H5T_copy(dt_src, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy") - if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0) { + if(H5T_set_loc(dt_dst, H5F_VOL_OBJ(f_dst), H5T_LOC_DISK) < 0) { (void)H5T_close_real(dt_dst); HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype on disk") } /* end if */ diff --git a/src/H5Dcontig.c b/src/H5Dcontig.c index 0be7364..e48c3b3 100644 --- a/src/H5Dcontig.c +++ b/src/H5Dcontig.c @@ -1398,7 +1398,7 @@ H5D__contig_copy(H5F_t *f_src, const H5O_storage_contig_t *storage_src, /* create variable-length datatype at the destinaton file */ if(NULL == (dt_dst = H5T_copy(dt_src, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to copy") - if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0) { + if(H5T_set_loc(dt_dst, H5F_VOL_OBJ(f_dst), H5T_LOC_DISK) < 0) { (void)H5T_close_real(dt_dst); HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "cannot mark datatype on disk") } /* end if */ diff --git a/src/H5Dint.c b/src/H5Dint.c index 21447c0..0acb030 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -575,7 +575,7 @@ H5D__init_type(H5F_t *file, const H5D_t *dset, hid_t type_id, const H5T_t *type) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't get shared datatype info") /* Mark any datatypes as being on disk now */ - if(H5T_set_loc(dset->shared->type, file, H5T_LOC_DISK) < 0) + if(H5T_set_loc(dset->shared->type, H5F_VOL_OBJ(file), H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't set datatype location") /* Set the version for datatype */ @@ -1713,7 +1713,7 @@ H5D__open_oid(H5D_t *dataset, hid_t dapl_id) if(NULL == (dataset->shared->type = (H5T_t *)H5O_msg_read(&(dataset->oloc), H5O_DTYPE_ID, NULL))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to load type info from dataset header") - if(H5T_set_loc(dataset->shared->type, dataset->oloc.file, H5T_LOC_DISK) < 0) + if(H5T_set_loc(dataset->shared->type, H5F_VOL_OBJ(dataset->oloc.file), H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location") if(NULL == (dataset->shared->space = H5S_read(&(dataset->oloc)))) diff --git a/src/H5Dio.c b/src/H5Dio.c index 79a856a..1237063 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -917,7 +917,7 @@ H5D__typeinfo_init(const H5D_t *dset, hid_t mem_type_id, hbool_t do_write, HDassert(dset); /* Patch the top level file pointer for dt->shared->u.vlen.f if needed */ - if(H5T_patch_vlen_file(dset->shared->type, dset->oloc.file) < 0 ) + if(H5T_patch_vlen_file(dset->shared->type, H5F_VOL_OBJ(dset->oloc.file)) < 0 ) HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "can't patch VL datatype file pointer") /* Initialize type info safely */ diff --git a/src/H5F.c b/src/H5F.c index d216cd2..35176fc 100644 --- a/src/H5F.c +++ b/src/H5F.c @@ -624,6 +624,7 @@ H5Fcreate(const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id) H5F_t *new_file = NULL; /* File struct for new file */ H5P_genplist_t *plist; /* Property list pointer */ H5VL_connector_prop_t connector_prop; /* Property for VOL connector ID & info */ + H5VL_object_t *vol_obj = NULL; /* VOL object for file */ hid_t ret_value; /* return value */ FUNC_ENTER_API(H5I_INVALID_HID) @@ -682,6 +683,14 @@ H5Fcreate(const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id) if((ret_value = H5VL_register_using_vol_id(H5I_FILE, new_file, connector_prop.connector_id, TRUE)) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize file handle") + /* Get the file object */ + if(NULL == (vol_obj = H5VL_vol_object(ret_value))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid object identifier") + + /* Make the post open callback */ + if(H5VL_file_specific(vol_obj, H5VL_FILE_POST_OPEN, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, H5I_INVALID_HID, "unable to make file post open callback") + done: FUNC_LEAVE_API(ret_value) } /* end H5Fcreate() */ @@ -712,6 +721,7 @@ H5Fopen(const char *filename, unsigned flags, hid_t fapl_id) H5F_t *new_file = NULL; /* File struct for new file */ H5P_genplist_t *plist; /* Property list pointer */ H5VL_connector_prop_t connector_prop; /* Property for VOL connector ID & info */ + H5VL_object_t *vol_obj = NULL; /* VOL object for file */ hid_t ret_value; /* return value */ FUNC_ENTER_API(H5I_INVALID_HID) @@ -756,6 +766,14 @@ H5Fopen(const char *filename, unsigned flags, hid_t fapl_id) if((ret_value = H5VL_register_using_vol_id(H5I_FILE, new_file, connector_prop.connector_id, TRUE)) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize file handle") + /* Get the file object */ + if(NULL == (vol_obj = H5VL_vol_object(ret_value))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid object identifier") + + /* Make the post open callback */ + if(H5VL_file_specific(vol_obj, H5VL_FILE_POST_OPEN, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, H5I_INVALID_HID, "unable to make file post open callback") + done: FUNC_LEAVE_API(ret_value) } /* end H5Fopen() */ @@ -941,6 +959,14 @@ H5Freopen(hid_t file_id) if((ret_value = H5VL_register(H5I_FILE, file, vol_obj->connector, TRUE)) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize file handle") + /* Get the file object */ + if(NULL == (vol_obj = H5VL_vol_object(ret_value))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid object identifier") + + /* Make the post open callback */ + if(H5VL_file_specific(vol_obj, H5VL_FILE_POST_OPEN, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, H5I_INVALID_HID, "unable to make file post open callback") + done: /* XXX (VOL MERGE): If registration fails, file will not be closed */ FUNC_LEAVE_API(ret_value) diff --git a/src/H5Fefc.c b/src/H5Fefc.c index 66d68b2..264a623 100644 --- a/src/H5Fefc.c +++ b/src/H5Fefc.c @@ -179,6 +179,10 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi if(NULL == (ret_value = H5F_open(name, flags, fcpl_id, fapl_id))) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "can't open file") + /* Make file post open call */ + if(H5F__post_open(ret_value) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "can't finish opening file") + /* Increment the number of open objects to prevent the file from being * closed out from under us - "simulate" having an open file id. Note * that this behaviour replaces the calls to H5F_incr_nopen_objs() and @@ -251,6 +255,10 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi if(NULL == (ret_value = H5F_open(name, flags, fcpl_id, fapl_id))) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "can't open file") + /* Make file post open call */ + if(H5F__post_open(ret_value) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "can't finish opening file") + /* Increment the number of open objects to prevent the file from * being closed out from under us - "simulate" having an open * file id */ @@ -273,6 +281,10 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "can't open file") open_file = TRUE; + /* Make file post open call */ + if(H5F__post_open(ent->file) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "can't finish opening file") + /* Increment the number of open objects to prevent the file from being * closed out from under us - "simulate" having an open file id */ ent->file->nopen_objs++; diff --git a/src/H5Fint.c b/src/H5Fint.c index 2ebcd94..435c1be 100644 --- a/src/H5Fint.c +++ b/src/H5Fint.c @@ -1138,9 +1138,15 @@ done: HDONE_ERROR(H5E_FILE, H5E_CANTDEC, NULL, "can't close property list") f->shared = H5FL_FREE(H5F_shared_t, f->shared); - } + } /* end if */ + + /* Free VOL object */ + if(f->vol_obj) + if(H5VL_free_object(f->vol_obj) < 0) + HDONE_ERROR(H5E_FILE, H5E_CANTDEC, NULL, "unable to free VOL object") + f = H5FL_FREE(H5F_t, f); - } + } /* end if */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5F__new() */ @@ -1407,6 +1413,9 @@ H5F__dest(H5F_t *f, hbool_t flush) /* Free the non-shared part of the file */ f->open_name = (char *)H5MM_xfree(f->open_name); f->actual_name = (char *)H5MM_xfree(f->actual_name); + if(f->vol_obj && H5VL_free_object(f->vol_obj) < 0) + HDONE_ERROR(H5E_FILE, H5E_CANTDEC, FAIL, "unable to free VOL object") + f->vol_obj = NULL; if(H5FO_top_dest(f) < 0) HDONE_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "problems closing file") f->shared = NULL; @@ -1820,6 +1829,35 @@ done: /*------------------------------------------------------------------------- + * Function: H5F__post_open + * + * Purpose: Finishes file open after wrapper context for file has been + * set. + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5F__post_open(H5F_t *f) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Sanity check arguments */ + HDassert(f); + + /* Store a vol object in the file struct */ + if(NULL == (f->vol_obj = H5VL_create_object_using_vol_id(H5I_FILE, f, f->shared->vol_id))) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "can't create VOL object") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5F__flush() */ + + +/*------------------------------------------------------------------------- * Function: H5F_flush_phase1 * * Purpose: First phase of flushing cached data. diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h index 4b5b788..7d9a090 100644 --- a/src/H5Fpkg.h +++ b/src/H5Fpkg.h @@ -375,6 +375,7 @@ struct H5F_t { char *open_name; /* Name used to open file */ char *actual_name; /* Actual name of the file, after resolving symlinks, etc. */ H5F_shared_t *shared; /* The shared file info */ + H5VL_object_t *vol_obj; /* VOL object */ unsigned nopen_objs; /* Number of open object headers */ H5FO_t *obj_count; /* # of time each object is opened through top file structure */ hbool_t id_exists; /* Whether an ID for this struct exists */ @@ -399,6 +400,7 @@ H5FL_EXTERN(H5F_shared_t); /******************************/ /* General routines */ +H5_DLL herr_t H5F__post_open(H5F_t *f); H5_DLL H5F_t *H5F__reopen(H5F_t *f); H5_DLL herr_t H5F__dest(H5F_t *f, hbool_t flush); H5_DLL herr_t H5F__flush(H5F_t *f); diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index c9a1b25..e1a8a2f 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -26,7 +26,6 @@ typedef struct H5F_t H5F_t; /* Public headers needed by this file */ #include "H5FDpublic.h" /* File drivers */ -#include "H5VLpublic.h" /* Virtual Object Layer */ /* Private headers needed by this file */ #include "H5MMprivate.h" /* Memory management */ @@ -34,6 +33,7 @@ typedef struct H5F_t H5F_t; #include "H5Pprivate.h" /* Property lists */ #endif /* H5_HAVE_PARALLEL */ #include "H5VMprivate.h" /* Vectors and arrays */ +#include "H5VLprivate.h" /* Virtual Object Layer */ /**************************/ @@ -337,6 +337,7 @@ typedef struct H5F_t H5F_t; #define H5F_GET_MIN_DSET_OHDR(F) ((F)->shared->crt_dset_min_ohdr_flag) #define H5F_SET_MIN_DSET_OHDR(F, V) ((F)->shared->crt_dset_min_ohdr_flag = (V)) #define H5F_VOL_CLS(F) ((F)->shared->vol_cls) +#define H5F_VOL_OBJ(F) ((F)->vol_obj) #else /* H5F_MODULE */ #define H5F_LOW_BOUND(F) (H5F_get_low_bound(F)) #define H5F_HIGH_BOUND(F) (H5F_get_high_bound(F)) @@ -398,6 +399,7 @@ typedef struct H5F_t H5F_t; #define H5F_GET_MIN_DSET_OHDR(F) (H5F_get_min_dset_ohdr(F)) #define H5F_SET_MIN_DSET_OHDR(F, V) (H5F_set_min_dset_ohdr((F), (V))) #define H5F_VOL_CLS(F) (H5F_get_vol_cls(F)) +#define H5F_VOL_OBJ(F) (H5F_get_vol_obj(F)) #endif /* H5F_MODULE */ @@ -759,6 +761,7 @@ H5_DLL hbool_t H5F_get_null_fsm_addr(const H5F_t *f); H5_DLL hbool_t H5F_get_min_dset_ohdr(const H5F_t *f); H5_DLL herr_t H5F_set_min_dset_ohdr(H5F_t *f, hbool_t minimize); H5_DLL const H5VL_class_t *H5F_get_vol_cls(const H5F_t *f); +H5_DLL H5VL_object_t *H5F_get_vol_obj(const H5F_t *f); /* Functions than retrieve values set/cached from the superblock/FCPL */ H5_DLL haddr_t H5F_get_base_addr(const H5F_t *f); diff --git a/src/H5Fquery.c b/src/H5Fquery.c index 32743c4..68ad8e5 100644 --- a/src/H5Fquery.c +++ b/src/H5Fquery.c @@ -1306,6 +1306,26 @@ H5F_get_vol_cls(const H5F_t *f) /*------------------------------------------------------------------------- + * Function: H5F_get_vol_obj + * + * Purpose: Get the VOL object for the file + * + * Return: VOL object pointer for file, can't fail + * + *------------------------------------------------------------------------- + */ +H5VL_object_t * +H5F_get_vol_obj(const H5F_t *f) +{ + FUNC_ENTER_NOAPI_NOINIT_NOERR + + HDassert(f); + + FUNC_LEAVE_NOAPI(f->vol_obj) +} /* end H5F_get_vol_obj */ + + +/*------------------------------------------------------------------------- * Function: H5F_get_cont_info * * Purpose: Get the VOL container info for the file diff --git a/src/H5Oattr.c b/src/H5Oattr.c index f685a00c..878cb8a 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -674,7 +674,7 @@ H5O__attr_copy_file(H5F_t *file_src, const H5O_msg_class_t H5_ATTR_UNUSED *mesg_ /* Mark datatype as being on disk now. This step used to be done in a lower level * by H5O_dtype_decode. But it has been moved up. Not an ideal place, but no better * place than here. */ - if(H5T_set_loc(((H5A_t *)native_src)->shared->dt, file_src, H5T_LOC_DISK) < 0) + if(H5T_set_loc(((H5A_t *)native_src)->shared->dt, H5F_VOL_OBJ(file_src), H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, NULL, "invalid datatype location") if(NULL == (ret_value = H5A__attr_copy_file((H5A_t *)native_src, file_dst, recompute_size, cpy_info))) diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c index 57ec9b8..71cbc1d 100644 --- a/src/H5Oattribute.c +++ b/src/H5Oattribute.c @@ -535,7 +535,7 @@ H5O__attr_open_by_name(const H5O_loc_t *loc, const char *name) } /* end else */ /* Mark datatype as being on disk now */ - if(H5T_set_loc(opened_attr->shared->dt, loc->file, H5T_LOC_DISK) < 0) + if(H5T_set_loc(opened_attr->shared->dt, H5F_VOL_OBJ(loc->file), H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, NULL, "invalid datatype location") } /* end else */ @@ -642,7 +642,7 @@ H5O__attr_open_by_idx(const H5O_loc_t *loc, H5_index_t idx_type, HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, NULL, "can't copy existing attribute") } else { /* Mark datatype as being on disk now */ - if(H5T_set_loc(opened_attr->shared->dt, loc->file, H5T_LOC_DISK) < 0) + if(H5T_set_loc(opened_attr->shared->dt, H5F_VOL_OBJ(loc->file), H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, NULL, "invalid datatype location") } /* end if */ } /* end if */ diff --git a/src/H5Ocopy_ref.c b/src/H5Ocopy_ref.c index 3b18073..d8efeb5 100644 --- a/src/H5Ocopy_ref.c +++ b/src/H5Ocopy_ref.c @@ -333,7 +333,7 @@ H5O__copy_expand_ref_object2(H5O_loc_t *src_oloc, hid_t tid_src, H5T_t *dt_src, /* create reference datatype at the destinaton file */ if(NULL == (dt_dst = H5T_copy(dt_src, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to copy") - if(H5T_set_loc(dt_dst, dst_oloc->file, H5T_LOC_DISK) < 0) { + if(H5T_set_loc(dt_dst, H5F_VOL_OBJ(dst_oloc->file), H5T_LOC_DISK) < 0) { (void)H5T_close_real(dt_dst); HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "cannot mark datatype on disk") } /* end if */ diff --git a/src/H5Odtype.c b/src/H5Odtype.c index 805df2b..c27ece0 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -1559,7 +1559,7 @@ H5O_dtype_pre_copy_file(H5F_t *file_src, const void *mesg_src, HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy") /* Set the location of the source datatype to describe the disk form of the data */ - if(H5T_set_loc(udata->src_dtype, file_src, H5T_LOC_DISK) < 0) + if(H5T_set_loc(udata->src_dtype, H5F_VOL_OBJ(file_src), H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype on disk") } /* end if */ @@ -1596,7 +1596,7 @@ H5O__dtype_copy_file(H5F_t H5_ATTR_UNUSED *file_src, const H5O_msg_class_t *mesg HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy") /* The datatype will be in the new file; set its location. */ - if(H5T_set_loc(dst_mesg, file_dst, H5T_LOC_DISK) < 0) + if(H5T_set_loc(dst_mesg, H5F_VOL_OBJ(file_dst), H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to set location") ret_value = dst_mesg; diff --git a/src/H5T.c b/src/H5T.c index f2d6c70..daf5434 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -227,7 +227,7 @@ H5T_INIT_TYPE_ALLOC_COMMON(H5T_REFERENCE) \ H5T_INIT_TYPE_NUM_COMMON(H5T_ORDER_NONE) \ dt->shared->force_conv = TRUE; \ - dt->shared->u.atomic.u.r.f = NULL; \ + dt->shared->u.atomic.u.r.file = NULL; \ dt->shared->u.atomic.u.r.loc = H5T_LOC_BADLOC; \ dt->shared->u.atomic.u.r.cls = NULL; \ } @@ -3345,6 +3345,9 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method) /* No VOL object */ new_dt->vol_obj = NULL; + /* No owned VOL object */ + new_dt->shared->owned_vol_obj = NULL; + /* Check what sort of copy we are making */ switch (method) { case H5T_COPY_TRANSIENT: @@ -3766,6 +3769,11 @@ H5T__free(H5T_t *dt) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close parent data type") dt->shared->parent = NULL; + /* Close the owned VOL object */ + if(dt->shared->owned_vol_obj && H5VL_free_object(dt->shared->owned_vol_obj) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close owned VOL object") + dt->shared->owned_vol_obj = NULL; + done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__free() */ @@ -4413,9 +4421,9 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset) } /* Don't allow VL types in different files to compare as equal */ - if(dt1->shared->u.vlen.f < dt2->shared->u.vlen.f) + if(dt1->shared->u.vlen.file < dt2->shared->u.vlen.file) HGOTO_DONE(-1); - if(dt1->shared->u.vlen.f > dt2->shared->u.vlen.f) + if(dt1->shared->u.vlen.file > dt2->shared->u.vlen.file) HGOTO_DONE(1); break; @@ -5411,7 +5419,7 @@ done: -------------------------------------------------------------------------- */ htri_t -H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc) +H5T_set_loc(H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc) { htri_t changed; /* Whether H5T_set_loc changed the type (even if the size didn't change) */ htri_t ret_value = 0; /* Indicate that success, but no location change */ @@ -5435,7 +5443,7 @@ H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc) old_size=dt->shared->parent->shared->size; /* Mark the VL, compound or array type */ - if((changed=H5T_set_loc(dt->shared->parent,f,loc))<0) + if((changed=H5T_set_loc(dt->shared->parent, file, loc))<0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "Unable to set VL location") if(changed>0) ret_value=changed; @@ -5475,7 +5483,7 @@ H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc) old_size = memb_type->shared->size; /* Mark the VL, compound, enum or array type */ - if((changed = H5T_set_loc(memb_type,f,loc)) < 0) + if((changed = H5T_set_loc(memb_type, file, loc)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "Unable to set VL location") if(changed > 0) ret_value = changed; @@ -5509,14 +5517,14 @@ H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc) /* Recurse if it's VL, compound, enum or array */ /* (If the force_conv flag is _not_ set, the type cannot change in size, so don't recurse) */ if(dt->shared->parent->shared->force_conv && H5T_IS_COMPLEX(dt->shared->parent->shared->type)) { - if((changed = H5T_set_loc(dt->shared->parent,f,loc)) < 0) + if((changed = H5T_set_loc(dt->shared->parent, file, loc)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "Unable to set VL location") if(changed > 0) ret_value = changed; } /* end if */ /* Mark this VL sequence */ - if((changed = H5T__vlen_set_loc(dt, f, loc)) < 0) + if((changed = H5T__vlen_set_loc(dt, file, loc)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "Unable to set VL location") if(changed > 0) ret_value = changed; @@ -5524,7 +5532,7 @@ H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc) case H5T_REFERENCE: /* Reference types go through type conversion */ - if((ret_value = H5T__ref_set_loc(dt, f, loc)) < 0) + if((ret_value = H5T__ref_set_loc(dt, file, loc)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "Unable to set reference location"); break; @@ -5863,8 +5871,8 @@ done: /*------------------------------------------------------------------------- * Function: H5T_patch_vlen_file * - * Purpose: Patch the top-level file pointer contained in (dt->shared->u.vlen.f) - * to point to f. This is possible because + * Purpose: Patch the top-level file pointer contained in (dt->shared->u.vlen.file) + * to point to file. This is possible because * the top-level file pointer can be closed out from under * dt while dt is contained in the shared file's cache. * @@ -5873,18 +5881,56 @@ done: *------------------------------------------------------------------------- */ herr_t -H5T_patch_vlen_file(H5T_t *dt, H5F_t *f) +H5T_patch_vlen_file(H5T_t *dt, H5VL_object_t *file) { FUNC_ENTER_NOAPI_NOINIT_NOERR /* Sanity check */ HDassert(dt); HDassert(dt->shared); - HDassert(f); + HDassert(file); - if((dt->shared->type == H5T_VLEN) && dt->shared->u.vlen.f != f) - dt->shared->u.vlen.f = f; + if((dt->shared->type == H5T_VLEN) && dt->shared->u.vlen.file != file) + dt->shared->u.vlen.file = file; FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5T_patch_vlen_file() */ + +/*------------------------------------------------------------------------- + * Function: H5T_own_vol_obj + * + * Purpose: Transfers ownership of the supplied VOL object to the + * datatype, the VOL object will be freed when the datatype + * is closed. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_own_vol_obj(H5T_t *dt, H5VL_object_t *vol_obj) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity check */ + HDassert(dt); + HDassert(dt->shared); + HDassert(vol_obj); + + /* Currently no support for owning multiple VOL objects, free the previous + * owned object. Currently this is only used for holding open VOL objects + * used in the "loc" for vlens and references, so if this is being + * overwritten we don't need the old one anyways. */ + if(dt->shared->owned_vol_obj && H5VL_free_object(dt->shared->owned_vol_obj) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close owned VOL object") + + /* Take ownership */ + dt->shared->owned_vol_obj = vol_obj; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T_own_vol_obj() */ + diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c index f099682..e5d12c0 100644 --- a/src/H5Tcommit.c +++ b/src/H5Tcommit.c @@ -232,7 +232,7 @@ done: HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "can't remove dataset from list of open objects") /* Close the datatype object */ - if(H5O_close(&(dt->oloc), NULL) < 0) + if(H5O_close(&(dt->oloc), NULL) < 0) HDONE_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to release object header") /* Remove the datatype's object header from the file */ @@ -240,7 +240,7 @@ done: HDONE_ERROR(H5E_DATATYPE, H5E_CANTDELETE, FAIL, "unable to delete object header") /* Mark datatype as being back in memory */ - if(H5T_set_loc(dt, dt->sh_loc.file, H5T_LOC_MEMORY)) + if(H5T_set_loc(dt, NULL, H5T_LOC_MEMORY)) HDONE_ERROR(H5E_DATATYPE, H5E_CANTDELETE, FAIL, "unable to return datatype to memory") dt->sh_loc.type = H5O_SHARE_TYPE_UNSHARED; dt->shared->state = old_state; @@ -417,7 +417,7 @@ H5T__commit(H5F_t *file, H5T_t *type, hid_t tcpl_id) /* Mark datatype as being on disk now. This step changes the size of * datatype as stored on disk. */ - if(H5T_set_loc(type, file, H5T_LOC_DISK) < 0) + if(H5T_set_loc(type, H5F_VOL_OBJ(file), H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype on disk") /* Reset datatype location and path */ diff --git a/src/H5Tconv.c b/src/H5Tconv.c index 84642f4..6aea00e 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -3132,7 +3132,7 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to retrieve VL allocation info") /* Set flags to indicate we are writing to or reading from the file */ - if(dst->shared->u.vlen.f != NULL) + if(dst->shared->u.vlen.file != NULL) write_to_file = TRUE; /* Set the flag for nested VL case */ @@ -3183,18 +3183,18 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, hbool_t is_nil; /* Whether sequence is "nil" */ /* Check for "nil" source sequence */ - if((*(src->shared->u.vlen.cls->isnull))(src->shared->u.vlen.f, s, &is_nil) < 0) + if((*(src->shared->u.vlen.cls->isnull))(src->shared->u.vlen.file, s, &is_nil) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't check if VL data is 'nil'") else if(is_nil) { /* Write "nil" sequence to destination location */ - if((*(dst->shared->u.vlen.cls->setnull))(dst->shared->u.vlen.f, d, b) < 0) + if((*(dst->shared->u.vlen.cls->setnull))(dst->shared->u.vlen.file, d, b) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't set VL data to 'nil'") } /* end else-if */ else { size_t seq_len; /* The number of elements in the current sequence */ /* Get length of element sequences */ - if((*(src->shared->u.vlen.cls->getlen))(src->shared->u.vlen.f, s, &seq_len) < 0) + if((*(src->shared->u.vlen.cls->getlen))(src->shared->u.vlen.file, s, &seq_len) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "bad sequence length") /* If we are reading from memory and there is no conversion, just get the pointer to sequence */ @@ -3226,7 +3226,7 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, } /* end else-if */ /* Read in VL sequence */ - if((*(src->shared->u.vlen.cls->read))(src->shared->u.vlen.f, s, conv_buf, src_size) < 0) + if((*(src->shared->u.vlen.cls->read))(src->shared->u.vlen.file, s, conv_buf, src_size) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "can't read VL data") } /* end else */ @@ -3248,7 +3248,7 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, HDassert(write_to_file); /* Get length of background element sequence */ - if((*(dst->shared->u.vlen.cls->getlen))(dst->shared->u.vlen.f, b, &bg_seq_len) < 0) + if((*(dst->shared->u.vlen.cls->getlen))(dst->shared->u.vlen.file, b, &bg_seq_len) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "bad sequence length") /* Read sequence if length > 0 */ @@ -3261,7 +3261,7 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, } /* end if */ /* Read in background VL sequence */ - if((*(dst->shared->u.vlen.cls->read))(dst->shared->u.vlen.f, b, tmp_buf, bg_seq_len) < 0) + if((*(dst->shared->u.vlen.cls->read))(dst->shared->u.vlen.file, b, tmp_buf, bg_seq_len * dst_base_size) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "can't read VL data") } /* end if */ @@ -3276,7 +3276,7 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, } /* end if */ /* Write sequence to destination location */ - if((*(dst->shared->u.vlen.cls->write))(dst->shared->u.vlen.f, &vl_alloc_info, d, conv_buf, b, seq_len, dst_base_size) < 0) + if((*(dst->shared->u.vlen.cls->write))(dst->shared->u.vlen.file, &vl_alloc_info, d, conv_buf, b, seq_len, dst_base_size) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't write VL data") if(!noop_conv) { @@ -3291,7 +3291,7 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, tmp = (uint8_t *)tmp_buf + seq_len * dst_base_size; for(u = seq_len; u < bg_seq_len; u++, tmp += dst_base_size) { /* Delete sequence in destination location */ - if((*(dst->shared->u.vlen.cls->del))(dst->shared->u.vlen.f, tmp) < 0) + if((*(dst->shared->u.vlen.cls->del))(dst->shared->u.vlen.file, tmp) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to remove heap object") } /* end for */ } /* end if */ @@ -3612,8 +3612,8 @@ H5T__conv_ref(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, /* Get size of references */ if(0 == (buf_size = src->shared->u.atomic.u.r.cls->getsize( - src->shared->u.atomic.u.r.f, s, src->shared->size, - dst->shared->u.atomic.u.r.f, &dst_copy))) + src->shared->u.atomic.u.r.file, s, src->shared->size, + dst->shared->u.atomic.u.r.file, &dst_copy))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "incorrect size") /* Check if conversion buffer is large enough, resize if necessary. */ @@ -3629,8 +3629,8 @@ H5T__conv_ref(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, } else { /* Read reference */ if(src->shared->u.atomic.u.r.cls->read( - src->shared->u.atomic.u.r.f, s, src->shared->size, - dst->shared->u.atomic.u.r.f, conv_buf, buf_size) < 0) + src->shared->u.atomic.u.r.file, s, src->shared->size, + dst->shared->u.atomic.u.r.file, conv_buf, buf_size) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "can't read reference data") } @@ -3639,8 +3639,8 @@ H5T__conv_ref(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, } else { /* Write reference to destination location */ if(dst->shared->u.atomic.u.r.cls->write( - src->shared->u.atomic.u.r.f, conv_buf, buf_size, src->shared->u.atomic.u.r.rtype, - dst->shared->u.atomic.u.r.f, d, dst->shared->size, b) < 0) + src->shared->u.atomic.u.r.file, conv_buf, buf_size, src->shared->u.atomic.u.r.rtype, + dst->shared->u.atomic.u.r.file, d, dst->shared->size, b) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't write reference data") } diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h index 9784abd..1dbc229 100644 --- a/src/H5Tpkg.h +++ b/src/H5Tpkg.h @@ -40,6 +40,7 @@ #include "H5Fprivate.h" /* Files */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Oprivate.h" /* Object headers */ +#include "H5VLprivate.h" /* Virtual Object Layer */ /* Other public headers needed by this file */ #include "H5Spublic.h" /* Dataspace functions */ @@ -181,9 +182,9 @@ struct H5T_path_t { }; /* Reference function pointers */ -typedef size_t (*H5T_ref_getsizefunc_t)(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, hbool_t *dst_copy); -typedef herr_t (*H5T_ref_readfunc_t)(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, void *dst_buf, size_t dst_size); -typedef herr_t (*H5T_ref_writefunc_t)(H5F_t *src_f, const void *src_buf, size_t src_size, H5R_type_t src_type, H5F_t *dst_f, void *dst_buf, size_t dst_size, void *bg_buf); +typedef size_t (*H5T_ref_getsizefunc_t)(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5VL_object_t *dst_file, hbool_t *dst_copy); +typedef herr_t (*H5T_ref_readfunc_t)(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5VL_object_t *dst_file, void *dst_buf, size_t dst_size); +typedef herr_t (*H5T_ref_writefunc_t)(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5R_type_t src_type, H5VL_object_t *dst_file, void *dst_buf, size_t dst_size, void *bg_buf); typedef struct H5T_ref_class_t { H5T_ref_getsizefunc_t getsize; /* get reference size (bytes) */ @@ -223,7 +224,7 @@ typedef struct H5T_atomic_t { unsigned version; /* version of encoded reference */ hbool_t opaque; /* opaque reference type */ H5T_loc_t loc; /* location of data in buffer */ - H5F_t *f; /* file pointer (if data is on disk) */ + H5VL_object_t *file; /* file VOL pointer (if data is on disk) */ const H5T_ref_class_t *cls; /* Pointer to ref class callbacks */ } r; /* reference types */ } u; @@ -272,13 +273,13 @@ typedef enum { } H5T_vlen_type_t; /* VL function pointers */ -typedef herr_t (*H5T_vlen_getlen_func_t)(H5F_t *f, const void *vl_addr, size_t *len); +typedef herr_t (*H5T_vlen_getlen_func_t)(H5VL_object_t *file, const void *vl_addr, size_t *len); typedef void * (*H5T_vlen_getptr_func_t)(void *vl_addr); -typedef herr_t (*H5T_vlen_isnull_func_t)(const H5F_t *f, void *vl_addr, hbool_t *isnull); -typedef herr_t (*H5T_vlen_setnull_func_t)(H5F_t *f, void *_vl, void *_bg); -typedef herr_t (*H5T_vlen_read_func_t)(H5F_t *f, void *_vl, void *buf, size_t len); -typedef herr_t (*H5T_vlen_write_func_t)(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void *_bg, size_t seq_len, size_t base_size); -typedef herr_t (*H5T_vlen_delete_func_t)(H5F_t *f, const void *_vl); +typedef herr_t (*H5T_vlen_isnull_func_t)(const H5VL_object_t *file, void *vl_addr, hbool_t *isnull); +typedef herr_t (*H5T_vlen_setnull_func_t)(H5VL_object_t *file, void *_vl, void *_bg); +typedef herr_t (*H5T_vlen_read_func_t)(H5VL_object_t *file, void *_vl, void *buf, size_t len); +typedef herr_t (*H5T_vlen_write_func_t)(H5VL_object_t *file, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void *_bg, size_t seq_len, size_t base_size); +typedef herr_t (*H5T_vlen_delete_func_t)(H5VL_object_t *file, const void *_vl); /* VL datatype callbacks */ typedef struct H5T_vlen_class_t { @@ -298,7 +299,7 @@ typedef struct H5T_vlen_t { H5T_cset_t cset; /* For VL string: character set */ H5T_str_t pad; /* For VL string: space or null padding of * extra bytes */ - H5F_t *f; /* File ID (if VL data is on disk) */ + H5VL_object_t *file; /* File object (if VL data is on disk) */ const H5T_vlen_class_t *cls; /* Pointer to VL class callbacks */ } H5T_vlen_t; @@ -331,6 +332,7 @@ typedef struct H5T_shared_t { unsigned version; /* Version of object header message to encode this object with */ hbool_t force_conv;/* Set if this type always needs to be converted and H5T__conv_noop cannot be called */ struct H5T_t *parent;/*parent type for derived datatypes */ + H5VL_object_t *owned_vol_obj; /* Vol object owned by this type (free on close) */ union { H5T_atomic_t atomic; /* an atomic datatype */ H5T_compnd_t compnd; /* a compound datatype (struct) */ @@ -1173,7 +1175,7 @@ H5_DLL void H5T__bit_neg(uint8_t *buf, size_t start, size_t size); /* VL functions */ H5_DLL H5T_t * H5T__vlen_create(const H5T_t *base); -H5_DLL htri_t H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc); +H5_DLL htri_t H5T__vlen_set_loc(const H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc); /* Array functions */ H5_DLL H5T_t *H5T__array_create(H5T_t *base, unsigned ndims, const hsize_t dim[/* ndims */]); @@ -1181,7 +1183,7 @@ H5_DLL int H5T__get_array_ndims(const H5T_t *dt); H5_DLL int H5T__get_array_dims(const H5T_t *dt, hsize_t dims[]); /* Reference functions */ -H5_DLL htri_t H5T__ref_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc); +H5_DLL htri_t H5T__ref_set_loc(const H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc); /* Compound functions */ H5_DLL herr_t H5T__insert(H5T_t *parent, const char *name, size_t offset, diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h index 13a0938..d8e98af 100644 --- a/src/H5Tprivate.h +++ b/src/H5Tprivate.h @@ -138,12 +138,13 @@ H5_DLL herr_t H5T_reclaim_cb(void *elem, const H5T_t *dt, unsigned ndim, const h H5_DLL herr_t H5T_ref_reclaim(void *elem, const H5T_t *dt); H5_DLL herr_t H5T_vlen_reclaim(void *elem, const H5T_t *dt, H5T_vlen_alloc_info_t *alloc_info); H5_DLL herr_t H5T_vlen_reclaim_elmt(void *elem, H5T_t *dt); -H5_DLL htri_t H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc); +H5_DLL htri_t H5T_set_loc(H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc); H5_DLL htri_t H5T_is_sensible(const H5T_t *dt); H5_DLL uint32_t H5T_hash(H5F_t * file, const H5T_t *dt); H5_DLL herr_t H5T_set_version(H5F_t *f, H5T_t *dt); H5_DLL herr_t H5T_patch_file(H5T_t *dt, H5F_t *f); -H5_DLL herr_t H5T_patch_vlen_file(H5T_t *dt, H5F_t *f); +H5_DLL herr_t H5T_patch_vlen_file(H5T_t *dt, H5VL_object_t *file); +H5_DLL herr_t H5T_own_vol_obj(H5T_t *dt, H5VL_object_t *vol_obj); H5_DLL htri_t H5T_is_variable_str(const H5T_t *dt); H5_DLL H5T_t *H5T_construct_datatype(H5VL_object_t *dt_obj); H5_DLL H5VL_object_t *H5T_get_named_type(const H5T_t *dt); diff --git a/src/H5Tref.c b/src/H5Tref.c index 937dc92..2e52954 100644 --- a/src/H5Tref.c +++ b/src/H5Tref.c @@ -27,6 +27,8 @@ #include "H5Rpkg.h" /* References */ #include "H5Tpkg.h" /* Datatypes */ +#include "H5VLnative_private.h" /* Native VOL connector */ + /****************/ /* Local Macros */ /****************/ @@ -52,20 +54,20 @@ struct H5Tref_dsetreg { /* Local Prototypes */ /********************/ -static size_t H5T__ref_mem_getsize(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, hbool_t *dst_copy); -static herr_t H5T__ref_mem_read(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, void *dst_buf, size_t dst_size); -static herr_t H5T__ref_mem_write(H5F_t *src_f, const void *src_buf, size_t src_size, H5R_type_t src_type, H5F_t *dst_f, void *dst_buf, size_t dst_size, void *bg_buf); +static size_t H5T__ref_mem_getsize(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5VL_object_t *dst_file, hbool_t *dst_copy); +static herr_t H5T__ref_mem_read(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5VL_object_t *dst_file, void *dst_buf, size_t dst_size); +static herr_t H5T__ref_mem_write(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5R_type_t src_type, H5VL_object_t *dst_file, void *dst_buf, size_t dst_size, void *bg_buf); -static size_t H5T__ref_disk_getsize(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, hbool_t *dst_copy); -static herr_t H5T__ref_disk_read(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, void *dst_buf, size_t dst_size); -static herr_t H5T__ref_disk_write(H5F_t *src_f, const void *src_buf, size_t src_size, H5R_type_t src_type, H5F_t *dst_f, void *dst_buf, size_t dst_size, void *bg_buf); +static size_t H5T__ref_disk_getsize(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5VL_object_t *dst_file, hbool_t *dst_copy); +static herr_t H5T__ref_disk_read(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5VL_object_t *dst_file, void *dst_buf, size_t dst_size); +static herr_t H5T__ref_disk_write(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5R_type_t src_type, H5VL_object_t *dst_file, void *dst_buf, size_t dst_size, void *bg_buf); /* For compatibility */ -static size_t H5T__ref_obj_disk_getsize(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, hbool_t *dst_copy); -static herr_t H5T__ref_obj_disk_read(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, void *dst_buf, size_t dst_size); +static size_t H5T__ref_obj_disk_getsize(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5VL_object_t *dst_file, hbool_t *dst_copy); +static herr_t H5T__ref_obj_disk_read(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5VL_object_t *dst_file, void *dst_buf, size_t dst_size); -static size_t H5T__ref_dsetreg_disk_getsize(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, hbool_t *dst_copy); -static herr_t H5T__ref_dsetreg_disk_read(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, void *dst_buf, size_t dst_size); +static size_t H5T__ref_dsetreg_disk_getsize(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5VL_object_t *dst_file, hbool_t *dst_copy); +static herr_t H5T__ref_dsetreg_disk_read(H5VL_object_t *src_file, const void *src_buf, size_t src_size, H5VL_object_t *dst_file, void *dst_buf, size_t dst_size); /*******************/ /* Local Variables */ @@ -112,7 +114,7 @@ static const H5T_ref_class_t H5T_ref_dsetreg_disk_g = { *------------------------------------------------------------------------- */ htri_t -H5T__ref_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) +H5T__ref_set_loc(const H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc) { htri_t ret_value = FALSE; /* Indicate success, but no location change */ @@ -123,18 +125,18 @@ H5T__ref_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) HDassert(loc >= H5T_LOC_BADLOC && loc < H5T_LOC_MAXLOC); /* Only change the location if it's different */ - if(loc == dt->shared->u.atomic.u.r.loc && f == dt->shared->u.atomic.u.r.f) + if(loc == dt->shared->u.atomic.u.r.loc && file == dt->shared->u.atomic.u.r.file) HGOTO_DONE(FALSE) switch(loc) { case H5T_LOC_MEMORY: /* Memory based reference datatype */ - HDassert(NULL == f); + HDassert(NULL == file); /* Mark this type as being stored in memory */ dt->shared->u.atomic.u.r.loc = H5T_LOC_MEMORY; /* Reset file ID (since this reference is in memory) */ - dt->shared->u.atomic.u.r.f = f; /* f is NULL */ + dt->shared->u.atomic.u.r.file = file; /* file is NULL */ if(dt->shared->u.atomic.u.r.opaque) { /* Size in memory, disk size is different */ @@ -164,15 +166,24 @@ H5T__ref_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) break; case H5T_LOC_DISK: /* Disk based reference datatype */ - HDassert(f); + HDassert(file); /* Mark this type as being stored on disk */ dt->shared->u.atomic.u.r.loc = H5T_LOC_DISK; /* Set file pointer (since this reference is on disk) */ - dt->shared->u.atomic.u.r.f = f; + dt->shared->u.atomic.u.r.file = file; if(dt->shared->u.atomic.u.r.rtype == H5R_OBJECT1) { + H5F_t *f; + + /* We should assert here that the terminal connector is H5VL_NATIVE once + * there is a facility to do so -NAF 2019/10/30 */ + + /* Retrieve file from VOL object */ + if(NULL == (f = (H5F_t *)H5VL_object_data(file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid VOL object") + /* Size on disk, memory size is different */ dt->shared->size = H5T_REF_OBJ_DISK_SIZE(f); dt->shared->u.atomic.prec = 8 * dt->shared->size; @@ -181,6 +192,15 @@ H5T__ref_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) dt->shared->u.atomic.u.r.cls = &H5T_ref_obj_disk_g; } else if(dt->shared->u.atomic.u.r.rtype == H5R_DATASET_REGION1) { + H5F_t *f; + + /* We should assert here that the terminal connector is H5VL_NATIVE once + * there is a facility to do so -NAF 2019/10/30 */ + + /* Retrieve file from VOL object */ + if(NULL == (f = (H5F_t *)H5VL_object_data(file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid VOL object") + /* Size on disk, memory size is different */ dt->shared->size = H5T_REF_DSETREG_DISK_SIZE(f); dt->shared->u.atomic.prec = 8 * dt->shared->size; @@ -194,8 +214,8 @@ H5T__ref_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) H5R_ref_priv_t fixed_ref; /* Get container info */ - if(H5F__get_cont_info(f, &cont_info) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get file container info") + if(H5VL_file_get(file, H5VL_FILE_GET_CONT_INFO, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &cont_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to get container info") /* Retrieve min encode size (when references have no vlen part) */ HDmemset(&fixed_ref, 0, sizeof(fixed_ref)); @@ -226,7 +246,7 @@ H5T__ref_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) dt->shared->u.atomic.u.r.loc = H5T_LOC_BADLOC; /* Reset file pointer */ - dt->shared->u.atomic.u.r.f = NULL; + dt->shared->u.atomic.u.r.file = NULL; /* Reset the function pointers */ dt->shared->u.atomic.u.r.cls = NULL; @@ -257,10 +277,12 @@ done: *------------------------------------------------------------------------- */ static size_t -H5T__ref_mem_getsize(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, - size_t H5_ATTR_UNUSED src_size, H5F_t *dst_f, hbool_t *dst_copy) +H5T__ref_mem_getsize(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf, + size_t H5_ATTR_UNUSED src_size, H5VL_object_t *dst_file, hbool_t *dst_copy) { - void *vol_obj = NULL; + H5F_t *src_f; + H5F_t *dst_f; + H5VL_object_t *vol_obj = NULL; const H5R_ref_priv_t *src_ref = (const H5R_ref_priv_t *)src_buf; unsigned flags = 0; size_t ret_value = 0; @@ -274,9 +296,14 @@ H5T__ref_mem_getsize(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, if(NULL == (vol_obj = H5VL_vol_object(src_ref->loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid location identifier") - /* Retrieve file from VOL object */ + /* We should assert here that the terminal connector is H5VL_NATIVE once + * there is a facility to do so -NAF 2019/10/30 */ + + /* Retrieve files from VOL objects */ if(NULL == (src_f = (H5F_t *)H5VL_object_data(vol_obj))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") + if(NULL == (dst_f = (H5F_t *)H5VL_object_data(dst_file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") /* Set external flag if referenced file is not destination file */ flags |= (src_f->shared != dst_f->shared) ? H5R_IS_EXTERNAL : 0; @@ -315,11 +342,13 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T__ref_mem_read(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, - size_t H5_ATTR_UNUSED src_size, H5F_t *dst_f, void *dst_buf, +H5T__ref_mem_read(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf, + size_t H5_ATTR_UNUSED src_size, H5VL_object_t *dst_file, void *dst_buf, size_t dst_size) { - void *vol_obj = NULL; + H5F_t *src_f; + H5F_t *dst_f; + H5VL_object_t *vol_obj = NULL; const H5R_ref_priv_t *src_ref = (const H5R_ref_priv_t *)src_buf; unsigned flags = 0; herr_t ret_value = SUCCEED; @@ -328,7 +357,7 @@ H5T__ref_mem_read(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, HDassert(src_buf); HDassert(src_size == H5T_REF_MEM_SIZE); - HDassert(dst_f); + HDassert(dst_file); HDassert(dst_buf); HDassert(dst_size); @@ -336,9 +365,14 @@ H5T__ref_mem_read(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, if(NULL == (vol_obj = H5VL_vol_object(src_ref->loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid location identifier") - /* Retrieve file from VOL object */ + /* We should assert here that the terminal connector is H5VL_NATIVE once + * there is a facility to do so -NAF 2019/10/30 */ + + /* Retrieve files from VOL objects */ if(NULL == (src_f = (H5F_t *)H5VL_object_data(vol_obj))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") + if(NULL == (dst_f = (H5F_t *)H5VL_object_data(dst_file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") /* Set external flag if referenced file is not destination file */ flags |= (src_f->shared != dst_f->shared) ? H5R_IS_EXTERNAL : 0; @@ -349,7 +383,7 @@ H5T__ref_mem_read(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, H5CX_set_libver_bounds(dst_f); /* Encode reference */ - if(H5R__encode(H5F_ACTUAL_NAME(src_f), src_ref, dst_buf, &dst_size, flags) < 0) + if(H5R__encode(H5F_ACTUAL_NAME(src_f), src_ref, (unsigned char *)dst_buf, &dst_size, flags) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, "Cannot encode reference") done: @@ -367,22 +401,30 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T__ref_mem_write(H5F_t *src_f, const void *src_buf, size_t src_size, - H5R_type_t src_type, H5F_t H5_ATTR_UNUSED *dst_f, void *dst_buf, +H5T__ref_mem_write(H5VL_object_t *src_file, const void *src_buf, size_t src_size, + H5R_type_t src_type, H5VL_object_t H5_ATTR_UNUSED *dst_file, void *dst_buf, size_t dst_size, void H5_ATTR_UNUSED *bg_buf) { + H5F_t *src_f; hid_t file_id = H5I_INVALID_HID; H5R_ref_priv_t *dst_ref = (H5R_ref_priv_t *)dst_buf; herr_t ret_value = SUCCEED; FUNC_ENTER_STATIC - HDassert(src_f); + HDassert(src_file); HDassert(src_buf); HDassert(src_size); HDassert(dst_buf); HDassert(dst_size == H5T_REF_MEM_SIZE); + /* We should assert here that the terminal connector is H5VL_NATIVE once + * there is a facility to do so -NAF 2019/10/30 */ + + /* Retrieve file from VOL object */ + if(NULL == (src_f = (H5F_t *)H5VL_object_data(src_file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid VOL object") + /* Make sure reference buffer is correctly initialized */ HDmemset(dst_buf, 0, dst_size); @@ -451,8 +493,8 @@ done: *------------------------------------------------------------------------- */ static size_t -H5T__ref_disk_getsize(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, - size_t src_size, H5F_t H5_ATTR_UNUSED *dst_f, hbool_t *dst_copy) +H5T__ref_disk_getsize(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf, + size_t src_size, H5VL_object_t H5_ATTR_UNUSED *dst_file, hbool_t *dst_copy) { const uint8_t *p = (const uint8_t *)src_buf; unsigned flags; @@ -499,50 +541,36 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T__ref_disk_read(H5F_t *src_f, const void *src_buf, size_t src_size, - H5F_t H5_ATTR_UNUSED *dst_f, void *dst_buf, size_t dst_size) +H5T__ref_disk_read(H5VL_object_t *src_file, const void *src_buf, size_t src_size, + H5VL_object_t H5_ATTR_UNUSED *dst_file, void *dst_buf, size_t dst_size) { - H5VL_object_t *vol_obj = NULL; /* Object info */ - hid_t file_id = H5I_INVALID_HID; const uint8_t *p = (const uint8_t *)src_buf; uint8_t *q = (uint8_t *)dst_buf; - size_t buf_size_left = src_size; - size_t expected_size = dst_size; + size_t blob_size = dst_size; herr_t ret_value = SUCCEED; FUNC_ENTER_STATIC - HDassert(src_f); + HDassert(src_file); HDassert(src_buf); HDassert(dst_buf); HDassert(dst_size); - /* TODO temporary hack to retrieve file object */ - if((file_id = H5F__get_file_id(src_f, FALSE)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") - if(NULL == (vol_obj = H5VL_vol_object(file_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - /* Copy header manually */ HDmemcpy(q, p, H5R_ENCODE_HEADER_SIZE); p += H5R_ENCODE_HEADER_SIZE; q += H5R_ENCODE_HEADER_SIZE; - expected_size -= H5R_ENCODE_HEADER_SIZE; + blob_size -= H5R_ENCODE_HEADER_SIZE; /* Skip the length of the sequence */ p += H5_SIZEOF_UINT32_T; - HDassert(buf_size_left > H5_SIZEOF_UINT32_T); - buf_size_left -= H5_SIZEOF_UINT32_T; + HDassert(src_size > (H5R_ENCODE_HEADER_SIZE + H5_SIZEOF_UINT32_T)); /* Retrieve blob */ - if(H5VL_blob_get(vol_obj, p, q, &dst_size, NULL) < 0) + if(H5VL_blob_get(src_file, p, q, blob_size, NULL) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to get blob") - if(dst_size != expected_size) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Expected data size does not match") done: - if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) - HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__ref_disk_read() */ @@ -557,12 +585,10 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T__ref_disk_write(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, - size_t src_size, H5R_type_t H5_ATTR_UNUSED src_type, H5F_t *dst_f, +H5T__ref_disk_write(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf, + size_t src_size, H5R_type_t H5_ATTR_UNUSED src_type, H5VL_object_t *dst_file, void *dst_buf, size_t dst_size, void *bg_buf) { - H5VL_object_t *vol_obj = NULL; /* Object info */ - hid_t file_id = H5I_INVALID_HID; const uint8_t *p = (const uint8_t *)src_buf; uint8_t *q = (uint8_t *)dst_buf; size_t buf_size_left = dst_size; @@ -573,15 +599,9 @@ H5T__ref_disk_write(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, HDassert(src_buf); HDassert(src_size); - HDassert(dst_f); + HDassert(dst_file); HDassert(dst_buf); - /* TODO temporary hack to retrieve file object */ - if((file_id = H5F__get_file_id(dst_f, FALSE)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") - if(NULL == (vol_obj = H5VL_vol_object(file_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - /* TODO Should get rid of bg stuff */ if(p_bg) { size_t p_buf_size_left = dst_size; @@ -592,7 +612,7 @@ H5T__ref_disk_write(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, p_buf_size_left -= H5_SIZEOF_UINT32_T; /* Remove blob for old data */ - if(H5VL_blob_specific(vol_obj, (void *)p_bg, H5VL_BLOB_DELETE) < 0) + if(H5VL_blob_specific(dst_file, (void *)p_bg, H5VL_BLOB_DELETE) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to delete blob") } /* end if */ @@ -609,12 +629,10 @@ H5T__ref_disk_write(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, buf_size_left -= H5_SIZEOF_UINT32_T; /* Store blob */ - if(H5VL_blob_put(vol_obj, p, src_size, q, NULL) < 0) + if(H5VL_blob_put(dst_file, p, src_size, q, NULL) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to put blob") done: - if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) - HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__ref_disk_write() */ @@ -629,20 +647,30 @@ done: *------------------------------------------------------------------------- */ static size_t -H5T__ref_obj_disk_getsize(H5F_t *src_f, const void H5_ATTR_UNUSED *src_buf, - size_t H5_ATTR_UNUSED src_size, H5F_t H5_ATTR_UNUSED *dst_f, +H5T__ref_obj_disk_getsize(H5VL_object_t *src_file, const void H5_ATTR_UNUSED *src_buf, + size_t H5_ATTR_UNUSED src_size, H5VL_object_t H5_ATTR_UNUSED *dst_file, hbool_t H5_ATTR_UNUSED *dst_copy) { + H5F_t *src_f; size_t ret_value = 0; - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_STATIC - HDassert(src_f); + HDassert(src_file); HDassert(src_buf); + + /* We should assert here that the terminal connector is H5VL_NATIVE once + * there is a facility to do so -NAF 2019/10/30 */ + + /* Retrieve file from VOL object */ + if(NULL == (src_f = (H5F_t *)H5VL_object_data(src_file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") + HDassert(src_size == H5T_REF_OBJ_DISK_SIZE(src_f)); ret_value = H5T_REF_OBJ_DISK_SIZE(src_f); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__ref_obj_disk_getsize() */ @@ -657,22 +685,31 @@ H5T__ref_obj_disk_getsize(H5F_t *src_f, const void H5_ATTR_UNUSED *src_buf, *------------------------------------------------------------------------- */ static herr_t -H5T__ref_obj_disk_read(H5F_t *src_f, const void *src_buf, size_t src_size, - H5F_t H5_ATTR_UNUSED *dst_f, void *dst_buf, size_t H5_ATTR_UNUSED dst_size) +H5T__ref_obj_disk_read(H5VL_object_t *src_file, const void *src_buf, size_t src_size, + H5VL_object_t H5_ATTR_UNUSED *dst_file, void *dst_buf, size_t H5_ATTR_UNUSED dst_size) { + H5F_t *src_f; herr_t ret_value = SUCCEED; FUNC_ENTER_STATIC - HDassert(src_f); + HDassert(src_file); HDassert(src_buf); - HDassert(src_size == H5T_REF_OBJ_DISK_SIZE(src_f)); HDassert(dst_buf); + + /* We should assert here that the terminal connector is H5VL_NATIVE once + * there is a facility to do so -NAF 2019/10/30 */ + + /* Retrieve file from VOL object */ + if(NULL == (src_f = (H5F_t *)H5VL_object_data(src_file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid VOL object") + + HDassert(src_size == H5T_REF_OBJ_DISK_SIZE(src_f)); HDassert(dst_size == H5F_SIZEOF_ADDR(src_f)); /* Get object address */ if(H5R__decode_token_obj_compat((const unsigned char *)src_buf, &src_size, - dst_buf, H5F_SIZEOF_ADDR(src_f)) < 0) + (unsigned char *)dst_buf, H5F_SIZEOF_ADDR(src_f)) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "unable to get object address") done: @@ -690,17 +727,32 @@ done: *------------------------------------------------------------------------- */ static size_t -H5T__ref_dsetreg_disk_getsize(H5F_t H5_ATTR_UNUSED *f, +H5T__ref_dsetreg_disk_getsize(H5VL_object_t H5_ATTR_UNUSED *file, const void H5_ATTR_UNUSED *buf, size_t H5_ATTR_UNUSED buf_size, - H5F_t H5_ATTR_UNUSED *dst_f, hbool_t H5_ATTR_UNUSED *dst_copy) + H5VL_object_t H5_ATTR_UNUSED *dst_file, hbool_t H5_ATTR_UNUSED *dst_copy) { size_t ret_value = sizeof(struct H5Tref_dsetreg); - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_STATIC HDassert(buf); - HDassert(buf_size == H5T_REF_DSETREG_DISK_SIZE(f)); +#ifndef NDEBUG + { + H5F_t *f; + + /* We should assert here that the terminal connector is H5VL_NATIVE once + * there is a facility to do so -NAF 2019/10/30 */ + + /* Retrieve file from VOL object */ + if(NULL == (f = (H5F_t *)H5VL_object_data(file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") + + HDassert(buf_size == H5T_REF_DSETREG_DISK_SIZE(f)); + } /* end block */ +#endif /* NDEBUG */ + +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__ref_dsetreg_disk_getsize() */ @@ -715,20 +767,29 @@ H5T__ref_dsetreg_disk_getsize(H5F_t H5_ATTR_UNUSED *f, *------------------------------------------------------------------------- */ static herr_t -H5T__ref_dsetreg_disk_read(H5F_t *src_f, const void *src_buf, size_t src_size, - H5F_t H5_ATTR_UNUSED *dst_f, void *dst_buf, size_t H5_ATTR_UNUSED dst_size) +H5T__ref_dsetreg_disk_read(H5VL_object_t *src_file, const void *src_buf, size_t src_size, + H5VL_object_t H5_ATTR_UNUSED *dst_file, void *dst_buf, size_t H5_ATTR_UNUSED dst_size) { + H5F_t *src_f; struct H5Tref_dsetreg *dst_reg = (struct H5Tref_dsetreg *)dst_buf; herr_t ret_value = SUCCEED; FUNC_ENTER_STATIC - HDassert(src_f); + HDassert(src_file); HDassert(src_buf); - HDassert(src_size == H5T_REF_DSETREG_DISK_SIZE(src_f)); HDassert(dst_buf); HDassert(dst_size == sizeof(struct H5Tref_dsetreg)); + /* We should assert here that the terminal connector is H5VL_NATIVE once + * there is a facility to do so -NAF 2019/10/30 */ + + /* Retrieve file from VOL object */ + if(NULL == (src_f = (H5F_t *)H5VL_object_data(src_file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid VOL object") + + HDassert(src_size == H5T_REF_DSETREG_DISK_SIZE(src_f)); + /* Retrieve object address and space */ if(H5R__decode_token_region_compat(src_f, (const unsigned char *)src_buf, &src_size, &dst_reg->token, H5F_SIZEOF_ADDR(src_f), &dst_reg->space) < 0) diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index 0253b01..ec84879 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -33,6 +33,7 @@ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5Tpkg.h" /* Datatypes */ +#include "H5VLprivate.h" /* Virtual Object Layer */ /****************/ /* Local Macros */ @@ -54,28 +55,28 @@ /********************/ /* Memory-based VL sequence callbacks */ -static herr_t H5T__vlen_mem_seq_getlen(H5F_t *f, const void *_vl, size_t *len); +static herr_t H5T__vlen_mem_seq_getlen(H5VL_object_t *file, const void *_vl, size_t *len); static void * H5T__vlen_mem_seq_getptr(void *_vl); -static herr_t H5T__vlen_mem_seq_isnull(const H5F_t *f, void *_vl, hbool_t *isnull); -static herr_t H5T__vlen_mem_seq_setnull(H5F_t *f, void *_vl, void *_bg); -static herr_t H5T__vlen_mem_seq_read(H5F_t *f, void *_vl, void *_buf, size_t len); -static herr_t H5T__vlen_mem_seq_write(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); +static herr_t H5T__vlen_mem_seq_isnull(const H5VL_object_t *file, void *_vl, hbool_t *isnull); +static herr_t H5T__vlen_mem_seq_setnull(H5VL_object_t *file, void *_vl, void *_bg); +static herr_t H5T__vlen_mem_seq_read(H5VL_object_t *file, void *_vl, void *_buf, size_t len); +static herr_t H5T__vlen_mem_seq_write(H5VL_object_t *file, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); /* Memory-based VL string callbacks */ -static herr_t H5T__vlen_mem_str_getlen(H5F_t *f, const void *_vl, size_t *len); +static herr_t H5T__vlen_mem_str_getlen(H5VL_object_t *file, const void *_vl, size_t *len); static void * H5T__vlen_mem_str_getptr(void *_vl); -static herr_t H5T__vlen_mem_str_isnull(const H5F_t *f, void *_vl, hbool_t *isnull); -static herr_t H5T__vlen_mem_str_setnull(H5F_t *f, void *_vl, void *_bg); -static herr_t H5T__vlen_mem_str_read(H5F_t *f, void *_vl, void *_buf, size_t len); -static herr_t H5T__vlen_mem_str_write(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); +static herr_t H5T__vlen_mem_str_isnull(const H5VL_object_t *file, void *_vl, hbool_t *isnull); +static herr_t H5T__vlen_mem_str_setnull(H5VL_object_t *file, void *_vl, void *_bg); +static herr_t H5T__vlen_mem_str_read(H5VL_object_t *file, void *_vl, void *_buf, size_t len); +static herr_t H5T__vlen_mem_str_write(H5VL_object_t *file, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); /* Disk-based VL sequence (and string) callbacks */ -static herr_t H5T__vlen_disk_getlen(H5F_t *f, const void *_vl, size_t *len); -static herr_t H5T__vlen_disk_isnull(const H5F_t *f, void *_vl, hbool_t *isnull); -static herr_t H5T__vlen_disk_setnull(H5F_t *f, void *_vl, void *_bg); -static herr_t H5T__vlen_disk_read(H5F_t *f, void *_vl, void *_buf, size_t len); -static herr_t H5T__vlen_disk_write(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); -static herr_t H5T__vlen_disk_delete(H5F_t *f, const void *_vl); +static herr_t H5T__vlen_disk_getlen(H5VL_object_t *file, const void *_vl, size_t *len); +static herr_t H5T__vlen_disk_isnull(const H5VL_object_t *file, void *_vl, hbool_t *isnull); +static herr_t H5T__vlen_disk_setnull(H5VL_object_t *file, void *_vl, void *_bg); +static herr_t H5T__vlen_disk_read(H5VL_object_t *file, void *_vl, void *_buf, size_t len); +static herr_t H5T__vlen_disk_write(H5VL_object_t *file, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); +static herr_t H5T__vlen_disk_delete(H5VL_object_t *file, const void *_vl); /*********************/ @@ -252,8 +253,9 @@ done: *------------------------------------------------------------------------- */ htri_t -H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) +H5T__vlen_set_loc(const H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc) { + H5VL_file_cont_info_t cont_info = {H5VL_CONTAINER_INFO_VERSION, 0, 0, 0}; htri_t ret_value = FALSE; /* Indicate success, but no location change */ FUNC_ENTER_PACKAGE @@ -263,10 +265,10 @@ H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) HDassert(loc >= H5T_LOC_BADLOC && loc < H5T_LOC_MAXLOC); /* Only change the location if it's different */ - if(loc != dt->shared->u.vlen.loc || f != dt->shared->u.vlen.f) { + if(loc != dt->shared->u.vlen.loc || file != dt->shared->u.vlen.file) { switch(loc) { case H5T_LOC_MEMORY: /* Memory based VL datatype */ - HDassert(NULL == f); + HDassert(NULL == file); /* Mark this type as being stored in memory */ dt->shared->u.vlen.loc = H5T_LOC_MEMORY; @@ -288,29 +290,30 @@ H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) else HDassert(0 && "Invalid VL type"); - /* Reset file ID (since this VL is in memory) */ - dt->shared->u.vlen.f = NULL; + /* Reset file pointer (since this VL is in memory) */ + dt->shared->u.vlen.file = NULL; break; case H5T_LOC_DISK: /* Disk based VL datatype */ - HDassert(f); + HDassert(file); /* Mark this type as being stored on disk */ dt->shared->u.vlen.loc = H5T_LOC_DISK; - /* - * Size of element on disk is 4 bytes for the length, plus the size - * of an address in this file, plus 4 bytes for the size of a heap - * ID. Memory size is different. - */ - dt->shared->size = 4 + (size_t)H5F_SIZEOF_ADDR(f) + 4; + /* Get container info */ + if(H5VL_file_get(file, H5VL_FILE_GET_CONT_INFO, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &cont_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to get container info") + + /* The datatype size is equal to 4 bytes for the sequence length + * plus the size of a blob id */ + dt->shared->size = 4 + cont_info.blob_id_size; /* Set up the function pointers to access the VL information on disk */ /* VL sequences and VL strings are stored identically on disk, so use the same functions */ dt->shared->u.vlen.cls = &H5T_vlen_disk_g; /* Set file ID (since this VL is on disk) */ - dt->shared->u.vlen.f = f; + dt->shared->u.vlen.file = file; break; case H5T_LOC_BADLOC: @@ -323,7 +326,7 @@ H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) dt->shared->u.vlen.cls = NULL; /* Reset file pointer */ - dt->shared->u.vlen.f = NULL; + dt->shared->u.vlen.file = NULL; break; case H5T_LOC_MAXLOC: @@ -354,7 +357,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_mem_seq_getlen(H5F_t H5_ATTR_UNUSED *f, const void *_vl, size_t *len) +H5T__vlen_mem_seq_getlen(H5VL_object_t H5_ATTR_UNUSED *file, const void *_vl, size_t *len) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS const hvl_t *vl = (const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ @@ -430,7 +433,7 @@ H5T__vlen_mem_seq_getptr(void *_vl) *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_mem_seq_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl, hbool_t *isnull) +H5T__vlen_mem_seq_isnull(const H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, hbool_t *isnull) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS const hvl_t *vl = (const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ @@ -468,7 +471,7 @@ H5T__vlen_mem_seq_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl, hbool_t *isnu *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_mem_seq_setnull(H5F_t H5_ATTR_UNUSED *f, void *_vl, void H5_ATTR_UNUSED *_bg) +H5T__vlen_mem_seq_setnull(H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, void H5_ATTR_UNUSED *_bg) { hvl_t vl; /* Temporary hvl_t to use during operation */ @@ -501,7 +504,7 @@ H5T__vlen_mem_seq_setnull(H5F_t H5_ATTR_UNUSED *f, void *_vl, void H5_ATTR_UNUSE *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_mem_seq_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len) +H5T__vlen_mem_seq_read(H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, void *buf, size_t len) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS const hvl_t *vl = (const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ @@ -542,7 +545,7 @@ H5T__vlen_mem_seq_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_mem_seq_write(H5F_t H5_ATTR_UNUSED *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void H5_ATTR_UNUSED *_bg, size_t seq_len, size_t base_size) +H5T__vlen_mem_seq_write(H5VL_object_t H5_ATTR_UNUSED *file, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void H5_ATTR_UNUSED *_bg, size_t seq_len, size_t base_size) { hvl_t vl; /* Temporary hvl_t to use during operation */ herr_t ret_value = SUCCEED; /* Return value */ @@ -595,7 +598,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_mem_str_getlen(H5F_t H5_ATTR_UNUSED *f, const void *_vl, size_t *len) +H5T__vlen_mem_str_getlen(H5VL_object_t H5_ATTR_UNUSED *file, const void *_vl, size_t *len) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS const char *s = *(const char * const *)_vl; /* Pointer to the user's string information */ @@ -666,7 +669,7 @@ H5T__vlen_mem_str_getptr(void *_vl) *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_mem_str_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl, hbool_t *isnull) +H5T__vlen_mem_str_isnull(const H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, hbool_t *isnull) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS char *s = *(char **)_vl; /* Pointer to the user's string information */ @@ -699,7 +702,7 @@ H5T__vlen_mem_str_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl, hbool_t *isnu *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_mem_str_setnull(H5F_t H5_ATTR_UNUSED *f, void *_vl, void H5_ATTR_UNUSED *_bg) +H5T__vlen_mem_str_setnull(H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, void H5_ATTR_UNUSED *_bg) { char *t = NULL; /* Pointer to temporary buffer allocated */ @@ -725,7 +728,7 @@ H5T__vlen_mem_str_setnull(H5F_t H5_ATTR_UNUSED *f, void *_vl, void H5_ATTR_UNUSE *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_mem_str_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len) +H5T__vlen_mem_str_read(H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, void *buf, size_t len) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS char *s = *(char **)_vl; /* Pointer to the user's string information */ @@ -765,7 +768,7 @@ H5T__vlen_mem_str_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_mem_str_write(H5F_t H5_ATTR_UNUSED *f, const H5T_vlen_alloc_info_t *vl_alloc_info, +H5T__vlen_mem_str_write(H5VL_object_t H5_ATTR_UNUSED *file, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void H5_ATTR_UNUSED *_bg, size_t seq_len, size_t base_size) { char *t; /* Pointer to temporary buffer allocated */ @@ -812,7 +815,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_disk_getlen(H5F_t H5_ATTR_UNUSED *f, const void *_vl, size_t *seq_len) +H5T__vlen_disk_getlen(H5VL_object_t H5_ATTR_UNUSED *file, const void *_vl, size_t *seq_len) { const uint8_t *vl = (const uint8_t *)_vl; /* Pointer to the user's hvl_t information */ @@ -842,36 +845,26 @@ H5T__vlen_disk_getlen(H5F_t H5_ATTR_UNUSED *f, const void *_vl, size_t *seq_len) *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_disk_isnull(const H5F_t *f, void *_vl, hbool_t *isnull) +H5T__vlen_disk_isnull(const H5VL_object_t *file, void *_vl, hbool_t *isnull) { - H5VL_object_t *vol_obj = NULL;/* Object info */ - hid_t file_id = H5I_INVALID_HID; uint8_t *vl = (uint8_t *)_vl; /* Pointer to the user's hvl_t information */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC /* Check parameters */ - HDassert(f); + HDassert(file); HDassert(vl); HDassert(isnull); /* Skip the sequence's length */ vl += 4; - /* TODO temporary hack to retrieve file object */ - if((file_id = H5F__get_file_id((H5F_t *)f, FALSE)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") - if(NULL == (vol_obj = H5VL_vol_object(file_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - /* Check if blob ID is "nil" */ - if(H5VL_blob_specific(vol_obj, vl, H5VL_BLOB_ISNULL, isnull) < 0) + if(H5VL_blob_specific(file, vl, H5VL_BLOB_ISNULL, isnull) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to check if a blob ID is 'nil'") done: - if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) - HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__vlen_disk_isnull() */ @@ -889,41 +882,31 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_disk_setnull(H5F_t *f, void *_vl, void *bg) +H5T__vlen_disk_setnull(H5VL_object_t *file, void *_vl, void *bg) { - H5VL_object_t *vol_obj = NULL;/* Object info */ - hid_t file_id = H5I_INVALID_HID; uint8_t *vl = (uint8_t *)_vl; /* Pointer to the user's hvl_t information */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC /* check parameters */ - HDassert(f); + HDassert(file); HDassert(vl); /* Free heap object for old data */ if(bg != NULL) /* Delete sequence in destination location */ - if(H5T__vlen_disk_delete(f, bg) < 0) + if(H5T__vlen_disk_delete(file, bg) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to remove background heap object") /* Set the length of the sequence */ UINT32ENCODE(vl, 0); - /* TODO temporary hack to retrieve file object */ - if((file_id = H5F__get_file_id(f, FALSE)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") - if(NULL == (vol_obj = H5VL_vol_object(file_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - /* Set blob ID to "nil" */ - if(H5VL_blob_specific(vol_obj, vl, H5VL_BLOB_SETNULL) < 0) + if(H5VL_blob_specific(file, vl, H5VL_BLOB_SETNULL) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to set a blob ID to 'nil'") done: - if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) - HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__vlen_disk_setnull() */ @@ -941,36 +924,26 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_disk_read(H5F_t *f, void *_vl, void *buf, size_t H5_ATTR_UNUSED len) +H5T__vlen_disk_read(H5VL_object_t *file, void *_vl, void *buf, size_t len) { - H5VL_object_t *vol_obj = NULL;/* Object info */ - hid_t file_id = H5I_INVALID_HID; const uint8_t *vl = (const uint8_t *)_vl; /* Pointer to the user's hvl_t information */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC /* Check parameters */ - HDassert(f); + HDassert(file); HDassert(vl); HDassert(buf); /* Skip the length of the sequence */ vl += 4; - /* TODO temporary hack to retrieve file object */ - if((file_id = H5F__get_file_id(f, FALSE)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") - if(NULL == (vol_obj = H5VL_vol_object(file_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - /* Retrieve blob */ - if(H5VL_blob_get(vol_obj, vl, buf, NULL, NULL) < 0) + if(H5VL_blob_get(file, vl, buf, len, NULL) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to get blob") done: - if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) - HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__vlen_disk_read() */ @@ -988,11 +961,10 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_disk_write(H5F_t *f, const H5T_vlen_alloc_info_t H5_ATTR_UNUSED *vl_alloc_info, - void *_vl, void *buf, void *_bg, size_t seq_len, size_t base_size) +H5T__vlen_disk_write(H5VL_object_t *file, + const H5T_vlen_alloc_info_t H5_ATTR_UNUSED *vl_alloc_info, void *_vl, + void *buf, void *_bg, size_t seq_len, size_t base_size) { - H5VL_object_t *vol_obj = NULL; /* Object info */ - hid_t file_id = H5I_INVALID_HID; uint8_t *vl = (uint8_t *)_vl; /* Pointer to the user's hvl_t information */ const uint8_t *bg = (const uint8_t *)_bg; /* Pointer to the old data hvl_t */ herr_t ret_value = SUCCEED; /* Return value */ @@ -1002,29 +974,21 @@ H5T__vlen_disk_write(H5F_t *f, const H5T_vlen_alloc_info_t H5_ATTR_UNUSED *vl_al /* check parameters */ HDassert(vl); HDassert(seq_len == 0 || buf); - HDassert(f); + HDassert(file); /* Free heap object for old data, if non-NULL */ if(bg != NULL) - if(H5T__vlen_disk_delete(f, bg) < 0) + if(H5T__vlen_disk_delete(file, bg) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to remove background heap object") /* Set the length of the sequence */ UINT32ENCODE(vl, seq_len); - /* TODO temporary hack to retrieve file object */ - if((file_id = H5F__get_file_id(f, FALSE)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") - if(NULL == (vol_obj = H5VL_vol_object(file_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - /* Store blob */ - if(H5VL_blob_put(vol_obj, buf, (seq_len * base_size), vl, NULL) < 0) + if(H5VL_blob_put(file, buf, (seq_len * base_size), vl, NULL) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to put blob") done: - if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) - HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__vlen_disk_write() */ @@ -1042,16 +1006,15 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T__vlen_disk_delete(H5F_t *f, const void *_vl) +H5T__vlen_disk_delete(H5VL_object_t *file, const void *_vl) { const uint8_t *vl = (const uint8_t *)_vl; /* Pointer to the user's hvl_t information */ - hid_t file_id = H5I_INVALID_HID; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC /* Check parameters */ - HDassert(f); + HDassert(file); /* Free heap object for old data */ if(vl != NULL) { @@ -1061,23 +1024,12 @@ H5T__vlen_disk_delete(H5F_t *f, const void *_vl) UINT32DECODE(vl, seq_len); /* Delete object, if length > 0 */ - if(seq_len > 0) { - H5VL_object_t *vol_obj = NULL; /* Object info */ - - /* TODO temporary hack to retrieve file object */ - if((file_id = H5F__get_file_id(f, FALSE)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") - if(NULL == (vol_obj = H5VL_vol_object(file_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - - if(H5VL_blob_specific(vol_obj, (void *)vl, H5VL_BLOB_DELETE) < 0) /* Casting away 'const' OK -QAK */ + if(seq_len > 0) + if(H5VL_blob_specific(file, (void *)vl, H5VL_BLOB_DELETE) < 0) /* Casting away 'const' OK -QAK */ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to delete blob") - } } /* end if */ done: - if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) - HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__vlen_disk_delete() */ diff --git a/src/H5VL.c b/src/H5VL.c index 5c62f6f..6790465 100644 --- a/src/H5VL.c +++ b/src/H5VL.c @@ -29,9 +29,11 @@ /***********/ #include "H5private.h" /* Generic Functions */ +#include "H5CXprivate.h" /* API Contexts */ #include "H5Eprivate.h" /* Error handling */ #include "H5Iprivate.h" /* IDs */ #include "H5Pprivate.h" /* Property lists */ +#include "H5Tprivate.h" /* Datatypes */ #include "H5VLpkg.h" /* Virtual Object Layer */ /* VOL connectors */ @@ -279,6 +281,38 @@ done: /*------------------------------------------------------------------------- + * Function: H5VLpeek_connector_id + * + * Purpose: Retrieves the ID for a registered VOL connector. + * + * Return: A valid VOL connector ID if a connector by that name has + * been registered. This ID is *not* owned by the caller and + * H5VLclose() should not be called. Intended for use by VOL + * connectors to find their own ID. + * + * H5I_INVALID_HID on error or if a VOL connector of that + * name has not been registered. + * + *------------------------------------------------------------------------- + */ +hid_t +H5VLpeek_connector_id(const char *name) +{ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE1("i", "*s", name); + + /* Get connector ID with this name */ + if((ret_value = H5VL__peek_connector_id(name)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, H5I_INVALID_HID, "can't get VOL id") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5VLpeek_connector_id() */ + + +/*------------------------------------------------------------------------- * Function: H5VLget_connector_name * * Purpose: Returns the connector name for the VOL associated with the @@ -503,6 +537,73 @@ done: } /* H5VLobject() */ +/*------------------------------------------------------------------------- + * Function: H5VLget_file_type + * + * Purpose: Returns a copy of dtype_id with its location set to be in + * the file, with updated size, etc. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +hid_t +H5VLget_file_type(void *file_obj, hid_t connector_id, hid_t dtype_id) +{ + H5T_t *dtype; /* unatomized type */ + H5T_t *file_type = NULL; /* copied file type */ + hid_t file_type_id = -1; /* copied file type id */ + H5VL_object_t *file_vol_obj = NULL; /* VOL object for file */ + hid_t ret_value = -1; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE3("i", "*xii", file_obj, connector_id, dtype_id); + + /* Check args */ + if(!file_obj) + HGOTO_ERROR(H5E_ARGS, H5E_UNINITIALIZED, FAIL, "no file object supplied") + if(NULL == (dtype = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type") + + /* Create VOL object for file */ + if(NULL == (file_vol_obj = H5VL_create_object_using_vol_id(H5I_FILE, file_obj, connector_id))) + HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, FAIL, "can't create VOL object") + + /* Copy the datatype */ + if(NULL == (file_type = H5T_copy(dtype, H5T_COPY_TRANSIENT))) + HGOTO_ERROR(H5E_VOL, H5E_CANTCOPY, FAIL, "unable to copy datatype") + + /* Register file type id */ + if((file_type_id = H5I_register(H5I_DATATYPE, file_type, FALSE)) < 0) { + (void)H5T_close_real(file_type); + HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, FAIL, "unable to register file datatype") + } /* end if */ + + /* Set the location of the datatype to be in the file */ + if(H5T_set_loc(file_type, file_vol_obj, H5T_LOC_DISK) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't set datatype location") + + /* file_type now owns file_vol_obj */ + if(H5T_own_vol_obj(file_type, file_vol_obj) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't give ownership of VOL object") + file_vol_obj = NULL; + + /* Set return value */ + ret_value = file_type_id; + +done: + /* Cleanup on error */ + if(ret_value < 0) { + if(file_vol_obj && H5VL_free_object(file_vol_obj) < 0) + HDONE_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to free VOL object") + if(file_type_id >= 0 && H5I_dec_ref(file_type_id) < 0) + HDONE_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to close file datatype") + } /* end if */ + + FUNC_LEAVE_API(ret_value) +} /* end H5VLget_file_type() */ + + /*--------------------------------------------------------------------------- * Function: H5VLretrieve_lib_state * diff --git a/src/H5VLcallback.c b/src/H5VLcallback.c index e486fde..02e2399 100644 --- a/src/H5VLcallback.c +++ b/src/H5VLcallback.c @@ -180,7 +180,7 @@ static herr_t H5VL__request_free(void *req, const H5VL_class_t *cls); static herr_t H5VL__blob_put(void *obj, const H5VL_class_t *cls, const void *buf, size_t size, void *blob_id, void *ctx); static herr_t H5VL__blob_get(void *obj, const H5VL_class_t *cls, - const void *blob_id, void *buf, size_t *size, void *ctx); + const void *blob_id, void *buf, size_t size, void *ctx); static herr_t H5VL__blob_specific(void *obj, const H5VL_class_t *cls, void *blob_id, H5VL_blob_specific_t specific_type, va_list arguments); @@ -6692,7 +6692,7 @@ done: */ static herr_t H5VL__blob_get(void *obj, const H5VL_class_t *cls, const void *blob_id, - void *buf, size_t *size, void *ctx) + void *buf, size_t size, void *ctx) { herr_t ret_value = SUCCEED; /* Return value */ @@ -6702,7 +6702,7 @@ H5VL__blob_get(void *obj, const H5VL_class_t *cls, const void *blob_id, HDassert(obj); HDassert(cls); HDassert(blob_id); - HDassert(size || buf); + HDassert(buf); /* Check if the corresponding VOL callback exists */ if(NULL == cls->blob_cls.get) @@ -6728,7 +6728,7 @@ done: */ herr_t H5VL_blob_get(const H5VL_object_t *vol_obj, const void *blob_id, void *buf, - size_t *size, void *ctx) + size_t size, void *ctx) { hbool_t vol_wrapper_set = FALSE; /* Whether the VOL object wrapping context was set up */ herr_t ret_value = SUCCEED; /* Return value */ @@ -6738,7 +6738,7 @@ H5VL_blob_get(const H5VL_object_t *vol_obj, const void *blob_id, void *buf, /* Sanity check */ HDassert(vol_obj); HDassert(blob_id); - HDassert(size || buf); + HDassert(buf); /* Set wrapper info in API context */ if(H5VL_set_vol_wrapper(vol_obj->data, vol_obj->connector) < 0) @@ -6768,13 +6768,13 @@ done: */ herr_t H5VLblob_get(void *obj, hid_t connector_id, const void *blob_id, void *buf, - size_t *size, void *ctx) + size_t size, void *ctx) { H5VL_class_t *cls; /* VOL connector's class struct */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API_NOINIT - H5TRACE6("e", "*xi*x*x*z*x", obj, connector_id, blob_id, buf, size, ctx); + H5TRACE6("e", "*xi*x*xz*x", obj, connector_id, blob_id, buf, size, ctx); /* Get class pointer */ if(NULL == obj) diff --git a/src/H5VLconnector.h b/src/H5VLconnector.h index 3597751..46383bb 100644 --- a/src/H5VLconnector.h +++ b/src/H5VLconnector.h @@ -116,6 +116,7 @@ typedef enum H5VL_file_get_t { /* types for file SPECIFIC callback */ typedef enum H5VL_file_specific_t { + H5VL_FILE_POST_OPEN, /* Adjust file after open, with wrapping context */ H5VL_FILE_FLUSH, /* Flush file */ H5VL_FILE_REOPEN, /* Reopen the file */ H5VL_FILE_MOUNT, /* Mount a file */ @@ -380,7 +381,7 @@ typedef struct H5VL_request_class_t { /* 'blob' routines */ typedef struct H5VL_blob_class_t { herr_t (*put)(void *obj, const void *buf, size_t size, void *blob_id, void *ctx); - herr_t (*get)(void *obj, const void *blob_id, void *buf, size_t *size, void *ctx); + herr_t (*get)(void *obj, const void *blob_id, void *buf, size_t size, void *ctx); herr_t (*specific)(void *obj, void *blob_id, H5VL_blob_specific_t specific_type, va_list arguments); herr_t (*optional)(void *obj, void *blob_id, va_list arguments); } H5VL_blob_class_t; @@ -440,6 +441,9 @@ extern "C" { /* Helper routines for VOL connector authors */ H5_DLL void *H5VLobject(hid_t obj_id); +H5_DLL hid_t H5VLget_file_type(void *file_obj, hid_t connector_id, + hid_t dtype_id); +H5_DLL hid_t H5VLpeek_connector_id(const char *name); #ifdef __cplusplus } diff --git a/src/H5VLconnector_passthru.h b/src/H5VLconnector_passthru.h index d0d73d2..a4c8742 100644 --- a/src/H5VLconnector_passthru.h +++ b/src/H5VLconnector_passthru.h @@ -160,7 +160,7 @@ H5_DLL herr_t H5VLrequest_free(void *req, hid_t connector_id); /* Public wrappers for blob callbacks */ H5_DLL herr_t H5VLblob_put(void *obj, hid_t connector_id, const void *buf, size_t size, void *blob_id, void *ctx); -H5_DLL herr_t H5VLblob_get(void *obj, hid_t connector_id, const void *blob_id, void *buf, size_t *size, void *ctx); +H5_DLL herr_t H5VLblob_get(void *obj, hid_t connector_id, const void *blob_id, void *buf, size_t size, void *ctx); H5_DLL herr_t H5VLblob_specific(void *obj, hid_t connector_id, void *blob_id, H5VL_blob_specific_t specific_type, va_list arguments); /* Public wrappers for generic 'optional' callback */ diff --git a/src/H5VLint.c b/src/H5VLint.c index 09acb2a..733a2b5 100644 --- a/src/H5VLint.c +++ b/src/H5VLint.c @@ -424,7 +424,7 @@ H5VL__set_def_conn(void) else { /* Register the VOL connector */ /* (NOTE: No provisions for vipl_id currently) */ - if((connector_id = H5VL__register_connector_by_name(tok, FALSE, H5P_DEFAULT)) < 0) + if((connector_id = H5VL__register_connector_by_name(tok, TRUE, H5P_DEFAULT)) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, FAIL, "can't register connector") } /* end else */ } /* end else */ @@ -815,6 +815,62 @@ done: /*------------------------------------------------------------------------- + * Function: H5VL_create_object_using_vol_id + * + * Purpose: Similar to H5VL_register_using_vol_id but does not create + * an id. Intended for use by internal library routines, + * therefore it wraps the object. + * + * Return: Success: VOL object pointer + * Failure: NULL + * + *------------------------------------------------------------------------- + */ +H5VL_object_t * +H5VL_create_object_using_vol_id(H5I_type_t type, void *obj, hid_t connector_id) +{ + H5VL_class_t *cls = NULL; /* VOL connector class */ + H5VL_t *connector = NULL; /* VOL connector struct */ + hbool_t conn_id_incr = FALSE; /* Whether the VOL connector ID has been incremented */ + H5VL_object_t *ret_value = NULL; /* Return value */ + + FUNC_ENTER_NOAPI(NULL) + + /* Get the VOL class object from the connector's ID */ + if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) + HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, NULL, "not a VOL connector ID") + + /* Setup VOL info struct */ + if(NULL == (connector = H5FL_CALLOC(H5VL_t))) + HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, NULL, "can't allocate VOL info struct") + connector->cls = cls; + connector->id = connector_id; + if(H5I_inc_ref(connector->id, FALSE) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINC, NULL, "unable to increment ref count on VOL connector") + conn_id_incr = TRUE; + + /* Set up VOL object for the passed-in data */ + /* (Wraps object, since it's a library object) */ + if(NULL == (ret_value = H5VL__new_vol_obj(type, obj, connector, TRUE))) + HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "can't create VOL object") + +done: + /* Clean up on error */ + if(!ret_value) { + /* Decrement VOL connector ID ref count on error */ + if(conn_id_incr && H5I_dec_ref(connector_id) < 0) + HDONE_ERROR(H5E_VOL, H5E_CANTDEC, NULL, "unable to decrement ref count on VOL connector") + + /* Free VOL connector struct */ + if(NULL != connector) + connector = H5FL_FREE(H5VL_t, connector); + } /* end if */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_create_object_using_vol_id() */ + + +/*------------------------------------------------------------------------- * Function: H5VL__conn_inc_rc * * Purpose: Wrapper to increment the ref. count on a connector. @@ -1052,7 +1108,7 @@ H5VL__register_connector_by_name(const char *name, hbool_t app_ref, hid_t vipl_i op_data.found_id = H5I_INVALID_HID; /* Check if connector is already registered */ - if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) + if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, app_ref) < 0) HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL ids") /* If connector alread registered, increment ref count on ID and return ID */ @@ -1196,6 +1252,37 @@ done: hid_t H5VL__get_connector_id(const char *name, hbool_t is_api) { + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Find connector with name */ + if((ret_value = H5VL__peek_connector_id(name)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't find VOL connector") + + /* Found a connector with that name */ + if(H5I_inc_ref(ret_value, is_api) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__get_connector_id() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__peek_connector_id + * + * Purpose: Retrieves the ID for a registered VOL connector. Does not + * increment the ref count + * + * Return: Positive if the VOL class has been registered + * Negative on error (if the class is not a valid class or not registered) + * + *------------------------------------------------------------------------- + */ +hid_t +H5VL__peek_connector_id(const char *name) +{ H5VL_get_connector_ud_t op_data; /* Callback info for connector search */ hid_t ret_value = H5I_INVALID_HID; /* Return value */ @@ -1210,16 +1297,12 @@ H5VL__get_connector_id(const char *name, hbool_t is_api) if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL connectors") - /* Found a connector with that name */ - if(op_data.found_id != H5I_INVALID_HID) { - if(H5I_inc_ref(op_data.found_id, is_api) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector") - ret_value = op_data.found_id; - } /* end if */ + /* Set return value */ + ret_value = op_data.found_id; done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL__get_connector_id() */ +} /* end H5VL__peek_connector_id() */ /*------------------------------------------------------------------------- diff --git a/src/H5VLnative_blob.c b/src/H5VLnative_blob.c index b16b407..6c7f9b2 100644 --- a/src/H5VLnative_blob.c +++ b/src/H5VLnative_blob.c @@ -109,12 +109,13 @@ done: *------------------------------------------------------------------------- */ herr_t -H5VL__native_blob_get(void *obj, const void *blob_id, void *buf, size_t *size, +H5VL__native_blob_get(void *obj, const void *blob_id, void *buf, size_t size, void H5_ATTR_UNUSED *ctx) { H5F_t *f = (H5F_t *)obj; /* Retrieve file pointer */ const uint8_t *id = (const uint8_t *)blob_id; /* Pointer to the disk blob ID */ H5HG_t hobjid; /* Global heap ID for sequence */ + size_t hobj_size; /* Global heap object size returned from H5HG_read() */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -131,9 +132,13 @@ H5VL__native_blob_get(void *obj, const void *blob_id, void *buf, size_t *size, /* Check if this sequence actually has any data */ if(hobjid.addr > 0) /* Read the VL information from disk */ - if(NULL == H5HG_read(f, &hobjid, buf, size)) + if(NULL == H5HG_read(f, &hobjid, buf, &hobj_size)) HGOTO_ERROR(H5E_VOL, H5E_READERROR, FAIL, "unable to read VL information") + /* Verify the size is correct */ + if(hobj_size != size) + HGOTO_ERROR(H5E_VOL, H5E_CANTDECODE, FAIL, "Expected global heap object size does not match") + done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL__native_blob_get() */ @@ -175,7 +180,7 @@ H5VL__native_blob_specific(void *obj, void *blob_id, H5F_addr_decode(f, &id, &(hobjid.addr)); UINT32DECODE(id, hobjid.idx); - /* Free heap object */ + /* Get heap object's size */ if(hobjid.addr > 0) { if(H5HG_get_obj_size(f, &hobjid, size) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTREMOVE, FAIL, "unable to remove heap object") diff --git a/src/H5VLnative_file.c b/src/H5VLnative_file.c index 63574c6..094722e 100644 --- a/src/H5VLnative_file.c +++ b/src/H5VLnative_file.c @@ -305,6 +305,15 @@ H5VL__native_file_specific(void *obj, H5VL_file_specific_t specific_type, FUNC_ENTER_PACKAGE switch(specific_type) { + /* Finalize H5Fopen */ + case H5VL_FILE_POST_OPEN: + { + /* Call package routine */ + if(H5F__post_open((H5F_t *)obj) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "can't finish opening file") + break; + } + /* H5Fflush */ case H5VL_FILE_FLUSH: { diff --git a/src/H5VLnative_private.h b/src/H5VLnative_private.h index 5ed0b1f..69a057e 100644 --- a/src/H5VLnative_private.h +++ b/src/H5VLnative_private.h @@ -103,7 +103,7 @@ H5_DLL herr_t H5VL__native_datatype_close(void *dt, hid_t dxpl_id, void **req); /* Blob callbacks */ H5_DLL herr_t H5VL__native_blob_put(void *obj, const void *buf, size_t size, void *blob_id, void *ctx); -H5_DLL herr_t H5VL__native_blob_get(void *obj, const void *blob_id, void *buf, size_t *size, void *ctx); +H5_DLL herr_t H5VL__native_blob_get(void *obj, const void *blob_id, void *buf, size_t size, void *ctx); H5_DLL herr_t H5VL__native_blob_specific(void *obj, void *blob_id, H5VL_blob_specific_t specific_type, va_list arguments); #ifdef __cplusplus diff --git a/src/H5VLpassthru.c b/src/H5VLpassthru.c index 85c2211..d8181bb 100644 --- a/src/H5VLpassthru.c +++ b/src/H5VLpassthru.c @@ -180,7 +180,7 @@ static herr_t H5VL_pass_through_request_free(void *req); /* Blob callbacks */ static herr_t H5VL_pass_through_blob_put(void *obj, const void *buf, size_t size, void *blob_id, void *ctx); -static herr_t H5VL_pass_through_blob_get(void *obj, const void *blob_id, void *buf, size_t *size, void *ctx); +static herr_t H5VL_pass_through_blob_get(void *obj, const void *blob_id, void *buf, size_t size, void *ctx); static herr_t H5VL_pass_through_blob_specific(void *obj, void *blob_id, H5VL_blob_specific_t specific_type, va_list arguments); @@ -2885,7 +2885,7 @@ H5VL_pass_through_blob_put(void *obj, const void *buf, size_t size, */ herr_t H5VL_pass_through_blob_get(void *obj, const void *blob_id, void *buf, - size_t *size, void *ctx) + size_t size, void *ctx) { H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; herr_t ret_value; diff --git a/src/H5VLpkg.h b/src/H5VLpkg.h index 69e51c2..fc3088d 100644 --- a/src/H5VLpkg.h +++ b/src/H5VLpkg.h @@ -55,6 +55,7 @@ H5_DLL hid_t H5VL__register_connector_by_value(H5VL_class_value_t value, hbool_t app_ref, hid_t vipl_id); H5_DLL htri_t H5VL__is_connector_registered(const char *name); H5_DLL hid_t H5VL__get_connector_id(const char *name, hbool_t is_api); +H5_DLL hid_t H5VL__peek_connector_id(const char *name); H5_DLL herr_t H5VL__connector_str_to_info(const char *str, hid_t connector_id, void **info); H5_DLL ssize_t H5VL__get_connector_name(hid_t id, char *name/*out*/, size_t size); diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index 2889524..ca474a7 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -89,6 +89,7 @@ H5_DLL void *H5VL_object_data(const H5VL_object_t *vol_obj); H5_DLL void *H5VL_object_unwrap(const H5VL_object_t *vol_obj); H5_DLL void *H5VL_object_verify(hid_t id, H5I_type_t obj_type); H5_DLL H5VL_object_t *H5VL_vol_object(hid_t id); +H5_DLL H5VL_object_t *H5VL_create_object_using_vol_id(H5I_type_t type, void *obj, hid_t connector_id); H5_DLL herr_t H5VL_free_object(H5VL_object_t *obj); /* Functions that wrap / unwrap VOL objects */ @@ -195,7 +196,7 @@ H5_DLL herr_t H5VL_request_free(const H5VL_object_t *vol_obj); /* Blob functions */ H5_DLL herr_t H5VL_blob_put(const H5VL_object_t *vol_obj, const void *buf, size_t size, void *blob_id, void *ctx); -H5_DLL herr_t H5VL_blob_get(const H5VL_object_t *vol_obj, const void *blob_id, void *buf, size_t *size, void *ctx); +H5_DLL herr_t H5VL_blob_get(const H5VL_object_t *vol_obj, const void *blob_id, void *buf, size_t size, void *ctx); H5_DLL herr_t H5VL_blob_specific(const H5VL_object_t *vol_obj, void *blob_id, H5VL_blob_specific_t specific_type, ...); /* Generic functions */ -- cgit v0.12 From 1b45a5c09f7f31dfc6920c3fe503b8e043e327a2 Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Fri, 6 Dec 2019 14:14:22 -0600 Subject: Add RELEASE.txt note for HVLget_file_type() --- release_docs/RELEASE.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index a0b9c6d..10a9596 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -90,6 +90,15 @@ New Features release. • h5dump will fail to display references on big-endian machines. + - Add new public function H5VLget_file_type. + + This function returns a datatype equivalent to the supplied datatype but + with the location set to be in the file. This datatype can then be used + with H5Tconvert to convert data between file and in-memory representation. + This funcition is intended for use only by VOL connector developers. + + (NAF - 2019/11/08, ID-127) + - New S3 and HDFS Virtual File Drivers (VFDs) This release has two new VFDs. The S3 VFD allows accessing HDF5 files on -- cgit v0.12 From 33357092c48b5cbc9ddd4b5ecad7ff3a69b7622c Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Fri, 8 Nov 2019 16:49:12 -0600 Subject: Implement public H5Sselect_project_intersection(). Updated internal algorithm to (optionally) avoid sharing selection data structures. Tested internal code (including with valgrind) by setting VDS code to avoid sharing selection, has since been changed to share selection for performance, so this code is not yet tested in regression tests. API has not been tested. --- src/H5Dvirtual.c | 10 +- src/H5Shyper.c | 276 +++++++++++++++++++++++++++++++++++++------------------ src/H5Smpio.c | 28 +++--- src/H5Spkg.h | 31 ++++--- src/H5Sprivate.h | 2 +- src/H5Spublic.h | 2 + src/H5Sselect.c | 81 +++++++++++++++- 7 files changed, 308 insertions(+), 122 deletions(-) diff --git a/src/H5Dvirtual.c b/src/H5Dvirtual.c index 53640e7..877aadb 100644 --- a/src/H5Dvirtual.c +++ b/src/H5Dvirtual.c @@ -2406,7 +2406,7 @@ H5D__virtual_pre_io(H5D_io_info_t *io_info, /* Project intersection of virtual space and clipped * virtual space onto source space (create * clipped_source_select) */ - if(H5S_select_project_intersection(storage->list[i].sub_dset[j].virtual_select, storage->list[i].source_select, storage->list[i].sub_dset[j].clipped_virtual_select, &storage->list[i].sub_dset[j].clipped_source_select) < 0) + if(H5S_select_project_intersection(storage->list[i].sub_dset[j].virtual_select, storage->list[i].source_select, storage->list[i].sub_dset[j].clipped_virtual_select, &storage->list[i].sub_dset[j].clipped_source_select, TRUE) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCLIP, FAIL, "can't project virtual intersection onto memory space") /* Set extents of virtual_select and @@ -2423,7 +2423,7 @@ H5D__virtual_pre_io(H5D_io_info_t *io_info, if(storage->list[i].sub_dset[j].clipped_virtual_select) { /* Project intersection of file space and mapping virtual space * onto memory space */ - if(H5S_select_project_intersection(file_space, mem_space, storage->list[i].sub_dset[j].clipped_virtual_select, &storage->list[i].sub_dset[j].projected_mem_space) < 0) + if(H5S_select_project_intersection(file_space, mem_space, storage->list[i].sub_dset[j].clipped_virtual_select, &storage->list[i].sub_dset[j].projected_mem_space, TRUE) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCLIP, FAIL, "can't project virtual intersection onto memory space") /* Check number of elements selected */ @@ -2460,7 +2460,7 @@ H5D__virtual_pre_io(H5D_io_info_t *io_info, if(storage->list[i].source_dset.clipped_virtual_select) { /* Project intersection of file space and mapping virtual space onto * memory space */ - if(H5S_select_project_intersection(file_space, mem_space, storage->list[i].source_dset.clipped_virtual_select, &storage->list[i].source_dset.projected_mem_space) < 0) + if(H5S_select_project_intersection(file_space, mem_space, storage->list[i].source_dset.clipped_virtual_select, &storage->list[i].source_dset.projected_mem_space, TRUE) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCLIP, FAIL, "can't project virtual intersection onto memory space") /* Check number of elements selected, add to tot_nelmts */ @@ -2590,7 +2590,7 @@ H5D__virtual_read_one(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, /* Project intersection of file space and mapping virtual space onto * mapping source space */ - if(H5S_select_project_intersection(source_dset->clipped_virtual_select, source_dset->clipped_source_select, file_space, &projected_src_space) < 0) + if(H5S_select_project_intersection(source_dset->clipped_virtual_select, source_dset->clipped_source_select, file_space, &projected_src_space, TRUE) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCLIP, FAIL, "can't project virtual intersection onto source space") /* Perform read on source dataset */ @@ -2781,7 +2781,7 @@ H5D__virtual_write_one(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, * extent in the unlimited dimension. -NAF */ /* Project intersection of file space and mapping virtual space onto * mapping source space */ - if(H5S_select_project_intersection(source_dset->virtual_select, source_dset->clipped_source_select, file_space, &projected_src_space) < 0) + if(H5S_select_project_intersection(source_dset->virtual_select, source_dset->clipped_source_select, file_space, &projected_src_space, TRUE) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCLIP, FAIL, "can't project virtual intersection onto source space") /* Perform write on source dataset */ diff --git a/src/H5Shyper.c b/src/H5Shyper.c index e9a7133..1a0da1e 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -96,6 +96,7 @@ typedef struct { hsize_t skip; /* Number of elements to skip in projected space */ hsize_t nelem; /* Number of elements to add to projected space (after skip) */ uint64_t op_gen; /* Operation generation for counting elements */ + hbool_t share_selection; /* Whether span trees in dst_space can be shared with proj_space */ } H5S_hyper_project_intersect_ud_t; /* Assert that H5S_MAX_RANK is <= 32 so our trick with using a 32 bit bitmap @@ -112,6 +113,9 @@ typedef struct { static H5S_hyper_span_t *H5S__hyper_new_span(hsize_t low, hsize_t high, H5S_hyper_span_info_t *down, H5S_hyper_span_t *next); static H5S_hyper_span_info_t *H5S__hyper_new_span_info(unsigned rank); +static H5S_hyper_span_info_t *H5S__hyper_copy_span_helper( + H5S_hyper_span_info_t *spans, unsigned rank, unsigned op_info_i, + uint64_t op_gen); static H5S_hyper_span_info_t *H5S__hyper_copy_span(H5S_hyper_span_info_t *spans, unsigned rank); static hbool_t H5S__hyper_cmp_spans(const H5S_hyper_span_info_t *span_info1, @@ -132,7 +136,7 @@ static herr_t H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t **a_and_b, H5S_hyper_span_info_t **b_not_a); static herr_t H5S__hyper_merge_spans(H5S_t *space, H5S_hyper_span_info_t *new_spans); static hsize_t H5S__hyper_spans_nelem_helper(H5S_hyper_span_info_t *spans, - uint64_t op_gen); + unsigned op_info_i, uint64_t op_gen); static hsize_t H5S__hyper_spans_nelem(H5S_hyper_span_info_t *spans); static herr_t H5S__hyper_add_disjoint_spans(H5S_t *space, H5S_hyper_span_info_t *new_spans); static H5S_hyper_span_info_t *H5S__hyper_make_spans(unsigned rank, @@ -2851,9 +2855,10 @@ done: PURPOSE Helper routine to copy a hyperslab span tree USAGE - H5S_hyper_span_info_t * H5S__hyper_copy_span_helper(spans, rank) + H5S_hyper_span_info_t * H5S__hyper_copy_span_helper(spans, rank, op_info_i, op_gen) H5S_hyper_span_info_t *spans; IN: Span tree to copy unsigned rank; IN: Rank of span tree + unsigned op_info_i; IN: Index of op info to use uint64_t op_gen; IN: Operation generation RETURNS Pointer to the copied span tree on success, NULL on failure @@ -2866,7 +2871,7 @@ done: --------------------------------------------------------------------------*/ static H5S_hyper_span_info_t * H5S__hyper_copy_span_helper(H5S_hyper_span_info_t *spans, unsigned rank, - uint64_t op_gen) + unsigned op_info_i, uint64_t op_gen) { H5S_hyper_span_t *span; /* Hyperslab span */ H5S_hyper_span_t *new_span; /* Temporary hyperslab span */ @@ -2880,9 +2885,9 @@ H5S__hyper_copy_span_helper(H5S_hyper_span_info_t *spans, unsigned rank, HDassert(spans); /* Check if the span tree was already copied */ - if(spans->op_gen == op_gen) { + if(spans->op_info[op_info_i].op_gen == op_gen) { /* Just return the value of the already copied span tree */ - ret_value = spans->u.copied; + ret_value = spans->op_info[op_info_i].u.copied; /* Increment the reference count of the span tree */ ret_value->count++; @@ -2898,10 +2903,10 @@ H5S__hyper_copy_span_helper(H5S_hyper_span_info_t *spans, unsigned rank, ret_value->count = 1; /* Set the operation generation for the span info, to avoid future copies */ - spans->op_gen = op_gen; + spans->op_info[op_info_i].op_gen = op_gen; /* Set the 'copied' pointer in the node being copied to the newly allocated node */ - spans->u.copied = ret_value; + spans->op_info[op_info_i].u.copied = ret_value; /* Copy over the nodes in the span list */ span = spans->head; @@ -2919,7 +2924,7 @@ H5S__hyper_copy_span_helper(H5S_hyper_span_info_t *spans, unsigned rank, /* Recurse to copy the 'down' spans, if there are any */ if(span->down != NULL) { - if(NULL == (new_down = H5S__hyper_copy_span_helper(span->down, rank - 1, op_gen))) + if(NULL == (new_down = H5S__hyper_copy_span_helper(span->down, rank - 1, op_info_i, op_gen))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy hyperslab spans") new_span->down = new_down; } /* end if */ @@ -2975,7 +2980,9 @@ H5S__hyper_copy_span(H5S_hyper_span_info_t *spans, unsigned rank) op_gen = H5S__hyper_get_op_gen(); /* Copy the hyperslab span tree */ - if(NULL == (ret_value = H5S__hyper_copy_span_helper(spans, rank, op_gen))) + /* Always use op_info[0] since we own this op_info, so there can be no + * simultaneous operations */ + if(NULL == (ret_value = H5S__hyper_copy_span_helper(spans, rank, 0, op_gen))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy hyperslab span tree") done: @@ -3314,8 +3321,9 @@ done: PURPOSE Helper routine to count the number of blocks in a span tree USAGE - hsize_t H5S__hyper_span_nblocks_helper(spans) + hsize_t H5S__hyper_span_nblocks_helper(spans, op_info_i, op_gen) H5S_hyper_span_info_t *spans; IN: Hyperslab span tree to count blocks of + unsigned op_info_i; IN: Index of op info to use uint64_t op_gen; IN: Operation generation RETURNS Number of blocks in span tree on success; negative on failure @@ -3327,7 +3335,8 @@ done: REVISION LOG --------------------------------------------------------------------------*/ static hsize_t -H5S__hyper_span_nblocks_helper(H5S_hyper_span_info_t *spans, uint64_t op_gen) +H5S__hyper_span_nblocks_helper(H5S_hyper_span_info_t *spans, unsigned op_info_i, + uint64_t op_gen) { hsize_t ret_value = 0; /* Return value */ @@ -3337,9 +3346,9 @@ H5S__hyper_span_nblocks_helper(H5S_hyper_span_info_t *spans, uint64_t op_gen) HDassert(spans); /* Check if the span tree was already counted */ - if(spans->op_gen == op_gen) + if(spans->op_info[op_info_i].op_gen == op_gen) /* Just return the # of blocks in the already counted span tree */ - ret_value = spans->u.nblocks; + ret_value = spans->op_info[op_info_i].u.nblocks; else { /* Count the number of elements in the span tree */ H5S_hyper_span_t *span; /* Hyperslab span */ @@ -3347,7 +3356,7 @@ H5S__hyper_span_nblocks_helper(H5S_hyper_span_info_t *spans, uint64_t op_gen) if(span->down) { while(span) { /* If there are down spans, add the total down span blocks */ - ret_value += H5S__hyper_span_nblocks_helper(span->down, op_gen); + ret_value += H5S__hyper_span_nblocks_helper(span->down, op_info_i, op_gen); /* Advance to next span */ span = span->next; @@ -3364,10 +3373,10 @@ H5S__hyper_span_nblocks_helper(H5S_hyper_span_info_t *spans, uint64_t op_gen) } /* end else */ /* Set the operation generation for this span tree, to avoid re-computing */ - spans->op_gen = op_gen; + spans->op_info[op_info_i].op_gen = op_gen; /* Hold a copy of the # of blocks */ - spans->u.nblocks = ret_value; + spans->op_info[op_info_i].u.nblocks = ret_value; } /* end else */ FUNC_LEAVE_NOAPI(ret_value) @@ -3405,7 +3414,10 @@ H5S__hyper_span_nblocks(H5S_hyper_span_info_t *spans) /* Acquire an operation generation value for this operation */ op_gen = H5S__hyper_get_op_gen(); - ret_value = H5S__hyper_span_nblocks_helper(spans, op_gen); + /* Count the blocks */ + /* Always use op_info[0] since we own this op_info, so there can be no + * simultaneous operations */ + ret_value = H5S__hyper_span_nblocks_helper(spans, 0, op_gen); } /* end if */ FUNC_LEAVE_NOAPI(ret_value) @@ -5948,7 +5960,7 @@ H5S__hyper_add_span_element_helper(H5S_hyper_span_info_t *span_tree, /* Check if we've compared the 'stop' span's "down tree" to * this span's "down tree" already. */ - if(tmp_span->down->op_gen != op_gen) { + if(tmp_span->down->op_info[0].op_gen != op_gen) { if(H5S__hyper_cmp_spans(tmp_span->down, stop_span->down)) attempt_merge_spans = TRUE; @@ -5956,7 +5968,7 @@ H5S__hyper_add_span_element_helper(H5S_hyper_span_info_t *span_tree, /* (Because it wasn't the same as the 'stop' span's down tree * and we don't need to compare it again) */ - tmp_span->down->op_gen = op_gen; + tmp_span->down->op_info[0].op_gen = op_gen; } /* end if */ } /* end else */ @@ -6161,11 +6173,12 @@ done: PURPOSE Helper routine to detect intersections in span trees USAGE - hbool_t H5S__hyper_intersect_block_helper(spans, start, end) + hbool_t H5S__hyper_intersect_block_helper(spans, rank, start, end, op_info_i, op_gen) H5S_hyper_span_info_t *spans; IN: First span tree to operate with unsigned rank; IN: Number of dimensions for span tree hsize_t *start; IN: Starting coordinate for block hsize_t *end; IN: Ending coordinate for block + unsigned op_info_i; IN: Index of op info to use uint64_t op_gen; IN: Operation generation RETURN Non-negative (TRUE/FALSE) on success, can't fail @@ -6178,7 +6191,8 @@ done: --------------------------------------------------------------------------*/ static hbool_t H5S__hyper_intersect_block_helper(H5S_hyper_span_info_t *spans, - unsigned rank, const hsize_t *start, const hsize_t *end, uint64_t op_gen) + unsigned rank, const hsize_t *start, const hsize_t *end, unsigned op_info_i, + uint64_t op_gen) { hbool_t ret_value = FALSE; /* Return value */ @@ -6190,7 +6204,7 @@ H5S__hyper_intersect_block_helper(H5S_hyper_span_info_t *spans, HDassert(end); /* Check if we've already visited this span tree */ - if(spans->op_gen != op_gen) { + if(spans->op_info[op_info_i].op_gen != op_gen) { H5S_hyper_span_t *curr; /* Pointer to current span in 1st span tree */ unsigned u; /* Local index variable */ @@ -6223,7 +6237,7 @@ H5S__hyper_intersect_block_helper(H5S_hyper_span_info_t *spans, /* If there is an intersection in the "down" dimensions, * the span trees overlap. */ - if(H5S__hyper_intersect_block_helper(curr->down, rank - 1, start + 1, end + 1, op_gen)) + if(H5S__hyper_intersect_block_helper(curr->down, rank - 1, start + 1, end + 1, op_info_i, op_gen)) HGOTO_DONE(TRUE) /* No intersection in down dimensions, advance to next span */ @@ -6233,7 +6247,7 @@ H5S__hyper_intersect_block_helper(H5S_hyper_span_info_t *spans, } /* end while */ /* Set the tree's operation generation */ - spans->op_gen = op_gen; + spans->op_info[op_info_i].op_gen = op_gen; } /* end if */ /* Fall through with 'FALSE' return value */ @@ -6269,7 +6283,7 @@ H5S__hyper_intersect_block(const H5S_t *space, const hsize_t *start, const hsize { htri_t ret_value = FAIL; /* Return value */ - FUNC_ENTER_STATIC + FUNC_ENTER_STATIC_NOERR /* Sanity check */ HDassert(space); @@ -6365,7 +6379,9 @@ H5S__hyper_intersect_block(const H5S_t *space, const hsize_t *start, const hsize op_gen = H5S__hyper_get_op_gen(); /* Perform the span-by-span intersection check */ - ret_value = H5S__hyper_intersect_block_helper(space->select.sel_info.hslab->span_lst, space->extent.rank, start, end, op_gen); + /* Always use op_info[0] since we own this op_info, so there can be no + * simultaneous operations */ + ret_value = H5S__hyper_intersect_block_helper(space->select.sel_info.hslab->span_lst, space->extent.rank, start, end, 0, op_gen); } /* end else */ done: @@ -6379,10 +6395,11 @@ done: PURPOSE Helper routine to adjust offsets in span trees USAGE - void H5S__hyper_adjust_u_helper(spans, offset) + void H5S__hyper_adjust_u_helper(spans, rank, offset, op_info_i, op_gen) H5S_hyper_span_info_t *spans; IN: Span tree to operate with unsigned rank; IN: Number of dimensions for span tree const hsize_t *offset; IN: Offset to subtract + unsigned op_info_i; IN: Index of op info to use uint64_t op_gen; IN: Operation generation RETURNS None @@ -6395,7 +6412,7 @@ done: --------------------------------------------------------------------------*/ static void H5S__hyper_adjust_u_helper(H5S_hyper_span_info_t *spans, unsigned rank, - const hsize_t *offset, uint64_t op_gen) + const hsize_t *offset, unsigned op_info_i, uint64_t op_gen) { FUNC_ENTER_STATIC_NOERR @@ -6404,7 +6421,7 @@ H5S__hyper_adjust_u_helper(H5S_hyper_span_info_t *spans, unsigned rank, HDassert(offset); /* Check if we've already set this span tree */ - if(spans->op_gen != op_gen) { + if(spans->op_info[op_info_i].op_gen != op_gen) { H5S_hyper_span_t *span; /* Pointer to current span in span tree */ unsigned u; /* Local index variable */ @@ -6425,14 +6442,14 @@ H5S__hyper_adjust_u_helper(H5S_hyper_span_info_t *spans, unsigned rank, /* Recursively adjust spans in next dimension down */ if(span->down != NULL) - H5S__hyper_adjust_u_helper(span->down, rank - 1, offset + 1, op_gen); + H5S__hyper_adjust_u_helper(span->down, rank - 1, offset + 1, op_info_i, op_gen); /* Advance to next span in this dimension */ span = span->next; } /* end while */ /* Set the tree's operation generation */ - spans->op_gen = op_gen; + spans->op_info[op_info_i].op_gen = op_gen; } /* end if */ FUNC_LEAVE_NOAPI_VOID @@ -6489,7 +6506,10 @@ H5S__hyper_adjust_u(H5S_t *space, const hsize_t *offset) /* Acquire an operation generation value for this operation */ op_gen = H5S__hyper_get_op_gen(); - H5S__hyper_adjust_u_helper(space->select.sel_info.hslab->span_lst, space->extent.rank, offset, op_gen); + /* Perform adjustment */ + /* Always use op_info[0] since we own this op_info, so there can be no + * simultaneous operations */ + H5S__hyper_adjust_u_helper(space->select.sel_info.hslab->span_lst, space->extent.rank, offset, 0, op_gen); } /* end if */ FUNC_LEAVE_NOAPI(SUCCEED) @@ -6899,10 +6919,11 @@ done: PURPOSE Helper routine to adjust offsets in span trees USAGE - void H5S__hyper_adjust_s_helper(spans, offset) + void H5S__hyper_adjust_s_helper(spans, rank, offset, op_info_i, op_gen) H5S_hyper_span_info_t *spans; IN: Span tree to operate with unsigned rank; IN: Number of dimensions for span tree const hssize_t *offset; IN: Offset to subtract + unsigned op_info_i; IN: Index of op info to use uint64_t op_gen; IN: Operation generation RETURNS None @@ -6915,7 +6936,7 @@ done: --------------------------------------------------------------------------*/ static void H5S__hyper_adjust_s_helper(H5S_hyper_span_info_t *spans, unsigned rank, - const hssize_t *offset, uint64_t op_gen) + const hssize_t *offset, unsigned op_info_i, uint64_t op_gen) { FUNC_ENTER_STATIC_NOERR @@ -6924,7 +6945,7 @@ H5S__hyper_adjust_s_helper(H5S_hyper_span_info_t *spans, unsigned rank, HDassert(offset); /* Check if we've already set this span tree */ - if(spans->op_gen != op_gen) { + if(spans->op_info[op_info_i].op_gen != op_gen) { H5S_hyper_span_t *span; /* Pointer to current span in span tree */ unsigned u; /* Local index variable */ @@ -6945,14 +6966,14 @@ H5S__hyper_adjust_s_helper(H5S_hyper_span_info_t *spans, unsigned rank, /* Recursively adjust spans in next dimension down */ if(span->down != NULL) - H5S__hyper_adjust_s_helper(span->down, rank - 1, offset + 1, op_gen); + H5S__hyper_adjust_s_helper(span->down, rank - 1, offset + 1, op_info_i, op_gen); /* Advance to next span in this dimension */ span = span->next; } /* end while */ /* Set the tree's operation generation */ - spans->op_gen = op_gen; + spans->op_info[op_info_i].op_gen = op_gen; } /* end if */ FUNC_LEAVE_NOAPI_VOID @@ -7020,7 +7041,10 @@ H5S_hyper_adjust_s(H5S_t *space, const hssize_t *offset) /* Acquire an operation generation value for this operation */ op_gen = H5S__hyper_get_op_gen(); - H5S__hyper_adjust_s_helper(space->select.sel_info.hslab->span_lst, space->extent.rank, offset, op_gen); + /* Perform the adjustment */ + /* Always use op_info[0] since we own this op_info, so there can be no + * simultaneous operations */ + H5S__hyper_adjust_s_helper(space->select.sel_info.hslab->span_lst, space->extent.rank, offset, 0, op_gen); } /* end if */ } /* end if */ @@ -8283,8 +8307,9 @@ done: PURPOSE Count the number of elements in a span tree USAGE - hsize_t H5S__hyper_spans_nelem_helper(spans, op_gen) + hsize_t H5S__hyper_spans_nelem_helper(spans, op_info_i, op_gen) const H5S_hyper_span_info_t *spans; IN: Hyperslan span tree to count elements of + unsigned op_info_i; IN: Index of op info to use uint64_t op_gen; IN: Operation generation RETURNS Number of elements in span tree on success; negative on failure @@ -8296,7 +8321,8 @@ done: REVISION LOG --------------------------------------------------------------------------*/ static hsize_t -H5S__hyper_spans_nelem_helper(H5S_hyper_span_info_t *spans, uint64_t op_gen) +H5S__hyper_spans_nelem_helper(H5S_hyper_span_info_t *spans, unsigned op_info_i, + uint64_t op_gen) { hsize_t ret_value = 0; /* Return value */ @@ -8306,9 +8332,9 @@ H5S__hyper_spans_nelem_helper(H5S_hyper_span_info_t *spans, uint64_t op_gen) HDassert(spans); /* Check if the span tree was already counted */ - if(spans->op_gen == op_gen) + if(spans->op_info[op_info_i].op_gen == op_gen) /* Just return the # of elements in the already counted span tree */ - ret_value = spans->u.nelmts; + ret_value = spans->op_info[op_info_i].u.nelmts; else { /* Count the number of elements in the span tree */ const H5S_hyper_span_t *span; /* Hyperslab span */ @@ -8330,7 +8356,7 @@ H5S__hyper_spans_nelem_helper(H5S_hyper_span_info_t *spans, uint64_t op_gen) nelmts = (span->high - span->low) + 1; /* Multiply the size of this span by the total down span elements */ - ret_value += nelmts * H5S__hyper_spans_nelem_helper(span->down, op_gen); + ret_value += nelmts * H5S__hyper_spans_nelem_helper(span->down, op_info_i, op_gen); /* Advance to next span */ span = span->next; @@ -8338,10 +8364,10 @@ H5S__hyper_spans_nelem_helper(H5S_hyper_span_info_t *spans, uint64_t op_gen) } /* end else */ /* Set the operation generation for this span tree, to avoid re-computing */ - spans->op_gen = op_gen; + spans->op_info[op_info_i].op_gen = op_gen; /* Hold a copy of the # of elements */ - spans->u.nelmts = ret_value; + spans->op_info[op_info_i].u.nelmts = ret_value; } /* end else */ FUNC_LEAVE_NOAPI(ret_value) @@ -8380,7 +8406,9 @@ H5S__hyper_spans_nelem(H5S_hyper_span_info_t *spans) op_gen = H5S__hyper_get_op_gen(); /* Count the number of elements in the span tree */ - ret_value = H5S__hyper_spans_nelem_helper(spans, op_gen); + /* Always use op_info[0] since we own this op_info, so there can be no + * simultaneous operations */ + ret_value = H5S__hyper_spans_nelem_helper(spans, 0, op_gen); FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_spans_nelem() */ @@ -8810,10 +8838,8 @@ H5S__hyper_update_diminfo(H5S_t *space, H5S_seloper_t op, (It can be recovered with regular selection) USAGE herr_t H5S__hyper_rebuild_helper(space) - const H5S_hyper_span_t *span; IN: Portion of span tree to check - H5S_hyper_dim_t span_slab[]; OUT: Rebuilt section of hyperslab description - unsigned rank; IN: Current dimension to work on - uint64_t op_gen; IN: Operation generation + const H5S_hyper_span_t *spans; IN: Portion of span tree to check + H5S_hyper_dim_t span_slab_info[]; OUT: Rebuilt section of hyperslab description RETURNS TRUE/FALSE for hyperslab selection rebuilt DESCRIPTION @@ -10835,6 +10861,7 @@ done: --------------------------------------------------------------------------*/ static herr_t H5S__hyper_proj_int_build_proj(H5S_hyper_project_intersect_ud_t *udata) { + H5S_hyper_span_info_t *copied_span_info = NULL; /* Temporary span info pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -10854,15 +10881,15 @@ H5S__hyper_proj_int_build_proj(H5S_hyper_project_intersect_ud_t *udata) { /* If we will run out of elements to skip in this span, * advance to the first not fully skipped span and break * out of this loop (start moving downwards) */ - if(udata->skip < H5S__hyper_spans_nelem_helper(udata->ds_span[udata->depth]->down, udata->op_gen) + if(udata->skip < H5S__hyper_spans_nelem_helper(udata->ds_span[udata->depth]->down, 0, udata->op_gen) * (udata->ds_span[udata->depth]->high - udata->ds_low[udata->depth] + 1)) { - udata->ds_low[udata->depth] += udata->skip / udata->ds_span[udata->depth]->down->u.nelmts; - udata->skip %= udata->ds_span[udata->depth]->down->u.nelmts; + udata->ds_low[udata->depth] += udata->skip / udata->ds_span[udata->depth]->down->op_info[0].u.nelmts; + udata->skip %= udata->ds_span[udata->depth]->down->op_info[0].u.nelmts; break; } /* end if */ /* Skip over this entire span */ - udata->skip -= udata->ds_span[udata->depth]->down->u.nelmts + udata->skip -= udata->ds_span[udata->depth]->down->op_info[0].u.nelmts * (udata->ds_span[udata->depth]->high - udata->ds_low[udata->depth] + 1); } /* end if */ } /* end if */ @@ -10921,15 +10948,15 @@ H5S__hyper_proj_int_build_proj(H5S_hyper_project_intersect_ud_t *udata) { /* If we will run out of elements to skip in this span, * advance to the first not fully skipped span and * continue down */ - if(udata->skip < H5S__hyper_spans_nelem_helper(udata->ds_span[udata->depth]->down, udata->op_gen) + if(udata->skip < H5S__hyper_spans_nelem_helper(udata->ds_span[udata->depth]->down, 0, udata->op_gen) * (udata->ds_span[udata->depth]->high - udata->ds_low[udata->depth] + 1)) { - udata->ds_low[udata->depth] += udata->skip / udata->ds_span[udata->depth]->down->u.nelmts; - udata->skip %= udata->ds_span[udata->depth]->down->u.nelmts; + udata->ds_low[udata->depth] += udata->skip / udata->ds_span[udata->depth]->down->op_info[0].u.nelmts; + udata->skip %= udata->ds_span[udata->depth]->down->op_info[0].u.nelmts; break; } /* end if */ /* Skip over this entire span */ - udata->skip -= udata->ds_span[udata->depth]->down->u.nelmts + udata->skip -= udata->ds_span[udata->depth]->down->op_info[0].u.nelmts * (udata->ds_span[udata->depth]->high - udata->ds_low[udata->depth] + 1); /* Advance to next span */ @@ -10974,27 +11001,59 @@ H5S__hyper_proj_int_build_proj(H5S_hyper_project_intersect_ud_t *udata) { * any complete spans, advance to the first not fully added * span, and break out of this loop (start moving downwards) */ - if(udata->nelem < H5S__hyper_spans_nelem_helper(udata->ds_span[udata->depth]->down, udata->op_gen) + if(udata->nelem < H5S__hyper_spans_nelem_helper(udata->ds_span[udata->depth]->down, 0, udata->op_gen) * (udata->ds_span[udata->depth]->high - udata->ds_low[udata->depth] + 1)) { - if(udata->nelem >= udata->ds_span[udata->depth]->down->u.nelmts) { - if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], - udata->ds_rank - udata->depth, udata->ds_low[udata->depth], - udata->ds_low[udata->depth] + (udata->nelem / udata->ds_span[udata->depth]->down->u.nelmts) - 1, - udata->ds_span[udata->depth]->down) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") - udata->ds_low[udata->depth] += udata->nelem / udata->ds_span[udata->depth]->down->u.nelmts; - udata->nelem %= udata->ds_span[udata->depth]->down->u.nelmts; + if(udata->nelem >= udata->ds_span[udata->depth]->down->op_info[0].u.nelmts) { + if(udata->share_selection) { + if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], + udata->ds_rank - udata->depth, udata->ds_low[udata->depth], + udata->ds_low[udata->depth] + (udata->nelem / udata->ds_span[udata->depth]->down->op_info[0].u.nelmts) - 1, + udata->ds_span[udata->depth]->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + } /* end if */ + else { + /* If we're not sharing the destination space's + * spans, we must copy it first (then release it + * afterwards) */ + if(NULL == (copied_span_info = H5S__hyper_copy_span_helper(udata->ds_span[udata->depth]->down, udata->ds_rank - udata->depth, 1, udata->op_gen))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "can't copy destination spans") + if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], + udata->ds_rank - udata->depth, udata->ds_low[udata->depth], + udata->ds_low[udata->depth] + (udata->nelem / udata->ds_span[udata->depth]->down->op_info[0].u.nelmts) - 1, + copied_span_info) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + H5S__hyper_free_span_info(copied_span_info); + copied_span_info = NULL; + } /* end else */ + udata->ds_low[udata->depth] += udata->nelem / udata->ds_span[udata->depth]->down->op_info[0].u.nelmts; + udata->nelem %= udata->ds_span[udata->depth]->down->op_info[0].u.nelmts; } /* end if */ break; } /* end if */ /* Append span tree for entire span */ - if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], + if(udata->share_selection) { + if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], udata->ds_rank - udata->depth, udata->ds_low[udata->depth], udata->ds_span[udata->depth]->high, udata->ds_span[udata->depth]->down) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") - udata->nelem -= udata->ds_span[udata->depth]->down->u.nelmts + } /* end if */ + else { + /* If we're not sharing the destination space's + * spans, we must copy it first (then release it + * afterwards) */ + if(NULL == (copied_span_info = H5S__hyper_copy_span_helper(udata->ds_span[udata->depth]->down, udata->ds_rank - udata->depth, 1, udata->op_gen))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "can't copy destination spans") + if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], + udata->ds_rank - udata->depth, udata->ds_low[udata->depth], + udata->ds_span[udata->depth]->high, + copied_span_info) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + H5S__hyper_free_span_info(copied_span_info); + copied_span_info = NULL; + } /* end else */ + udata->nelem -= udata->ds_span[udata->depth]->down->op_info[0].u.nelmts * (udata->ds_span[udata->depth]->high - udata->ds_low[udata->depth] + 1); } /* end if */ } /* end if */ @@ -11065,27 +11124,59 @@ H5S__hyper_proj_int_build_proj(H5S_hyper_project_intersect_ud_t *udata) { * span and continue down */ HDassert(udata->ds_low[udata->depth] <= udata->ds_span[udata->depth]->high); - if(udata->nelem < H5S__hyper_spans_nelem_helper(udata->ds_span[udata->depth]->down, udata->op_gen) + if(udata->nelem < H5S__hyper_spans_nelem_helper(udata->ds_span[udata->depth]->down, 0, udata->op_gen) * (udata->ds_span[udata->depth]->high - udata->ds_low[udata->depth] + 1)) { - if(udata->nelem >= udata->ds_span[udata->depth]->down->u.nelmts) { - if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], - udata->ds_rank - udata->depth, udata->ds_low[udata->depth], - udata->ds_low[udata->depth] + (udata->nelem / udata->ds_span[udata->depth]->down->u.nelmts) - 1, - udata->ds_span[udata->depth]->down) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") - udata->ds_low[udata->depth] += udata->nelem / udata->ds_span[udata->depth]->down->u.nelmts; - udata->nelem %= udata->ds_span[udata->depth]->down->u.nelmts; + if(udata->nelem >= udata->ds_span[udata->depth]->down->op_info[0].u.nelmts) { + if(udata->share_selection) { + if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], + udata->ds_rank - udata->depth, udata->ds_low[udata->depth], + udata->ds_low[udata->depth] + (udata->nelem / udata->ds_span[udata->depth]->down->op_info[0].u.nelmts) - 1, + udata->ds_span[udata->depth]->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + } /* end if */ + else { + /* If we're not sharing the destination space's + * spans, we must copy it first (then release it + * afterwards) */ + if(NULL == (copied_span_info = H5S__hyper_copy_span_helper(udata->ds_span[udata->depth]->down, udata->ds_rank - udata->depth, 1, udata->op_gen))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "can't copy destination spans") + if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], + udata->ds_rank - udata->depth, udata->ds_low[udata->depth], + udata->ds_low[udata->depth] + (udata->nelem / udata->ds_span[udata->depth]->down->op_info[0].u.nelmts) - 1, + copied_span_info) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + H5S__hyper_free_span_info(copied_span_info); + copied_span_info = NULL; + } /* end else */ + udata->ds_low[udata->depth] += udata->nelem / udata->ds_span[udata->depth]->down->op_info[0].u.nelmts; + udata->nelem %= udata->ds_span[udata->depth]->down->op_info[0].u.nelmts; } /* end if */ break; } /* end if */ /* Append span tree for entire span */ - if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], + if(udata->share_selection) { + if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], udata->ds_rank - udata->depth, udata->ds_low[udata->depth], udata->ds_span[udata->depth]->high, udata->ds_span[udata->depth]->down) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") - udata->nelem -= udata->ds_span[udata->depth]->down->u.nelmts + } /* end if */ + else { + /* If we're not sharing the destination space's + * spans, we must copy it first (then release it + * afterwards) */ + if(NULL == (copied_span_info = H5S__hyper_copy_span_helper(udata->ds_span[udata->depth]->down, udata->ds_rank - udata->depth, 1, udata->op_gen))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "can't copy destination spans") + if(H5S__hyper_append_span(&udata->ps_span_info[udata->depth], + udata->ds_rank - udata->depth, udata->ds_low[udata->depth], + udata->ds_span[udata->depth]->high, + copied_span_info) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + H5S__hyper_free_span_info(copied_span_info); + copied_span_info = NULL; + } /* end else */ + udata->nelem -= udata->ds_span[udata->depth]->down->op_info[0].u.nelmts * (udata->ds_span[udata->depth]->high - udata->ds_low[udata->depth] + 1); /* Advance to next span */ @@ -11130,6 +11221,13 @@ H5S__hyper_proj_int_build_proj(H5S_hyper_project_intersect_ud_t *udata) { udata->ps_clean_bitmap = 0; done: + /* Cleanup on failure */ + if(copied_span_info) { + HDassert(ret_value < 0); + H5S__hyper_free_span_info(copied_span_info); + copied_span_info = NULL; + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_proj_int_build_proj() */ @@ -11219,7 +11317,7 @@ H5S__hyper_proj_int_iterate(const H5S_hyper_span_info_t *ss_span_info, /* Add skipped elements if there's a pre-gap */ if(ss_low < sis_low) { low = sis_low; - H5S_HYPER_PROJ_INT_ADD_SKIP(udata, H5S__hyper_spans_nelem_helper(ss_span->down, udata->op_gen) * (sis_low - ss_low), FAIL); + H5S_HYPER_PROJ_INT_ADD_SKIP(udata, H5S__hyper_spans_nelem_helper(ss_span->down, 0, udata->op_gen) * (sis_low - ss_low), FAIL); } /* end if */ else low = ss_low; @@ -11275,7 +11373,7 @@ H5S__hyper_proj_int_iterate(const H5S_hyper_span_info_t *ss_span_info, if(ss_span->high < sis_low) { /* Add skipped elements */ if(ss_span->down) - H5S_HYPER_PROJ_INT_ADD_SKIP(udata, H5S__hyper_spans_nelem_helper(ss_span->down, udata->op_gen) * (ss_span->high - ss_low + 1), FAIL); + H5S_HYPER_PROJ_INT_ADD_SKIP(udata, H5S__hyper_spans_nelem_helper(ss_span->down, 0, udata->op_gen) * (ss_span->high - ss_low + 1), FAIL); else H5S_HYPER_PROJ_INT_ADD_SKIP(udata, ss_span->high - ss_low + 1, FAIL); @@ -11297,10 +11395,10 @@ H5S__hyper_proj_int_iterate(const H5S_hyper_span_info_t *ss_span_info, if(ss_span && !((depth == 0) && (u == count - 1))) { /* Count remaining elements in ss_span_info */ if(ss_span->down) { - H5S_HYPER_PROJ_INT_ADD_SKIP(udata, H5S__hyper_spans_nelem_helper(ss_span->down, udata->op_gen) * (ss_span->high - ss_low + 1), FAIL); + H5S_HYPER_PROJ_INT_ADD_SKIP(udata, H5S__hyper_spans_nelem_helper(ss_span->down, 0, udata->op_gen) * (ss_span->high - ss_low + 1), FAIL); ss_span = ss_span->next; while(ss_span) { - H5S_HYPER_PROJ_INT_ADD_SKIP(udata, H5S__hyper_spans_nelem_helper(ss_span->down, udata->op_gen) * (ss_span->high - ss_span->low + 1), FAIL); + H5S_HYPER_PROJ_INT_ADD_SKIP(udata, H5S__hyper_spans_nelem_helper(ss_span->down, 0, udata->op_gen) * (ss_span->high - ss_span->low + 1), FAIL); ss_span = ss_span->next; } /* end while */ } /* end if */ @@ -11358,7 +11456,7 @@ H5S__hyper_proj_int_iterate(const H5S_hyper_span_info_t *ss_span_info, } /* end if */ else if(depth > 0) /* Just count skipped elements */ - H5S_HYPER_PROJ_INT_ADD_SKIP(udata, H5S__hyper_spans_nelem_helper((H5S_hyper_span_info_t *)ss_span_info, udata->op_gen) * count, FAIL); /* Casting away const OK -NAF */ + H5S_HYPER_PROJ_INT_ADD_SKIP(udata, H5S__hyper_spans_nelem_helper((H5S_hyper_span_info_t *)ss_span_info, 0, udata->op_gen) * count, FAIL); /* Casting away const OK -NAF */ /* Clean up if we are done */ if(depth == 0) { @@ -11393,11 +11491,12 @@ done: src_intersect_space within the selection of src_space as a selection within the selection of dst_space USAGE - herr_t H5S__hyper_project_intersection(src_space,dst_space,src_intersect_space,proj_space) + herr_t H5S__hyper_project_intersection(src_space,dst_space,src_intersect_space,proj_space,share_selection) H5S_t *src_space; IN: Selection that is mapped to dst_space, and intersected with src_intersect_space H5S_t *dst_space; IN: Selection that is mapped to src_space, and which contains the result H5S_t *src_intersect_space; IN: Selection whose intersection with src_space is projected to dst_space to obtain the result H5S_t *proj_space; OUT: Will contain the result (intersection of src_intersect_space and src_space projected from src_space to dst_space) after the operation + hbool_t share_selection; IN: Whether we are allowed to share structures inside dst_space with proj_space RETURNS Non-negative on success/Negative on failure. DESCRIPTION @@ -11416,7 +11515,8 @@ done: --------------------------------------------------------------------------*/ herr_t H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, - const H5S_t *src_intersect_space, H5S_t *proj_space) + const H5S_t *src_intersect_space, H5S_t *proj_space, + hbool_t share_selection) { H5S_hyper_project_intersect_ud_t udata; /* User data for subroutines */ const H5S_hyper_span_info_t *ss_span_info; @@ -11487,12 +11587,14 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "can't construct span tree for source intersect hyperslab selection") /* Initialize udata */ + /* We will use op_info[0] for nelem and op_info[1] for copied spans */ HDmemset(&udata, 0, sizeof(udata)); udata.ds_span[0] = ds_span_info->head; udata.ds_low[0] = udata.ds_span[0]->low; udata.ss_rank = H5S_GET_EXTENT_NDIMS(src_space); udata.ds_rank = H5S_GET_EXTENT_NDIMS(dst_space); udata.op_gen = H5S__hyper_get_op_gen(); + udata.share_selection = share_selection; /* Iterate over selections and build projected span tree */ if(H5S__hyper_proj_int_iterate(ss_span_info, src_intersect_space->select.sel_info.hslab->span_lst, 1, 0, &udata) < 0) diff --git a/src/H5Smpio.c b/src/H5Smpio.c index f605a8a..800913f 100644 --- a/src/H5Smpio.c +++ b/src/H5Smpio.c @@ -86,7 +86,7 @@ static herr_t H5S__mpio_span_hyper_type(const H5S_t *space, size_t elmt_size, static herr_t H5S__release_datatype(H5S_mpio_mpitype_list_t *type_list); static herr_t H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *down, size_t elmt_size, const MPI_Datatype *elmt_type, MPI_Datatype *span_type, - H5S_mpio_mpitype_list_t *type_list, uint64_t op_gen); + H5S_mpio_mpitype_list_t *type_list, unsigned op_info_i, uint64_t op_gen); /*****************************/ @@ -1007,8 +1007,10 @@ H5S__mpio_span_hyper_type(const H5S_t *space, size_t elmt_size, op_gen = H5S__hyper_get_op_gen(); /* Obtain derived MPI data type */ + /* Always use op_info[0] since we own this op_info, so there can be no + * simultaneous operations */ type_list.head = type_list.tail = NULL; - if(H5S__obtain_datatype(space->select.sel_info.hslab->span_lst, down, elmt_size, &elmt_type, &span_type, &type_list, op_gen) < 0) + if(H5S__obtain_datatype(space->select.sel_info.hslab->span_lst, down, elmt_size, &elmt_type, &span_type, &type_list, 0, op_gen) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "couldn't obtain MPI derived data type") if(MPI_SUCCESS != (mpi_code = MPI_Type_dup(span_type, new_type))) HMPI_GOTO_ERROR(FAIL, "MPI_Type_commit failed", mpi_code) @@ -1096,7 +1098,7 @@ done: static herr_t H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *down, size_t elmt_size, const MPI_Datatype *elmt_type, MPI_Datatype *span_type, - H5S_mpio_mpitype_list_t *type_list, uint64_t op_gen) + H5S_mpio_mpitype_list_t *type_list, unsigned op_info_i, uint64_t op_gen) { H5S_hyper_span_t *span; /* Hyperslab span to iterate with */ hsize_t bigio_count; /* Transition point to create derived type */ @@ -1119,7 +1121,7 @@ H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *down, bigio_count = H5_mpi_get_bigio_count(); /* Check if we've visited this span tree before */ - if(spans->op_gen != op_gen) { + if(spans->op_info[op_info_i].op_gen != op_gen) { H5S_mpio_mpitype_node_t *type_node; /* Pointer to new node in MPI data type list */ /* Allocate the initial displacement & block length buffers */ @@ -1172,7 +1174,7 @@ H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *down, /* Everything fits into integers, so cast them and use hindexed */ if(bigio_count >= outercount && large_block == FALSE) { - if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hindexed((int)outercount, blocklen, disp, *elmt_type, &spans->u.down_type))) + if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hindexed((int)outercount, blocklen, disp, *elmt_type, &spans->op_info[op_info_i].u.down_type))) HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_hindexed failed", mpi_code) } /* end if */ else { /* LARGE_DATATYPE:: Something doesn't fit into a 32 bit integer */ @@ -1190,17 +1192,17 @@ H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *down, /* Combine the current datatype that is created with this current block type */ if(0 == u) /* first iteration, there is no combined datatype yet */ - spans->u.down_type = temp_type; + spans->op_info[op_info_i].u.down_type = temp_type; else { int bl[2] = {1, 1}; MPI_Aint ds[2] = {disp[u - 1], disp[u]}; - MPI_Datatype dt[2] = {spans->u.down_type, temp_type}; + MPI_Datatype dt[2] = {spans->op_info[op_info_i].u.down_type, temp_type}; if(MPI_SUCCESS != (mpi_code = MPI_Type_create_struct(2, /* count */ bl, /* blocklength */ ds, /* stride in bytes*/ dt, /* old type */ - &spans->u.down_type))) /* new type */ + &spans->op_info[op_info_i].u.down_type))) /* new type */ HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_struct failed", mpi_code) /* Release previous temporary datatype */ @@ -1253,7 +1255,7 @@ H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *down, blocklen[outercount] = 1; /* Generate MPI datatype for next dimension down */ - if(H5S__obtain_datatype(span->down, down + 1, elmt_size, elmt_type, &down_type, type_list, op_gen) < 0) + if(H5S__obtain_datatype(span->down, down + 1, elmt_size, elmt_type, &down_type, type_list, op_info_i, op_gen) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "couldn't obtain MPI derived data type") /* Compute the number of elements to attempt in this span */ @@ -1270,7 +1272,7 @@ H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *down, /* Building the whole vector datatype */ H5_CHECK_OVERFLOW(outercount, size_t, int) - if(MPI_SUCCESS != (mpi_code = MPI_Type_create_struct((int)outercount, blocklen, disp, inner_type, &spans->u.down_type))) + if(MPI_SUCCESS != (mpi_code = MPI_Type_create_struct((int)outercount, blocklen, disp, inner_type, &spans->op_info[op_info_i].u.down_type))) HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_struct failed", mpi_code) /* Release inner node types */ @@ -1285,7 +1287,7 @@ H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *down, HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate MPI data type list node") /* Set up MPI type node */ - type_node->type = spans->u.down_type; + type_node->type = spans->op_info[op_info_i].u.down_type; type_node->next = NULL; /* Add MPI type node to list */ @@ -1297,11 +1299,11 @@ H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *down, } /* end else */ /* Remember that we've visited this span tree */ - spans->op_gen = op_gen; + spans->op_info[op_info_i].op_gen = op_gen; } /* end else */ /* Return MPI data type for span tree */ - *span_type = spans->u.down_type; + *span_type = spans->op_info[op_info_i].u.down_type; done: /* General cleanup */ diff --git a/src/H5Spkg.h b/src/H5Spkg.h index 6a78e52..2f15a74 100644 --- a/src/H5Spkg.h +++ b/src/H5Spkg.h @@ -148,6 +148,21 @@ struct H5S_hyper_span_t { struct H5S_hyper_span_t *next; /* Pointer to next span in list */ }; +/* "Operation info" struct. Used to hold temporary information during copies, + * 'adjust', 'nelem', and 'rebuild' operations, and higher level algorithms that + * generate this information. */ +typedef struct H5S_hyper_op_info_t { + uint64_t op_gen; /* Generation of the scratch info */ + union { + struct H5S_hyper_span_info_t *copied; /* Pointer to already copied span tree */ + hsize_t nelmts; /* # of elements */ + hsize_t nblocks; /* # of blocks */ +#ifdef H5_HAVE_PARALLEL + MPI_Datatype down_type; /* MPI datatype for span tree */ +#endif /* H5_HAVE_PARALLEL */ + }u; +} H5S_hyper_op_info_t; + /* Information about a list of hyperslab spans in one dimension (typedef'd in H5Sprivate.h) */ struct H5S_hyper_span_info_t { unsigned count; /* Ref. count of number of spans which share this span */ @@ -166,17 +181,10 @@ struct H5S_hyper_span_info_t { hsize_t *low_bounds; /* The smallest element selected in each dimension */ hsize_t *high_bounds; /* The largest element selected in each dimension */ - /* "Operation generation" fields */ + /* "Operation info" fields */ /* (Used during copies, 'adjust', 'nelem', and 'rebuild' operations) */ - uint64_t op_gen; /* Generation of the scratch info */ - union { - struct H5S_hyper_span_info_t *copied; /* Pointer to already copied span tree */ - hsize_t nelmts; /* # of elements */ - hsize_t nblocks; /* # of blocks */ -#ifdef H5_HAVE_PARALLEL - MPI_Datatype down_type; /* MPI datatype for span tree */ -#endif /* H5_HAVE_PARALLEL */ - }u; + /* Currently the maximum number of simultaneous operations is 2 */ + H5S_hyper_op_info_t op_info[2]; struct H5S_hyper_span_t *head; /* Pointer to the first span of list of spans in the current dimension */ struct H5S_hyper_span_t *tail; /* Pointer to the last span of list of spans in the current dimension */ @@ -378,7 +386,8 @@ H5_DLL uint64_t H5S__hyper_get_op_gen(void); H5_DLL void H5S__hyper_rebuild(H5S_t *space); H5_DLL herr_t H5S__modify_select(H5S_t *space1, H5S_seloper_t op, H5S_t *space2); H5_DLL herr_t H5S__hyper_project_intersection(const H5S_t *src_space, - const H5S_t *dst_space, const H5S_t *src_intersect_space, H5S_t *proj_space); + const H5S_t *dst_space, const H5S_t *src_intersect_space, H5S_t *proj_space, + hbool_t share_space); /* Testing functions */ #ifdef H5S_TESTING diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index 3d68de0..41c8b95 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -261,7 +261,7 @@ H5_DLL herr_t H5S_select_project_scalar(const H5S_t *space, hsize_t *offset); H5_DLL herr_t H5S_select_project_simple(const H5S_t *space, H5S_t *new_space, hsize_t *offset); H5_DLL herr_t H5S_select_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, const H5S_t *src_intersect_space, - H5S_t **new_space_ptr); + H5S_t **new_space_ptr, hbool_t share_space); H5_DLL herr_t H5S_select_subtract(H5S_t *space, H5S_t *subtract_space); /* Operations on all selections */ diff --git a/src/H5Spublic.h b/src/H5Spublic.h index a04f3c1..263a880 100644 --- a/src/H5Spublic.h +++ b/src/H5Spublic.h @@ -172,6 +172,8 @@ H5_DLL hssize_t H5Sget_select_hyper_nblocks(hid_t spaceid); H5_DLL herr_t H5Sget_select_hyper_blocklist(hid_t spaceid, hsize_t startblock, hsize_t numblocks, hsize_t buf[/*numblocks*/]); H5_DLL herr_t H5Shyper_adjust_s(hid_t space_id, const hssize_t *offset); +H5_DLL hid_t H5Sselect_project_intersection(hid_t src_space_id, + hid_t dst_space_id, hid_t src_intersect_space_id); /* Operations on dataspace selection iterators */ H5_DLL hid_t H5Ssel_iter_create(hid_t spaceid, size_t elmt_size, unsigned flags); diff --git a/src/H5Sselect.c b/src/H5Sselect.c index 1a13f2c..65a66cb 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -2533,11 +2533,12 @@ done: within the selection of dst_space USAGE - herr_t H5S_select_project_intersection(src_space,dst_space,src_intersect_space,proj_space) + herr_t H5S_select_project_intersection(src_space,dst_space,src_intersect_space,proj_space,share_selection) H5S_t *src_space; IN: Selection that is mapped to dst_space, and intersected with src_intersect_space - H5S_t *dst_space; IN: Selection that is mapped to src_space, and which contains the result + H5S_t *dst_space; IN: Selection that is mapped to src_space H5S_t *src_intersect_space; IN: Selection whose intersection with src_space is projected to dst_space to obtain the result H5S_t **new_space_ptr; OUT: Will contain the result (intersection of src_intersect_space and src_space projected from src_space to dst_space) after the operation + hbool_t share_selection; IN: Whether we are allowed to share structures inside dst_space with proj_space RETURNS Non-negative on success/Negative on failure. @@ -2555,7 +2556,8 @@ done: --------------------------------------------------------------------------*/ herr_t H5S_select_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, - const H5S_t *src_intersect_space, H5S_t **new_space_ptr) + const H5S_t *src_intersect_space, H5S_t **new_space_ptr, + hbool_t share_selection) { H5S_t *new_space = NULL; /* New dataspace constructed */ herr_t ret_value = SUCCEED; /* Return value */ @@ -2602,8 +2604,8 @@ H5S_select_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, /* Intersecting space is hyperslab selection. Call the hyperslab * routine to project to another hyperslab selection. */ - if(H5S__hyper_project_intersection(src_space, dst_space, src_intersect_space, new_space) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCLIP, FAIL, "can't project hyperslab ondot destination selection") + if(H5S__hyper_project_intersection(src_space, dst_space, src_intersect_space, new_space, share_selection) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCLIP, FAIL, "can't project hyperslab onto destination selection") } /* end else */ /* load the address of the new space into *new_space_ptr */ @@ -2621,6 +2623,75 @@ done: /*-------------------------------------------------------------------------- NAME + H5Sselect_project_intersection + + PURPOSE + Projects the intersection of of the selections of src_space_id and + src_intersect_space_id within the selection of src_space_id as a + selection within the selection of dst_space_id. Currently does not + support point selections. + + USAGE + hid_t H5Sselect_project_intersection(src_space_id,dst_space_d,src_intersect_space_id) + hid_t src_space_id; IN: Selection that is mapped to dst_space_id, and intersected with src_intersect_space_id + hid_t dst_space_id; IN: Selection that is mapped to src_space_id + hid_t src_intersect_space_id; IN: Selection whose intersection with src_space_id is projected to dst_space_id to obtain the result + + RETURNS + A dataspace with a selection equal to the intersection of + src_intersect_space_id and src_space_id projected from src_space to + dst_space on success, negative on failure. + + DESCRIPTION + Projects the intersection of of the selections of src_space and + src_intersect_space within the selection of src_space as a selection + within the selection of dst_space. The result is placed in the + selection of new_space_ptr. + + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +hid_t +H5Sselect_project_intersection(hid_t src_space_id, hid_t dst_space_id, + hid_t src_intersect_space_id) +{ + H5S_t *src_space, *dst_space, *src_intersect_space; /* Input dataspaces */ + H5S_t *proj_space = NULL; /* Output dataspace */ + hid_t ret_value; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE3("i", "iii", src_space_id, dst_space_id, src_intersect_space_id); + + /* Check args */ + if(NULL == (src_space = (H5S_t *)H5I_object_verify(src_space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "not a dataspace") + if(NULL == (dst_space = (H5S_t *)H5I_object_verify(dst_space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "not a dataspace") + if(NULL == (src_intersect_space = (H5S_t *)H5I_object_verify(src_intersect_space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "not a dataspace") + + /* Perform operation */ + if(H5S_select_project_intersection(src_space, dst_space, + src_intersect_space, &proj_space, FALSE) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTCLIP, FAIL, "can't project dataspace intersection") + + /* Atomize */ + if((ret_value = H5I_register(H5I_DATASPACE, proj_space, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace atom") + +done: + if(ret_value < 0) + if(proj_space && H5S_close(proj_space) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release dataspace") + + FUNC_LEAVE_API(ret_value) +} /* end H5Sselect_project_intersection() */ + + +/*-------------------------------------------------------------------------- + NAME H5S_select_subtract PURPOSE -- cgit v0.12 From 9191a09aa80a1ef8049d8598d98e94bf2fb36a74 Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Fri, 6 Dec 2019 14:34:56 -0600 Subject: Add RELEASE.txt note for H5Sselect_project_interesection --- release_docs/RELEASE.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 10a9596..7a237cb 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -90,6 +90,14 @@ New Features release. • h5dump will fail to display references on big-endian machines. + - Add new public function H5Sselect_project_intersection. + + This function computes the intersection between two dataspace selections + and projects that intersection into a third selection. This can be useful + for VOL developers to implement chunked or virtual datasets. + + (NAF - 2019/11/13, ID-148) + - Add new public function H5VLget_file_type. This function returns a datatype equivalent to the supplied datatype but -- cgit v0.12