From b866bbfe3a2f8b0c3e643a99aebf505bebc3418c Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Tue, 29 Nov 2016 17:45:20 -0600 Subject: Fix bugs in read/write implementation. Only seems to read/write the first element. Examples don't build correctly with make. --- examples/Makefile.am | 6 +++--- examples/h5dsm_dset_open.c | 3 --- examples/h5dsm_dset_read.c | 5 +---- examples/h5dsm_dset_write.c | 18 ++++++++++++++---- examples/h5dsm_file_open.c | 10 ++++++++++ src/H5FF.c | 12 ++++++------ src/H5FFpublic.h | 8 ++++++-- src/H5VLdaosm.c | 42 ++++++++++++++++++++++-------------------- 8 files changed, 62 insertions(+), 42 deletions(-) diff --git a/examples/Makefile.am b/examples/Makefile.am index 2bb8bf4..623e3ae 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -42,7 +42,7 @@ EXAMPLE_PROG = h5_write h5_read h5_extend_write h5_chunk_read h5_compound \ h5_vds h5_vds-exc \ h5_vds-exclim h5_vds-eiger h5_vds-simpleIO h5_vds-percival \ h5_vds-percival-unlim h5_vds-percival-unlim-maxmin \ - h5dsm_file_create h5dsm_file_open h5dsm_dset_create h5dsm_dset_open + h5dsm_file_create h5dsm_file_open h5dsm_dset_create h5dsm_dset_open \ h5dsm_dset_write h5dsm_dset_read TEST_SCRIPT=testh5cc.sh TEST_EXAMPLES_SCRIPT=$(INSTALL_SCRIPT_FILES) @@ -67,10 +67,10 @@ INSTALL_FILES = h5_write.c h5_read.c h5_extend_write.c h5_chunk_read.c \ # How to build examples, using installed version of h5cc if BUILD_PARALLEL_CONDITIONAL $(EXTRA_PROG): $(H5CC_PP) - $(H5CC_PP) $(H5CCFLAGS) $(CFLAGS) -o $@ $(srcdir)/$@.c; + $(H5CC_PP) $(H5CCFLAGS) $(CFLAGS) -luuid -o $@ $(srcdir)/$@.c; else $(EXTRA_PROG): $(H5CC) - $(H5CC) $(H5CCFLAGS) $(CFLAGS) -o $@ $(srcdir)/$@.c; + $(H5CC) $(H5CCFLAGS) $(CFLAGS) -luuid -o $@ $(srcdir)/$@.c; endif # Some examples depend on files created by other examples. diff --git a/examples/h5dsm_dset_open.c b/examples/h5dsm_dset_open.c index c45147a..18cfad8 100644 --- a/examples/h5dsm_dset_open.c +++ b/examples/h5dsm_dset_open.c @@ -37,8 +37,6 @@ int main(int argc, char *argv[]) { ERROR; if(H5Fclose(file) < 0) ERROR; - if(H5Sclose(space) < 0) - ERROR; if(H5Pclose(fapl) < 0) ERROR; @@ -53,7 +51,6 @@ error: H5Dclose_ff(dset, -1); H5TRclose(trans); H5Fclose(file); - H5Sclose(space); H5Pclose(fapl); } H5E_END_TRY; diff --git a/examples/h5dsm_dset_read.c b/examples/h5dsm_dset_read.c index aeb9d71..39af503 100644 --- a/examples/h5dsm_dset_read.c +++ b/examples/h5dsm_dset_read.c @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) { buf[i][j] = -1; /* Read data */ - if(H5Dread_ff(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) + if(H5Dread_ff(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf, trans) < 0) ERROR; /* Print buffer */ @@ -59,8 +59,6 @@ int main(int argc, char *argv[]) { ERROR; if(H5Fclose(file) < 0) ERROR; - if(H5Sclose(space) < 0) - ERROR; if(H5Pclose(fapl) < 0) ERROR; @@ -75,7 +73,6 @@ error: H5Dclose_ff(dset, -1); H5TRclose(trans); H5Fclose(file); - H5Sclose(space); H5Pclose(fapl); } H5E_END_TRY; diff --git a/examples/h5dsm_dset_write.c b/examples/h5dsm_dset_write.c index a49265d..9b45892 100644 --- a/examples/h5dsm_dset_write.c +++ b/examples/h5dsm_dset_write.c @@ -5,6 +5,7 @@ int main(int argc, char *argv[]) { uuid_t pool_uuid; char *pool_grp = "daos_tier0"; hid_t file = -1, dset = -1, trans = -1, fapl = -1; + uint64_t trans_num; int buf[4][6]; int i, j; @@ -35,6 +36,14 @@ int main(int argc, char *argv[]) { if((dset = H5Dopen_ff(file, argv[3], H5P_DEFAULT, trans)) < 0) ERROR; + /* Get next transaction */ + if(H5TRget_trans_num(trans, &trans_num) < 0) + ERROR; + if(H5TRclose(trans) < 0) + ERROR; + if((trans = H5TRcreate(file, trans_num + 1)) < 0) + ERROR; + /* Fill and print buffer */ printf("Writing data. Buffer is:\n"); for(i = 0; i < 4; i++) { @@ -46,7 +55,11 @@ int main(int argc, char *argv[]) { } /* Write data */ - if(H5Dwrite_ff(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) + if(H5Dwrite_ff(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf, trans) < 0) + ERROR; + + /* Commit transaction */ + if(H5TRcommit(trans) < 0) ERROR; /* Close */ @@ -56,8 +69,6 @@ int main(int argc, char *argv[]) { ERROR; if(H5Fclose(file) < 0) ERROR; - if(H5Sclose(space) < 0) - ERROR; if(H5Pclose(fapl) < 0) ERROR; @@ -72,7 +83,6 @@ error: H5Dclose_ff(dset, -1); H5TRclose(trans); H5Fclose(file); - H5Sclose(space); H5Pclose(fapl); } H5E_END_TRY; diff --git a/examples/h5dsm_file_open.c b/examples/h5dsm_file_open.c index 7016699..379d39f 100644 --- a/examples/h5dsm_file_open.c +++ b/examples/h5dsm_file_open.c @@ -36,5 +36,15 @@ int main(int argc, char *argv[]) { (void)MPI_Finalize(); return 0; + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + H5Pclose(fapl); + } H5E_END_TRY; + + (void)daos_fini(); + (void)MPI_Finalize(); + return 1; } diff --git a/src/H5FF.c b/src/H5FF.c index 41bba51..2495377 100644 --- a/src/H5FF.c +++ b/src/H5FF.c @@ -570,12 +570,12 @@ H5Dwrite_ff(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, if(NULL == (plist = (H5P_genplist_t *)H5I_object(dxpl_id))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") if(H5P_set(plist, H5VL_TRANS_ID, &trans_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for trans_id") + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set property value for trans_id") /* Write the data through the VOL */ if((ret_value = H5VL_dataset_write(dset->vol_obj, dset->vol_info->vol_cls, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, H5_REQUEST_NULL)) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data")= + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data") done: FUNC_LEAVE_API(ret_value) @@ -597,7 +597,7 @@ done: */ herr_t H5Dread_ff(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, - hid_t file_space_id, hid_t dxpl_id, void *buf, hid_t rcxt_id) + hid_t file_space_id, hid_t dxpl_id, void *buf, hid_t trans_id) { H5VL_object_t *dset = NULL; H5P_genplist_t *plist; /* Property list pointer */ @@ -605,7 +605,7 @@ H5Dread_ff(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, FUNC_ENTER_API(FAIL) H5TRACE7("e", "iiiii*xi", dset_id, mem_type_id, mem_space_id, file_space_id, - dxpl_id, buf, rcxt_id); + dxpl_id, buf, trans_id); if(NULL == (dset = (H5VL_object_t *)H5I_object_verify(dset_id, H5I_DATASET))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") @@ -622,8 +622,8 @@ H5Dread_ff(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, /* store the transaction ID in the dxpl */ if(NULL == (plist = (H5P_genplist_t *)H5I_object(dxpl_id))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - if(H5P_set(plist, H5VL_CONTEXT_ID, &rcxt_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for rcxt_id") + if(H5P_set(plist, H5VL_TRANS_ID, &trans_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set property value for trans_id") /* Read the data through the VOL */ if((ret_value = H5VL_dataset_read(dset->vol_obj, dset->vol_info->vol_cls, mem_type_id, mem_space_id, diff --git a/src/H5FFpublic.h b/src/H5FFpublic.h index 4ccdb01..1208f62 100644 --- a/src/H5FFpublic.h +++ b/src/H5FFpublic.h @@ -50,15 +50,19 @@ extern "C" { /* API wrappers */ H5_DLL hid_t H5Fcreate_ff(const char *filename, unsigned flags, hid_t fcpl_id, - hid_t fapl_id, hid_t *trans_id); + hid_t fapl_id, hid_t *trans_id/*out*/); H5_DLL hid_t H5Fopen_ff(const char *filename, unsigned flags, hid_t fapl_id, - hid_t *trans_id); + hid_t *trans_id/*out*/); H5_DLL herr_t H5Fclose_ff(hid_t file_id, hid_t trans_id); H5_DLL hid_t H5Dcreate_ff(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id, hid_t trans_id); H5_DLL hid_t H5Dopen_ff(hid_t loc_id, const char *name, hid_t dapl_id, hid_t trans_id); +H5_DLL herr_t H5Dwrite_ff(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, + hid_t file_space_id, hid_t dxpl_id, const void *buf, hid_t trans_id); +H5_DLL herr_t H5Dread_ff(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, + hid_t file_space_id, hid_t dxpl_id, void *buf/*out*/, hid_t trans_id); H5_DLL herr_t H5Dclose_ff(hid_t dset_id, hid_t trans_id); #endif /* H5_HAVE_EFF */ diff --git a/src/H5VLdaosm.c b/src/H5VLdaosm.c index 4f53a5b..b32ce92 100644 --- a/src/H5VLdaosm.c +++ b/src/H5VLdaosm.c @@ -1588,7 +1588,7 @@ done: /*------------------------------------------------------------------------- - * Function: H5VL_daos_dataset_read + * Function: H5VL_daosm_dataset_read * * Purpose: Reads raw data from a dataset into a buffer. * @@ -1601,7 +1601,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5VL_iod_dataset_read(void *_dset, hid_t H5_ATTR_UNUSED mem_type_id, hid_t H5_ATTR_UNUSED mem_space_id, +H5VL_daosm_dataset_read(void *_dset, hid_t H5_ATTR_UNUSED mem_type_id, hid_t H5_ATTR_UNUSED mem_space_id, hid_t H5_ATTR_UNUSED file_space_id, hid_t dxpl_id, void *buf, void H5_ATTR_UNUSED **req) { @@ -1622,20 +1622,21 @@ H5VL_iod_dataset_read(void *_dset, hid_t H5_ATTR_UNUSED mem_type_id, hid_t H5_AT size_t type_size; uint64_t chunk_size; uint8_t *p; + int ret; int i; - void *ret_value = NULL; + herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI_NOINIT /* get the transaction ID */ if(NULL == (plist = (H5P_genplist_t *)H5I_object(dxpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, NULL, "can't find object for ID"); + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID"); if(H5P_get(plist, H5VL_TRANS_ID, &trans_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get property value for trans_id"); + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for trans_id"); /* get the TR object */ if(NULL == (tr = (H5TR_t *)H5I_object_verify(trans_id, H5I_TR))) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "not a Transaction ID") + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a Transaction ID") /* Get dataspace extent */ if((ndims = H5Sget_simple_extent_ndims(dset->space_id)) < 0) @@ -1657,13 +1658,13 @@ H5VL_iod_dataset_read(void *_dset, hid_t H5_ATTR_UNUSED mem_type_id, hid_t H5_AT * starting at 0. */ HDmemset(chunk_coords, 0, sizeof(chunk_coords)); //DSMINC p = dkey_buf; - *p++ == (uint8_t)'/'; + *p++ = (uint8_t)'/'; for(i = 0; i < ndims; i++) UINT64ENCODE(p, chunk_coords[i]) /* Set up operation to write data */ /* Set up dkey */ - daos_iov_set(&dkey, dkey_buf, (daos_size_t)(1 + (ndims * sizeof(chunk_coords[0])))); + daos_iov_set(&dkey, dkey_buf, (daos_size_t)(1 + ((size_t)ndims * sizeof(chunk_coords[0])))); /* Set up recx */ recx.rx_rsize = (uint64_t)type_size; @@ -1684,15 +1685,15 @@ H5VL_iod_dataset_read(void *_dset, hid_t H5_ATTR_UNUSED mem_type_id, hid_t H5_AT /* Write data to dataset */ if(0 != (ret = daos_obj_fetch(dset->obj_oh, tr->epoch, &dkey, 1, &iod, &sgl, NULL /*maps*/, NULL /*event*/))) - HGOTO_ERROR(H5E_DATASET, H5E_READERROR, NULL, "can't read data from dataset: %d", ret) + HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read data from dataset: %d", ret) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_iod_dataset_read() */ +} /* end H5VL_daosm_dataset_read() */ /*------------------------------------------------------------------------- - * Function: H5VL_daos_dataset_write + * Function: H5VL_daosm_dataset_write * * Purpose: Writes raw data from a buffer into a dataset. * @@ -1705,7 +1706,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5VL_iod_dataset_write(void *_dset, hid_t H5_ATTR_UNUSED mem_type_id, hid_t H5_ATTR_UNUSED mem_space_id, +H5VL_daosm_dataset_write(void *_dset, hid_t H5_ATTR_UNUSED mem_type_id, hid_t H5_ATTR_UNUSED mem_space_id, hid_t H5_ATTR_UNUSED file_space_id, hid_t dxpl_id, const void *buf, void H5_ATTR_UNUSED **req) { @@ -1726,20 +1727,21 @@ H5VL_iod_dataset_write(void *_dset, hid_t H5_ATTR_UNUSED mem_type_id, hid_t H5_A size_t type_size; uint64_t chunk_size; uint8_t *p; + int ret; int i; - void *ret_value = NULL; + herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI_NOINIT /* get the transaction ID */ if(NULL == (plist = (H5P_genplist_t *)H5I_object(dxpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, NULL, "can't find object for ID"); + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID"); if(H5P_get(plist, H5VL_TRANS_ID, &trans_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get property value for trans_id"); + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for trans_id"); /* get the TR object */ if(NULL == (tr = (H5TR_t *)H5I_object_verify(trans_id, H5I_TR))) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "not a Transaction ID") + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a Transaction ID") /* Get dataspace extent */ if((ndims = H5Sget_simple_extent_ndims(dset->space_id)) < 0) @@ -1761,13 +1763,13 @@ H5VL_iod_dataset_write(void *_dset, hid_t H5_ATTR_UNUSED mem_type_id, hid_t H5_A * starting at 0. */ HDmemset(chunk_coords, 0, sizeof(chunk_coords)); //DSMINC p = dkey_buf; - *p++ == (uint8_t)'/'; + *p++ = (uint8_t)'/'; for(i = 0; i < ndims; i++) UINT64ENCODE(p, chunk_coords[i]) /* Set up operation to write data */ /* Set up dkey */ - daos_iov_set(&dkey, dkey_buf, (daos_size_t)(1 + (ndims * sizeof(chunk_coords[0])))); + daos_iov_set(&dkey, dkey_buf, (daos_size_t)(1 + ((size_t)ndims * sizeof(chunk_coords[0])))); /* Set up recx */ recx.rx_rsize = (uint64_t)type_size; @@ -1788,11 +1790,11 @@ H5VL_iod_dataset_write(void *_dset, hid_t H5_ATTR_UNUSED mem_type_id, hid_t H5_A /* Write data to dataset */ if(0 != (ret = daos_obj_update(dset->obj_oh, tr->epoch, &dkey, 1, &iod, &sgl, NULL /*event*/))) - HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, NULL, "can't write data to dataset: %d", ret) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data to dataset: %d", ret) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_iod_dataset_write() */ +} /* end H5VL_daosm_dataset_write() */ /*------------------------------------------------------------------------- -- cgit v0.12